Skip to content

Commit

Permalink
[#272]: Fix tests for Billable Services Domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruhanga committed Jul 26, 2024
1 parent 777f242 commit 8a629ab
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 32 deletions.
44 changes: 43 additions & 1 deletion api-2.4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

<properties>
<openmrsPlatformVersion>${openmrsVersion2.4}</openmrsPlatformVersion>
<datafilterVersion>2.2.0</datafilterVersion>
<billingVersion>1.1.0</billingVersion>
<stockmanagementVersion>2.0.0</stockmanagementVersion>
</properties>

<dependencies>
Expand Down Expand Up @@ -71,6 +73,46 @@
<version>${billingVersion}</version>
<scope>provided</scope>
</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>
<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>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.1</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 @@ -9,6 +9,7 @@
import org.openmrs.module.initializer.api.CsvLine;
import org.openmrs.module.initializer.api.CsvParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

@OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" })
public class BillableServiceCsvParser extends CsvParser<BillableService, BaseLineProcessor<BillableService>> {
Expand All @@ -18,7 +19,7 @@ public class BillableServiceCsvParser extends CsvParser<BillableService, BaseLin
private final BillableServicesLineProcessor billableServicesLineProcessor;

@Autowired
public BillableServiceCsvParser(IBillableItemsService billableItemsService, BillableServicesLineProcessor billableServicesLineProcessor) {
public BillableServiceCsvParser(@Qualifier("billableItemsService") IBillableItemsService billableItemsService, BillableServicesLineProcessor billableServicesLineProcessor) {
super(billableServicesLineProcessor);
this.billableItemsService = billableItemsService;
this.billableServicesLineProcessor = billableServicesLineProcessor;
Expand Down Expand Up @@ -47,7 +48,8 @@ public BillableService bootstrap(CsvLine line) throws IllegalArgumentException {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CashPointCsvParser extends CsvParser<CashPoint, BaseLineProcessor<C
private final ICashPointService iCashPointService;

@Autowired
public CashPointCsvParser(@Qualifier("iCashPointService") ICashPointService iCashPointService,
public CashPointCsvParser(@Qualifier("cashierCashPointService") ICashPointService iCashPointService,
CashPointsLineProcessor processor) {
super(processor);
this.iCashPointService = iCashPointService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ServicePricesCsvParser extends CsvParser<PaymentMode, BaseLineProce
private final IPaymentModeService paymentModeService;

@Autowired
public ServicePricesCsvParser(@Qualifier("paymentModeService") IPaymentModeService paymentModeService,
public ServicePricesCsvParser(@Qualifier("cashierPaymentModeService") IPaymentModeService paymentModeService,
ServicePricesLineProcessor processor) {
super(processor);
this.paymentModeService = paymentModeService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class BillableServiceLoaderIntegrationTest extends DomainBaseModuleContex
public void setup() {
executeDataSet("testdata/test-concepts-2.4.xml");
{
Concept concept = conceptService.getConceptByUuid("164949AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
// To be edited
Concept concept = conceptService.getConceptByUuid("3f6f6c92-8d5c-4a9e-bb1c-d3e00e4f8b71");

BillableService service = new BillableService();
service.setUuid("a0f7d8a1-4fa2-418c-aa8a-9b358f43d605");
Expand All @@ -47,6 +48,21 @@ public void setup() {
service.setServiceStatus(BillableServiceStatus.ENABLED);
billableItemsService.save(service);
}

{
// To be retired
Concept concept = conceptService.getConceptByUuid("550e8400-e29b-41d4-a716-446655440000");

BillableService service = new BillableService();
service.setUuid("16435ab4-27c3-4d91-b21e-52819bd654d8");
service.setName("Nutrition");
service.setShortName("NUC");
service.setVoided(false);
service.setConcept(concept);
service.setServiceType(concept);
service.setServiceStatus(BillableServiceStatus.ENABLED);
billableItemsService.save(service);
}
}

@Test
Expand All @@ -59,38 +75,28 @@ public void load_shouldLoadBillableServicesAccordingToCsvFiles() {
BillableService service = billableItemsService.getByUuid("44ebd6cd-04ad-4eba-8ce1-0de4564bfd17");
Assert.assertNotNull(service);
Assert.assertNotNull(service.getServiceType());
Assert.assertEquals(conceptService.getConceptByUuid("1592AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"),
service.getConcept());
Assert.assertEquals("Antenatal Care", service.getName());
Assert.assertEquals(conceptService.getConceptByUuid("d4b4b6ef-6f3e-43a4-a3b9-9c56f3a1e2d8").getId(),
service.getConcept().getId());
Assert.assertEquals(BillableServiceStatus.ENABLED, service.getServiceStatus());
}

// Verify edition
{
BillableService service = billableItemsService.getByUuid("16435ab4-27c3-4d91-b21e-52819bd654d8");
service.setName("Nutrition counseling updated");
service.setServiceStatus(BillableServiceStatus.DISABLED);
billableItemsService.save(service);

BillableService updatedService = billableItemsService.getByUuid("16435ab4-27c3-4d91-b21e-52819bd654d8");
Assert.assertEquals("Nutrition counseling updated", updatedService.getName());
Assert.assertEquals(BillableServiceStatus.DISABLED, updatedService.getServiceStatus());
BillableService service = billableItemsService.getByUuid("a0f7d8a1-4fa2-418c-aa8a-9b358f43d605");
Assert.assertNotNull(service);
Assert.assertNotNull(service.getServiceType());
Assert.assertEquals("Orthopedic Modified", service.getName());
Assert.assertEquals(conceptService.getConceptByUuid("3f6f6c92-8d5c-4a9e-bb1c-d3e00e4f8b71").getId(),
service.getConcept().getId());
Assert.assertEquals(BillableServiceStatus.DISABLED, service.getServiceStatus());
}

// Verify retirement
{
BillableService service = billableItemsService.getByUuid("16435ab4-27c3-4d91-b21e-52819bd654d8");
service.setServiceStatus(BillableServiceStatus.DISABLED);
billableItemsService.save(service);

BillableService retiredService = billableItemsService.getByUuid("16435ab4-27c3-4d91-b21e-52819bd654d8");
Assert.assertEquals(BillableServiceStatus.DISABLED, retiredService.getServiceStatus());

// Unretire the entity
retiredService.setServiceStatus(BillableServiceStatus.ENABLED);
billableItemsService.save(retiredService);
Assert.assertTrue(service.getVoided());

BillableService unretiredService = billableItemsService.getByUuid("16435ab4-27c3-4d91-b21e-52819bd654d8");
Assert.assertEquals(BillableServiceStatus.ENABLED, unretiredService.getServiceStatus());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public DomainBaseModuleContextSensitive_2_4_test() {
public void updateSearchIndex() {
// to prevent Data Filter's 'Illegal Record Access'
}

@Override
public void revertContextMocks() {

}
}
13 changes: 13 additions & 0 deletions api-2.4/src/test/resources/test-hibernate.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- Billing -->
<mapping resource="Bill.hbm.xml"/>
<mapping resource="Cashier.hbm.xml"/>
<mapping resource="SequentialReceiptNumberGenerator.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Uuid, Service Name, Short Name, Concept, Service Type, Service Status
44ebd6cd-04ad-4eba-8ce1-0de4564bfd17, Antenatal Care, ANTC, 1592AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, Antenatal Services, Enabled
a0f7d8a1-4fa2-418c-aa8a-9b358f43d605, Orthopedic Therapy Modified, OTHS Modified, 164949AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, Orthopedic Services, Enabled
16435ab4-27c3-4d91-b21e-52819bd654d8, Nutrition counseling, NUC, 1380AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, Nutrition Counselling, Enabled
Uuid, Void/Retire, Service Name, Short Name, Concept, Service Type, Service Status
44ebd6cd-04ad-4eba-8ce1-0de4564bfd17,, Antenatal Care, ANTC, d4b4b6ef-6f3e-43a4-a3b9-9c56f3a1e2d8, Antenatal Services, Enabled
a0f7d8a1-4fa2-418c-aa8a-9b358f43d605,, Orthopedic Modified, OTHS Modified, 3f6f6c92-8d5c-4a9e-bb1c-d3e00e4f8b71, Orthopedic Services, Disabled
16435ab4-27c3-4d91-b21e-52819bd654d8,true, Nutrition, NUC, 550e8400-e29b-41d4-a716-446655440000, Nutrition Services, Disabled
2 changes: 1 addition & 1 deletion api-2.4/src/test/resources/testdata/test-concepts-2.4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<concept CONCEPT_ID="6002" UUID="3f6f6c92-8d5c-4a9e-bb1c-d3e00e4f8b71" RETIRED="false" DATE_CREATED="2019-12-11 16:59:47.0" DATE_CHANGED="2019-12-11 16:59:47.0" IS_SET="false" DATATYPE_ID="3" CLASS_ID="11" CHANGED_BY="1" CREATOR="1"/>
<concept CONCEPT_ID="6003" UUID="d4b4b6ef-6f3e-43a4-a3b9-9c56f3a1e2d8" RETIRED="false" DATE_CREATED="2019-12-11 16:59:47.0" DATE_CHANGED="2019-12-11 16:59:47.0" IS_SET="false" DATATYPE_ID="3" CLASS_ID="11" CHANGED_BY="1" CREATOR="1"/>

<concept_name CONCEPT_NAME_ID="7001" CONCEPT_ID="6001" NAME="Nutrition Counselling" LOCALE="en" DATE_CREATED="2019-12-11 16:59:47.0" CREATOR="1" VOIDED="false" CONCEPT_NAME_TYPE="FULLY_SPECIFIED" LOCALE_PREFERRED="true" UUID="4421da0d-42d0-410d-8ffd-47ec6f155d8f"/>
<concept_name CONCEPT_NAME_ID="7001" CONCEPT_ID="6001" NAME="Nutrition Services" LOCALE="en" DATE_CREATED="2019-12-11 16:59:47.0" CREATOR="1" VOIDED="false" CONCEPT_NAME_TYPE="FULLY_SPECIFIED" LOCALE_PREFERRED="true" UUID="4421da0d-42d0-410d-8ffd-47ec6f155d8f"/>
<concept_name CONCEPT_NAME_ID="7002" CONCEPT_ID="6002" NAME="Orthopedic Services" LOCALE="en" DATE_CREATED="2019-12-11 16:59:47.0" CREATOR="1" VOIDED="false" CONCEPT_NAME_TYPE="FULLY_SPECIFIED" LOCALE_PREFERRED="true" UUID="276c5861-cd46-429f-9665-e067ddeca8e3"/>
<concept_name CONCEPT_NAME_ID="7003" CONCEPT_ID="6003" NAME="Antenatal Services" LOCALE="en" DATE_CREATED="2019-12-11 16:59:47.0" CREATOR="1" VOIDED="false" CONCEPT_NAME_TYPE="FULLY_SPECIFIED" LOCALE_PREFERRED="false" UUID="e2b05c0e-cd0b-4e8b-b3a1-d8eecf3babb9"/>
</dataset>

0 comments on commit 8a629ab

Please sign in to comment.