From b9496bd53bb4fdf97820a9fc775da044807f2de5 Mon Sep 17 00:00:00 2001 From: jecihjoy Date: Mon, 29 Jan 2024 00:39:33 +0300 Subject: [PATCH] Tests - wip --- .../search/EncounterSearchHandlerTest2_4.java | 56 +++++++++++++++++++ .../test/resources/encounterTestDataset.xml | 36 ++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/search/EncounterSearchHandlerTest2_4.java create mode 100644 omod-2.4/src/test/resources/encounterTestDataset.xml diff --git a/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/search/EncounterSearchHandlerTest2_4.java b/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/search/EncounterSearchHandlerTest2_4.java new file mode 100644 index 000000000..58819b7ef --- /dev/null +++ b/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/search/EncounterSearchHandlerTest2_4.java @@ -0,0 +1,56 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.search; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openmrs.Encounter; +import org.openmrs.api.EncounterService; +import org.openmrs.api.LocationService; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.web.RestTestConstants1_8; +import org.openmrs.module.webservices.rest.web.RestTestConstants1_9; +import org.openmrs.module.webservices.rest.web.v1_0.controller.RestControllerTestUtils; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.List; + +public class EncounterSearchHandlerTest2_4 extends RestControllerTestUtils { + + private static final String ENCOUNTER_TEST_INITIAL_XML = "encounterTestDataset.xml"; + + @Before + public void init() throws Exception { + service = Context.getEncounterService(); + executeDataSet(ENCOUNTER_TEST_INITIAL_XML); + } + + /** + * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getURI() + */ + + protected String getURI() { + return "encounter"; + } + + @Test + public void searchEncounter_shouldReturnEncounterForAPatient() throws Exception { + MockHttpServletRequest req = request(RequestMethod.GET, getURI()); + req.addParameter("s", "byEncounterForms"); + req.addParameter("patient", "41c6b35e-c093-11e3-be87-005056821db0"); + + SimpleObject result = deserialize(handle(req)); + List hits = result.get("results"); + Assert.assertEquals(3, hits.size()); + } +} diff --git a/omod-2.4/src/test/resources/encounterTestDataset.xml b/omod-2.4/src/test/resources/encounterTestDataset.xml new file mode 100644 index 000000000..02d1b393d --- /dev/null +++ b/omod-2.4/src/test/resources/encounterTestDataset.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file