From 76c7b4310480e3b768871c3952024495d2621286 Mon Sep 17 00:00:00 2001 From: AJAL ODORA JONATHAN <43242517+ODORA0@users.noreply.github.com> Date: Tue, 30 Jul 2024 13:00:18 +0300 Subject: [PATCH] Enhance Integration Tests --- .vscode/settings.json | 4 + .../api/CashPointLoaderIntegrationTest.java | 128 ++++++++---------- .../ServicePricesLoaderIntegrationTest.java | 92 ++++++------- .../billableserviceprices/ServicePrices.csv | 8 +- .../configuration/cashpoints/cashPoints.csv | 8 +- .../resources/testdata/test-concepts-2.4.xml | 9 ++ .../web/controller/InitializerController.java | 4 +- 7 files changed, 126 insertions(+), 127 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..08b91d7c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.configuration.updateBuildConfiguration" : "automatic", + "java.debug.settings.onBuildFailureProceed" : true +} \ No newline at end of file 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 e14e1c6e..a86cd687 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 @@ -1,17 +1,10 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ package org.openmrs.module.initializer.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; + +import org.junit.Assert; + import static org.junit.Assert.assertFalse; import org.junit.Before; @@ -38,72 +31,71 @@ public class CashPointLoaderIntegrationTest extends DomainBaseModuleContextSensi @Before public void setup() throws Exception { - executeDataSet("testdata/test-metadata.xml"); + executeDataSet("testdata/test-concepts-2.4.xml"); + { + // To be edited + Location location = locationService.getLocationByUuid("c4bb4f44-726d-11eb-9439-0242ac130002"); + + CashPoint cashPoint = new CashPoint(); + cashPoint.setUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); + cashPoint.setName("OPD Cash Point"); + cashPoint.setDescription("Opd cash point for billing"); + cashPoint.setLocation(location); + iCashPointService.save(cashPoint); + } + + { + // To be retired + Location location = locationService.getLocationByUuid("c4bb4f44-726d-11eb-9439-0242ac130003"); + + CashPoint cashPoint = new CashPoint(); + cashPoint.setUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); + cashPoint.setName("IPD Cash Point"); + cashPoint.setDescription("IPD cash point for billing"); + cashPoint.setLocation(location); + cashPoint.setRetired(false); + iCashPointService.save(cashPoint); + } } @Test - public void shouldCreateCashPointsFromCSV() { + public void load_shouldLoadCashPointsAccordingToCsvFiles() { // 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); + // Verify creation + { + CashPoint cashPoint = iCashPointService.getByUuid("8e48e0be-1a31-4bd3-a54d-ace82653f8b8"); + assertNotNull(cashPoint); + assertEquals("MCH Cash Point", cashPoint.getName()); + assertEquals("MCH cash point for billing", cashPoint.getDescription()); + assertEquals(locationService.getLocationByUuid("c4bb4f44-726d-11eb-9439-0242ac130004"), cashPoint.getLocation()); + } - CashPoint retiredCashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); - assertTrue(retiredCashPoint.getRetired()); + // Verify edition + { + CashPoint cashPoint = iCashPointService.getByUuid("54065383-b4d4-42d2-af4d-d250a1fd2590"); + assertNotNull(cashPoint); + assertEquals("OPD Cash Point Modified", cashPoint.getName()); + assertEquals("Opd cash point for billing", cashPoint.getDescription()); + assertEquals(locationService.getLocationByUuid("c4bb4f44-726d-11eb-9439-0242ac130002"), cashPoint.getLocation()); + } - // Unretire the entity - retiredCashPoint.setRetired(false); - iCashPointService.save(retiredCashPoint); + // Verify retirement + { + CashPoint cashPoint = iCashPointService.getByUuid("8e48e0be-1a31-4bd3-a54d-ace82653f8b8"); + Assert.assertTrue(cashPoint.getRetired()); + + } - CashPoint unretiredCashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); - assertFalse(unretiredCashPoint.getRetired()); + // Verify unretirement + { + CashPoint cashPoint = iCashPointService.getByUuid("c56a108f-e3c5-4881-a5e8-a796601883b9"); + cashPoint.setRetired(false); + iCashPointService.save(cashPoint); + + 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 af7086cc..3a9bbed3 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 @@ -1,12 +1,3 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ package org.openmrs.module.initializer.api; import static org.junit.Assert.assertEquals; @@ -30,54 +21,57 @@ public class ServicePricesLoaderIntegrationTest extends DomainBaseModuleContextS @Before public void setup() throws Exception { - executeDataSet("testdata/test-metadata.xml"); + executeDataSet("testdata/test-concepts-2.4.xml"); + { + // To be edited + PaymentMode paymentMode = new PaymentMode(); + paymentMode.setUuid("526bf278-ba81-4436-b867-c2f6641d060a"); + paymentMode.setName("Antenatal Cash Item"); + paymentMode.setRetired(false); + } + + { + // To be retired + PaymentMode paymentMode = new PaymentMode(); + paymentMode.setUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + paymentMode.setName("Orthopedic Cash Item"); + paymentMode.setRetired(false); + } } @Test - public void shouldCreatePaymentModesFromCSV() { + public void load_shouldLoadPaymentModesAccordingToCsvFiles() { // 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); + // Verify creation + { + PaymentMode paymentMode = paymentModeService.getByUuid("e168c141-f5fd-4eec-bd3e-633bed1c9606"); + assertNotNull(paymentMode); + assertEquals("Nutrition Cash Item", paymentMode.getName()); + } - PaymentMode retiredPaymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); - Assert.assertTrue(retiredPaymentMode.getRetired()); + // Verify edition + { + PaymentMode paymentMode = paymentModeService.getByUuid("526bf278-ba81-4436-b867-c2f6641d060a"); + assertNotNull(paymentMode); + assertEquals("Antenatal Cash Item Modified", paymentMode.getName()); + } - // Unretire the entity - retiredPaymentMode.setRetired(false); - paymentModeService.save(retiredPaymentMode); + // Verify retirement + { + PaymentMode paymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + Assert.assertTrue(paymentMode.getRetired()); + } - PaymentMode unretiredPaymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); - Assert.assertFalse(unretiredPaymentMode.getRetired()); + // Verify unretirement + { + PaymentMode paymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + paymentMode.setRetired(false); + paymentModeService.save(paymentMode); + + PaymentMode unretiredPaymentMode = paymentModeService.getByUuid("2b1b9aae-5d35-43dd-9214-3fd370fd7737"); + Assert.assertFalse(unretiredPaymentMode.getRetired()); + } } } diff --git a/api-2.4/src/test/resources/testAppDataDir/configuration/billableserviceprices/ServicePrices.csv b/api-2.4/src/test/resources/testAppDataDir/configuration/billableserviceprices/ServicePrices.csv index 09544ff0..58cb41e3 100644 --- a/api-2.4/src/test/resources/testAppDataDir/configuration/billableserviceprices/ServicePrices.csv +++ b/api-2.4/src/test/resources/testAppDataDir/configuration/billableserviceprices/ServicePrices.csv @@ -1,4 +1,4 @@ -uuid, name, price, paymentMode, item, billableService -526bf278-ba81-4436-b867-c2f6641d060a, Antenatal Cash Item, 10000, Cash, , Antenatal Care -2b1b9aae-5d35-43dd-9214-3fd370fd7737, Orthopedic Cash Item, 20000, Credit Card, ,Orthopedic Therapy -e168c141-f5fd-4eec-bd3e-633bed1c9606, Nutrition Cash Item, 15000, Mobile money, ,Nutrition counseling \ No newline at end of file +uuid, Void/Retire, name, price, paymentMode, item, billableService +526bf278-ba81-4436-b867-c2f6641d060a, , Antenatal Cash Item Modified, 10000, Cash, , Antenatal Care +2b1b9aae-5d35-43dd-9214-3fd370fd7737, true, Orthopedic Cash Item, 20000, Credit Card, ,Orthopedic Therapy +e168c141-f5fd-4eec-bd3e-633bed1c9606, , Nutrition Cash Item, 15000, Mobile money, ,Nutrition counseling \ No newline at end of file diff --git a/api-2.4/src/test/resources/testAppDataDir/configuration/cashpoints/cashPoints.csv b/api-2.4/src/test/resources/testAppDataDir/configuration/cashpoints/cashPoints.csv index 200a845e..529c96bc 100644 --- a/api-2.4/src/test/resources/testAppDataDir/configuration/cashpoints/cashPoints.csv +++ b/api-2.4/src/test/resources/testAppDataDir/configuration/cashpoints/cashPoints.csv @@ -1,4 +1,4 @@ -uuid,name,description,location -54065383-b4d4-42d2-af4d-d250a1fd2590, OPD Cash Point, Opd cash point for billing, ART Clinic -c56a108f-e3c5-4881-a5e8-a796601883b9, IPD Cash Point, IPD cash point for billing, Inpatient Ward -8e48e0be-1a31-4bd3-a54d-ace82653f8b8, MCH Cash Point, MCH cash point for billing, MCH Clinic \ No newline at end of file +uuid,Void/Retire,name,description,location +54065383-b4d4-42d2-af4d-d250a1fd2590,, OPD Cash Point Modified, Opd cash point for billing, ART Clinic +c56a108f-e3c5-4881-a5e8-a796601883b9,, IPD Cash Point, IPD cash point for billing, Inpatient Ward +8e48e0be-1a31-4bd3-a54d-ace82653f8b8,true, MCH Cash Point, MCH cash point for billing, MCH Clinic \ No newline at end of file diff --git a/api-2.4/src/test/resources/testdata/test-concepts-2.4.xml b/api-2.4/src/test/resources/testdata/test-concepts-2.4.xml index 0bd5e557..9a5c889b 100644 --- a/api-2.4/src/test/resources/testdata/test-concepts-2.4.xml +++ b/api-2.4/src/test/resources/testdata/test-concepts-2.4.xml @@ -7,4 +7,13 @@ + + + + + + + + + diff --git a/omod/src/main/java/org/openmrs/module/initializer/web/controller/InitializerController.java b/omod/src/main/java/org/openmrs/module/initializer/web/controller/InitializerController.java index f1f145be..d00d76ac 100644 --- a/omod/src/main/java/org/openmrs/module/initializer/web/controller/InitializerController.java +++ b/omod/src/main/java/org/openmrs/module/initializer/web/controller/InitializerController.java @@ -74,8 +74,8 @@ public String onPost(HttpSession httpSession, @ModelAttribute("anyRequestObject" /** * This class returns the form backing object. This can be a string, a boolean, or a normal Java - * POJO. The bean name is defined in the ModelAttribute annotation and the type can be just defined by - * the return type of this method + * POJO. The bean name is defined in the ModelAttribute annotation and the type can be just defined + * by the return type of this method */ @ModelAttribute("users") protected List getUsers() throws Exception {