Fix failing tests

This commit is contained in:
James Agnew 2017-01-14 07:55:42 -06:00
parent dbc6abc658
commit 322051a383
6 changed files with 96 additions and 32 deletions

View File

@ -382,18 +382,6 @@ class ModelScanner {
* sure that this type gets scanned as well
*/
resourceDef.populateScanAlso(myScanAlso);
/*
* See #504:
* Bundle types may not have extensions
*/
if (resourceDef.hasExtensions()) {
if (IAnyResource.class.isAssignableFrom(theClass)) {
if (!IDomainResource.class.isAssignableFrom(theClass)) {
throw new ConfigurationException("Class \"" + theClass + "\" is invalid. This resource type is not a DomainResource, it must not have extensions");
}
}
}
return resourceName;
}

View File

@ -28,8 +28,10 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IDomainResource;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.util.UrlUtil;
@ -203,6 +205,19 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
myBaseType = (Class<? extends IBaseResource>) target;
}
} while (target.equals(Object.class) == false);
/*
* See #504:
* Bundle types may not have extensions
*/
if (hasExtensions()) {
if (IAnyResource.class.isAssignableFrom(getImplementingClass())) {
if (!IDomainResource.class.isAssignableFrom(getImplementingClass())) {
throw new ConfigurationException("Class \"" + getImplementingClass() + "\" is invalid. This resource type is not a DomainResource, it must not have extensions");
}
}
}
}
@Deprecated

View File

@ -86,6 +86,18 @@ public class TokenClientParam extends BaseClientParam implements IParam {
return new TokenCriterion(getParamName(), defaultString(theSystem), convertToList(theValues));
}
@Override
public ICriterion<?> codes(String... theCodes) {
return new TokenCriterion(getParamName(), convertToList(theCodes));
}
@Override
public ICriterion<?> codes(Collection<String> theCodes) {
return new TokenCriterion(getParamName(), theCodes);
}
private List<String> convertToList(String[] theValues) {
String[] values = ObjectUtils.defaultIfNull(theValues, EMPTY_STRING_LIST);
return Arrays.asList(values);
@ -126,6 +138,17 @@ public class TokenClientParam extends BaseClientParam implements IParam {
ICriterion<TokenClientParam> code(String theIdentifier);
/**
* Creates a search criterion that matches a given system with a collection of possible
* codes (this will be used to form a comma-separated OR query) with any system value.
* The URL form of this method will create a parameter like
* <code>parameter=code1,code2</code>
*
* @param theCodes The codes
*/
ICriterion<?> codes(Collection<String> theCodes);
/**
* Creates a search criterion that matches against the given identifier (system and code if both are present, or whatever is present)
*
@ -204,6 +227,17 @@ public class TokenClientParam extends BaseClientParam implements IParam {
*/
public ICriterion<?> systemAndValues(String theSystem, Collection<String> theValues);
/**
* Creates a search criterion that matches a given system with a collection of possible
* codes (this will be used to form a comma-separated OR query) with any system value.
* The URL form of this method will create a parameter like
* <code>parameter=code1,code2</code>
*
* @param theCodes The codes
*/
ICriterion<?> codes(String...theCodes);
}
}

View File

@ -85,6 +85,10 @@ class TokenCriterion implements ICriterion<TokenClientParam>, ICriterionInternal
myValue = b.toString();
}
public TokenCriterion(String theParamName, Collection<String> theCodes) {
this(theParamName, null, theCodes);
}
@Override
public String getParameterValue(FhirContext theContext) {
return myValue;

View File

@ -2287,16 +2287,53 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
.search()
.forResource(Patient.class)
.where(BaseResource.RES_ID.exactly().systemAndValues(null, id1.getIdPart(), id2.getIdPart()))
.and(BaseResource.RES_ID.exactly().systemAndCode(null, id1.getIdPart()))
.returnBundle(Bundle.class)
.execute();
assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1));
assertThat(toUnqualifiedVersionlessIds(found), empty());
found = ourClient
.search()
.forResource(Patient.class)
.where(BaseResource.RES_ID.exactly().systemAndValues(null, id1.getIdPart(), id2.getIdPart()))
.where(BaseResource.RES_ID.exactly().systemAndValues(null, Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO")))
.returnBundle(Bundle.class)
.execute();
assertThat(toUnqualifiedVersionlessIds(found), empty());
found = ourClient
.search()
.forResource(Patient.class)
.where(BaseResource.RES_ID.exactly().systemAndCode(null, id1.getIdPart()))
.returnBundle(Bundle.class)
.execute();
assertThat(toUnqualifiedVersionlessIds(found), empty());
found = ourClient
.search()
.forResource(Patient.class)
.where(BaseResource.RES_ID.exactly().codes(id1.getIdPart(), id2.getIdPart()))
.and(BaseResource.RES_ID.exactly().code(id1.getIdPart()))
.returnBundle(Bundle.class)
.execute();
assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1));
found = ourClient
.search()
.forResource(Patient.class)
.where(BaseResource.RES_ID.exactly().codes(Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO")))
.and(BaseResource.RES_ID.exactly().code(id1.getIdPart()))
.returnBundle(Bundle.class)
.execute();
assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1));
found = ourClient
.search()
.forResource(Patient.class)
.where(BaseResource.RES_ID.exactly().codes(id1.getIdPart(), id2.getIdPart(), "FOOO"))
.returnBundle(Bundle.class)
.execute();

View File

@ -2,21 +2,7 @@ package ca.uhn.fhir.context;
import java.util.List;
import org.hl7.fhir.dstu3.model.BaseResource;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Identifier;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.Property;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseMetaType;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.dstu3.model.*;
import ca.uhn.fhir.model.api.BaseIdentifiableElement;
import ca.uhn.fhir.model.api.IElement;
@ -28,7 +14,7 @@ import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
@ResourceDef(name = "ResourceWithExtensionsA", id="0001")
public class ResourceWithExtensionsDstu3A extends Resource {
public class ResourceWithExtensionsDstu3A extends DomainResource {
/*
* NB: several unit tests depend on the structure here
@ -243,7 +229,7 @@ public class ResourceWithExtensionsDstu3A extends Resource {
}
@Override
public Resource copy() {
public DomainResource copy() {
return null;
}