Skip to content

Commit

Permalink
Additional fix of omod tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton committed May 6, 2024
1 parent 34b2292 commit 760615e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 155 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package org.openmrs.module.emrapi.web.controller;

import org.apache.poi.util.SystemOutLogger;
import org.codehaus.jackson.type.TypeReference;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.ConceptSource;
import org.openmrs.api.ConceptService;
import org.openmrs.module.emrapi.EmrApiProperties;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.mock.web.MockHttpServletRequest;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -21,11 +19,14 @@
import static org.junit.Assert.assertNull;

@org.springframework.test.context.ContextConfiguration(locations = {"classpath:moduleApplicationContext.xml"}, inheritLocations = true)
public class EmrConceptSearchControllerTest extends BaseEmrControllerTest {
public class EmrConceptSearchControllerTest extends BaseModuleWebContextSensitiveTest {

@Autowired
EmrApiProperties emrApiProperties;

@Autowired
EmrConceptSearchController conceptSearchController;

@Autowired
@Qualifier("conceptService")
private ConceptService cs;
Expand All @@ -38,14 +39,14 @@ public void setUp() throws Exception {

@Test
public void shouldSearchByName() throws Exception {
List<SimpleObject> response = deserialize(handle(newGetRequest("/rest/emrapi/concept",new Parameter[]{new Parameter("term", "Diabetes"), new Parameter("limit", "100")})), new TypeReference<List>() {});
List<SimpleObject> response = (List<SimpleObject>)conceptSearchController.search("Diabetes", 100, null);
assertEquals(2, response.size());
}


@Test
public void shouldSearchByCodeExact() throws Exception {
List<SimpleObject> response = deserialize(handle(newGetRequest("/rest/emrapi/concept",new Parameter[]{new Parameter("term", "ABC123"), new Parameter("limit", "100")})), new TypeReference<List>() {});
List<SimpleObject> response = (List<SimpleObject>)conceptSearchController.search("ABC123", 100, null);
assertEquals(1, response.size());
assertEquals("Diabetes", ((Map)response.get(0)).get("conceptName"));
Map diagnosisResponse = response.get(0);
Expand All @@ -58,7 +59,7 @@ public void shouldSearchByCodeExact() throws Exception {

@Test
public void shouldNotDoLikeSearchByCode() throws Exception {
List<SimpleObject> response = deserialize(handle(newGetRequest("/rest/emrapi/concept",new Parameter[]{new Parameter("term", "ABC12"), new Parameter("limit", "100")})), new TypeReference<List>() {});
List<SimpleObject> response = (List<SimpleObject>)conceptSearchController.search("ABC12", 100, null);
assertEquals(0, response.size());
}

Expand All @@ -72,9 +73,7 @@ public void shouldHandleEmptyListOfDiagnosesConceptSource() throws Exception {
Assert.assertNotNull(emrApiProperties.getConceptSourcesForDiagnosisSearch());
Assert.assertEquals(0, emrApiProperties.getConceptSourcesForDiagnosisSearch().size());

MockHttpServletRequest getRequest = newGetRequest("/rest/emrapi/concept",new Parameter[]{new Parameter("term", "Diabetes"), new Parameter("limit", "100")});
@SuppressWarnings("unchecked")
List<SimpleObject> response = deserialize(handle(getRequest), new TypeReference<List>() {});
List<SimpleObject> response = (List<SimpleObject>)conceptSearchController.search("Diabetes", 100, null);
Assert.assertEquals(2, response.size());

List<String> actualUuids = new ArrayList<String>();
Expand All @@ -90,7 +89,7 @@ public void shouldHandleEmptyListOfDiagnosesConceptSource() throws Exception {
Assert.assertNotNull(emrApiProperties.getConceptSourcesForDiagnosisSearch());
Assert.assertEquals(1, emrApiProperties.getConceptSourcesForDiagnosisSearch().size());

response = deserialize(handle(getRequest), new TypeReference<List>() {});
response = (List<SimpleObject>)conceptSearchController.search("Diabetes", 100, null);
Assert.assertEquals(2, response.size());

List<String> expectedUuids = new ArrayList<String>();
Expand All @@ -102,5 +101,4 @@ public void shouldHandleEmptyListOfDiagnosesConceptSource() throws Exception {
//both lists shall have the same concepts identified by the unique UUID.
Assert.assertArrayEquals(expectedUuids.toArray(), actualUuids.toArray());
}

}
1 change: 1 addition & 0 deletions omod/src/test/resources/diagnosisMetaData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<concept_set concept_set_id="7" concept_id="409" concept_set="402" creator="1" date_created="2004-08-12 00:00:00.0" sort_weight="1"></concept_set>

<global_property property="emr.concept.diagnosisSetOfSets" property_value="baef67ac-b24e-4b04-ac83-c3b994132b85" uuid="4f55827e-26fe-102b-hacb-0017a47871b3"/>
<global_property property="emrapi.conceptSourcesForDiagnosisSearch" property_value="ICD-10-WHO" uuid="4f55827e-26fe-999b-hacb-0017a47871b3"/>


</dataset>
Expand Down

0 comments on commit 760615e

Please sign in to comment.