forked from DIGI-UW/OpenELIS-Global-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DIGI-UW#1591 from Agaba-derrick/Add-Requester-Tests
Add RequestServiceTest
- Loading branch information
Showing
4 changed files
with
138 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/org/openelisglobal/requester/RequesterTypeServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/org/openelisglobal/requester/SampleRequesterServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |