Created
January 29, 2018 11:30
-
-
Save mks-d/1c66770dec80666fd395d34ed7c88a89 to your computer and use it in GitHub Desktop.
RESTWS-696: ProviderController2_0Test
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
/** | |
* 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.controller.openmrs2_0; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.openmrs.api.context.Context; | |
import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_0; | |
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; | |
import org.springframework.mock.web.MockHttpServletRequest; | |
public class ProviderController2_0Test extends MainResourceControllerTest { | |
@Before | |
public void setup() throws Exception { | |
executeDataSet(RestTestConstants2_0.PROVIDER_TEST_DATA_XML); | |
} | |
@Test | |
public void doGetAll_shouldProcessIncludeAllParameter() throws Exception { | |
// Setup | |
MockHttpServletRequest request = newGetRequest(getURI()); | |
request.setParameter("v", "custom:(uuid:ref,retired:ref)"); | |
// Replay getting all by default | |
List<?> defaultResults = deserialize(handle(request)).get("results"); | |
// Verif there shouldn't be any retired | |
Set<Boolean> retired = ((List<Map<String, Boolean>>) defaultResults) | |
.stream().map( | |
p -> p.get("retired") | |
).collect(Collectors.toSet()); | |
Assert.assertFalse(retired.contains("true")); | |
// Replay getting all | |
request.setParameter("includeAll", "true"); | |
List<String> allUuids = ((List<Map<String, String>>) deserialize(handle(request)).get("results")) | |
.stream().map( | |
p -> p.get("uuid") | |
).collect(Collectors.toList()); | |
// Verif same as service | |
Assert.assertArrayEquals(Context.getProviderService().getAllProviders(true).stream() | |
.map(p -> p.getUuid()).collect(Collectors.toList()).toArray(), allUuids.toArray()); | |
// Replay getting all non-retired | |
request.setParameter("includeAll", "false"); | |
List<String> allNonRetiredUuids = ((List<Map<String, String>>) deserialize(handle(request)).get("results")).stream() | |
.map( | |
p -> p.get("uuid") | |
).collect(Collectors.toList()); | |
List<String> defaultUuids = ((List<Map<String, String>>) defaultResults) | |
.stream().map( | |
p -> p.get("uuid") | |
).collect(Collectors.toList()); | |
// Verif same as service and same as by default | |
Assert.assertArrayEquals(Context.getProviderService().getAllProviders(false).stream().map(p -> p.getUuid()).collect(Collectors.toList()).toArray(), allNonRetiredUuids.toArray()); | |
Assert.assertArrayEquals(defaultUuids.toArray(), allNonRetiredUuids.toArray()); | |
} | |
@Override | |
public String getURI() { | |
return "provider"; | |
} | |
@Override | |
public String getUuid() { | |
return RestTestConstants2_0.PROVIDER_UUID; | |
} | |
@Override | |
public long getAllCount() { | |
return Context.getProviderService().getAllProviders(false).size(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment