From 8a9e94b4ddeee5fee5ab3d072c3faf937e1c7c36 Mon Sep 17 00:00:00 2001 From: ruhanga Date: Mon, 29 Jul 2024 14:52:58 +0300 Subject: [PATCH] Setup tests to run conviniently + formatting changes --- api-2.4/pom.xml | 58 +++---- .../api/billing/BillableServiceCsvParser.java | 87 +++++----- .../api/billing/CashPointsLineProcessor.java | 42 ++--- .../billing/ServicePricesLineProcessor.java | 70 ++++---- .../api/BillableServiceCsvParserTest.java | 1 - .../api/CashPointLoaderIntegrationTest.java | 162 +++++++++--------- .../ServicePricesLoaderIntegrationTest.java | 118 ++++++------- api-2.4/src/test/resources/log4j2.xml | 34 ++++ pom.xml | 2 +- 9 files changed, 301 insertions(+), 273 deletions(-) create mode 100644 api-2.4/src/test/resources/log4j2.xml diff --git a/api-2.4/pom.xml b/api-2.4/pom.xml index fe1eee13..7d67c37b 100644 --- a/api-2.4/pom.xml +++ b/api-2.4/pom.xml @@ -22,6 +22,20 @@ + + org.openmrs.test + openmrs-test + pom + ${openmrsPlatformVersion} + test + + + org.powermock + powermock-api-mockito2 + + + + ${project.parent.groupId} ${project.parent.artifactId}-api @@ -36,7 +50,7 @@ test test-jar - + ${project.parent.groupId} ${project.parent.artifactId}-api-2.3 @@ -75,44 +89,24 @@ - org.openmrs.module - stockmanagement-api - ${stockmanagementVersion} - test - - - org.openmrs.module - datafilter-api - ${datafilterVersion} + stockmanagement-api + ${stockmanagementVersion} test - - - org.powermock - powermock-api-mockito - 1.7.1 - - - mockito-all - org.mockito - - + + + org.openmrs.module + fhir2-api-2.5 + ${fhir2Version} test - + - org.powermock - powermock-module-junit4 - 1.7.1 + org.openmrs.module + datafilter-api + ${datafilterVersion} test - - - org.mockito - mockito-core - 1.10.19 - test - diff --git a/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/BillableServiceCsvParser.java b/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/BillableServiceCsvParser.java index bf4a6a49..46c77eef 100644 --- a/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/BillableServiceCsvParser.java +++ b/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/BillableServiceCsvParser.java @@ -13,47 +13,48 @@ @OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" }) public class BillableServiceCsvParser extends CsvParser> { - - 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); + } } diff --git a/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/CashPointsLineProcessor.java b/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/CashPointsLineProcessor.java index 825ec6c6..6b09c235 100644 --- a/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/CashPointsLineProcessor.java +++ b/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/CashPointsLineProcessor.java @@ -12,27 +12,27 @@ @OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" }) public class CashPointsLineProcessor extends BaseLineProcessor { - - 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; + } } diff --git a/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/ServicePricesLineProcessor.java b/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/ServicePricesLineProcessor.java index 80d1b674..13dc3ad9 100644 --- a/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/ServicePricesLineProcessor.java +++ b/api-2.4/src/main/java/org/openmrs/module/initializer/api/billing/ServicePricesLineProcessor.java @@ -11,39 +11,39 @@ @OpenmrsProfile(modules = { "billing:1.1.0 - 9.*" }) public class ServicePricesLineProcessor extends BaseLineProcessor { - - 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); + } + } } diff --git a/api-2.4/src/test/java/org/openmrs/module/initializer/api/BillableServiceCsvParserTest.java b/api-2.4/src/test/java/org/openmrs/module/initializer/api/BillableServiceCsvParserTest.java index 5ef4786d..0803a41c 100644 --- a/api-2.4/src/test/java/org/openmrs/module/initializer/api/BillableServiceCsvParserTest.java +++ b/api-2.4/src/test/java/org/openmrs/module/initializer/api/BillableServiceCsvParserTest.java @@ -64,7 +64,6 @@ public void bootstrap_shouldReturnNewServiceGivenUuidNotPresent() { // Verify assertNotNull(result); - assertNull(result.getId()); assertEquals(uuid, result.getUuid()); } diff --git a/api-2.4/src/test/java/org/openmrs/module/initializer/api/CashPointLoaderIntegrationTest.java b/api-2.4/src/test/java/org/openmrs/module/initializer/api/CashPointLoaderIntegrationTest.java index ae9f68ba..e14e1c6e 100644 --- a/api-2.4/src/test/java/org/openmrs/module/initializer/api/CashPointLoaderIntegrationTest.java +++ b/api-2.4/src/test/java/org/openmrs/module/initializer/api/CashPointLoaderIntegrationTest.java @@ -25,85 +25,85 @@ import org.springframework.beans.factory.annotation.Qualifier; public class CashPointLoaderIntegrationTest extends DomainBaseModuleContextSensitive_2_4_test { - - @Autowired - @Qualifier("locationService") - private LocationService locationService; - - @Autowired - private ICashPointService iCashPointService; - - @Autowired - private CashPointLoader loader; - - @Before - public void setup() throws Exception { - executeDataSet("testdata/test-metadata.xml"); - } - - @Test - public void shouldCreateCashPointsFromCSV() { - // Replay - loader.load(); - - // Verify creation for all CashPoints - CashPoint cashPoint1 = iCashPointService.getByUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); - assertNotNull(cashPoint1); - assertEquals("OPD Cash Point", cashPoint1.getName()); - assertEquals("Opd cash point for billing", cashPoint1.getDescription()); - - Location location1 = locationService.getLocation("ART Clinic"); - assertNotNull(location1); - assertEquals("ART Clinic", location1.getName()); - assertEquals(location1, cashPoint1.getLocation()); - - CashPoint cashPoint2 = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); - assertNotNull(cashPoint2); - assertEquals("IPD Cash Point", cashPoint2.getName()); - assertEquals("IPD cash point for billing", cashPoint2.getDescription()); - - Location location2 = locationService.getLocation("Inpatient Ward"); - assertNotNull(location2); - assertEquals("Inpatient Ward", location2.getName()); - assertEquals(location2, cashPoint2.getLocation()); - - CashPoint cashPoint3 = iCashPointService.getByUuid("8e48e0be-1a31-4bd3-a54d-ace82653f8b8"); - assertNotNull(cashPoint3); - assertEquals("MCH Cash Point", cashPoint3.getName()); - assertEquals("MCH cash point for billing", cashPoint3.getDescription()); - - Location location3 = locationService.getLocation("MCH Clinic"); - assertNotNull(location3); - assertEquals("MCH Clinic", location3.getName()); - assertEquals(location3, cashPoint3.getLocation()); - } - - @Test - public void shouldEditExistingCashPointFromCSV() { - // Modify an existing entity in the CSV - CashPoint cashPoint = iCashPointService.getByUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); - cashPoint.setName("OPD Cash Point Updated"); - iCashPointService.save(cashPoint); - - CashPoint updatedCashPoint = iCashPointService.getByUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); - assertEquals("OPD Cash Point Updated", updatedCashPoint.getName()); - } - - @Test - public void shouldRetireAndUnretireCashPointFromCSV() { - // Retire an existing entity in the CSV - CashPoint cashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); - cashPoint.setRetired(true); - iCashPointService.save(cashPoint); - - CashPoint retiredCashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); - assertTrue(retiredCashPoint.getRetired()); - - // Unretire the entity - retiredCashPoint.setRetired(false); - iCashPointService.save(retiredCashPoint); - - CashPoint unretiredCashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); - assertFalse(unretiredCashPoint.getRetired()); - } + + @Autowired + @Qualifier("locationService") + private LocationService locationService; + + @Autowired + private ICashPointService iCashPointService; + + @Autowired + private CashPointLoader loader; + + @Before + public void setup() throws Exception { + executeDataSet("testdata/test-metadata.xml"); + } + + @Test + public void shouldCreateCashPointsFromCSV() { + // Replay + loader.load(); + + // Verify creation for all CashPoints + CashPoint cashPoint1 = iCashPointService.getByUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); + assertNotNull(cashPoint1); + assertEquals("OPD Cash Point", cashPoint1.getName()); + assertEquals("Opd cash point for billing", cashPoint1.getDescription()); + + Location location1 = locationService.getLocation("ART Clinic"); + assertNotNull(location1); + assertEquals("ART Clinic", location1.getName()); + assertEquals(location1, cashPoint1.getLocation()); + + CashPoint cashPoint2 = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); + assertNotNull(cashPoint2); + assertEquals("IPD Cash Point", cashPoint2.getName()); + assertEquals("IPD cash point for billing", cashPoint2.getDescription()); + + Location location2 = locationService.getLocation("Inpatient Ward"); + assertNotNull(location2); + assertEquals("Inpatient Ward", location2.getName()); + assertEquals(location2, cashPoint2.getLocation()); + + CashPoint cashPoint3 = iCashPointService.getByUuid("8e48e0be-1a31-4bd3-a54d-ace82653f8b8"); + assertNotNull(cashPoint3); + assertEquals("MCH Cash Point", cashPoint3.getName()); + assertEquals("MCH cash point for billing", cashPoint3.getDescription()); + + Location location3 = locationService.getLocation("MCH Clinic"); + assertNotNull(location3); + assertEquals("MCH Clinic", location3.getName()); + assertEquals(location3, cashPoint3.getLocation()); + } + + @Test + public void shouldEditExistingCashPointFromCSV() { + // Modify an existing entity in the CSV + CashPoint cashPoint = iCashPointService.getByUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); + cashPoint.setName("OPD Cash Point Updated"); + iCashPointService.save(cashPoint); + + CashPoint updatedCashPoint = iCashPointService.getByUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); + assertEquals("OPD Cash Point Updated", updatedCashPoint.getName()); + } + + @Test + public void shouldRetireAndUnretireCashPointFromCSV() { + // Retire an existing entity in the CSV + CashPoint cashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); + cashPoint.setRetired(true); + iCashPointService.save(cashPoint); + + CashPoint retiredCashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); + assertTrue(retiredCashPoint.getRetired()); + + // Unretire the entity + retiredCashPoint.setRetired(false); + iCashPointService.save(retiredCashPoint); + + CashPoint unretiredCashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); + assertFalse(unretiredCashPoint.getRetired()); + } } diff --git a/api-2.4/src/test/java/org/openmrs/module/initializer/api/ServicePricesLoaderIntegrationTest.java b/api-2.4/src/test/java/org/openmrs/module/initializer/api/ServicePricesLoaderIntegrationTest.java index a64e1980..af7086cc 100644 --- a/api-2.4/src/test/java/org/openmrs/module/initializer/api/ServicePricesLoaderIntegrationTest.java +++ b/api-2.4/src/test/java/org/openmrs/module/initializer/api/ServicePricesLoaderIntegrationTest.java @@ -21,63 +21,63 @@ import org.springframework.beans.factory.annotation.Autowired; public class ServicePricesLoaderIntegrationTest extends DomainBaseModuleContextSensitive_2_4_test { - - @Autowired - private IPaymentModeService paymentModeService; - - @Autowired - private ServicePricesLoader loader; - - @Before - public void setup() throws Exception { - executeDataSet("testdata/test-metadata.xml"); - } - - @Test - public void shouldCreatePaymentModesFromCSV() { - // Replay - loader.load(); - - // Verify creation for all PaymentModes - PaymentMode paymentMode1 = paymentModeService.getByUuid("526bf278-ba81-4436-b867-c2f6641d060a"); - assertNotNull(paymentMode1); - assertEquals("Cash", paymentMode1.getName()); - - PaymentMode paymentMode2 = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); - assertNotNull(paymentMode2); - assertEquals("Credit Card", paymentMode2.getName()); - - PaymentMode paymentMode3 = paymentModeService.getByUuid("e168c141-f5fd-4eec-bd3e-633bed1c9606"); - assertNotNull(paymentMode3); - assertEquals("Mobile money", paymentMode3.getName()); - } - - @Test - public void shouldEditExistingPaymentModeFromCSV() { - // Modify an existing entity in the CSV - PaymentMode paymentMode = paymentModeService.getByUuid("526bf278-ba81-4436-b867-c2f6641d060a"); - paymentMode.setName("Cash Updated"); - paymentModeService.save(paymentMode); - - PaymentMode updatedPaymentMode = paymentModeService.getByUuid("526bf278-ba81-4436-b867-c2f6641d060a"); - assertEquals("Cash Updated", updatedPaymentMode.getName()); - } - - @Test - public void shouldRetireAndUnretirePaymentModeFromCSV() { - // Retire an existing entity in the CSV - PaymentMode paymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); - paymentMode.setRetired(true); - paymentModeService.save(paymentMode); - - PaymentMode retiredPaymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); - Assert.assertTrue(retiredPaymentMode.getRetired()); - - // Unretire the entity - retiredPaymentMode.setRetired(false); - paymentModeService.save(retiredPaymentMode); - - PaymentMode unretiredPaymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); - Assert.assertFalse(unretiredPaymentMode.getRetired()); - } + + @Autowired + private IPaymentModeService paymentModeService; + + @Autowired + private ServicePricesLoader loader; + + @Before + public void setup() throws Exception { + executeDataSet("testdata/test-metadata.xml"); + } + + @Test + public void shouldCreatePaymentModesFromCSV() { + // Replay + loader.load(); + + // Verify creation for all PaymentModes + PaymentMode paymentMode1 = paymentModeService.getByUuid("526bf278-ba81-4436-b867-c2f6641d060a"); + assertNotNull(paymentMode1); + assertEquals("Cash", paymentMode1.getName()); + + PaymentMode paymentMode2 = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + assertNotNull(paymentMode2); + assertEquals("Credit Card", paymentMode2.getName()); + + PaymentMode paymentMode3 = paymentModeService.getByUuid("e168c141-f5fd-4eec-bd3e-633bed1c9606"); + assertNotNull(paymentMode3); + assertEquals("Mobile money", paymentMode3.getName()); + } + + @Test + public void shouldEditExistingPaymentModeFromCSV() { + // Modify an existing entity in the CSV + PaymentMode paymentMode = paymentModeService.getByUuid("526bf278-ba81-4436-b867-c2f6641d060a"); + paymentMode.setName("Cash Updated"); + paymentModeService.save(paymentMode); + + PaymentMode updatedPaymentMode = paymentModeService.getByUuid("526bf278-ba81-4436-b867-c2f6641d060a"); + assertEquals("Cash Updated", updatedPaymentMode.getName()); + } + + @Test + public void shouldRetireAndUnretirePaymentModeFromCSV() { + // Retire an existing entity in the CSV + PaymentMode paymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + paymentMode.setRetired(true); + paymentModeService.save(paymentMode); + + PaymentMode retiredPaymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + Assert.assertTrue(retiredPaymentMode.getRetired()); + + // Unretire the entity + retiredPaymentMode.setRetired(false); + paymentModeService.save(retiredPaymentMode); + + PaymentMode unretiredPaymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + Assert.assertFalse(unretiredPaymentMode.getRetired()); + } } diff --git a/api-2.4/src/test/resources/log4j2.xml b/api-2.4/src/test/resources/log4j2.xml new file mode 100644 index 00000000..478cf73e --- /dev/null +++ b/api-2.4/src/test/resources/log4j2.xml @@ -0,0 +1,34 @@ + + + + + + + %p - %C{1}.%M(%L) |%d{ISO8601}| %m%n + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 5d151658..9b7ee033 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ 2.1.1 2.2.0 2.3.6 - 2.4.3 + 2.4.5 2.5.5 ${openmrsVersion2.1}