Skip to content

Commit

Permalink
Merge pull request DIGI-UW#1591 from Agaba-derrick/Add-Requester-Tests
Browse files Browse the repository at this point in the history
Add RequestServiceTest
  • Loading branch information
mozzy11 authored Feb 21, 2025
2 parents 5901e5e + 06b3c34 commit a8b7e10
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/test/java/org/openelisglobal/AppTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.openelisglobal.referral.service.ReferralService;
import org.openelisglobal.referral.service.ReferralSetService;
import org.openelisglobal.requester.service.RequesterTypeService;
import org.openelisglobal.requester.service.SampleRequesterService;
import org.openelisglobal.sample.service.SampleEditService;
import org.openelisglobal.sampleorganization.service.SampleOrganizationService;
import org.openelisglobal.sampleqaevent.service.SampleQaEventService;
import org.openelisglobal.siteinformation.service.SiteInformationService;
Expand Down Expand Up @@ -86,7 +86,8 @@
"org.openelisglobal.typeoftestresult", "org.openelisglobal.samplehuman", "org.openelisglobal.provider",
"org.openelisglobal.role", "org.openelisglobal.organization", "org.openelisglobal.region.service",
"org.openelisglobal.region.dao", "org.openelisglobal.program.service", "org.openelisglobal.program.dao",
"org.openelisglobal.systemuser.service", "org.openelisglobal.systemuser.daoimpl" }, excludeFilters = {
"org.openelisglobal.systemuser.service", "org.openelisglobal.systemuser.daoimpl",
"org.openelisglobal.requester.service", "org.openelisglobal.requester.daoimpl", }, excludeFilters = {
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"),
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.provider.controller.*"),
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.organization.controller.*"),
Expand Down Expand Up @@ -202,15 +203,8 @@ public SampleQaEventService sampleQaEventService() {
}

@Bean()
@Profile("test")
public SampleRequesterService sampleRequesterService() {
return mock(SampleRequesterService.class);
}

@Bean()
@Profile("test")
public RequesterTypeService requesterTypeService() {
return mock(RequesterTypeService.class);
public SampleEditService sampleEditService() {
return mock(SampleEditService.class);
}

@Bean()
Expand Down Expand Up @@ -386,6 +380,12 @@ public IStatusService iStatusService() {
return mock(IStatusService.class);
}

@Bean()
@Profile("Test")
public RequesterTypeService RequesterTypeService() {
return mock(RequesterTypeService.class);
}

@Bean()
@Profile("test")
public StatusOfSampleService statusOfSampleService() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.openelisglobal.requester;

import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openelisglobal.BaseWebContextSensitiveTest;
import org.openelisglobal.requester.service.RequesterTypeService;
import org.openelisglobal.requester.valueholder.RequesterType;
import org.springframework.beans.factory.annotation.Autowired;

public class RequesterTypeServiceTest extends BaseWebContextSensitiveTest {

@Autowired
RequesterTypeService requesterTypeService;

@Before
public void init() throws Exception {
executeDataSetWithStateManagement("testdata/requester.xml");
}

@Test
public void verifyRequesterTypeData() {
List<RequesterType> requesterTypes = requesterTypeService.getAll();
System.out.println("Requester Types in DB: " + requesterTypes.size());
requesterTypes.forEach(type -> System.out.println(type.getId() + " - " + type.getRequesterType()));

Assert.assertFalse("❌ requester_type table should not be empty!", requesterTypes.isEmpty());
}

@Test
public void getRequesterTypeByName_shouldReturnCorrectRequesterType() {
String typeName = "LABORATORY";
RequesterType requesterType = requesterTypeService.getRequesterTypeByName(typeName);
Assert.assertNotNull("Requester type should not be null", requesterType);
Assert.assertEquals("Expected requester type name to be LABORATORY", "LABORATORY",
requesterType.getRequesterType());
}

@Test
public void getAll_shouldReturnAllRequesterTypes() {
List<RequesterType> requesterTypes = requesterTypeService.getAll();
Assert.assertNotNull("Requester types list should not be null", requesterTypes);
Assert.assertTrue("Requester types list should not be empty", !requesterTypes.isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.openelisglobal.requester;

import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openelisglobal.BaseWebContextSensitiveTest;
import org.openelisglobal.requester.service.RequesterTypeService;
import org.openelisglobal.requester.service.SampleRequesterService;
import org.openelisglobal.requester.valueholder.RequesterType;
import org.openelisglobal.requester.valueholder.SampleRequester;
import org.springframework.beans.factory.annotation.Autowired;

public class SampleRequesterServiceTest extends BaseWebContextSensitiveTest {

@Autowired
SampleRequesterService sampleRequesterService;

@Autowired
RequesterTypeService requesterTypeService;

@Before
public void init() throws Exception {
executeDataSetWithStateManagement("testdata/requester.xml");
}

@Test
public void verifyTestData() {
List<SampleRequester> sampleRequesters = sampleRequesterService.getAll();
System.out.println("Sample Requesters in DB: " + sampleRequesters.size());
sampleRequesters.forEach(requester -> System.out
.println(requester.getId() + " - Sample ID: " + requester.getSampleId() + ", Requester ID: "
+ requester.getRequesterId() + ", Requester Type ID: " + requester.getRequesterTypeId()));

List<RequesterType> requesterTypes = requesterTypeService.getAll();
System.out.println("Requester Types in DB: " + requesterTypes.size());
requesterTypes.forEach(type -> System.out.println(type.getId() + " - " + type.getRequesterType()));

Assert.assertFalse("❌ sample_requester table should not be empty!", sampleRequesters.isEmpty());
Assert.assertFalse("❌ requester_type table should not be empty!", requesterTypes.isEmpty());
}

@Test
public void getRequestersForSampleId_shouldReturnCorrectRequesters() {
List<SampleRequester> requesters = sampleRequesterService.getRequestersForSampleId("1");
Assert.assertNotNull("Requesters list should not be null", requesters);
Assert.assertEquals("Expected exactly 1 requester for sample_id=1", 1, requesters.size());
}

@Test
public void getAll_shouldReturnAllRequesters() {
List<SampleRequester> requesters = sampleRequesterService.getAll();
Assert.assertNotNull("Requesters list should not be null", requesters);
Assert.assertTrue("Requesters list should not be empty", !requesters.isEmpty());
}

}
24 changes: 24 additions & 0 deletions src/test/resources/testdata/requester.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- * The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in * compliance
with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/
* * Software distributed under the License is distributed on an "AS IS" *
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the *
License for the specific language governing rights and limitations under
* the License. * * The Original Code is OpenELIS code. * * Copyright (C)
ITECH, University of Washington, Seattle WA. All Rights Reserved. -->

<dataset>
<!-- RequesterType data -->
<requester_type id="1" requester_type="LABORATORY" />
<requester_type id="2" requester_type="CLINIC" />
<requester_type id="3" requester_type="HOSPITAL" />

<!-- SampleRequester data -->
<sample_requester id="1" sample_id="1"
requester_id="3" requester_type_id="2" />
<sample_requester id="2" sample_id="2"
requester_id="2" requester_type_id="1" />
<sample_requester id="3" sample_id="3"
requester_id="1" requester_type_id="3" />
</dataset>

0 comments on commit a8b7e10

Please sign in to comment.