diff --git a/src/test/java/org/openelisglobal/AppTestConfig.java b/src/test/java/org/openelisglobal/AppTestConfig.java index 58b807c5eb..01fa6356c6 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -2,14 +2,20 @@ import static org.mockito.Mockito.mock; +import ca.uhn.fhir.context.FhirContext; import com.fasterxml.jackson.annotation.JsonInclude; import java.util.ArrayList; import java.util.List; import lombok.NonNull; +import org.apache.http.impl.client.CloseableHttpClient; import org.openelisglobal.audittrail.dao.AuditTrailService; +import org.openelisglobal.citystatezip.service.CityStateZipService; import org.openelisglobal.common.services.IStatusService; import org.openelisglobal.common.util.Versioning; +import org.openelisglobal.dataexchange.fhir.FhirConfig; +import org.openelisglobal.dataexchange.fhir.FhirUtil; import org.openelisglobal.dataexchange.fhir.service.FhirPersistanceService; +import org.openelisglobal.dataexchange.fhir.service.FhirTransformService; import org.openelisglobal.dataexchange.service.order.ElectronicOrderService; import org.openelisglobal.externalconnections.service.BasicAuthenticationDataService; import org.openelisglobal.externalconnections.service.ExternalConnectionService; @@ -21,7 +27,8 @@ import org.openelisglobal.notification.service.TestNotificationConfigService; import org.openelisglobal.observationhistory.service.ObservationHistoryService; import org.openelisglobal.observationhistorytype.service.ObservationHistoryTypeService; -import org.openelisglobal.organization.service.OrganizationService; +import org.openelisglobal.panel.service.PanelService; +import org.openelisglobal.panelitem.service.PanelItemService; import org.openelisglobal.program.service.ImmunohistochemistrySampleService; import org.openelisglobal.program.service.PathologySampleService; import org.openelisglobal.program.service.ProgramSampleService; @@ -35,9 +42,11 @@ import org.openelisglobal.sampleqaevent.service.SampleQaEventService; import org.openelisglobal.siteinformation.service.SiteInformationService; import org.openelisglobal.statusofsample.service.StatusOfSampleService; +import org.openelisglobal.systemusersection.service.SystemUserSectionService; import org.openelisglobal.test.dao.TestDAO; import org.openelisglobal.test.service.TestSectionService; import org.openelisglobal.test.service.TestServiceImpl; +import org.openelisglobal.testanalyte.service.TestAnalyteService; import org.openelisglobal.testresult.service.TestResultService; import org.openelisglobal.typeofsample.service.TypeOfSampleService; import org.openelisglobal.typeofsample.service.TypeOfSampleTestService; @@ -77,9 +86,10 @@ "org.openelisglobal.view", "org.openelisglobal.search.service", "org.openelisglobal.sample", "org.openelisglobal.sampleitem.", "org.openelisglobal.analysis", "org.openelisglobal.result.service", "org.openelisglobal.result.daoimpl", "org.openelisglobal.resultlimit", "org.openelisglobal.resultlimits", - "org.openelisglobal.typeoftestresult", "org.openelisglobal.samplehuman", - "org.openelisglobal.role", }, excludeFilters = { + "org.openelisglobal.typeoftestresult", "org.openelisglobal.samplehuman", "org.openelisglobal.role", + "org.openelisglobal.organization" }, excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"), + @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.organization.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.sample.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.dictionary.controller.*.java"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.config.*"), @@ -101,12 +111,66 @@ public LocalizationServiceImpl localise() { return mock(LocalizationServiceImpl.class); } + @Bean() + @Profile("test") + public FhirContext fhirContext() { + return mock(FhirContext.class); + } + + @Bean() + @Profile("test") + public FhirTransformService fhirTransformService() { + return mock(FhirTransformService.class); + } + + @Bean() + @Profile("test") + public PanelService panelService() { + return mock(PanelService.class); + } + + @Bean() + @Profile("test") + public PanelItemService panelItemService() { + return mock(PanelItemService.class); + } + + @Bean() + @Profile("test") + public SystemUserSectionService stemUserSectionService() { + return mock(SystemUserSectionService.class); + } + + @Bean() + @Profile("test") + public TestAnalyteService testAnalyteService() { + return mock(TestAnalyteService.class); + } + + @Bean() + @Profile("test") + public FhirUtil fhirUtil() { + return mock(FhirUtil.class); + } + + @Bean() + @Profile("test") + public FhirConfig fhirConfig() { + return mock(FhirConfig.class); + } + @Bean() @Profile("test") public LocalizationDAO localiseDao() { return mock(LocalizationDAO.class); } + @Bean() + @Profile("test") + public CloseableHttpClient cityStateZipServiceloseableHttpClient() { + return mock(CloseableHttpClient.class); + } + @Bean() @Profile("test") public ExternalConnectionService externalConnectService() { @@ -143,12 +207,6 @@ public RequesterTypeService requesterTypeService() { return mock(RequesterTypeService.class); } - @Bean() - @Profile("test") - public OrganizationService organizationService() { - return mock(OrganizationService.class); - } - @Bean() @Profile("test") public BasicAuthenticationDataService basicAuthenticationDataService() { @@ -239,6 +297,12 @@ public ReferralResultService ReferralResultService() { return mock(ReferralResultService.class); } + @Bean() + @Profile("test") + public CityStateZipService cityStateZipService() { + return mock(CityStateZipService.class); + } + @Bean() @Profile("test") public ReferralService referralService() { @@ -346,4 +410,4 @@ public void configureMessageConverters(@NonNull List> co converters.add(new StringHttpMessageConverter()); converters.add(jsonConverter()); } -} +} \ No newline at end of file diff --git a/src/test/java/org/openelisglobal/address/AddressPartServiceTest.java b/src/test/java/org/openelisglobal/address/AddressPartServiceTest.java new file mode 100644 index 0000000000..cf13752ae6 --- /dev/null +++ b/src/test/java/org/openelisglobal/address/AddressPartServiceTest.java @@ -0,0 +1,106 @@ +package org.openelisglobal.address; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.address.service.AddressPartService; +import org.openelisglobal.address.valueholder.AddressPart; +import org.springframework.beans.factory.annotation.Autowired; + +public class AddressPartServiceTest extends BaseWebContextSensitiveTest { + + @Autowired + AddressPartService partService; + + @Before + public void init() { + partService.deleteAll(partService.getAll()); + } + + @After + public void tearDown() { + partService.deleteAll(partService.getAll()); + } + + @Test + public void createAddressPart_shouldCreateAddressPart() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + partService.save(part); + + Assert.assertEquals(1, partService.getAll().size()); + Assert.assertEquals("PartName", part.getPartName()); + Assert.assertEquals("022", part.getDisplayOrder()); + } + + @Test + public void getAll_shouldGetAllAddressParts() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + partService.save(part); + + AddressPart part2 = new AddressPart(); + part2.setPartName("PartName2"); + part2.setDisplayOrder("023"); + + partService.save(part2); + + Assert.assertEquals(2, partService.getAll().size()); + + } + + @Test + public void updateAddressPart_shouldUpdateAddressPart() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + String partId = partService.insert(part); + AddressPart savedPart = partService.get(partId); + savedPart.setPartName("updatedName"); + partService.save(savedPart); + + Assert.assertEquals("updatedName", savedPart.getPartName()); + + } + + @Test + public void deleteAddressPart_shouldDeleteAddressPart() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + String partId = partService.insert(part); + AddressPart savedPart = partService.get(partId); + savedPart.setPartName("updatedName"); + partService.delete(savedPart); + + Assert.assertEquals(0, partService.getAll().size()); + + } + + @Test + public void getAddressPartByNam_shouldReturnAddressPartByName() throws Exception { + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + Assert.assertEquals(0, partService.getAll().size()); + + partService.save(part); + + Assert.assertEquals("022", part.getDisplayOrder()); + } +} diff --git a/src/test/java/org/openelisglobal/address/OrganizationAddressServiceTest.java b/src/test/java/org/openelisglobal/address/OrganizationAddressServiceTest.java new file mode 100644 index 0000000000..45a6fd62f4 --- /dev/null +++ b/src/test/java/org/openelisglobal/address/OrganizationAddressServiceTest.java @@ -0,0 +1,94 @@ + +package org.openelisglobal.address; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.address.service.AddressPartService; +import org.openelisglobal.address.service.OrganizationAddressService; +import org.openelisglobal.address.valueholder.AddressPart; +import org.openelisglobal.address.valueholder.OrganizationAddress; +import org.openelisglobal.organization.service.OrganizationService; +import org.openelisglobal.organization.valueholder.Organization; +import org.springframework.beans.factory.annotation.Autowired; + +public class OrganizationAddressServiceTest extends BaseWebContextSensitiveTest { + @Autowired + OrganizationAddressService addressService; + + @Autowired + AddressPartService partService; + + @Autowired + OrganizationService orgService; + + @Before + public void init() { + addressService.deleteAll(addressService.getAll()); + partService.deleteAll(partService.getAll()); + orgService.deleteAll(orgService.getAll()); + } + + @After + public void tearDown() { + addressService.deleteAll(addressService.getAll()); + partService.deleteAll(partService.getAll()); + orgService.deleteAll(orgService.getAll()); + } + + @Test + public void createOrganizationAdress_shouldCreateOrganisationAdress() throws Exception { + + Organization organization = new Organization(); + organization.setOrganizationName("MTN"); + organization.setIsActive("Y"); + organization.setMlsSentinelLabFlag("Y"); + String orgId = orgService.insert(organization); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + OrganizationAddress address = new OrganizationAddress(); + address.setAddressPartId(partId); + address.setOrganizationId(orgId); + address.setType("B"); + address.setValue("123"); + + Assert.assertEquals("MTN", organization.getOrganizationName()); + + addressService.save(address); + + Assert.assertEquals(1, addressService.getAll().size()); + } + + @Test + public void getAddressPartsByOrganizationId_shouldReturnAddressPartsByOrganizationId() throws Exception { + + Organization organization = new Organization(); + organization.setOrganizationName("MTN"); + organization.setIsActive("Y"); + organization.setMlsSentinelLabFlag("Y"); + String orgId = orgService.insert(organization); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + OrganizationAddress address = new OrganizationAddress(); + address.setAddressPartId(partId); + address.setOrganizationId(orgId); + address.setType("B"); + address.setValue("123"); + + addressService.save(address); + + Assert.assertEquals(1, addressService.getAddressPartsByOrganizationId(orgId).size()); + } +} diff --git a/src/test/java/org/openelisglobal/address/PersonAdressServiceTest.java b/src/test/java/org/openelisglobal/address/PersonAdressServiceTest.java new file mode 100644 index 0000000000..4d9d20101e --- /dev/null +++ b/src/test/java/org/openelisglobal/address/PersonAdressServiceTest.java @@ -0,0 +1,199 @@ +package org.openelisglobal.address; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.address.service.AddressPartService; +import org.openelisglobal.address.service.PersonAddressService; +import org.openelisglobal.address.valueholder.AddressPK; +import org.openelisglobal.address.valueholder.AddressPart; +import org.openelisglobal.address.valueholder.PersonAddress; +import org.openelisglobal.person.service.PersonService; +import org.openelisglobal.person.valueholder.Person; +import org.springframework.beans.factory.annotation.Autowired; + +public class PersonAdressServiceTest extends BaseWebContextSensitiveTest { + @Autowired + PersonAddressService pAddressService; + + @Autowired + AddressPartService partService; + + @Autowired + PersonService personService; + + @Before + public void init() { + pAddressService.deleteAll(pAddressService.getAll()); + partService.deleteAll(partService.getAll()); + personService.deleteAll(personService.getAll()); + } + + @After + @Before + public void tearDown() { + pAddressService.deleteAll(pAddressService.getAll()); + partService.deleteAll(partService.getAll()); + personService.deleteAll(personService.getAll()); + } + + @Test + public void createPersonAddress_shouldCreatePersonAddress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + pAddressService.save(personAddress); + Assert.assertEquals(1, pAddressService.getAll().size()); + Assert.assertEquals("123", personAddress.getValue()); + Assert.assertEquals("B", personAddress.getType()); + } + + @Test + public void updatePersonAddress_shouldUpdatePersonAdress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + AddressPK savedPAID = pAddressService.insert(personAddress); + PersonAddress address = pAddressService.get(savedPAID); + address.setValue("124"); + pAddressService.save(address); + + Assert.assertEquals("124", address.getValue()); + Assert.assertEquals("B", address.getType()); + } + + @Test + public void deletePersonAddress_shouldDeletePersonAddress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + PersonAddress pAddress = pAddressService.save(personAddress); + pAddressService.delete(pAddress); + + Assert.assertEquals(0, pAddressService.getAll().size()); + } + + @Test + public void insert_shouldInsertPersonAdress() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + AddressPK savedAddressPK = pAddressService.insert(personAddress); + PersonAddress address = pAddressService.get(savedAddressPK); + + Assert.assertEquals("123", address.getValue()); + Assert.assertEquals("B", address.getType()); + } + + @Test + public void getAddressPartsByPersonId_shouldAddressPartsByPersonId() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + pAddressService.insert(personAddress); + + Assert.assertEquals(1, pAddressService.getAddressPartsByPersonId(personId).size()); + } + + @Test + public void getByPersonIdAndPartId_shouldReturnPersonAdressByPersonIdAndPartId() throws Exception { + + Person person = new Person(); + String personId = personService.insert(person); + + AddressPart part = new AddressPart(); + part.setPartName("PartName"); + part.setDisplayOrder("022"); + + String partId = partService.insert(part); + + PersonAddress personAddress = new PersonAddress(); + personAddress.setAddressPartId(partId); + personAddress.setPersonId(personId); + personAddress.setType("B"); + personAddress.setValue("123"); + + Assert.assertEquals(0, pAddressService.getAll().size()); + + pAddressService.insert(personAddress); + PersonAddress address = pAddressService.getByPersonIdAndPartId(personId, partId); + + Assert.assertEquals("123", address.getValue()); + Assert.assertEquals("B", address.getType()); + } +}