Add some tests
This commit is contained in:
parent
a9cfce3615
commit
1e4a497181
|
@ -8,7 +8,9 @@ import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam;
|
|||
import ca.uhn.fhir.jpa.searchparam.extractor.PathAndRef;
|
||||
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorR4;
|
||||
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
|
||||
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
|
@ -34,6 +36,7 @@ public class SearchParamExtractorR4Test {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
|
||||
mySearchParamRegistry = new ISearchParamRegistry() {
|
||||
@Override
|
||||
public void forceRefresh() {
|
||||
|
@ -52,11 +55,12 @@ public class SearchParamExtractorR4Test {
|
|||
|
||||
@Override
|
||||
public Map<String, RuntimeSearchParam> getActiveSearchParams(String theResourceName) {
|
||||
RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName);
|
||||
Map<String, RuntimeSearchParam> sps = new HashMap<>();
|
||||
RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName);
|
||||
for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) {
|
||||
sps.put(nextSp.getName(), nextSp);
|
||||
}
|
||||
|
||||
return sps;
|
||||
}
|
||||
|
||||
|
@ -130,6 +134,21 @@ public class SearchParamExtractorR4Test {
|
|||
assertEquals("Consent/999", ((Reference) links.get(0).getRef()).getReference());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExtensionContainingReference() {
|
||||
String path = "Patient.extension('http://patext').value.as(Reference)";
|
||||
|
||||
RuntimeSearchParam sp = new RuntimeSearchParam("extpat", "Patient SP", path, RestSearchParameterTypeEnum.REFERENCE, new HashSet<>(), Sets.newHashSet("Patient"), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addExtension("http://patext", new Reference("Organization/AAA"));
|
||||
|
||||
SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry);
|
||||
List<PathAndRef> links = extractor.extractResourceLinks(patient, sp);
|
||||
assertEquals(1, links.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractComponentQuantities() {
|
||||
Observation o1 = new Observation();
|
||||
|
|
|
@ -267,6 +267,84 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithDeepChain() throws IOException {
|
||||
|
||||
SearchParameter sp = new SearchParameter();
|
||||
sp.addBase("Patient");
|
||||
sp.setStatus(Enumerations.PublicationStatus.ACTIVE);
|
||||
sp.setType(Enumerations.SearchParamType.REFERENCE);
|
||||
sp.setCode("extpatorg");
|
||||
sp.setName("extpatorg");
|
||||
sp.setExpression("Patient.extension('http://patext').value.as(Reference)");
|
||||
ourClient.create().resource(sp).execute();
|
||||
|
||||
sp = new SearchParameter();
|
||||
sp.addBase("Organization");
|
||||
sp.setStatus(Enumerations.PublicationStatus.ACTIVE);
|
||||
sp.setType(Enumerations.SearchParamType.REFERENCE);
|
||||
sp.setCode("extorgorg");
|
||||
sp.setName("extorgorg");
|
||||
sp.setExpression("Organization.extension('http://orgext').value.as(Reference)");
|
||||
ourClient.create().resource(sp).execute();
|
||||
|
||||
mySearchParamRegistry.forceRefresh();
|
||||
|
||||
Organization grandParent = new Organization();
|
||||
grandParent.setName("GRANDPARENT");
|
||||
IIdType grandParentId = ourClient.create().resource(grandParent).execute().getId().toUnqualifiedVersionless();
|
||||
|
||||
Organization parent = new Organization();
|
||||
parent.setName("PARENT");
|
||||
parent.getPartOf().setReference(grandParentId.getValue());
|
||||
parent.addExtension("http://orgext", new Reference().setReference(grandParentId.getValue()));
|
||||
IIdType parentId = ourClient.create().resource(parent).execute().getId().toUnqualifiedVersionless();
|
||||
|
||||
Organization org = new Organization();
|
||||
org.setName("ORGANIZATION");
|
||||
org.getPartOf().setReference(parentId.getValue());
|
||||
org.addExtension("http://orgext", new Reference().setReference(parentId.getValue()));
|
||||
IIdType orgId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless();
|
||||
|
||||
myCaptureQueriesListener.logSelectQueriesForCurrentThread();
|
||||
myCaptureQueriesListener.clear();
|
||||
|
||||
Patient p = new Patient();
|
||||
p.getManagingOrganization().setReference(orgId.getValue());
|
||||
p.addExtension("http://patext", new Reference().setReference(orgId.getValue()));
|
||||
String pid = ourClient.create().resource(p).execute().getId().toUnqualified().getValue();
|
||||
|
||||
List<String> idValues;
|
||||
|
||||
// Regular search param
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?organization=" + orgId.getValue());
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?organization.name=ORGANIZATION");
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?organization.partof.name=PARENT");
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?organization.partof.partof.name=GRANDPARENT");
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
// Search param on extension
|
||||
myCaptureQueriesListener.clear();
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?extpatorg=" + orgId.getValue());
|
||||
myCaptureQueriesListener.logSelectQueries();
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?extpatorg.name=ORGANIZATION");
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?extpatorg.extorgorg.name=PARENT");
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
idValues = searchAndReturnUnqualifiedIdValues(ourServerBase + "/Patient?extpatorg.extorgorg.extorgorg.name=GRANDPARENT");
|
||||
assertThat(idValues, contains(pid));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchFetchPageBeyondEnd() {
|
||||
|
@ -430,7 +508,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
@Test
|
||||
@Ignore
|
||||
public void test() throws IOException {
|
||||
HttpGet get = new HttpGet(ourServerBase + "/QuestionnaireResponse?_count=50&status=completed&questionnaire=ARIncenterAbsRecord&_lastUpdated=%3E"+UrlUtil.escapeUrlParam("=2018-01-01")+"&context.organization=O3435");
|
||||
HttpGet get = new HttpGet(ourServerBase + "/QuestionnaireResponse?_count=50&status=completed&questionnaire=ARIncenterAbsRecord&_lastUpdated=%3E" + UrlUtil.escapeUrlParam("=2018-01-01") + "&context.organization=O3435");
|
||||
ourLog.info("*** MAKING QUERY");
|
||||
ourHttpClient.execute(get);
|
||||
System.exit(0);
|
||||
|
@ -581,7 +659,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
Binary fromDB = ourClient.read().resource(Binary.class).withId(resource.toVersionless()).execute();
|
||||
assertEquals("1", fromDB.getIdElement().getVersionIdPart());
|
||||
|
||||
arr[ 0 ] = 2;
|
||||
arr[0] = 2;
|
||||
HttpPut putRequest = new HttpPut(ourServerBase + "/Binary/" + resource.getIdPart());
|
||||
putRequest.setEntity(new ByteArrayEntity(arr, ContentType.parse("dansk")));
|
||||
CloseableHttpResponse resp = ourHttpClient.execute(putRequest);
|
||||
|
@ -595,7 +673,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
fromDB = ourClient.read().resource(Binary.class).withId(resource.toVersionless()).execute();
|
||||
assertEquals("2", fromDB.getIdElement().getVersionIdPart());
|
||||
|
||||
arr[ 0 ] = 3;
|
||||
arr[0] = 3;
|
||||
fromDB.setContent(arr);
|
||||
String encoded = myFhirCtx.newJsonParser().encodeResourceToString(fromDB);
|
||||
putRequest = new HttpPut(ourServerBase + "/Binary/" + resource.getIdPart());
|
||||
|
@ -613,7 +691,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
|
||||
// Now an update with the wrong ID in the body
|
||||
|
||||
arr[ 0 ] = 4;
|
||||
arr[0] = 4;
|
||||
binary.setId("");
|
||||
encoded = myFhirCtx.newJsonParser().encodeResourceToString(binary);
|
||||
putRequest = new HttpPut(ourServerBase + "/Binary/" + resource.getIdPart());
|
||||
|
@ -667,12 +745,13 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
ourClient.registerInterceptor(new IClientInterceptor() {
|
||||
@Override
|
||||
public void interceptRequest(IHttpRequest theRequest) {
|
||||
theRequest.addHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_RETURN + "=" + Constants.HEADER_PREFER_RETURN_OPERATION_OUTCOME);
|
||||
theRequest.addHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_RETURN + "=" + Constants.HEADER_PREFER_RETURN_OPERATION_OUTCOME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interceptResponse(IHttpResponse theResponse) { // TODO Auto-generated method stu
|
||||
public void interceptResponse(IHttpResponse theResponse) { // TODO Auto-generated method stu
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
try {
|
||||
// Missing status, which is mandatory
|
||||
|
@ -869,7 +948,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateResourceReturnsOperationOutcome() throws IOException {
|
||||
String resource = "<Patient xmlns=\"http://hl7.org/fhir\"></Patient>";
|
||||
|
@ -1225,7 +1304,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
|
||||
// String response = "";
|
||||
StringBuilder b = new StringBuilder();
|
||||
char[] buf = new char[ 1000 ];
|
||||
char[] buf = new char[1000];
|
||||
while (socketInput.read(buf) != -1) {
|
||||
b.append(buf);
|
||||
}
|
||||
|
@ -5226,7 +5305,6 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private String toStr(Date theDate) {
|
||||
return new InstantDt(theDate).getValueAsString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue