Skip to content

Commit

Permalink
Enhance Integration Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ODORA0 committed Jul 30, 2024
1 parent 8a9e94b commit 76c7b43
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 127 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.configuration.updateBuildConfiguration" : "automatic",
"java.debug.settings.onBuildFailureProceed" : true
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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
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
Original file line number Diff line number Diff line change
@@ -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
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
9 changes: 9 additions & 0 deletions api-2.4/src/test/resources/testdata/test-concepts-2.4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@
<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"/>

<location LOCATION_ID="8001" UUID="c4bb4f44-726d-11eb-9439-0242ac130002" NAME="ART Clinic" DESCRIPTION="Clinic for ART patients" RETIRED="false" CREATOR="1" DATE_CREATED="2020-01-01 00:00:00.0"/>
<location LOCATION_ID="8002" UUID="c4bb4f44-726d-11eb-9439-0242ac130003" NAME="Inpatient Ward" DESCRIPTION="Ward for inpatients" RETIRED="false" CREATOR="1" DATE_CREATED="2020-01-01 00:00:00.0"/>
<location LOCATION_ID="8003" UUID="c4bb4f44-726d-11eb-9439-0242ac130004" NAME="MCH Clinic" DESCRIPTION="Clinic for maternal and child health" RETIRED="false" CREATOR="1" DATE_CREATED="2020-01-01 00:00:00.0"/>

<CASHIER_PAYMENT_MODE PAYMENT_MODE_ID="9001" UUID="526bf278-ba81-4436-b867-c2f6641d060a" NAME="Antenatal Cash Item" RETIRED="false" CREATOR="1" DATE_CREATED="2020-01-01 00:00:00.0"/>
<CASHIER_PAYMENT_MODE PAYMENT_MODE_ID="9002" UUID="2b1b9aae-5d35-43dd-9214-3fd370fd7737" NAME="Orthopedic Cash Item" RETIRED="false" CREATOR="1" DATE_CREATED="2020-01-01 00:00:00.0"/>
<CASHIER_PAYMENT_MODE PAYMENT_MODE_ID="9003" UUID="e168c141-f5fd-4eec-bd3e-633bed1c9606" NAME="Nutrition Cash Item" RETIRED="false" CREATOR="1" DATE_CREATED="2020-01-01 00:00:00.0"/>

</dataset>
Original file line number Diff line number Diff line change
Expand Up @@ -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<User> getUsers() throws Exception {
Expand Down

0 comments on commit 76c7b43

Please sign in to comment.