Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Tests for Adress Packge #1316

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 74 additions & 10 deletions src/test/java/org/openelisglobal/AppTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.*"),
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -346,4 +410,4 @@ public void configureMessageConverters(@NonNull List<HttpMessageConverter<?>> co
converters.add(new StringHttpMessageConverter());
converters.add(jsonConverter());
}
}
}
106 changes: 106 additions & 0 deletions src/test/java/org/openelisglobal/address/AddressPartServiceTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading
Loading