Resolve failing test

This commit is contained in:
James Agnew 2018-12-09 14:09:12 -05:00
parent b442982310
commit 19954fa252
2 changed files with 17 additions and 10 deletions

View File

@ -23,12 +23,10 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.ConfigurationException;
@ -52,12 +50,20 @@ import javax.annotation.Nonnull;
public class SearchMethodBinding extends BaseResourceReturningMethodBinding { public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchMethodBinding.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchMethodBinding.class);
private static final Set<String> SPECIAL_SEARCH_PARAMS;
private String myCompartmentName; private String myCompartmentName;
private String myDescription; private String myDescription;
private Integer myIdParamIndex; private Integer myIdParamIndex;
private String myQueryName; private String myQueryName;
private boolean myAllowUnknownParams; private boolean myAllowUnknownParams;
static {
HashSet<String> specialSearchParams = new HashSet<>();
specialSearchParams.add(IAnyResource.SP_RES_ID);
specialSearchParams.add(IAnyResource.SP_RES_LANGUAGE);
SPECIAL_SEARCH_PARAMS = Collections.unmodifiableSet(specialSearchParams);
}
public SearchMethodBinding(Class<? extends IBaseResource> theReturnResourceType, Method theMethod, FhirContext theContext, Object theProvider) { public SearchMethodBinding(Class<? extends IBaseResource> theReturnResourceType, Method theMethod, FhirContext theContext, Object theProvider) {
super(theReturnResourceType, theMethod, theContext, theProvider); super(theReturnResourceType, theMethod, theContext, theProvider);
Search search = theMethod.getAnnotation(Search.class); Search search = theMethod.getAnnotation(Search.class);
@ -211,7 +217,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
} }
} }
for (String next : theRequest.getParameters().keySet()) { for (String next : theRequest.getParameters().keySet()) {
if (next.startsWith("_")) { if (next.startsWith("_") && !SPECIAL_SEARCH_PARAMS.contains(next)) {
methodParamsTemp.add(next); methodParamsTemp.add(next);
} }
} }

View File

@ -13,6 +13,7 @@ import ca.uhn.fhir.util.TestUtil;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Observation;
@ -237,7 +238,7 @@ public class HashMapResourceProviderTest {
Bundle resp = ourClient Bundle resp = ourClient
.search() .search()
.forResource("Patient") .forResource("Patient")
.where(Patient.RES_ID.exactly().codes("2", "3")) .where(IAnyResource.RES_ID.exactly().codes("2", "3"))
.returnBundle(Bundle.class).execute(); .returnBundle(Bundle.class).execute();
assertEquals(2, resp.getTotal()); assertEquals(2, resp.getTotal());
assertEquals(2, resp.getEntry().size()); assertEquals(2, resp.getEntry().size());
@ -248,8 +249,8 @@ public class HashMapResourceProviderTest {
resp = ourClient resp = ourClient
.search() .search()
.forResource("Patient") .forResource("Patient")
.where(Patient.RES_ID.exactly().codes("2", "3")) .where(IAnyResource.RES_ID.exactly().codes("2", "3"))
.where(Patient.RES_ID.exactly().codes("2", "3")) .where(IAnyResource.RES_ID.exactly().codes("2", "3"))
.returnBundle(Bundle.class).execute(); .returnBundle(Bundle.class).execute();
assertEquals(2, resp.getTotal()); assertEquals(2, resp.getTotal());
assertEquals(2, resp.getEntry().size()); assertEquals(2, resp.getEntry().size());
@ -259,8 +260,8 @@ public class HashMapResourceProviderTest {
resp = ourClient resp = ourClient
.search() .search()
.forResource("Patient") .forResource("Patient")
.where(Patient.RES_ID.exactly().codes("2", "3")) .where(IAnyResource.RES_ID.exactly().codes("2", "3"))
.where(Patient.RES_ID.exactly().codes("4", "3")) .where(IAnyResource.RES_ID.exactly().codes("4", "3"))
.returnBundle(Bundle.class).execute(); .returnBundle(Bundle.class).execute();
respIds = resp.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList()); respIds = resp.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList());
assertThat(respIds, containsInAnyOrder("Patient/3")); assertThat(respIds, containsInAnyOrder("Patient/3"));