Skip to content

Commit

Permalink
Setup tests to run conviniently + formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruhanga committed Jul 29, 2024
1 parent b1b9dc5 commit 8a9e94b
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 273 deletions.
58 changes: 26 additions & 32 deletions api-2.4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
</properties>

<dependencies>
<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<version>${openmrsPlatformVersion}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
Expand All @@ -36,7 +50,7 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api-2.3</artifactId>
Expand Down Expand Up @@ -75,44 +89,24 @@
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>stockmanagement-api</artifactId>
<version>${stockmanagementVersion}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>datafilter-api</artifactId>
<version>${datafilterVersion}</version>
<artifactId>stockmanagement-api</artifactId>
<version>${stockmanagementVersion}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.7.1</version>
<exclusions>
<exclusion>
<artifactId>mockito-all</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
</exclusions>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>fhir2-api-2.5</artifactId>
<version>${fhir2Version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.1</version>
<groupId>org.openmrs.module</groupId>
<artifactId>datafilter-api</artifactId>
<version>${datafilterVersion}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,48 @@

@OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" })
public class BillableServiceCsvParser extends CsvParser<BillableService, BaseLineProcessor<BillableService>> {

private final IBillableItemsService billableItemsService;

private final BillableServicesLineProcessor billableServicesLineProcessor;

@Autowired
public BillableServiceCsvParser(@Qualifier("billableItemsService") IBillableItemsService billableItemsService, BillableServicesLineProcessor billableServicesLineProcessor) {
super(billableServicesLineProcessor);
this.billableItemsService = billableItemsService;
this.billableServicesLineProcessor = billableServicesLineProcessor;
}

@Override
public Domain getDomain() {
return Domain.BILLABLE_SERVICES;
}

@Override
public BillableService bootstrap(CsvLine line) throws IllegalArgumentException {
String uuid = line.getUuid();

BillableService billableService = billableItemsService.getByUuid(uuid);

if (billableService == null) {
billableService = new BillableService();
if (!StringUtils.isEmpty(uuid)) {
billableService.setUuid(uuid);
}
}

return billableService;
}

@Override
public BillableService save(BillableService instance) {
return billableItemsService.save(instance);
}

@Override
protected void setLineProcessors(String version) {
lineProcessors.clear();
lineProcessors.add(billableServicesLineProcessor);
}

private final IBillableItemsService billableItemsService;

private final BillableServicesLineProcessor billableServicesLineProcessor;

@Autowired
public BillableServiceCsvParser(@Qualifier("billableItemsService") IBillableItemsService billableItemsService,
BillableServicesLineProcessor billableServicesLineProcessor) {
super(billableServicesLineProcessor);
this.billableItemsService = billableItemsService;
this.billableServicesLineProcessor = billableServicesLineProcessor;
}

@Override
public Domain getDomain() {
return Domain.BILLABLE_SERVICES;
}

@Override
public BillableService bootstrap(CsvLine line) throws IllegalArgumentException {
String uuid = line.getUuid();

BillableService billableService = billableItemsService.getByUuid(uuid);

if (billableService == null) {
billableService = new BillableService();
if (!StringUtils.isEmpty(uuid)) {
billableService.setUuid(uuid);
}
}

return billableService;
}

@Override
public BillableService save(BillableService instance) {
return billableItemsService.save(instance);
}

@Override
protected void setLineProcessors(String version) {
lineProcessors.clear();
lineProcessors.add(billableServicesLineProcessor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@

@OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" })
public class CashPointsLineProcessor extends BaseLineProcessor<CashPoint> {

protected static final String HEADER_DESCRIPTION = "description";

protected static final String HEADER_LOCATION = "location";

private final LocationService locationService;

@Autowired
public CashPointsLineProcessor(@Qualifier("locationService") LocationService locationService) {
super();
this.locationService = locationService;
}

@Override
public CashPoint fill(CashPoint cashPoint, CsvLine line) throws IllegalArgumentException {
cashPoint.setUuid(line.get(HEADER_UUID, true));
cashPoint.setName(line.get(HEADER_NAME, true));
cashPoint.setDescription(line.getString(HEADER_DESCRIPTION));
protected static final String HEADER_DESCRIPTION = "description";
protected static final String HEADER_LOCATION = "location";
private final LocationService locationService;
@Autowired
public CashPointsLineProcessor(@Qualifier("locationService") LocationService locationService) {
super();
this.locationService = locationService;
}
@Override
public CashPoint fill(CashPoint cashPoint, CsvLine line) throws IllegalArgumentException {
cashPoint.setUuid(line.get(HEADER_UUID, true));
cashPoint.setName(line.get(HEADER_NAME, true));
cashPoint.setDescription(line.getString(HEADER_DESCRIPTION));
String location = line.getString(HEADER_LOCATION);
cashPoint.setLocation(Utils.fetchLocation(location, locationService));

return cashPoint;
}
return cashPoint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@

@OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" })
public class ServicePricesLineProcessor extends BaseLineProcessor<PaymentMode> {
protected static final String HEADER_PRICE = "price";
protected static final String HEADER_PAYMENT_MODE = "paymentMode";
protected static final String HEADER_ITEM = "item";
protected static final String HEADER_BILLABLE_SERVICE = "billableService";
private final ConceptService conceptService;
@Autowired
public ServicePricesLineProcessor(@Qualifier("conceptService") ConceptService conceptService) {
super();
this.conceptService = conceptService;
}
@Override
public PaymentMode fill(PaymentMode paymentMode, CsvLine line) throws IllegalArgumentException {
paymentMode.setUuid(line.get(HEADER_UUID, true));
paymentMode.setName(line.get(HEADER_NAME, true));
processAttribute(line, HEADER_PRICE, paymentMode);
processAttribute(line, HEADER_PAYMENT_MODE, paymentMode);
processAttribute(line, HEADER_ITEM, paymentMode);
processAttribute(line, HEADER_BILLABLE_SERVICE, paymentMode);
return paymentMode;
}
private void processAttribute(CsvLine line, String header, PaymentMode paymentMode) {
String value = line.getString(header);
if (StringUtils.isNotBlank(value)) {
paymentMode.addAttributeType(header, "String", null, false);
}
}
protected static final String HEADER_PRICE = "price";
protected static final String HEADER_PAYMENT_MODE = "paymentMode";
protected static final String HEADER_ITEM = "item";
protected static final String HEADER_BILLABLE_SERVICE = "billableService";
private final ConceptService conceptService;
@Autowired
public ServicePricesLineProcessor(@Qualifier("conceptService") ConceptService conceptService) {
super();
this.conceptService = conceptService;
}
@Override
public PaymentMode fill(PaymentMode paymentMode, CsvLine line) throws IllegalArgumentException {
paymentMode.setUuid(line.get(HEADER_UUID, true));
paymentMode.setName(line.get(HEADER_NAME, true));
processAttribute(line, HEADER_PRICE, paymentMode);
processAttribute(line, HEADER_PAYMENT_MODE, paymentMode);
processAttribute(line, HEADER_ITEM, paymentMode);
processAttribute(line, HEADER_BILLABLE_SERVICE, paymentMode);
return paymentMode;
}
private void processAttribute(CsvLine line, String header, PaymentMode paymentMode) {
String value = line.getString(header);
if (StringUtils.isNotBlank(value)) {
paymentMode.addAttributeType(header, "String", null, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void bootstrap_shouldReturnNewServiceGivenUuidNotPresent() {

// Verify
assertNotNull(result);
assertNull(result.getId());
assertEquals(uuid, result.getUuid());
}

Expand Down
Loading

0 comments on commit 8a9e94b

Please sign in to comment.