Merge branch 'master' of github.com:jamesagnew/hapi-fhir
This commit is contained in:
commit
153c3ac5aa
|
@ -12,6 +12,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
|
@ -1111,40 +1112,13 @@ public class TagMethodProvider
|
|||
|
||||
//START SNIPPET: transaction
|
||||
@Transaction
|
||||
public List<IResource> transaction(@TransactionParam List<IResource> theResources) {
|
||||
// theResources will contain a complete bundle of all resources to persist
|
||||
// in a single transaction
|
||||
for (IResource next : theResources) {
|
||||
InstantDt deleted = (InstantDt) next.getResourceMetadata().get(ResourceMetadataKeyEnum.DELETED_AT);
|
||||
if (deleted != null && deleted.isEmpty() == false) {
|
||||
// delete this resource
|
||||
} else {
|
||||
// create or update this resource
|
||||
}
|
||||
public Bundle transaction(@TransactionParam Bundle theInput) {
|
||||
for (BundleEntry nextEntry : theInput.getEntries()) {
|
||||
// Process entry
|
||||
}
|
||||
|
||||
// According to the specification, a bundle must be returned. This bundle will contain
|
||||
// all of the created/updated/deleted resources, including their new/updated identities.
|
||||
//
|
||||
// The returned list must be the exact same size as the list of resources
|
||||
// passed in, and it is acceptable to return the same list instance that was
|
||||
// passed in.
|
||||
List<IResource> retVal = new ArrayList<IResource>(theResources);
|
||||
for (IResource next : theResources) {
|
||||
/*
|
||||
* Populate each returned resource with the new ID for that resource,
|
||||
* including the new version if the server supports versioning.
|
||||
*/
|
||||
IdDt newId = new IdDt("Patient", "1", "2");
|
||||
next.setId(newId);
|
||||
}
|
||||
|
||||
// If wanted, you may optionally also return an OperationOutcome resource
|
||||
// If present, the OperationOutcome must come first in the returned list.
|
||||
OperationOutcome oo = new OperationOutcome();
|
||||
oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Completed successfully");
|
||||
retVal.add(0, oo);
|
||||
|
||||
Bundle retVal = new Bundle();
|
||||
// Populate return bundle
|
||||
return retVal;
|
||||
}
|
||||
//END SNIPPET: transaction
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
package ca.uhn.fhir.context;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2016 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
package ca.uhn.fhir.context;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2016 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
|
|
|
@ -97,7 +97,7 @@ public abstract class BasePrimitive<T> extends BaseIdentifiableElement implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public IPrimitiveType<T> setValue(T theValue) throws DataFormatException {
|
||||
public BasePrimitive<T> setValue(T theValue) throws DataFormatException {
|
||||
myCoercedValue = theValue;
|
||||
updateStringValue();
|
||||
return this;
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.commons.lang3.Validate;
|
|||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
||||
import org.hl7.fhir.instance.model.api.IBaseElement;
|
||||
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
||||
import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
|
||||
import org.hl7.fhir.instance.model.api.IBaseMetaType;
|
||||
|
@ -65,6 +66,7 @@ import ca.uhn.fhir.context.RuntimeChildNarrativeDefinition;
|
|||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.IIdentifiableElement;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
|
@ -105,10 +107,10 @@ public abstract class BaseParser implements IParser {
|
|||
}
|
||||
|
||||
protected Iterable<CompositeChildElement> compositeChildIterator(IBase theCompositeElement, final boolean theContainedResource, final CompositeChildElement theParent) {
|
||||
|
||||
|
||||
BaseRuntimeElementCompositeDefinition<?> elementDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(theCompositeElement.getClass());
|
||||
final List<BaseRuntimeChildDefinition> children = elementDef.getChildrenAndExtension();
|
||||
|
||||
|
||||
return new Iterable<BaseParser.CompositeChildElement>() {
|
||||
@Override
|
||||
public Iterator<CompositeChildElement> iterator() {
|
||||
|
@ -143,9 +145,9 @@ public abstract class BaseParser implements IParser {
|
|||
/*
|
||||
* There are lots of reasons we might skip encoding a particular child
|
||||
*/
|
||||
// if (myNext.getDef().getElementName().equals("extension") || myNext.getDef().getElementName().equals("modifierExtension")) {
|
||||
// myNext = null;
|
||||
// } else
|
||||
// if (myNext.getDef().getElementName().equals("extension") || myNext.getDef().getElementName().equals("modifierExtension")) {
|
||||
// myNext = null;
|
||||
// } else
|
||||
if (myNext.getDef().getElementName().equals("id")) {
|
||||
myNext = null;
|
||||
} else if (!myNext.shouldBeEncoded()) {
|
||||
|
@ -377,7 +379,7 @@ public abstract class BaseParser implements IParser {
|
|||
if (theResource.getStructureFhirVersionEnum() != myContext.getVersion().getVersion()) {
|
||||
throw new IllegalArgumentException("This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not encode a structure for version " + theResource.getStructureFhirVersionEnum());
|
||||
}
|
||||
|
||||
|
||||
doEncodeResourceToWriter(theResource, theWriter);
|
||||
}
|
||||
|
||||
|
@ -411,6 +413,18 @@ public abstract class BaseParser implements IParser {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
protected String getCompositeElementId(IBase theElement) {
|
||||
String elementId = null;
|
||||
if (!(theElement instanceof IBaseResource)) {
|
||||
if (theElement instanceof IBaseElement) {
|
||||
elementId = ((IBaseElement) theElement).getId();
|
||||
} else if (theElement instanceof IIdentifiableElement) {
|
||||
elementId = ((IIdentifiableElement) theElement).getElementSpecificId();
|
||||
}
|
||||
}
|
||||
return elementId;
|
||||
}
|
||||
|
||||
ContainedResources getContainedResources() {
|
||||
return myContainedResources;
|
||||
}
|
||||
|
@ -552,14 +566,14 @@ public abstract class BaseParser implements IParser {
|
|||
|
||||
@Override
|
||||
public <T extends IBaseResource> T parseResource(Class<T> theResourceType, Reader theReader) throws DataFormatException {
|
||||
|
||||
|
||||
if (theResourceType != null) {
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResourceType);
|
||||
if (def.getStructureVersion() != myContext.getVersion().getVersion()) {
|
||||
throw new IllegalArgumentException("This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not parse a structure for version " + def.getStructureVersion());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
T retVal = doParseResource(theResourceType, theReader);
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(retVal);
|
||||
|
@ -684,20 +698,20 @@ public abstract class BaseParser implements IParser {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IBase> retVal = (List<IBase>) theValues;
|
||||
|
||||
|
||||
for (int i = 0; i < retVal.size(); i++) {
|
||||
IBase next = retVal.get(i);
|
||||
|
||||
|
||||
/*
|
||||
* If we have automatically contained any resources via
|
||||
* their references, this ensures that we output the new
|
||||
* local reference
|
||||
*/
|
||||
if (next instanceof IBaseReference) {
|
||||
IBaseReference nextRef = (IBaseReference)next;
|
||||
IBaseReference nextRef = (IBaseReference) next;
|
||||
String refText = determineReferenceText(nextRef);
|
||||
if (!StringUtils.equals(refText, nextRef.getReferenceElement().getValue())) {
|
||||
|
||||
|
||||
if (retVal == theValues) {
|
||||
retVal = new ArrayList<IBase>(theValues);
|
||||
}
|
||||
|
@ -705,11 +719,11 @@ public abstract class BaseParser implements IParser {
|
|||
myContext.newTerser().cloneInto(nextRef, newRef, true);
|
||||
newRef.setReference(refText);
|
||||
retVal.set(i, newRef);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.hl7.fhir.instance.model.api.IBase;
|
|||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBooleanDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDecimalDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseElement;
|
||||
import org.hl7.fhir.instance.model.api.IBaseExtension;
|
||||
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
||||
import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions;
|
||||
|
@ -140,7 +141,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
myContext = theContext;
|
||||
}
|
||||
|
||||
private void addToHeldComments(int valueIdx, List<String> theCommentsToAdd, ArrayList<ArrayList<String>> theListToAddTo) {
|
||||
private boolean addToHeldComments(int valueIdx, List<String> theCommentsToAdd, ArrayList<ArrayList<String>> theListToAddTo) {
|
||||
if (theCommentsToAdd.size() > 0) {
|
||||
theListToAddTo.ensureCapacity(valueIdx);
|
||||
while (theListToAddTo.size() <= valueIdx) {
|
||||
|
@ -150,10 +151,13 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
theListToAddTo.set(valueIdx, new ArrayList<String>());
|
||||
}
|
||||
theListToAddTo.get(valueIdx).addAll(theCommentsToAdd);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void addToHeldExtensions(int valueIdx, List<? extends IBaseExtension<?, ?>> ext, ArrayList<ArrayList<HeldExtension>> list, boolean theIsModifier) {
|
||||
private boolean addToHeldExtensions(int valueIdx, List<? extends IBaseExtension<?, ?>> ext, ArrayList<ArrayList<HeldExtension>> list, boolean theIsModifier) {
|
||||
if (ext.size() > 0) {
|
||||
list.ensureCapacity(valueIdx);
|
||||
while (list.size() <= valueIdx) {
|
||||
|
@ -165,6 +169,9 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
for (IBaseExtension<?, ?> next : ext) {
|
||||
list.get(valueIdx).add(new HeldExtension(next, theIsModifier));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,8 +407,8 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
theEventWriter.writeEnd();
|
||||
}
|
||||
|
||||
private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theWriter, IBase theNextValue, BaseRuntimeElementDefinition<?> theChildDef, String theChildName, boolean theContainedResource, CompositeChildElement theChildElem)
|
||||
throws IOException {
|
||||
private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theWriter, IBase theNextValue, BaseRuntimeElementDefinition<?> theChildDef, String theChildName, boolean theContainedResource, CompositeChildElement theChildElem,
|
||||
boolean theForceEmpty) throws IOException {
|
||||
|
||||
switch (theChildDef.getChildType()) {
|
||||
case ID_DATATYPE: {
|
||||
|
@ -420,6 +427,9 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
case PRIMITIVE_DATATYPE: {
|
||||
final IPrimitiveType<?> value = (IPrimitiveType<?>) theNextValue;
|
||||
if (isBlank(value.getValueAsString())) {
|
||||
if (theForceEmpty) {
|
||||
theWriter.writeNull();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -460,7 +470,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case RESOURCE_REF:
|
||||
case RESOURCE_REF:
|
||||
case RESOURCE_BLOCK:
|
||||
case COMPOSITE_DATATYPE: {
|
||||
if (theChildName != null) {
|
||||
|
@ -523,14 +533,20 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
|
||||
}
|
||||
|
||||
private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, JsonGenerator theEventWriter, boolean theContainedResource, CompositeChildElement theParent)
|
||||
throws IOException {
|
||||
private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, JsonGenerator theEventWriter, boolean theContainedResource, CompositeChildElement theParent) throws IOException {
|
||||
|
||||
{
|
||||
String elementId = getCompositeElementId(theElement);
|
||||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.write("id", elementId);
|
||||
}
|
||||
}
|
||||
|
||||
boolean haveWrittenExtensions = false;
|
||||
for (CompositeChildElement nextChildElem : super.compositeChildIterator(theElement, theContainedResource, theParent)) {
|
||||
|
||||
BaseRuntimeChildDefinition nextChild = nextChildElem.getDef();
|
||||
|
||||
|
||||
if (nextChildElem.getDef().getElementName().equals("extension") || nextChildElem.getDef().getElementName().equals("modifierExtension") || nextChild instanceof RuntimeChildDeclaredExtensionDefinition) {
|
||||
if (!haveWrittenExtensions) {
|
||||
extractAndWriteExtensionsAsDirectChild(theElement, theEventWriter, myContext.getElementDefinition(theElement.getClass()), theResDef, theResource);
|
||||
|
@ -538,7 +554,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (nextChild instanceof RuntimeChildNarrativeDefinition) {
|
||||
INarrativeGenerator gen = myContext.getNarrativeGenerator();
|
||||
if (gen != null) {
|
||||
|
@ -556,7 +572,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild;
|
||||
String childName = nextChild.getChildNameByDatatype(child.getDatatype());
|
||||
BaseRuntimeElementDefinition<?> type = child.getChildByName(childName);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, type, childName, theContainedResource, nextChildElem);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, type, childName, theContainedResource, nextChildElem, false);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -564,7 +580,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
} else if (nextChild instanceof RuntimeChildContainedResources) {
|
||||
String childName = nextChild.getValidChildNames().iterator().next();
|
||||
BaseRuntimeElementDefinition<?> child = nextChild.getChildByName(childName);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, null, child, childName, theContainedResource, nextChildElem);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, null, child, childName, theContainedResource, nextChildElem, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -581,6 +597,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
ArrayList<ArrayList<HeldExtension>> extensions = new ArrayList<ArrayList<HeldExtension>>(0);
|
||||
ArrayList<ArrayList<HeldExtension>> modifierExtensions = new ArrayList<ArrayList<HeldExtension>>(0);
|
||||
ArrayList<ArrayList<String>> comments = new ArrayList<ArrayList<String>>(0);
|
||||
ArrayList<String> ids = new ArrayList<String>(0);
|
||||
|
||||
int valueIdx = 0;
|
||||
for (IBase nextValue : values) {
|
||||
|
@ -596,13 +613,10 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
}
|
||||
|
||||
Class<? extends IBase> type = nextValue.getClass();
|
||||
|
||||
|
||||
String childName = nextChild.getChildNameByDatatype(type);
|
||||
BaseRuntimeElementDefinition<?> childDef = nextChild.getChildElementDefinitionByDatatype(type);
|
||||
if (childDef == null) {
|
||||
// if (IBaseExtension.class.isAssignableFrom(type)) {
|
||||
// continue;
|
||||
// }
|
||||
super.throwExceptionForUnknownChildType(nextChild, type);
|
||||
}
|
||||
boolean primitive = childDef.getChildType() == ChildTypeEnum.PRIMITIVE_DATATYPE;
|
||||
|
@ -611,55 +625,54 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
continue;
|
||||
}
|
||||
|
||||
// if (nextChild instanceof RuntimeChildDeclaredExtensionDefinition) {
|
||||
// RuntimeChildDeclaredExtensionDefinition extDef = (RuntimeChildDeclaredExtensionDefinition) nextChild;
|
||||
// new HeldExtension(extDef, nextValue).write(theResDef, theResource, theEventWriter);
|
||||
// } else {
|
||||
boolean force = false;
|
||||
if (primitive) {
|
||||
if (nextValue instanceof ISupportsUndeclaredExtensions) {
|
||||
List<ExtensionDt> ext = ((ISupportsUndeclaredExtensions) nextValue).getUndeclaredExtensions();
|
||||
force |= addToHeldExtensions(valueIdx, ext, extensions, false);
|
||||
|
||||
if (currentChildName == null || !currentChildName.equals(childName)) {
|
||||
if (inArray) {
|
||||
theEventWriter.writeEnd();
|
||||
}
|
||||
if (nextChild.getMax() > 1 || nextChild.getMax() == Child.MAX_UNLIMITED) {
|
||||
theEventWriter.writeStartArray(childName);
|
||||
inArray = true;
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theContainedResource, nextChildElem);
|
||||
} else if (nextChild instanceof RuntimeChildNarrativeDefinition && theContainedResource) {
|
||||
// suppress narratives from contained resources
|
||||
} else {
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, childName, theContainedResource, nextChildElem);
|
||||
}
|
||||
currentChildName = childName;
|
||||
ext = ((ISupportsUndeclaredExtensions) nextValue).getUndeclaredModifierExtensions();
|
||||
force |= addToHeldExtensions(valueIdx, ext, modifierExtensions, true);
|
||||
} else {
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theContainedResource, nextChildElem);
|
||||
}
|
||||
|
||||
if (primitive) {
|
||||
if (nextValue instanceof ISupportsUndeclaredExtensions) {
|
||||
List<ExtensionDt> ext = ((ISupportsUndeclaredExtensions) nextValue).getUndeclaredExtensions();
|
||||
addToHeldExtensions(valueIdx, ext, extensions, false);
|
||||
|
||||
ext = ((ISupportsUndeclaredExtensions) nextValue).getUndeclaredModifierExtensions();
|
||||
addToHeldExtensions(valueIdx, ext, modifierExtensions, true);
|
||||
} else {
|
||||
if (nextValue instanceof IBaseHasExtensions) {
|
||||
IBaseHasExtensions element = (IBaseHasExtensions) nextValue;
|
||||
List<? extends IBaseExtension<?, ?>> ext = element.getExtension();
|
||||
addToHeldExtensions(valueIdx, ext, extensions, false);
|
||||
}
|
||||
if (nextValue instanceof IBaseHasModifierExtensions) {
|
||||
IBaseHasModifierExtensions element = (IBaseHasModifierExtensions) nextValue;
|
||||
List<? extends IBaseExtension<?, ?>> ext = element.getModifierExtension();
|
||||
addToHeldExtensions(valueIdx, ext, extensions, true);
|
||||
}
|
||||
if (nextValue instanceof IBaseHasExtensions) {
|
||||
IBaseHasExtensions element = (IBaseHasExtensions) nextValue;
|
||||
List<? extends IBaseExtension<?, ?>> ext = element.getExtension();
|
||||
force |= addToHeldExtensions(valueIdx, ext, extensions, false);
|
||||
}
|
||||
if (nextValue.hasFormatComment()) {
|
||||
addToHeldComments(valueIdx, nextValue.getFormatCommentsPre(), comments);
|
||||
addToHeldComments(valueIdx, nextValue.getFormatCommentsPost(), comments);
|
||||
if (nextValue instanceof IBaseHasModifierExtensions) {
|
||||
IBaseHasModifierExtensions element = (IBaseHasModifierExtensions) nextValue;
|
||||
List<? extends IBaseExtension<?, ?>> ext = element.getModifierExtension();
|
||||
force |= addToHeldExtensions(valueIdx, ext, extensions, true);
|
||||
}
|
||||
}
|
||||
if (nextValue.hasFormatComment()) {
|
||||
force |= addToHeldComments(valueIdx, nextValue.getFormatCommentsPre(), comments);
|
||||
force |= addToHeldComments(valueIdx, nextValue.getFormatCommentsPost(), comments);
|
||||
}
|
||||
String elementId = getCompositeElementId(nextValue);
|
||||
if (isNotBlank(elementId)) {
|
||||
force = true;
|
||||
addToHeldIds(valueIdx, ids, elementId);
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
if (currentChildName == null || !currentChildName.equals(childName)) {
|
||||
if (inArray) {
|
||||
theEventWriter.writeEnd();
|
||||
}
|
||||
if (nextChild.getMax() > 1 || nextChild.getMax() == Child.MAX_UNLIMITED) {
|
||||
theEventWriter.writeStartArray(childName);
|
||||
inArray = true;
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theContainedResource, nextChildElem, force);
|
||||
} else if (nextChild instanceof RuntimeChildNarrativeDefinition && theContainedResource) {
|
||||
// suppress narratives from contained resources
|
||||
} else {
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, childName, theContainedResource, nextChildElem, false);
|
||||
}
|
||||
currentChildName = childName;
|
||||
} else {
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theContainedResource, nextChildElem, force);
|
||||
}
|
||||
|
||||
valueIdx++;
|
||||
}
|
||||
|
@ -701,12 +714,21 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
haveContent = true;
|
||||
}
|
||||
|
||||
String elementId = null;
|
||||
if (ids.size() > i) {
|
||||
elementId = ids.get(i);
|
||||
haveContent |= isNotBlank(elementId);
|
||||
}
|
||||
|
||||
if (!haveContent) {
|
||||
theEventWriter.writeNull();
|
||||
} else {
|
||||
if (inArray) {
|
||||
theEventWriter.writeStartObject();
|
||||
}
|
||||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.write("id", elementId);
|
||||
}
|
||||
if (nextComments != null && !nextComments.isEmpty()) {
|
||||
theEventWriter.writeStartArray("fhir_comments");
|
||||
for (String next : nextComments) {
|
||||
|
@ -726,8 +748,17 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter, boolean theContainedResource, CompositeChildElement theParent)
|
||||
throws IOException, DataFormatException {
|
||||
private void addToHeldIds(int theValueIdx, ArrayList<String> theListToAddTo, String theId) {
|
||||
theListToAddTo.ensureCapacity(theValueIdx);
|
||||
while (theListToAddTo.size() <= theValueIdx) {
|
||||
theListToAddTo.add(null);
|
||||
}
|
||||
if (theListToAddTo.get(theValueIdx) == null) {
|
||||
theListToAddTo.set(theValueIdx, theId);
|
||||
}
|
||||
}
|
||||
|
||||
private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter, boolean theContainedResource, CompositeChildElement theParent) throws IOException, DataFormatException {
|
||||
|
||||
writeCommentsPreAndPost(theNextValue, theEventWriter);
|
||||
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, theContainedResource, theParent);
|
||||
|
@ -802,7 +833,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
List<BaseCodingDt> securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS);
|
||||
List<? extends IIdType> profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES);
|
||||
profiles = super.getProfileTagsForEncoding(resource, profiles);
|
||||
|
||||
|
||||
TagList tags = getMetaTagsForEncoding(resource);
|
||||
InstantDt updated = (InstantDt) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
|
||||
IdDt resourceId = resource.getId();
|
||||
|
@ -1305,6 +1336,9 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
theState.endingElement();
|
||||
break;
|
||||
case NULL:
|
||||
theState.enteringNewElement(null, theName);
|
||||
parseAlternates(theAlternateVal, theState, theAlternateName);
|
||||
theState.endingElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1564,7 +1598,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
|
||||
public void write(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter) throws IOException {
|
||||
if (myUndeclaredExtension != null) {
|
||||
writeUndeclaredExtInDstu1Format(theResDef, theResource, theEventWriter, myUndeclaredExtension);
|
||||
writeUndeclaredExtension(theResDef, theResource, theEventWriter, myUndeclaredExtension);
|
||||
} else {
|
||||
theEventWriter.writeStartObject();
|
||||
|
||||
|
@ -1577,14 +1611,14 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
extractAndWriteExtensionsAsDirectChild(myValue, theEventWriter, def, theResDef, theResource);
|
||||
} else {
|
||||
String childName = myDef.getChildNameByDatatype(myValue.getClass());
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, myValue, def, childName, false, null);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, myValue, def, childName, false, null, false);
|
||||
}
|
||||
|
||||
theEventWriter.writeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeUndeclaredExtInDstu1Format(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter, IBaseExtension<?, ?> ext) throws IOException {
|
||||
private void writeUndeclaredExtension(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter, IBaseExtension<?, ?> ext) throws IOException {
|
||||
IBase value = ext.getValue();
|
||||
String extensionUrl = ext.getUrl();
|
||||
|
||||
|
@ -1592,6 +1626,11 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
|
||||
writeCommentsPreAndPost(myUndeclaredExtension, theEventWriter);
|
||||
|
||||
String elementId = getCompositeElementId(ext);
|
||||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.write("id", getCompositeElementId(ext));
|
||||
}
|
||||
|
||||
theEventWriter.write("url", extensionUrl);
|
||||
|
||||
boolean noValue = value == null || value.isEmpty();
|
||||
|
@ -1606,17 +1645,17 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
}
|
||||
|
||||
for (Object next : ext.getExtension()) {
|
||||
writeUndeclaredExtInDstu1Format(theResDef, theResource, theEventWriter, (IBaseExtension<?, ?>) next);
|
||||
writeUndeclaredExtension(theResDef, theResource, theEventWriter, (IBaseExtension<?, ?>) next);
|
||||
}
|
||||
theEventWriter.writeEnd();
|
||||
} else {
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* Pre-process value - This is called in case the value is a reference
|
||||
* since we might modify the text
|
||||
* since we might modify the text
|
||||
*/
|
||||
value = JsonParser.super.preProcessValues(myDef, theResource, Collections.singletonList(value)).get(0);
|
||||
|
||||
|
||||
RuntimeChildUndeclaredExtensionDefinition extDef = myContext.getRuntimeChildUndeclaredExtensionDefinition();
|
||||
String childName = extDef.getChildNameByDatatype(value.getClass());
|
||||
if (childName == null) {
|
||||
|
@ -1626,7 +1665,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
if (childDef == null) {
|
||||
throw new ConfigurationException("Unable to encode extension, unregognized child element type: " + value.getClass().getCanonicalName());
|
||||
}
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, value, childDef, childName, true, null);
|
||||
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, value, childDef, childName, true, null, false);
|
||||
}
|
||||
|
||||
// theEventWriter.name(myUndeclaredExtension.get);
|
||||
|
|
|
@ -94,15 +94,15 @@ import ca.uhn.fhir.util.IModelVisitor;
|
|||
class ParserState<T> {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ParserState.class);
|
||||
|
||||
private List<String> myComments = new ArrayList<String>(2);
|
||||
private final FhirContext myContext;
|
||||
private final IParserErrorHandler myErrorHandler;
|
||||
private final boolean myJsonMode;
|
||||
private T myObject;
|
||||
private BaseState myState;
|
||||
private IBase myPreviousElement;
|
||||
private final IParser myParser;
|
||||
|
||||
private IBase myPreviousElement;
|
||||
private BaseState myState;
|
||||
private ParserState(IParser theParser, FhirContext theContext, boolean theJsonMode, IParserErrorHandler theErrorHandler) {
|
||||
myParser = theParser;
|
||||
myContext = theContext;
|
||||
|
@ -1121,10 +1121,6 @@ class ParserState<T> {
|
|||
}
|
||||
}
|
||||
|
||||
protected BundleEntry getEntry() {
|
||||
return myEntry;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void populateResourceMetadata() {
|
||||
if (myEntry.getResource() == null) {
|
||||
|
@ -1624,6 +1620,13 @@ class ParserState<T> {
|
|||
try {
|
||||
child = myDefinition.getChildByNameOrThrowDataFormatException(theChildName);
|
||||
} catch (DataFormatException e) {
|
||||
if (theChildName.equals("id")) {
|
||||
if (getCurrentElement() instanceof IIdentifiableElement) {
|
||||
push(new IdentifiableElementIdState(getPreResourceState(), (IIdentifiableElement) getCurrentElement()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This means we've found an element that doesn't exist on the structure. If the error handler doesn't throw
|
||||
* an exception, swallow the element silently along with any child elements
|
||||
|
@ -1751,6 +1754,27 @@ class ParserState<T> {
|
|||
|
||||
}
|
||||
|
||||
public class ElementIdState extends BaseState {
|
||||
|
||||
private IBaseElement myElement;
|
||||
|
||||
public ElementIdState(ParserState<T>.PreResourceState thePreResourceState, IBaseElement theElement) {
|
||||
super(thePreResourceState);
|
||||
myElement = theElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
myElement.setId(theValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement() {
|
||||
pop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ExtensionState extends BaseState {
|
||||
|
||||
private IBaseExtension<?, ?> myExtension;
|
||||
|
@ -1767,6 +1791,15 @@ class ParserState<T> {
|
|||
// of "value" like every single other place
|
||||
return;
|
||||
}
|
||||
if ("id".equals(theName)) {
|
||||
if (getCurrentElement() instanceof IBaseElement) {
|
||||
((IBaseElement)getCurrentElement()).setId(theValue);
|
||||
return;
|
||||
} else if (getCurrentElement() instanceof IIdentifiableElement) {
|
||||
((IIdentifiableElement)getCurrentElement()).setElementSpecificId(theValue);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.attributeValue(theName, theValue);
|
||||
}
|
||||
|
||||
|
@ -1780,6 +1813,16 @@ class ParserState<T> {
|
|||
|
||||
@Override
|
||||
public void enteringNewElement(String theNamespaceUri, String theLocalPart) throws DataFormatException {
|
||||
if (theLocalPart.equals("id")) {
|
||||
if (getCurrentElement() instanceof IBaseElement) {
|
||||
push(new ElementIdState(getPreResourceState(), (IBaseElement)getCurrentElement()));
|
||||
return;
|
||||
} else if (getCurrentElement() instanceof IIdentifiableElement) {
|
||||
push(new IdentifiableElementIdState(getPreResourceState(), (IIdentifiableElement)getCurrentElement()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BaseRuntimeElementDefinition<?> target = myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildByName(theLocalPart);
|
||||
if (target == null) {
|
||||
myErrorHandler.unknownElement(null, theLocalPart);
|
||||
|
@ -1836,6 +1879,27 @@ class ParserState<T> {
|
|||
|
||||
}
|
||||
|
||||
public class IdentifiableElementIdState extends BaseState {
|
||||
|
||||
private IIdentifiableElement myElement;
|
||||
|
||||
public IdentifiableElementIdState(ParserState<T>.PreResourceState thePreResourceState, IIdentifiableElement theElement) {
|
||||
super(thePreResourceState);
|
||||
myElement = theElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attributeValue(String theName, String theValue) throws DataFormatException {
|
||||
myElement.setElementSpecificId(theValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endingElement() {
|
||||
pop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class MetaElementState extends BaseState {
|
||||
private ResourceMetadataMap myMap;
|
||||
|
||||
|
|
|
@ -518,6 +518,10 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
String value = pd.getValueAsString();
|
||||
if (value != null || super.hasExtensions(pd)) {
|
||||
theEventWriter.writeStartElement(childName);
|
||||
String elementId = getCompositeElementId(theElement);
|
||||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.writeAttribute("id", elementId);
|
||||
}
|
||||
if (value != null) {
|
||||
theEventWriter.writeAttribute("value", value);
|
||||
}
|
||||
|
@ -530,10 +534,13 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
case RESOURCE_BLOCK:
|
||||
case COMPOSITE_DATATYPE: {
|
||||
theEventWriter.writeStartElement(childName);
|
||||
String elementId = getCompositeElementId(theElement);
|
||||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.writeAttribute("id", elementId);
|
||||
}
|
||||
if (isNotBlank(theExtensionUrl)) {
|
||||
theEventWriter.writeAttribute("url", theExtensionUrl);
|
||||
}
|
||||
BaseRuntimeElementCompositeDefinition<?> childCompositeDef = (BaseRuntimeElementCompositeDefinition<?>) childDef;
|
||||
encodeCompositeElementToStreamWriter(theResource, theElement, theEventWriter, theIncludedResource, theParent);
|
||||
theEventWriter.writeEndElement();
|
||||
break;
|
||||
|
@ -592,6 +599,7 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
@SuppressWarnings("rawtypes")
|
||||
private void encodeCompositeElementToStreamWriter(IBaseResource theResource, IBase theElement, XMLStreamWriter theEventWriter, boolean theContainedResource, CompositeChildElement theParent)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
|
||||
for (CompositeChildElement nextChildElem : super.compositeChildIterator(theElement, theContainedResource, theParent)) {
|
||||
|
||||
BaseRuntimeChildDefinition nextChild = nextChildElem.getDef();
|
||||
|
@ -701,6 +709,11 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
theEventWriter.writeStartElement("extension");
|
||||
}
|
||||
|
||||
String elementId = getCompositeElementId(nextValue);
|
||||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.writeAttribute("id", elementId);
|
||||
}
|
||||
|
||||
theEventWriter.writeAttribute("url", extensionUrl);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextValue, childName, childDef, null, theContainedResource, nextChildElem);
|
||||
theEventWriter.writeEndElement();
|
||||
|
@ -892,18 +905,23 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeUndeclaredExtensions(IBaseResource theResource, XMLStreamWriter theWriter, List<? extends IBaseExtension<?, ?>> theExtensions, String tagName, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
|
||||
private void encodeUndeclaredExtensions(IBaseResource theResource, XMLStreamWriter theEventWriter, List<? extends IBaseExtension<?, ?>> theExtensions, String tagName, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
|
||||
for (IBaseExtension<?, ?> next : theExtensions) {
|
||||
if (next == null || (ElementUtil.isEmpty(next.getValue()) && next.getExtension().isEmpty())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
writeCommentsPre(theWriter, next);
|
||||
writeCommentsPre(theEventWriter, next);
|
||||
|
||||
theWriter.writeStartElement(tagName);
|
||||
theEventWriter.writeStartElement(tagName);
|
||||
|
||||
String elementId = getCompositeElementId(next);
|
||||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.writeAttribute("id", elementId);
|
||||
}
|
||||
|
||||
String url = next.getUrl();
|
||||
theWriter.writeAttribute("url", url);
|
||||
theEventWriter.writeAttribute("url", url);
|
||||
|
||||
if (next.getValue() != null) {
|
||||
IBaseDatatype value = next.getValue();
|
||||
|
@ -923,15 +941,15 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
throw new ConfigurationException("Unable to encode extension, unrecognized child element type: " + value.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
encodeChildElementToStreamWriter(theResource, theWriter, value, childName, childDef, null, theIncludedResource, null);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, value, childName, childDef, null, theIncludedResource, null);
|
||||
}
|
||||
|
||||
// child extensions
|
||||
encodeExtensionsIfPresent(theResource, theWriter, next, theIncludedResource);
|
||||
encodeExtensionsIfPresent(theResource, theEventWriter, next, theIncludedResource);
|
||||
|
||||
theWriter.writeEndElement();
|
||||
theEventWriter.writeEndElement();
|
||||
|
||||
writeCommentsPost(theWriter, next);
|
||||
writeCommentsPost(theEventWriter, next);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor;
|
|||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
@ -39,6 +40,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
|
|||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
|
||||
|
@ -441,6 +443,25 @@ public interface IServerInterceptor {
|
|||
myResource = theObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method may be invoked by user code to notify interceptors that a nested
|
||||
* operation is being invoked which is denoted by this request details.
|
||||
*/
|
||||
public void notifyIncomingRequestPreHandled(RestOperationTypeEnum theOperationType) {
|
||||
RequestDetails requestDetails = getRequestDetails();
|
||||
if (requestDetails == null) {
|
||||
return;
|
||||
}
|
||||
IRestfulServerDefaults server = requestDetails.getServer();
|
||||
if (server == null) {
|
||||
return;
|
||||
}
|
||||
List<IServerInterceptor> interceptors = server.getInterceptors();
|
||||
for (IServerInterceptor next : interceptors) {
|
||||
next.incomingRequestPreHandled(theOperationType, this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import ca.uhn.fhir.model.api.TagList;
|
|||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
|
||||
import ca.uhn.fhir.util.BundleUtil;
|
||||
|
@ -49,7 +50,7 @@ import ca.uhn.fhir.util.CoverageIgnore;
|
|||
* inspect requests and responses to determine whether the calling user
|
||||
* has permission to perform the given action.
|
||||
*/
|
||||
public class AuthorizationInterceptor extends InterceptorAdapter implements IServerOperationInterceptor {
|
||||
public class AuthorizationInterceptor extends InterceptorAdapter implements IServerOperationInterceptor, IRuleApplier {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(AuthorizationInterceptor.class);
|
||||
|
||||
|
@ -72,9 +73,8 @@ public class AuthorizationInterceptor extends InterceptorAdapter implements ISer
|
|||
setDefaultPolicy(theDefaultPolicy);
|
||||
}
|
||||
|
||||
private void applyRulesAndFailIfDeny(List<IAuthRule> theRules, RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource) {
|
||||
ourLog.trace("Applying {} rules to render an auth decision for operation {}", theRules.size(), theOperation);
|
||||
Verdict decision = applyRulesAndReturnDecision(theRules, theOperation, theRequestDetails, theInputResource, theOutputResource);
|
||||
private void applyRulesAndFailIfDeny(RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource) {
|
||||
Verdict decision = applyRulesAndReturnDecision(theOperation, theRequestDetails, theInputResource, theOutputResource);
|
||||
|
||||
if (decision.getDecision() == PolicyEnum.ALLOW) {
|
||||
return;
|
||||
|
@ -83,38 +83,26 @@ public class AuthorizationInterceptor extends InterceptorAdapter implements ISer
|
|||
handleDeny(decision);
|
||||
}
|
||||
|
||||
private Verdict applyRulesAndReturnDecision(List<IAuthRule> theRules, RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource) {
|
||||
PolicyEnum result = null;
|
||||
// PolicyEnum preference = null;
|
||||
IAuthRule decidingRule = null;
|
||||
|
||||
for (IAuthRule nextRule : theRules) {
|
||||
RuleVerdictEnum decision = nextRule.applyRule(theOperation, theRequestDetails, theInputResource, theOutputResource);
|
||||
|
||||
switch (decision) {
|
||||
case NO_DECISION:
|
||||
continue;
|
||||
case ALLOW:
|
||||
result = PolicyEnum.ALLOW;
|
||||
decidingRule = nextRule;
|
||||
break;
|
||||
case DENY:
|
||||
result = PolicyEnum.DENY;
|
||||
decidingRule = nextRule;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
ourLog.trace("Rule {} returned decision {}", nextRule, result);
|
||||
@Override
|
||||
public Verdict applyRulesAndReturnDecision(RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource) {
|
||||
List<IAuthRule> rules = buildRuleList(theRequestDetails);
|
||||
ourLog.trace("Applying {} rules to render an auth decision for operation {}", rules.size(), theOperation);
|
||||
|
||||
Verdict verdict = null;
|
||||
for (IAuthRule nextRule : rules) {
|
||||
verdict = nextRule.applyRule(theOperation, theRequestDetails, theInputResource, theOutputResource, this);
|
||||
if (verdict != null) {
|
||||
ourLog.trace("Rule {} returned decision {}", nextRule, verdict.getDecision());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
if (verdict == null) {
|
||||
ourLog.trace("No rules returned a decision, applying default {}", myDefaultPolicy);
|
||||
result = myDefaultPolicy;
|
||||
return new Verdict(myDefaultPolicy, null);
|
||||
}
|
||||
return new Verdict(result, decidingRule);
|
||||
|
||||
return verdict;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,22 +185,21 @@ public class AuthorizationInterceptor extends InterceptorAdapter implements ISer
|
|||
* Handle an access control verdict of {@link PolicyEnum#DENY}.
|
||||
* <p>
|
||||
* Subclasses may override to implement specific behaviour, but default is to
|
||||
* throw {@link AuthenticationException} (HTTP 401) with error message citing the
|
||||
* throw {@link ForbiddenOperationException} (HTTP 403) with error message citing the
|
||||
* rule name which trigered failure
|
||||
* </p>
|
||||
*/
|
||||
protected void handleDeny(Verdict decision) {
|
||||
if (decision.getDecidingRule() != null) {
|
||||
String ruleName = defaultString(decision.getDecidingRule().getName(), "(unnamed rule)");
|
||||
throw new AuthenticationException("Access denied by rule: " + ruleName);
|
||||
throw new ForbiddenOperationException("Access denied by rule: " + ruleName);
|
||||
} else {
|
||||
throw new AuthenticationException("Access denied by default policy (no applicable rules)");
|
||||
throw new ForbiddenOperationException("Access denied by default policy (no applicable rules)");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleUserOperation(RequestDetails theRequest, IBaseResource theResource, RestOperationTypeEnum operation) {
|
||||
List<IAuthRule> rules = buildRuleList(theRequest);
|
||||
applyRulesAndFailIfDeny(rules, operation, theRequest, theResource, null);
|
||||
applyRulesAndFailIfDeny(operation, theRequest, theResource, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -227,8 +214,7 @@ public class AuthorizationInterceptor extends InterceptorAdapter implements ISer
|
|||
}
|
||||
|
||||
RequestDetails requestDetails = theProcessedRequest.getRequestDetails();
|
||||
List<IAuthRule> rules = buildRuleList(requestDetails);
|
||||
applyRulesAndFailIfDeny(rules, theOperation, requestDetails, theProcessedRequest.getResource(), null);
|
||||
applyRulesAndFailIfDeny(theOperation, requestDetails, theProcessedRequest.getResource(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -281,7 +267,7 @@ public class AuthorizationInterceptor extends InterceptorAdapter implements ISer
|
|||
}
|
||||
|
||||
for (IBaseResource nextResponse : resources) {
|
||||
applyRulesAndFailIfDeny(rules, theRequestDetails.getRestOperationType(), theRequestDetails, null, nextResponse);
|
||||
applyRulesAndFailIfDeny(theRequestDetails.getRestOperationType(), theRequestDetails, null, nextResponse);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
|
|||
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationInterceptor.Verdict;
|
||||
|
||||
public interface IAuthRule {
|
||||
|
||||
|
@ -38,9 +39,12 @@ public interface IAuthRule {
|
|||
* The resource being input by the client, or <code>null</code>
|
||||
* @param theOutputResource
|
||||
* The resource being returned by the server, or <code>null</code>
|
||||
* @return Returns a policy decision, or {@link RuleVerdictEnum#NO_DECISION} if the rule does not apply
|
||||
* @param theRuleApplier
|
||||
* The rule applying module (this can be used by rules to apply the rule set to
|
||||
* nested objects in the request, such as nested requests in a transaction)
|
||||
* @return Returns a policy decision, or <code>null</code> if the rule does not apply
|
||||
*/
|
||||
RuleVerdictEnum applyRule(RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource);
|
||||
Verdict applyRule(RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource, IRuleApplier theRuleApplier);
|
||||
|
||||
/**
|
||||
* Returns a name for this rule, to be used in logs and error messages
|
||||
|
|
|
@ -22,6 +22,11 @@ package ca.uhn.fhir.rest.server.interceptor.auth;
|
|||
|
||||
public interface IAuthRuleBuilderRule {
|
||||
|
||||
/**
|
||||
* This rule applies to the FHIR delete operation
|
||||
*/
|
||||
IAuthRuleBuilderRuleOp delete();
|
||||
|
||||
/**
|
||||
* This rules applies to the metadata operation (retrieve the
|
||||
* server's conformance statement)
|
||||
|
|
|
@ -20,8 +20,14 @@ package ca.uhn.fhir.rest.server.interceptor.auth;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
enum RuleVerdictEnum {
|
||||
ALLOW,
|
||||
DENY,
|
||||
NO_DECISION
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationInterceptor.Verdict;
|
||||
|
||||
public interface IRuleApplier {
|
||||
|
||||
Verdict applyRulesAndReturnDecision(RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource);
|
||||
|
||||
}
|
|
@ -21,16 +21,23 @@ package ca.uhn.fhir.rest.server.interceptor.auth;
|
|||
*/
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationInterceptor.Verdict;
|
||||
import ca.uhn.fhir.util.BundleUtil;
|
||||
import ca.uhn.fhir.util.BundleUtil.BundleEntryParts;
|
||||
import ca.uhn.fhir.util.FhirTerser;
|
||||
|
||||
class Rule implements IAuthRule {
|
||||
|
@ -40,7 +47,7 @@ class Rule implements IAuthRule {
|
|||
private String myClassifierCompartmentName;
|
||||
private Collection<? extends IIdType> myClassifierCompartmentOwners;
|
||||
private ClassifierTypeEnum myClassifierType;
|
||||
private RuleVerdictEnum myMode;
|
||||
private PolicyEnum myMode;
|
||||
private String myName;
|
||||
private RuleOpEnum myOp;
|
||||
private TransactionAppliesToEnum myTransactionAppliesToOp;
|
||||
|
@ -50,33 +57,107 @@ class Rule implements IAuthRule {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RuleVerdictEnum applyRule(RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource) {
|
||||
public Verdict applyRule(RestOperationTypeEnum theOperation, RequestDetails theRequestDetails, IBaseResource theInputResource, IBaseResource theOutputResource, IRuleApplier theRuleApplier) {
|
||||
FhirContext ctx = theRequestDetails.getServer().getFhirContext();
|
||||
|
||||
IBaseResource appliesTo;
|
||||
switch (myOp) {
|
||||
case READ:
|
||||
if (theOutputResource == null) {
|
||||
return null;
|
||||
}
|
||||
appliesTo = theOutputResource;
|
||||
break;
|
||||
case WRITE:
|
||||
if (theInputResource == null) {
|
||||
return null;
|
||||
}
|
||||
appliesTo = theInputResource;
|
||||
break;
|
||||
case DELETE:
|
||||
if (theOperation == RestOperationTypeEnum.DELETE) {
|
||||
if (theInputResource == null) {
|
||||
return new Verdict(myMode, this);
|
||||
} else {
|
||||
appliesTo = theInputResource;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
case BATCH:
|
||||
case TRANSACTION:
|
||||
if (requestAppliesToTransaction(ctx, myOp, theInputResource)) {
|
||||
return myMode;
|
||||
if (theInputResource != null && requestAppliesToTransaction(ctx, myOp, theInputResource)) {
|
||||
if (myMode == PolicyEnum.DENY) {
|
||||
return new Verdict(PolicyEnum.DENY, this);
|
||||
} else {
|
||||
List<BundleEntryParts> inputResources = BundleUtil.toListOfEntries(ctx, (IBaseBundle) theInputResource);
|
||||
Verdict verdict = null;
|
||||
for (BundleEntryParts nextPart : inputResources) {
|
||||
|
||||
IBaseResource inputResource = nextPart.getResource();
|
||||
RestOperationTypeEnum operation = null;
|
||||
if (nextPart.getRequestType() == RequestTypeEnum.GET) {
|
||||
continue;
|
||||
}
|
||||
if (nextPart.getRequestType() == RequestTypeEnum.POST) {
|
||||
operation = RestOperationTypeEnum.CREATE;
|
||||
} else if (nextPart.getRequestType() == RequestTypeEnum.PUT) {
|
||||
operation = RestOperationTypeEnum.UPDATE;
|
||||
} else {
|
||||
throw new InvalidRequestException("Can not handle transaction with operation of type " + nextPart.getRequestType());
|
||||
}
|
||||
|
||||
/*
|
||||
* This is basically just being conservative - Be careful of transactions containing
|
||||
* nested operations and nested transactions. We block the by default. At some point
|
||||
* it would be nice to be more nuanced here.
|
||||
*/
|
||||
RuntimeResourceDefinition resourceDef = ctx.getResourceDefinition(nextPart.getResource());
|
||||
if ("Parameters".equals(resourceDef.getName()) || "Bundle".equals(resourceDef.getName())) {
|
||||
throw new InvalidRequestException("Can not handle transaction with nested resource of type " + resourceDef.getName());
|
||||
}
|
||||
|
||||
Verdict newVerdict = theRuleApplier.applyRulesAndReturnDecision(operation, theRequestDetails, inputResource, null);
|
||||
if (newVerdict == null) {
|
||||
continue;
|
||||
} else if (verdict == null) {
|
||||
verdict = newVerdict;
|
||||
} else if (verdict.getDecision() == PolicyEnum.ALLOW && newVerdict.getDecision() == PolicyEnum.DENY) {
|
||||
verdict = newVerdict;
|
||||
}
|
||||
}
|
||||
return verdict;
|
||||
}
|
||||
} else if (theOutputResource != null) {
|
||||
List<BundleEntryParts> inputResources = BundleUtil.toListOfEntries(ctx, (IBaseBundle) theInputResource);
|
||||
Verdict verdict = null;
|
||||
for (BundleEntryParts nextPart : inputResources) {
|
||||
if (nextPart.getResource() == null) {
|
||||
continue;
|
||||
}
|
||||
Verdict newVerdict = theRuleApplier.applyRulesAndReturnDecision(RestOperationTypeEnum.READ, theRequestDetails, null, nextPart.getResource());
|
||||
if (newVerdict == null) {
|
||||
continue;
|
||||
} else if (verdict == null) {
|
||||
verdict = newVerdict;
|
||||
} else if (verdict.getDecision() == PolicyEnum.ALLOW && newVerdict.getDecision() == PolicyEnum.DENY) {
|
||||
verdict = newVerdict;
|
||||
}
|
||||
}
|
||||
return verdict;
|
||||
} else {
|
||||
return RuleVerdictEnum.NO_DECISION;
|
||||
return null;
|
||||
}
|
||||
case ALLOW_ALL:
|
||||
return RuleVerdictEnum.ALLOW;
|
||||
return new Verdict(PolicyEnum.ALLOW, this);
|
||||
case DENY_ALL:
|
||||
return RuleVerdictEnum.DENY;
|
||||
return new Verdict(PolicyEnum.DENY, this);
|
||||
case METADATA:
|
||||
if (theOperation == RestOperationTypeEnum.METADATA) {
|
||||
return myMode;
|
||||
return new Verdict(myMode, this);
|
||||
} else {
|
||||
return RuleVerdictEnum.NO_DECISION;
|
||||
return null;
|
||||
}
|
||||
default:
|
||||
// Should not happen
|
||||
|
@ -88,7 +169,7 @@ class Rule implements IAuthRule {
|
|||
break;
|
||||
case TYPES:
|
||||
if (myAppliesToTypes.contains(appliesTo.getClass()) == false) {
|
||||
return RuleVerdictEnum.NO_DECISION;
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -108,17 +189,21 @@ class Rule implements IAuthRule {
|
|||
}
|
||||
}
|
||||
if (!foundMatch) {
|
||||
return RuleVerdictEnum.NO_DECISION;
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unable to apply security to event of applies to type " + myAppliesTo);
|
||||
}
|
||||
|
||||
return myMode;
|
||||
return new Verdict(myMode, this);
|
||||
}
|
||||
|
||||
private boolean requestAppliesToTransaction(FhirContext theContext, RuleOpEnum theOp, IBaseResource theInputResource) {
|
||||
if (!"Bundle".equals(theContext.getResourceDefinition(theInputResource).getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBaseBundle request = (IBaseBundle) theInputResource;
|
||||
String bundleType = BundleUtil.getBundleType(theContext, request);
|
||||
switch (theOp) {
|
||||
|
@ -160,7 +245,7 @@ class Rule implements IAuthRule {
|
|||
myClassifierType = theClassifierType;
|
||||
}
|
||||
|
||||
public void setMode(RuleVerdictEnum theRuleMode) {
|
||||
public void setMode(PolicyEnum theRuleMode) {
|
||||
myMode = theRuleMode;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class RuleBuilder implements IAuthRuleBuilder {
|
|||
|
||||
@Override
|
||||
public IAuthRuleBuilderRule allow(String theRuleName) {
|
||||
return new RuleBuilderRule(RuleVerdictEnum.ALLOW, theRuleName);
|
||||
return new RuleBuilderRule(PolicyEnum.ALLOW, theRuleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,7 +72,7 @@ public class RuleBuilder implements IAuthRuleBuilder {
|
|||
|
||||
@Override
|
||||
public IAuthRuleBuilderRule deny(String theRuleName) {
|
||||
return new RuleBuilderRule(RuleVerdictEnum.DENY, theRuleName);
|
||||
return new RuleBuilderRule(PolicyEnum.DENY, theRuleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,15 +101,21 @@ public class RuleBuilder implements IAuthRuleBuilder {
|
|||
|
||||
private class RuleBuilderRule implements IAuthRuleBuilderRule {
|
||||
|
||||
private RuleOpEnum myRuleOp;
|
||||
private RuleVerdictEnum myRuleMode;
|
||||
private PolicyEnum myRuleMode;
|
||||
private String myRuleName;
|
||||
private RuleOpEnum myRuleOp;
|
||||
|
||||
public RuleBuilderRule(RuleVerdictEnum theRuleMode, String theRuleName) {
|
||||
public RuleBuilderRule(PolicyEnum theRuleMode, String theRuleName) {
|
||||
myRuleMode = theRuleMode;
|
||||
myRuleName = theRuleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAuthRuleBuilderRuleOp delete() {
|
||||
myRuleOp = RuleOpEnum.DELETE;
|
||||
return new RuleBuilderRuleOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleBuilderFinished metadata() {
|
||||
Rule rule = new Rule(myRuleName);
|
||||
|
@ -118,13 +124,13 @@ public class RuleBuilder implements IAuthRuleBuilder {
|
|||
myRules.add(rule);
|
||||
return new RuleBuilderFinished();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IAuthRuleBuilderRuleOp read() {
|
||||
myRuleOp = RuleOpEnum.READ;
|
||||
return new RuleBuilderRuleOp();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IAuthRuleBuilderRuleTransaction transaction() {
|
||||
myRuleOp = RuleOpEnum.TRANSACTION;
|
||||
|
@ -136,7 +142,7 @@ public class RuleBuilder implements IAuthRuleBuilder {
|
|||
myRuleOp = RuleOpEnum.WRITE;
|
||||
return new RuleBuilderRuleOp();
|
||||
}
|
||||
|
||||
|
||||
private class RuleBuilderRuleOp implements IAuthRuleBuilderRuleOp {
|
||||
|
||||
private AppliesTypeEnum myAppliesTo;
|
||||
|
|
|
@ -27,5 +27,6 @@ enum RuleOpEnum {
|
|||
DENY_ALL,
|
||||
TRANSACTION,
|
||||
METADATA,
|
||||
BATCH
|
||||
BATCH,
|
||||
DELETE
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ca.uhn.fhir.util;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
|
@ -33,33 +35,13 @@ import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
|||
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||
|
||||
/**
|
||||
* Fetch resources from a bundle
|
||||
*/
|
||||
public class BundleUtil {
|
||||
|
||||
/**
|
||||
* Extract all of the resources from a given bundle
|
||||
*/
|
||||
public static List<IBaseResource> toListOfResources(FhirContext theContext, IBaseBundle theBundle) {
|
||||
List<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
||||
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
|
||||
BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
|
||||
List<IBase> entries = entryChild.getAccessor().getValues(theBundle);
|
||||
|
||||
BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry");
|
||||
BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource");
|
||||
for (IBase nextEntry : entries) {
|
||||
for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) {
|
||||
retVal.add((IBaseResource) next);
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Pair<String, IBaseResource>> getBundleEntryUrlsAndResources(FhirContext theContext, IBaseBundle theBundle) {
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
|
||||
|
@ -96,7 +78,7 @@ public class BundleUtil {
|
|||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
public static String getBundleType(FhirContext theContext, IBaseBundle theBundle) {
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
|
||||
BaseRuntimeChildDefinition entryChild = def.getChildByName("type");
|
||||
|
@ -108,4 +90,96 @@ public class BundleUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract all of the resources from a given bundle
|
||||
*/
|
||||
public static List<BundleEntryParts> toListOfEntries(FhirContext theContext, IBaseBundle theBundle) {
|
||||
List<BundleEntryParts> retVal = new ArrayList<BundleEntryParts>();
|
||||
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
|
||||
BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
|
||||
List<IBase> entries = entryChild.getAccessor().getValues(theBundle);
|
||||
|
||||
BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry");
|
||||
|
||||
BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource");
|
||||
BaseRuntimeChildDefinition requestChild = entryChildElem.getChildByName("request");
|
||||
BaseRuntimeElementCompositeDefinition<?> requestElem = (BaseRuntimeElementCompositeDefinition<?>) requestChild.getChildByName("request");
|
||||
BaseRuntimeChildDefinition urlChild = requestElem.getChildByName("url");
|
||||
BaseRuntimeChildDefinition methodChild = requestElem.getChildByName("method");
|
||||
|
||||
IBaseResource resource = null;
|
||||
String url = null;
|
||||
RequestTypeEnum requestType = null;
|
||||
|
||||
for (IBase nextEntry : entries) {
|
||||
for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) {
|
||||
resource = (IBaseResource) next;
|
||||
}
|
||||
for (IBase nextRequest : requestChild.getAccessor().getValues(nextEntry)) {
|
||||
for (IBase nextUrl : urlChild.getAccessor().getValues(nextRequest)) {
|
||||
url = ((IPrimitiveType<?>)nextUrl).getValueAsString();
|
||||
}
|
||||
for (IBase nextUrl : methodChild.getAccessor().getValues(nextRequest)) {
|
||||
String methodString = ((IPrimitiveType<?>)nextUrl).getValueAsString();
|
||||
if (isNotBlank(methodString)) {
|
||||
requestType = RequestTypeEnum.valueOf(methodString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* All 3 might be null - That's ok because we still want to know the
|
||||
* order in the original bundle.
|
||||
*/
|
||||
retVal.add(new BundleEntryParts(requestType, url, resource));
|
||||
}
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract all of the resources from a given bundle
|
||||
*/
|
||||
public static List<IBaseResource> toListOfResources(FhirContext theContext, IBaseBundle theBundle) {
|
||||
List<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
||||
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
|
||||
BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
|
||||
List<IBase> entries = entryChild.getAccessor().getValues(theBundle);
|
||||
|
||||
BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry");
|
||||
BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource");
|
||||
for (IBase nextEntry : entries) {
|
||||
for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) {
|
||||
retVal.add((IBaseResource) next);
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static class BundleEntryParts
|
||||
{
|
||||
private final RequestTypeEnum myRequestType;
|
||||
private final IBaseResource myResource;
|
||||
private final String myUrl;
|
||||
public BundleEntryParts(RequestTypeEnum theRequestType, String theUrl, IBaseResource theResource) {
|
||||
super();
|
||||
myRequestType = theRequestType;
|
||||
myUrl = theUrl;
|
||||
myResource = theResource;
|
||||
}
|
||||
public RequestTypeEnum getRequestType() {
|
||||
return myRequestType;
|
||||
}
|
||||
public IBaseResource getResource() {
|
||||
return myResource;
|
||||
}
|
||||
public String getUrl() {
|
||||
return myUrl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
package ca.uhn.fhir.util;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2016 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -24,4 +24,6 @@ public interface IBaseElement {
|
|||
|
||||
IBaseElement setId(String theValue);
|
||||
|
||||
String getId();
|
||||
|
||||
}
|
||||
|
|
|
@ -190,11 +190,13 @@ public class App {
|
|||
System.err.println(" " + ansi().fg(Color.RED).bold() + e.getMessage());
|
||||
System.err.println("" + ansi().fg(Color.WHITE).boldOff());
|
||||
logCommandUsageNoHeader(command);
|
||||
return;
|
||||
System.exit(1);
|
||||
} catch (CommandFailureException e) {
|
||||
ourLog.error(e.getMessage());
|
||||
System.exit(1);
|
||||
} catch (Exception e) {
|
||||
ourLog.error("Error during execution: ", e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@ public class CommandFailureException extends Error {
|
|||
super(theMessage);
|
||||
}
|
||||
|
||||
public CommandFailureException(String theString, Exception theCause) {
|
||||
super(theString, theCause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.SocketException;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
@ -61,9 +62,7 @@ public class RunServerCommand extends BaseCommand {
|
|||
|
||||
ContextHolder.setCtx(getSpecVersionContext(theCommandLine));
|
||||
|
||||
// ((ch.qos.logback.classic.Logger)LoggerFactory.getLogger("/")).setLevel(Level.ERROR);
|
||||
|
||||
ourLog.info("Preparing HAPI FHIR JPA server");
|
||||
ourLog.info("Preparing HAPI FHIR JPA server on port {}", myPort);
|
||||
File tempWarFile;
|
||||
try {
|
||||
tempWarFile = File.createTempFile("hapi-fhir", ".war");
|
||||
|
@ -113,9 +112,11 @@ public class RunServerCommand extends BaseCommand {
|
|||
myServer.setHandler(root);
|
||||
try {
|
||||
myServer.start();
|
||||
} catch (SocketException e) {
|
||||
throw new CommandFailureException("Server failed to start on port " + myPort + " because of the following error \"" + e.toString() + "\". Note that you can use the '-p' option to specify an alternate port.");
|
||||
} catch (Exception e) {
|
||||
ourLog.error("Server failed to start", e);
|
||||
return;
|
||||
throw new CommandFailureException("Server failed to start", e);
|
||||
}
|
||||
|
||||
ourLog.info("Server started on port {}", myPort);
|
||||
|
@ -125,21 +126,25 @@ public class RunServerCommand extends BaseCommand {
|
|||
|
||||
}
|
||||
|
||||
public void run(String[] theArgs) {
|
||||
public static void main(String[] theArgs) {
|
||||
|
||||
getOptions();
|
||||
|
||||
// myServer = new Server(myPort);
|
||||
//
|
||||
// WebAppContext webAppContext = new WebAppContext();
|
||||
// webAppContext.setContextPath("/");
|
||||
// webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
|
||||
// webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-example");
|
||||
// webAppContext.setParentLoaderPriority(true);
|
||||
//
|
||||
// myServer.setHandler(webAppContext);
|
||||
// myServer.start();
|
||||
Server server = new Server(22);
|
||||
String path = "../hapi-fhir-cli-jpaserver";
|
||||
WebAppContext webAppContext = new WebAppContext();
|
||||
webAppContext.setContextPath("/");
|
||||
webAppContext.setDescriptor(path + "/src/main/webapp/WEB-INF/web.xml");
|
||||
webAppContext.setResourceBase(path + "/target/hapi-fhir-jpaserver-example");
|
||||
webAppContext.setParentLoaderPriority(true);
|
||||
|
||||
server.setHandler(webAppContext);
|
||||
try {
|
||||
server.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ourLog.info("Started");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ValidateCommand extends BaseCommand {
|
|||
addFhirVersionOption(retVal);
|
||||
|
||||
OptionGroup source = new OptionGroup();
|
||||
source.addOption(new Option("f", "file", true, "The name of the file to validate"));
|
||||
source.addOption(new Option("n", "file", true, "The name of the file to validate"));
|
||||
source.addOption(new Option("d", "data", true, "The text to validate"));
|
||||
retVal.addOptionGroup(source);
|
||||
|
||||
|
@ -72,13 +72,13 @@ public class ValidateCommand extends BaseCommand {
|
|||
|
||||
@Override
|
||||
public void run(CommandLine theCommandLine) throws ParseException, Exception {
|
||||
String fileName = theCommandLine.getOptionValue("f");
|
||||
String fileName = theCommandLine.getOptionValue("n");
|
||||
String contents = theCommandLine.getOptionValue("c");
|
||||
if (isNotBlank(fileName) && isNotBlank(contents)) {
|
||||
throw new ParseException("Can not supply both a file (-f) and data (-d)");
|
||||
throw new ParseException("Can not supply both a file (-n) and data (-d)");
|
||||
}
|
||||
if (isBlank(fileName) && isBlank(contents)) {
|
||||
throw new ParseException("Must supply either a file (-f) or data (-d)");
|
||||
throw new ParseException("Must supply either a file (-n) or data (-d)");
|
||||
}
|
||||
|
||||
if (isNotBlank(fileName)) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.cli.App;
|
||||
|
@ -5,24 +7,31 @@ import ca.uhn.fhir.cli.App;
|
|||
public class ValidateTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateTest.class);
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
System.setProperty("noexit", "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testValidateLocalProfile() {
|
||||
String profilePath = ValidateTest.class.getResource("/uslab-patient.profile.xml").getFile();
|
||||
String resourcePath = ValidateTest.class.getResource("/patient-uslab-example1.xml").getFile();
|
||||
ourLog.info(profilePath);
|
||||
ourLog.info(resourcePath);
|
||||
|
||||
App.main(new String[] {"validate", "-p", "-f", resourcePath, "-l", profilePath});
|
||||
App.main(new String[] {"validate", "-p", "-n", resourcePath, "-l", profilePath});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testValidateLocalProfileWithReferenced() {
|
||||
String profilePath = ValidateTest.class.getResource("/nl/nl-core-patient.dstu2.xml").getFile();
|
||||
String resourcePath = ValidateTest.class.getResource("/nl/patient-example-a.xml").getFile();
|
||||
ourLog.info(profilePath);
|
||||
ourLog.info(resourcePath);
|
||||
|
||||
App.main(new String[] {"validate", "-p", "-f", resourcePath, "-l", profilePath});
|
||||
App.main(new String[] {"validate", "-p", "-n", resourcePath, "-l", profilePath});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package ca.uhn.fhir.jpa.config;
|
||||
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR JPA Server
|
||||
|
@ -34,6 +38,8 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
|
@ -110,11 +116,22 @@ public class BaseConfig implements SchedulingConfigurer {
|
|||
return new StaleSearchDeletingSvc();
|
||||
}
|
||||
|
||||
@Bean()
|
||||
public ScheduledExecutorFactoryBean scheduledExecutorService() {
|
||||
ScheduledExecutorFactoryBean b = new ScheduledExecutorFactoryBean();
|
||||
b.setPoolSize(5);
|
||||
return b;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskScheduler taskScheduler() {
|
||||
ThreadPoolTaskScheduler retVal = new ThreadPoolTaskScheduler();
|
||||
retVal.setPoolSize(5);
|
||||
ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler();
|
||||
retVal.setConcurrentExecutor(scheduledExecutorService().getObject());
|
||||
retVal.setScheduledExecutor(scheduledExecutorService().getObject());
|
||||
return retVal;
|
||||
// ThreadPoolTaskScheduler retVal = new ThreadPoolTaskScheduler();
|
||||
// retVal.setPoolSize(5);
|
||||
// return retVal;
|
||||
}
|
||||
|
||||
@Bean(autowire = Autowire.BY_TYPE)
|
||||
|
|
|
@ -665,18 +665,21 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
theProvider.setSearchResultDao(mySearchResultDao);
|
||||
}
|
||||
|
||||
protected void notifyInterceptors(RestOperationTypeEnum operationType, ActionRequestDetails requestDetails) {
|
||||
protected void notifyInterceptors(RestOperationTypeEnum theOperationType, ActionRequestDetails requestDetails) {
|
||||
if (requestDetails.getId() != null && requestDetails.getId().hasResourceType() && isNotBlank(requestDetails.getResourceType())) {
|
||||
if (requestDetails.getId().getResourceType().equals(requestDetails.getResourceType()) == false) {
|
||||
throw new InternalErrorException("Inconsistent server state - Resource types don't match: " + requestDetails.getId().getResourceType() + " / " + requestDetails.getResourceType());
|
||||
}
|
||||
}
|
||||
|
||||
requestDetails.notifyIncomingRequestPreHandled(theOperationType);
|
||||
|
||||
List<IServerInterceptor> interceptors = getConfig().getInterceptors();
|
||||
if (interceptors == null) {
|
||||
return;
|
||||
}
|
||||
for (IServerInterceptor next : interceptors) {
|
||||
next.incomingRequestPreHandled(operationType, requestDetails);
|
||||
next.incomingRequestPreHandled(theOperationType, requestDetails);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
|
|||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
|
@ -50,6 +51,7 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
|||
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
|
||||
import ca.uhn.fhir.rest.method.IRequestOperationCallback;
|
||||
import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
|
@ -71,8 +73,9 @@ public class BaseJpaTest {
|
|||
|
||||
@Before
|
||||
public void beforeCreateSrd() {
|
||||
mySrd = mock(ServletRequestDetails.class);
|
||||
mySrd = mock(ServletRequestDetails.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
when(mySrd.getRequestOperationCallback()).thenReturn(mock(IRequestOperationCallback.class));
|
||||
when(mySrd.getServer().getInterceptors()).thenReturn(new ArrayList<IServerInterceptor>());
|
||||
}
|
||||
|
||||
protected List<IIdType> toUnqualifiedVersionlessIds(Bundle theFound) {
|
||||
|
|
|
@ -9,7 +9,6 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -46,7 +45,6 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
|
|||
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
@ -61,7 +59,6 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
private static IFhirResourceDao<Observation> ourObservationDao;
|
||||
private static IFhirResourceDao<Patient> ourPatientDao;
|
||||
private static IFhirSystemDao<List<IResource>, MetaDt> ourSystemDao;
|
||||
private RequestDetails myRequestDetails;
|
||||
private static EntityManager ourEntityManager;
|
||||
private static PlatformTransactionManager ourTxManager;
|
||||
|
||||
|
@ -74,7 +71,6 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
myRequestDetails = mock(RequestDetails.class);
|
||||
super.purgeDatabase(ourEntityManager, ourTxManager);
|
||||
}
|
||||
|
||||
|
@ -163,7 +159,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
|
||||
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) patient, obs));
|
||||
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) patient, obs));
|
||||
|
||||
String patientId = (patient.getId().getIdPart());
|
||||
String obsId = (obs.getId().getIdPart());
|
||||
|
@ -192,7 +188,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
|
||||
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO02");
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) patient, obs));
|
||||
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) patient, obs));
|
||||
|
||||
String patientId2 = (patient.getId().getIdPart());
|
||||
String patientVersion2 = (patient.getId().getVersionIdPart());
|
||||
|
@ -213,7 +209,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
obs.setSubject(new ResourceReferenceDt("Patient/999998888888"));
|
||||
|
||||
try {
|
||||
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) obs));
|
||||
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) obs));
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.getMessage(), containsString("Resource Patient/999998888888 not found, specified in path: Observation.subject"));
|
||||
}
|
||||
|
@ -223,7 +219,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
obs.setSubject(new ResourceReferenceDt("Patient/1.2.3.4"));
|
||||
|
||||
try {
|
||||
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) obs));
|
||||
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) obs));
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.getMessage(), containsString("Resource Patient/1.2.3.4 not found, specified in path: Observation.subject"));
|
||||
}
|
||||
|
@ -313,7 +309,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
patient2.setId(new IdDt("Patient/testTransactionFailsWithDusplicateIds"));
|
||||
patient2.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) patient1, patient2));
|
||||
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) patient1, patient2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -323,7 +319,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
Bundle bundle = ourFhirContext.newXmlParser().parseBundle(new InputStreamReader(bundleRes));
|
||||
List<IResource> res = bundle.toListOfResources();
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, res);
|
||||
ourSystemDao.transaction(mySrd, res);
|
||||
|
||||
Patient p1 = (Patient) res.get(0);
|
||||
String id = p1.getId().getValue();
|
||||
|
@ -356,7 +352,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
o2.setSubject(new ResourceReferenceDt("Patient/cid:patient1"));
|
||||
res.add(o2);
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, res);
|
||||
ourSystemDao.transaction(mySrd, res);
|
||||
|
||||
assertTrue(p1.getId().getValue(), p1.getId().getIdPart().matches("^[0-9]+$"));
|
||||
assertTrue(o1.getId().getValue(), o1.getId().getIdPart().matches("^[0-9]+$"));
|
||||
|
@ -378,7 +374,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
res.add(next.getResource());
|
||||
}
|
||||
|
||||
List<IResource> response = ourSystemDao.transaction(myRequestDetails, res);
|
||||
List<IResource> response = ourSystemDao.transaction(mySrd, res);
|
||||
|
||||
String encodeResourceToString = ourFhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(response.get(0));
|
||||
ourLog.info(encodeResourceToString);
|
||||
|
@ -411,7 +407,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
o2.setSubject(new ResourceReferenceDt("cid:patient1"));
|
||||
res.add(o2);
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, res);
|
||||
ourSystemDao.transaction(mySrd, res);
|
||||
|
||||
assertTrue(p1.getId().getValue(), p1.getId().getIdPart().matches("^[0-9]+$"));
|
||||
assertTrue(o1.getId().getValue(), o1.getId().getIdPart().matches("^[0-9]+$"));
|
||||
|
@ -444,7 +440,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
p3.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
|
||||
res.add(p3);
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, res);
|
||||
ourSystemDao.transaction(mySrd, res);
|
||||
|
||||
/*
|
||||
* Verify
|
||||
|
@ -470,7 +466,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
|
|||
ResourceMetadataKeyEnum.DELETED_AT.put(p2, InstantDt.withCurrentTime());
|
||||
res.add(p2);
|
||||
|
||||
ourSystemDao.transaction(myRequestDetails, res);
|
||||
ourSystemDao.transaction(mySrd, res);
|
||||
|
||||
/*
|
||||
* Verify
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
|
|
@ -82,19 +82,13 @@ import ca.uhn.fhir.util.TestUtil;
|
|||
//@formatter:on
|
||||
public abstract class BaseJpaDstu3Test extends BaseJpaTest {
|
||||
|
||||
private static IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> ourValueSetDao;
|
||||
private static JpaValidationSupportChainDstu3 ourJpaValidationSupportChainDstu3;
|
||||
private static IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> ourValueSetDao;
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private JpaValidationSupportChainDstu3 myJpaValidationSupportChainDstu3;
|
||||
@Autowired
|
||||
protected ApplicationContext myAppCtx;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("myCodeSystemDaoDstu3")
|
||||
protected IFhirResourceDao<CodeSystem> myCodeSystemDao;
|
||||
|
@ -126,6 +120,8 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
|
|||
protected IFhirResourceDao<Immunization> myImmunizationDao;
|
||||
protected IServerInterceptor myInterceptor;
|
||||
@Autowired
|
||||
private JpaValidationSupportChainDstu3 myJpaValidationSupportChainDstu3;
|
||||
@Autowired
|
||||
@Qualifier("myLocationDaoDstu3")
|
||||
protected IFhirResourceDao<Location> myLocationDao;
|
||||
@Autowired
|
||||
|
@ -140,14 +136,14 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
|
|||
@Autowired
|
||||
@Qualifier("myNamingSystemDaoDstu3")
|
||||
protected IFhirResourceDao<NamingSystem> myNamingSystemDao;
|
||||
@Autowired
|
||||
@Qualifier("myObservationDaoDstu3")
|
||||
protected IFhirResourceDao<Observation> myObservationDao;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("myObservationDaoDstu3")
|
||||
protected IFhirResourceDao<Observation> myObservationDao;
|
||||
@Qualifier("myOrganizationDaoDstu3")
|
||||
protected IFhirResourceDao<Organization> myOrganizationDao;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("myOrganizationDaoDstu3")
|
||||
protected IFhirResourceDao<Organization> myOrganizationDao;
|
||||
@Autowired
|
||||
@Qualifier("myPatientDaoDstu3")
|
||||
protected IFhirResourceDaoPatient<Patient> myPatientDao;
|
||||
|
@ -204,7 +200,6 @@ protected IFhirResourceDao<Observation> myObservationDao;
|
|||
myInterceptor = mock(IServerInterceptor.class);
|
||||
myDaoConfig.setInterceptors(myInterceptor);
|
||||
}
|
||||
|
||||
@Before
|
||||
@Transactional
|
||||
public void beforeFlushFT() {
|
||||
|
@ -230,7 +225,6 @@ protected IFhirResourceDao<Observation> myObservationDao;
|
|||
myDaoConfig.setIncludeLimit(2000);
|
||||
}
|
||||
|
||||
|
||||
protected <T extends IBaseResource> T loadResourceFromClasspath(Class<T> type, String resourceName) throws IOException {
|
||||
InputStream stream = FhirResourceDaoDstu2SearchNoFtTest.class.getResourceAsStream(resourceName);
|
||||
if (stream == null) {
|
||||
|
@ -241,6 +235,7 @@ protected IFhirResourceDao<Observation> myObservationDao;
|
|||
return newJsonParser.parseResource(type, string);
|
||||
}
|
||||
|
||||
|
||||
public TransactionTemplate newTxTemplate() {
|
||||
TransactionTemplate retVal = new TransactionTemplate(myTxManager);
|
||||
retVal.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
|
@ -249,9 +244,10 @@ protected IFhirResourceDao<Observation> myObservationDao;
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterFlushCaches() {
|
||||
public static void afterClassClearContextBaseJpaDstu3Test() throws Exception {
|
||||
ourValueSetDao.purgeCaches();
|
||||
ourJpaValidationSupportChainDstu3.flush();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,267 @@
|
|||
package ca.uhn.fhir.jpa.provider.dstu3;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsInRelativeOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.hl7.fhir.dstu3.model.BaseResource;
|
||||
import org.hl7.fhir.dstu3.model.Bundle;
|
||||
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
||||
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
|
||||
import org.hl7.fhir.dstu3.model.Bundle.SearchEntryMode;
|
||||
import org.hl7.fhir.dstu3.model.CodeSystem;
|
||||
import org.hl7.fhir.dstu3.model.Coding;
|
||||
import org.hl7.fhir.dstu3.model.Condition;
|
||||
import org.hl7.fhir.dstu3.model.DateTimeType;
|
||||
import org.hl7.fhir.dstu3.model.DateType;
|
||||
import org.hl7.fhir.dstu3.model.Device;
|
||||
import org.hl7.fhir.dstu3.model.DiagnosticOrder;
|
||||
import org.hl7.fhir.dstu3.model.DocumentManifest;
|
||||
import org.hl7.fhir.dstu3.model.DocumentReference;
|
||||
import org.hl7.fhir.dstu3.model.Encounter;
|
||||
import org.hl7.fhir.dstu3.model.Encounter.EncounterClass;
|
||||
import org.hl7.fhir.dstu3.model.Encounter.EncounterLocationComponent;
|
||||
import org.hl7.fhir.dstu3.model.Encounter.EncounterState;
|
||||
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
|
||||
import org.hl7.fhir.dstu3.model.IdType;
|
||||
import org.hl7.fhir.dstu3.model.ImagingStudy;
|
||||
import org.hl7.fhir.dstu3.model.InstantType;
|
||||
import org.hl7.fhir.dstu3.model.Location;
|
||||
import org.hl7.fhir.dstu3.model.Medication;
|
||||
import org.hl7.fhir.dstu3.model.MedicationOrder;
|
||||
import org.hl7.fhir.dstu3.model.Meta;
|
||||
import org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus;
|
||||
import org.hl7.fhir.dstu3.model.Observation;
|
||||
import org.hl7.fhir.dstu3.model.OperationOutcome;
|
||||
import org.hl7.fhir.dstu3.model.Organization;
|
||||
import org.hl7.fhir.dstu3.model.Parameters;
|
||||
import org.hl7.fhir.dstu3.model.Patient;
|
||||
import org.hl7.fhir.dstu3.model.Period;
|
||||
import org.hl7.fhir.dstu3.model.Practitioner;
|
||||
import org.hl7.fhir.dstu3.model.Questionnaire;
|
||||
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType;
|
||||
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
|
||||
import org.hl7.fhir.dstu3.model.Reference;
|
||||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
import org.hl7.fhir.dstu3.model.Subscription;
|
||||
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType;
|
||||
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus;
|
||||
import org.hl7.fhir.dstu3.model.TemporalPrecisionEnum;
|
||||
import org.hl7.fhir.dstu3.model.UnsignedIntType;
|
||||
import org.hl7.fhir.dstu3.model.ValueSet;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.SummaryEnum;
|
||||
import ca.uhn.fhir.rest.client.IGenericClient;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
||||
import ca.uhn.fhir.rest.param.StringAndListParam;
|
||||
import ca.uhn.fhir.rest.param.StringOrListParam;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.auth.IAuthRule;
|
||||
import ca.uhn.fhir.rest.server.interceptor.auth.PolicyEnum;
|
||||
import ca.uhn.fhir.rest.server.interceptor.auth.RuleBuilder;
|
||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
|
||||
public class AuthorizationInterceptorResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(AuthorizationInterceptorResourceProviderDstu3Test.class);
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
super.before();
|
||||
myDaoConfig.setAllowMultipleDelete(true);
|
||||
unregisterInterceptors();
|
||||
}
|
||||
|
||||
|
||||
private void unregisterInterceptors() {
|
||||
for (IServerInterceptor next : new ArrayList<IServerInterceptor>(ourRestServer.getInterceptors())) {
|
||||
if (next instanceof AuthorizationInterceptor) {
|
||||
ourRestServer.unregisterInterceptor(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateConditional() {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
||||
patient.addName().addFamily("Tester").addGiven("Raghad");
|
||||
final MethodOutcome output1 = ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute();
|
||||
|
||||
ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) {
|
||||
@Override
|
||||
public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
|
||||
//@formatter:off
|
||||
return new RuleBuilder()
|
||||
.allow("Rule 2").write().allResources().inCompartment("Patient", new IdDt("Patient/" + output1.getId().getIdPart())).andThen()
|
||||
.build();
|
||||
//@formatter:on
|
||||
}
|
||||
});
|
||||
|
||||
patient = new Patient();
|
||||
patient.setId(output1.getId().toUnqualifiedVersionless());
|
||||
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
||||
patient.addName().addFamily("Tester").addGiven("Raghad");
|
||||
MethodOutcome output2 = ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute();
|
||||
|
||||
assertEquals(output1.getId().getIdPart(), output2.getId().getIdPart());
|
||||
|
||||
patient = new Patient();
|
||||
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
||||
patient.addName().addFamily("Tester").addGiven("Raghad");
|
||||
try {
|
||||
ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|101").execute();
|
||||
fail();
|
||||
} catch (ForbiddenOperationException e) {
|
||||
assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage());
|
||||
}
|
||||
|
||||
patient = new Patient();
|
||||
patient.setId("999");
|
||||
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
||||
patient.addName().addFamily("Tester").addGiven("Raghad");
|
||||
try {
|
||||
ourClient.update().resource(patient).execute();
|
||||
fail();
|
||||
} catch (ForbiddenOperationException e) {
|
||||
assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteResourceConditional() throws IOException {
|
||||
String methodName = "testDeleteResourceConditional";
|
||||
|
||||
Patient pt = new Patient();
|
||||
pt.addName().addFamily(methodName);
|
||||
String resource = myFhirCtx.newXmlParser().encodeResourceToString(pt);
|
||||
|
||||
HttpPost post = new HttpPost(ourServerBase + "/Patient");
|
||||
post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
CloseableHttpResponse response = ourHttpClient.execute(post);
|
||||
final IdType id;
|
||||
try {
|
||||
assertEquals(201, response.getStatusLine().getStatusCode());
|
||||
String newIdString = response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue();
|
||||
assertThat(newIdString, startsWith(ourServerBase + "/Patient/"));
|
||||
id = new IdType(newIdString);
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
|
||||
pt = new Patient();
|
||||
pt.addName().addFamily("FOOFOOFOO");
|
||||
resource = myFhirCtx.newXmlParser().encodeResourceToString(pt);
|
||||
|
||||
post = new HttpPost(ourServerBase + "/Patient");
|
||||
post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
response = ourHttpClient.execute(post);
|
||||
final IdType id2;
|
||||
try {
|
||||
assertEquals(201, response.getStatusLine().getStatusCode());
|
||||
String newIdString = response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue();
|
||||
assertThat(newIdString, startsWith(ourServerBase + "/Patient/"));
|
||||
id2 = new IdType(newIdString);
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
|
||||
ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) {
|
||||
@Override
|
||||
public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
|
||||
//@formatter:off
|
||||
return new RuleBuilder()
|
||||
.allow("Rule 2").delete().allResources().inCompartment("Patient", new IdDt("Patient/" + id.getIdPart())).andThen()
|
||||
.build();
|
||||
//@formatter:on
|
||||
}
|
||||
});
|
||||
|
||||
HttpDelete delete = new HttpDelete(ourServerBase + "/Patient?name=" + methodName);
|
||||
response = ourHttpClient.execute(delete);
|
||||
try {
|
||||
assertEquals(204, response.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
|
||||
delete = new HttpDelete(ourServerBase + "/Patient?name=FOOFOOFOO");
|
||||
response = ourHttpClient.execute(delete);
|
||||
try {
|
||||
assertEquals(403, response.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -42,48 +42,19 @@ import ca.uhn.fhir.util.TestUtil;
|
|||
|
||||
public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test {
|
||||
|
||||
private static JpaValidationSupportChainDstu3 myValidationSupport;
|
||||
protected static IGenericClient ourClient;
|
||||
protected static CloseableHttpClient ourHttpClient;
|
||||
protected static int ourPort;
|
||||
protected static RestfulServer ourRestServer;
|
||||
private static Server ourServer;
|
||||
protected static String ourServerBase;
|
||||
protected static RestfulServer ourRestServer;
|
||||
private static JpaValidationSupportChainDstu3 myValidationSupport;
|
||||
private static GenericWebApplicationContext ourWebApplicationContext;
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
|
||||
public BaseResourceProviderDstu3Test() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected List<String> toNameList(Bundle resp) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (BundleEntryComponent next : resp.getEntry()) {
|
||||
Patient nextPt = (Patient) next.getResource();
|
||||
String nextStr = nextPt.getName().size() > 0 ? nextPt.getName().get(0).getGivenAsSingleString() + " " + nextPt.getName().get(0).getFamilyAsSingleString() : "";
|
||||
if (isNotBlank(nextStr)) {
|
||||
names.add(nextStr);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
ourHttpClient.close();
|
||||
ourServer = null;
|
||||
ourHttpClient = null;
|
||||
myValidationSupport.flush();
|
||||
myValidationSupport = null;
|
||||
ourWebApplicationContext.close();
|
||||
ourWebApplicationContext = null;
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
|
@ -159,4 +130,29 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test {
|
|||
}
|
||||
}
|
||||
|
||||
protected List<String> toNameList(Bundle resp) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (BundleEntryComponent next : resp.getEntry()) {
|
||||
Patient nextPt = (Patient) next.getResource();
|
||||
String nextStr = nextPt.getName().size() > 0 ? nextPt.getName().get(0).getGivenAsSingleString() + " " + nextPt.getName().get(0).getFamilyAsSingleString() : "";
|
||||
if (isNotBlank(nextStr)) {
|
||||
names.add(nextStr);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContextBaseResourceProviderDstu3Test() throws Exception {
|
||||
ourServer.stop();
|
||||
ourHttpClient.close();
|
||||
ourServer = null;
|
||||
ourHttpClient = null;
|
||||
myValidationSupport.flush();
|
||||
myValidationSupport = null;
|
||||
ourWebApplicationContext.close();
|
||||
ourWebApplicationContext = null;
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package ca.uhn.fhir.context;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
|
@ -14,6 +15,7 @@ import ca.uhn.fhir.model.dstu.resource.Observation;
|
|||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.Profile;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by Bill de Beaubien on 12/10/2014.
|
||||
|
@ -79,4 +81,10 @@ public class DuplicateExtensionTest extends TestCase {
|
|||
@ProvidesResources(resources = CustomPatient.class)
|
||||
public static class CustomPatientProvider {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
|
@ -12,6 +13,7 @@ import ca.uhn.fhir.model.primitive.StringDt;
|
|||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.parser.MyPatient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ExtensionTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExtensionTest.class);
|
||||
|
@ -84,4 +86,10 @@ public class ExtensionTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ package ca.uhn.fhir.context;
|
|||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.ValueSet;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class FhirContextDstu1Test {
|
||||
|
||||
|
@ -58,4 +60,10 @@ public class FhirContextDstu1Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package ca.uhn.fhir.context;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class FhirVersionEnumTest {
|
||||
|
||||
@Test
|
||||
|
@ -11,4 +14,10 @@ public class FhirVersionEnumTest {
|
|||
assertFalse(FhirVersionEnum.DSTU1.isNewerThan(FhirVersionEnum.DSTU2));
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ package ca.uhn.fhir.context;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class InvalidResourceTypeTest {
|
||||
|
||||
|
@ -28,4 +30,10 @@ public class InvalidResourceTypeTest {
|
|||
// nothing
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package ca.uhn.fhir.context;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.parser.MyOrganization;
|
||||
import ca.uhn.fhir.parser.MyPatient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ModelExtensionTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ModelExtensionTest.class);
|
||||
|
@ -35,4 +37,10 @@ public class ModelExtensionTest {
|
|||
// assertEquals("arg0", parsedOrg.getName().getValue());
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -14,6 +15,7 @@ import ca.uhn.fhir.model.dstu.resource.CarePlan;
|
|||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.parser.MyPatient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ModelScannerDstu1Test {
|
||||
|
||||
|
@ -129,4 +131,10 @@ public class ModelScannerDstu1Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,11 +4,13 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.ClassPath;
|
||||
|
@ -80,5 +82,10 @@ public class NameChanges {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,12 +3,15 @@ package ca.uhn.fhir.context;
|
|||
import ca.uhn.fhir.model.api.annotation.ProvidesResources;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
|
||||
public class ProvidedResourceScannerTest extends TestCase {
|
||||
@Test
|
||||
public void testScannerShouldAddProvidedResources() {
|
||||
|
@ -33,4 +36,10 @@ public class ProvidedResourceScannerTest extends TestCase {
|
|||
@ProvidesResources(resources = { CustomPatient.class, ResourceWithExtensionsA.class })
|
||||
public static class TestResourceProviderB {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@ package ca.uhn.fhir.context;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
|
||||
import ca.uhn.fhir.model.api.BaseIdentifiableElement;
|
||||
import ca.uhn.fhir.model.api.IElement;
|
||||
import ca.uhn.fhir.model.api.IExtension;
|
||||
|
@ -12,6 +14,7 @@ import ca.uhn.fhir.model.dstu.resource.BaseResource;
|
|||
import ca.uhn.fhir.model.primitive.DateDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
@ResourceDef(name = "ResourceWithExtensionsA", id="0001")
|
||||
public class ResourceWithExtensionsA extends BaseResource {
|
||||
|
@ -212,4 +215,10 @@ public class ResourceWithExtensionsA extends BaseResource {
|
|||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -8,6 +8,9 @@ import ca.uhn.fhir.model.dstu.resource.Profile.Structure;
|
|||
import ca.uhn.fhir.model.dstu.resource.Profile.StructureElement;
|
||||
import ca.uhn.fhir.model.dstu.resource.ValueSet;
|
||||
import ca.uhn.fhir.model.dstu.valueset.DataTypeEnum;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -147,4 +150,10 @@ public class RuntimeResourceDefinitionTest {
|
|||
public static class PatientWithShortProfile extends Patient {
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class TagListTest {
|
||||
|
||||
|
@ -78,4 +80,10 @@ public class TagListTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,11 @@ package ca.uhn.fhir.model.base.composite;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.composite.CodingDt;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -68,4 +72,10 @@ public class BaseCodingDtTest {
|
|||
public void whenTokenIncludesEmptySystem_CodeWithSystem_shouldNotMatch() {
|
||||
assertFalse(new CodingDt("http://bar.org", "53").matchesToken(myTokenWithEmptySystem));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package ca.uhn.fhir.model.primitive;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
|
||||
public class Base64BinaryDtTest {
|
||||
|
||||
|
@ -10,4 +13,10 @@ public class Base64BinaryDtTest {
|
|||
new Base64BinaryDt().setValueAsString(null);
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.TimeZone;
|
|||
|
||||
import org.apache.commons.lang3.time.FastDateFormat;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -21,6 +22,7 @@ import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
|||
import ca.uhn.fhir.model.dstu.resource.Condition;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
|
||||
public class BaseDateTimeDtTest {
|
||||
|
@ -279,4 +281,10 @@ public class BaseDateTimeDtTest {
|
|||
assertEquals("2014-06-20T20:22:09Z", i.getValueAsString());
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package ca.uhn.fhir.model.primitive;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.CodingDt;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class CodingDtTest {
|
||||
|
||||
|
@ -55,4 +57,10 @@ public class CodingDtTest {
|
|||
|
||||
assertEquals("|b\\|c", dt.getValueAsQueryToken(ourCtx));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package ca.uhn.fhir.model.primitive;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class DecimalDtTest {
|
||||
|
||||
@Test
|
||||
|
@ -13,4 +16,10 @@ public class DecimalDtTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,14 @@ import static org.junit.Assert.*;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class IdDtTest {
|
||||
|
||||
|
@ -230,4 +232,10 @@ public class IdDtTest {
|
|||
ourCtx = FhirContext.forDstu1();
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package ca.uhn.fhir.model.primitive;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class IdentifierDtTest {
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
|
@ -56,4 +58,10 @@ public class IdentifierDtTest {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package ca.uhn.fhir.model.primitive;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class StringDtTest {
|
||||
|
||||
@Test
|
||||
|
@ -13,4 +16,10 @@ public class StringDtTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package ca.uhn.fhir.model.primitive;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class UriDtTest {
|
||||
@Test
|
||||
public void testEquals() {
|
||||
|
@ -16,4 +19,10 @@ public class UriDtTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package ca.uhn.fhir.model.primitive;
|
|||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class XhtmlDtTest {
|
||||
|
||||
|
@ -97,4 +99,10 @@ public class XhtmlDtTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
@ -11,6 +12,7 @@ import ca.uhn.fhir.model.api.ExtensionDt;
|
|||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ViewGeneratorTest {
|
||||
|
||||
|
@ -107,4 +109,10 @@ public class ViewGeneratorTest {
|
|||
|
||||
assertEquals(0, va.getAllUndeclaredExtensions().size());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package ca.uhn.fhir.narrative;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class BaseThymeleafNarrativeGeneratorTest {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGeneratorTest.class);
|
||||
|
||||
|
@ -59,4 +62,10 @@ public class BaseThymeleafNarrativeGeneratorTest {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ package ca.uhn.fhir.narrative;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Practitioner;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class CustomThymeleafNarrativeGeneratorTest {
|
||||
|
||||
|
@ -35,4 +37,10 @@ public class CustomThymeleafNarrativeGeneratorTest {
|
|||
assertThat(actual, containsString("<h1>Name</h1><div class=\"nameElement\"> given <b>FAM1 </b></div><h1>Address</h1><div><span>line1 </span><br /><span>line2 </span><br /></div></div>"));
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.InputStreamReader;
|
|||
import java.util.Date;
|
||||
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -33,6 +34,7 @@ import ca.uhn.fhir.model.dstu.valueset.ObservationStatusEnum;
|
|||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class DefaultThymeleafNarrativeGeneratorTest {
|
||||
private FhirContext myCtx;
|
||||
|
@ -238,4 +240,10 @@ public class DefaultThymeleafNarrativeGeneratorTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,11 +5,13 @@ import static org.hamcrest.Matchers.not;
|
|||
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.AllergyIntolerance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Composition;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class BaseParserTest {
|
||||
|
||||
|
@ -156,4 +158,10 @@ public class BaseParserTest {
|
|||
assertEquals(WorkflowActionEnum.SIGNOFF, res.getWorkflowAction().getValueAsEnum());
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -31,6 +32,7 @@ import ca.uhn.fhir.model.dstu.valueset.NameUseEnum;
|
|||
import ca.uhn.fhir.model.dstu.valueset.PractitionerRoleEnum;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.server.IVersionSpecificBundleFactory;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Initially contributed by Alexander Kley for bug #29
|
||||
|
@ -249,4 +251,10 @@ public class ContainedResourceEncodingTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.hamcrest.core.StringContains;
|
|||
import org.hamcrest.text.StringContainsInOrder;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.INarrative;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
|
@ -74,6 +75,7 @@ import ca.uhn.fhir.model.primitive.InstantDt;
|
|||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import net.sf.json.JSON;
|
||||
import net.sf.json.JSONSerializer;
|
||||
|
||||
|
@ -1484,4 +1486,10 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.hamcrest.core.StringContains;
|
|||
import org.hamcrest.text.StringContainsInOrder;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.INarrative;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -72,6 +73,7 @@ import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
|||
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
||||
import ca.uhn.fhir.parser.JsonParserTest.MyPatientWithOneDeclaredAddressExtension;
|
||||
import ca.uhn.fhir.parser.JsonParserTest.MyPatientWithOneDeclaredExtension;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class XmlParserTest {
|
||||
|
||||
|
@ -1957,4 +1959,10 @@ public class XmlParserTest {
|
|||
System.setProperty("file.encoding", "ISO-8859-1");
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.http.client.HttpClient;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -25,6 +26,7 @@ import ca.uhn.fhir.context.FhirContext;
|
|||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -100,4 +102,10 @@ public class BasicAuthInterceptorTest {
|
|||
ourCtx = FhirContext.forDstu1();
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.http.client.HttpClient;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -25,6 +26,7 @@ import ca.uhn.fhir.context.FhirContext;
|
|||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -85,4 +87,10 @@ public class BearerTokenAuthInterceptorTest {
|
|||
ourCtx = FhirContext.forDstu1();
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -33,6 +34,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
|
|||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class BinaryClientTest {
|
||||
|
||||
|
@ -106,4 +108,10 @@ public class BinaryClientTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.http.message.BasicHeader;
|
|||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.hamcrest.core.StringEndsWith;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -86,6 +87,7 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
|||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
|
||||
public class ClientDstu1Test {
|
||||
|
@ -1410,4 +1412,10 @@ public class ClientDstu1Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -28,6 +29,7 @@ import ca.uhn.fhir.rest.client.api.IBasicClient;
|
|||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ClientIntegrationTest {
|
||||
|
||||
|
@ -116,4 +118,10 @@ public class ClientIntegrationTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.http.client.HttpClient;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -29,6 +30,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
|
|||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ClientServerValidationTestDstu {
|
||||
|
||||
|
@ -106,4 +108,10 @@ public class ClientServerValidationTestDstu {
|
|||
assertThat(e.toString(), containsString("The server at base URL \"http://foo/metadata\" returned a conformance statement indicating that it supports FHIR version \"0.4.0\" which corresponds to DSTU2, but this client is configured to use DSTU1 (via the FhirContext)"));
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.apache.http.client.methods.HttpUriRequest;
|
|||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -30,6 +31,7 @@ import ca.uhn.fhir.rest.annotation.Read;
|
|||
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ExceptionHandlingTest {
|
||||
|
||||
|
@ -182,4 +184,10 @@ public class ExceptionHandlingTest {
|
|||
Patient read(@IdParam IdDt theId);
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.http.message.BasicHeader;
|
|||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -62,6 +63,7 @@ import ca.uhn.fhir.rest.server.Constants;
|
|||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
|
||||
public class GenericClientTest {
|
||||
|
@ -1675,4 +1677,10 @@ public class GenericClientTest {
|
|||
ourCtx = FhirContext.forDstu1();
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -33,6 +34,7 @@ import ca.uhn.fhir.rest.annotation.Read;
|
|||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class HttpProxyTest {
|
||||
private static FhirContext ourCtx;
|
||||
|
@ -148,4 +150,10 @@ public class HttpProxyTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -30,6 +31,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
|
|||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.IncludeTest;
|
||||
import ca.uhn.fhir.rest.server.IncludeTest.ExtPatient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class IncludedResourceStitchingClientTest {
|
||||
|
||||
|
@ -245,4 +247,10 @@ public class IncludedResourceStitchingClientTest {
|
|||
//@formatter:off
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
|||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ch.qos.logback.classic.BasicConfigurator;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
|
@ -42,11 +43,16 @@ import ch.qos.logback.core.Appender;
|
|||
*/
|
||||
public class LoggingInterceptorTest {
|
||||
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private Appender<ILoggingEvent> myMockAppender;
|
||||
private Logger myLoggerRoot;
|
||||
private Appender<ILoggingEvent> myMockAppender;
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
myLoggerRoot.detachAppender(myMockAppender);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
|
@ -64,11 +70,6 @@ public class LoggingInterceptorTest {
|
|||
myLoggerRoot.addAppender(myMockAppender);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
myLoggerRoot.detachAppender(myMockAppender);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogger() throws Exception {
|
||||
System.out.println("Starting testLogger");
|
||||
|
@ -88,8 +89,9 @@ public class LoggingInterceptorTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -119,6 +121,7 @@ public class LoggingInterceptorTest {
|
|||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -29,6 +30,7 @@ import ca.uhn.fhir.rest.annotation.Search;
|
|||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ReferenceClientTest {
|
||||
|
||||
|
@ -125,4 +127,10 @@ public class ReferenceClientTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.http.client.methods.HttpUriRequest;
|
|||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -41,6 +42,7 @@ import ca.uhn.fhir.rest.param.TokenOrListParam;
|
|||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class SearchClientDstu1Test {
|
||||
|
||||
|
@ -127,4 +129,10 @@ public class SearchClientDstu1Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -32,6 +33,7 @@ import ca.uhn.fhir.rest.api.SortSpec;
|
|||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class SortClientTest {
|
||||
|
||||
|
@ -98,4 +100,10 @@ public class SortClientTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -29,6 +30,7 @@ import ca.uhn.fhir.rest.annotation.Search;
|
|||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class StringClientTest {
|
||||
|
||||
|
@ -113,4 +115,10 @@ public class StringClientTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -36,6 +37,7 @@ import ca.uhn.fhir.rest.annotation.TagListParam;
|
|||
import ca.uhn.fhir.rest.annotation.VersionIdParam;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class TagsClientTest {
|
||||
|
||||
|
@ -290,4 +292,10 @@ public class TagsClientTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.apache.http.client.methods.HttpPost;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -34,6 +35,7 @@ import ca.uhn.fhir.rest.annotation.Transaction;
|
|||
import ca.uhn.fhir.rest.annotation.TransactionParam;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class TransactionClientTest {
|
||||
|
||||
|
@ -155,4 +157,10 @@ public class TransactionClientTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package ca.uhn.fhir.rest.method;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class BaseOutcomeReturningMethodBindingTest {
|
||||
|
||||
|
@ -193,4 +195,10 @@ public class BaseOutcomeReturningMethodBindingTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,11 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class QualifiedParamListTest {
|
||||
|
||||
@Test
|
||||
|
@ -32,4 +35,10 @@ public class QualifiedParamListTest {
|
|||
assertEquals("b,bb", actual.get(1));
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
|
@ -15,10 +16,11 @@ import ca.uhn.fhir.model.primitive.DateTimeDt;
|
|||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.rest.method.QualifiedParamList;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class DateRangeParamTest {
|
||||
|
||||
private static SimpleDateFormat ourFmt;
|
||||
private static final SimpleDateFormat ourFmt;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateRangeParamTest.class);
|
||||
|
||||
static {
|
||||
|
@ -167,4 +169,10 @@ public class DateRangeParamTest {
|
|||
return new Date(ourFmt.parse(theString).getTime() - 1L);
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package ca.uhn.fhir.rest.param;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class QuantityParamTest {
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
|
@ -57,4 +59,10 @@ public class QuantityParamTest {
|
|||
assertEquals("5.4||", p.getValueAsQueryToken(ourCtx));
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package ca.uhn.fhir.rest.param;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ReferenceParamTest {
|
||||
|
||||
@Test
|
||||
|
@ -26,4 +29,10 @@ public class ReferenceParamTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ package ca.uhn.fhir.rest.param;
|
|||
import static org.junit.Assert.*;
|
||||
import ca.uhn.fhir.model.dstu.composite.CodingDt;
|
||||
import ca.uhn.fhir.rest.method.QualifiedParamList;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -62,4 +64,10 @@ public class TokenOrListParamTest {
|
|||
assertEquals("code-include-but-not-end-with-comma,suffix", params.getListAsCodings().get(0).getCodeElement().getValue());
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
|
|||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -31,9 +32,9 @@ import ca.uhn.fhir.util.PortUtil;
|
|||
public class AcceptHeaderTest {
|
||||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
|
||||
@Test
|
||||
public void testReadNoHeader() throws Exception {
|
||||
|
@ -54,16 +55,6 @@ public class AcceptHeaderTest {
|
|||
assertEquals(Constants.CT_FHIR_XML + Constants.CHARSET_UTF8_CTSUFFIX.replace(" ", "").toLowerCase(), status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue().replace(" ", "").replace("UTF", "utf"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadXmlHeaderHigherPriorityWithStar() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
|
||||
httpGet.addHeader(Constants.HEADER_ACCEPT, "*/*; q=1.0, " + Constants.CT_FHIR_XML + "; q=1.0, " + Constants.CT_FHIR_JSON + "; q=0.9");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(Constants.CT_FHIR_XML + Constants.CHARSET_UTF8_CTSUFFIX.replace(" ", "").toLowerCase(), status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue().replace(" ", "").replace("UTF", "utf"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadXmlHeaderHigherPriorityBackwards() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
|
||||
|
@ -82,9 +73,20 @@ public class AcceptHeaderTest {
|
|||
assertEquals(Constants.CT_FHIR_XML + Constants.CHARSET_UTF8_CTSUFFIX.replace(" ", "").toLowerCase(), status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue().replace(" ", "").replace("UTF", "utf"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadXmlHeaderHigherPriorityWithStar() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
|
||||
httpGet.addHeader(Constants.HEADER_ACCEPT, "*/*; q=1.0, " + Constants.CT_FHIR_XML + "; q=1.0, " + Constants.CT_FHIR_JSON + "; q=0.9");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(Constants.CT_FHIR_XML + Constants.CHARSET_UTF8_CTSUFFIX.replace(" ", "").toLowerCase(), status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue().replace(" ", "").replace("UTF", "utf"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -108,11 +110,17 @@ public class AcceptHeaderTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class PatientProvider implements IResourceProvider {
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@Read(version = true)
|
||||
public Patient read(@IdParam IdDt theId) {
|
||||
Patient patient = new Patient();
|
||||
|
@ -121,11 +129,6 @@ public class AcceptHeaderTest {
|
|||
return patient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
|
|||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class BinaryTest {
|
||||
|
||||
|
@ -55,53 +56,6 @@ public class BinaryTest {
|
|||
ourLast=null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary/foo");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
byte[] responseContent = IOUtils.toByteArray(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals("foo", status.getFirstHeader("content-type").getValue());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, responseContent);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadWithExplicitTypeXml() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary/foo?_format=xml");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), "UTF-8");
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.getFirstHeader("content-type").getValue(), startsWith(Constants.CT_FHIR_XML + ";"));
|
||||
|
||||
Binary bin = ourCtx.newXmlParser().parseResource(Binary.class, responseContent);
|
||||
assertEquals("foo", bin.getContentType());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadWithExplicitTypeJson() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary/foo?_format=json");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), "UTF-8");
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.getFirstHeader("content-type").getValue(), startsWith(Constants.CT_FHIR_JSON + ";"));
|
||||
|
||||
Binary bin = ourCtx.newJsonParser().parseResource(Binary.class, responseContent);
|
||||
assertEquals("foo", bin.getContentType());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreate() throws Exception {
|
||||
HttpPost http = new HttpPost("http://localhost:" + ourPort + "/Binary");
|
||||
|
@ -132,6 +86,53 @@ public class BinaryTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary/foo");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
byte[] responseContent = IOUtils.toByteArray(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals("foo", status.getFirstHeader("content-type").getValue());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, responseContent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadWithExplicitTypeJson() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary/foo?_format=json");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), "UTF-8");
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.getFirstHeader("content-type").getValue(), startsWith(Constants.CT_FHIR_JSON + ";"));
|
||||
|
||||
Binary bin = ourCtx.newJsonParser().parseResource(Binary.class, responseContent);
|
||||
assertEquals("foo", bin.getContentType());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadWithExplicitTypeXml() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary/foo?_format=xml");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), "UTF-8");
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.getFirstHeader("content-type").getValue(), startsWith(Constants.CT_FHIR_XML + ";"));
|
||||
|
||||
Binary bin = ourCtx.newXmlParser().parseResource(Binary.class, responseContent);
|
||||
assertEquals("foo", bin.getContentType());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary?");
|
||||
|
@ -150,11 +151,13 @@ public class BinaryTest {
|
|||
assertEquals("text/plain", bin.getContentType());
|
||||
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
||||
}
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
ourPort = PortUtil.findFreePort();
|
||||
|
@ -176,7 +179,8 @@ public class BinaryTest {
|
|||
ourClient = builder.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
|
|
|
@ -33,6 +33,7 @@ import ca.uhn.fhir.rest.param.CompositeParam;
|
|||
import ca.uhn.fhir.rest.param.DateParam;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -94,8 +95,9 @@ public class CompositeParameterTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -119,6 +121,7 @@ public class CompositeParameterTest {
|
|||
ourClient = builder.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
|
|
|
@ -31,6 +31,7 @@ import ca.uhn.fhir.parser.DataFormatException;
|
|||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -38,21 +39,11 @@ import ca.uhn.fhir.util.PortUtil;
|
|||
public class CompressionTest {
|
||||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CompressionTest.class);
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
|
||||
public static String decompress(byte[] theResource) {
|
||||
GZIPInputStream is;
|
||||
try {
|
||||
is = new GZIPInputStream(new ByteArrayInputStream(theResource));
|
||||
return IOUtils.toString(is, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
throw new DataFormatException("Failed to decompress contents", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
{
|
||||
|
@ -79,7 +70,7 @@ public class CompressionTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVRead() throws Exception {
|
||||
{
|
||||
|
@ -95,8 +86,9 @@ public class CompressionTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -127,6 +119,17 @@ public class CompressionTest {
|
|||
|
||||
}
|
||||
|
||||
public static String decompress(byte[] theResource) {
|
||||
GZIPInputStream is;
|
||||
try {
|
||||
is = new GZIPInputStream(new ByteArrayInputStream(theResource));
|
||||
return IOUtils.toString(is, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
throw new DataFormatException("Failed to decompress contents", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
|||
import org.eclipse.jetty.servlet.FilterHolder;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -33,6 +34,7 @@ import ca.uhn.fhir.model.api.Bundle;
|
|||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.rest.server.RestfulServerSelfReferenceTest.DummyPatientResourceProvider;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class CorsTest {
|
||||
private static CloseableHttpClient ourClient;
|
||||
|
@ -148,4 +150,10 @@ public class CorsTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import ca.uhn.fhir.rest.annotation.Search;
|
|||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -90,50 +91,6 @@ public class CreateTest {
|
|||
assertEquals(EncodingEnum.XML, ourLastEncoding);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithWrongContentTypeXml() throws Exception {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("001");
|
||||
patient.addIdentifier().setValue("002");
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
|
||||
String inputString = ourCtx.newJsonParser().encodeResourceToString(patient);
|
||||
ContentType inputCt = ContentType.create(Constants.CT_FHIR_XML, "UTF-8");
|
||||
httpPost.setEntity(new StringEntity(inputString, inputCt));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
assertThat(responseContent, containsString("Unexpected character"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithWrongContentTypeJson() throws Exception {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("001");
|
||||
patient.addIdentifier().setValue("002");
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
|
||||
String inputString = ourCtx.newXmlParser().encodeResourceToString(patient);
|
||||
ContentType inputCt = ContentType.create(Constants.CT_FHIR_JSON, "UTF-8");
|
||||
httpPost.setEntity(new StringEntity(inputString, inputCt));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
assertThat(responseContent, containsString("Unexpected char"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateById() throws Exception {
|
||||
|
||||
|
@ -249,11 +206,56 @@ public class CreateTest {
|
|||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
ourServer.stop();
|
||||
@Test
|
||||
public void testCreateWithWrongContentTypeJson() throws Exception {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("001");
|
||||
patient.addIdentifier().setValue("002");
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
|
||||
String inputString = ourCtx.newXmlParser().encodeResourceToString(patient);
|
||||
ContentType inputCt = ContentType.create(Constants.CT_FHIR_JSON, "UTF-8");
|
||||
httpPost.setEntity(new StringEntity(inputString, inputCt));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
assertThat(responseContent, containsString("Unexpected char"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithWrongContentTypeXml() throws Exception {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("001");
|
||||
patient.addIdentifier().setValue("002");
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
|
||||
String inputString = ourCtx.newJsonParser().encodeResourceToString(patient);
|
||||
ContentType inputCt = ContentType.create(Constants.CT_FHIR_XML, "UTF-8");
|
||||
httpPost.setEntity(new StringEntity(inputString, inputCt));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
assertThat(responseContent, containsString("Unexpected character"));
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
ourPort = PortUtil.findFreePort();
|
||||
|
@ -279,6 +281,7 @@ public class CreateTest {
|
|||
ourClient = builder.build();
|
||||
|
||||
}
|
||||
|
||||
@ResourceDef(name = "Observation")
|
||||
public static class CustomObservation extends Observation {
|
||||
|
||||
|
@ -315,7 +318,7 @@ public class CreateTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class DiagnosticReportProvider implements IResourceProvider {
|
||||
private TagList myLastTags;
|
||||
|
||||
|
@ -392,6 +395,7 @@ public class CreateTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public static class PatientProvider implements IResourceProvider {
|
||||
|
||||
@Create()
|
||||
|
|
|
@ -36,6 +36,7 @@ import ca.uhn.fhir.rest.annotation.OptionalParam;
|
|||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -44,9 +45,68 @@ public class CustomTypeTest {
|
|||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static FhirContext ourCtx = new FhirContext(ExtendedPatient.class);
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomTypeTest.class);
|
||||
private static int ourPort;
|
||||
private static boolean ourReturnExtended = false;
|
||||
|
||||
|
||||
private static Server ourServer;
|
||||
|
||||
private static RestfulServer ourServlet;
|
||||
|
||||
@Test
|
||||
public void testFindProfileItself() throws Exception {
|
||||
ourServlet.setAddProfileTag(AddProfileTagEnum.ONLY_FOR_CUSTOM);
|
||||
ourReturnExtended=true;
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Profile/prof2?_pretty=true");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Profile bundle = ourCtx.newXmlParser().parseResource(Profile.class, responseContent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchReturnsNoProfileForExtendedType() throws Exception {
|
||||
ourServlet.setAddProfileTag(AddProfileTagEnum.NEVER);
|
||||
ourReturnExtended=true;
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=aaa");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
BundleEntry entry = bundle.getEntries().get(0);
|
||||
List<Tag> profileTags = entry.getCategories().getTagsWithScheme(Tag.HL7_ORG_PROFILE_TAG);
|
||||
assertEquals(0, profileTags.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchReturnsNoProfileForNormalType() throws Exception {
|
||||
ourServlet.setAddProfileTag(AddProfileTagEnum.ONLY_FOR_CUSTOM);
|
||||
ourReturnExtended=false;
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=aaa");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
BundleEntry entry = bundle.getEntries().get(0);
|
||||
List<Tag> profileTags = entry.getCategories().getTagsWithScheme(Tag.HL7_ORG_PROFILE_TAG);
|
||||
assertEquals(0, profileTags.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
|
@ -71,64 +131,7 @@ public class CustomTypeTest {
|
|||
assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString());
|
||||
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomTypeTest.class);
|
||||
|
||||
@Test
|
||||
public void testFindProfileItself() throws Exception {
|
||||
ourServlet.setAddProfileTag(AddProfileTagEnum.ONLY_FOR_CUSTOM);
|
||||
ourReturnExtended=true;
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Profile/prof2?_pretty=true");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
Profile bundle = ourCtx.newXmlParser().parseResource(Profile.class, responseContent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchReturnsNoProfileForNormalType() throws Exception {
|
||||
ourServlet.setAddProfileTag(AddProfileTagEnum.ONLY_FOR_CUSTOM);
|
||||
ourReturnExtended=false;
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=aaa");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
BundleEntry entry = bundle.getEntries().get(0);
|
||||
List<Tag> profileTags = entry.getCategories().getTagsWithScheme(Tag.HL7_ORG_PROFILE_TAG);
|
||||
assertEquals(0, profileTags.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchReturnsNoProfileForExtendedType() throws Exception {
|
||||
ourServlet.setAddProfileTag(AddProfileTagEnum.NEVER);
|
||||
ourReturnExtended=true;
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=aaa");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
BundleEntry entry = bundle.getEntries().get(0);
|
||||
List<Tag> profileTags = entry.getCategories().getTagsWithScheme(Tag.HL7_ORG_PROFILE_TAG);
|
||||
assertEquals(0, profileTags.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchReturnsProfileForNormalType() throws Exception {
|
||||
ourServlet.setAddProfileTag(AddProfileTagEnum.ALWAYS);
|
||||
|
@ -152,11 +155,13 @@ public class CustomTypeTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
ourPort = PortUtil.findFreePort();
|
||||
|
@ -183,8 +188,31 @@ public class CustomTypeTest {
|
|||
fhirContext.getResourceDefinition(ExtendedPatient.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class DummyPatientResourceProvider implements IResourceProvider {
|
||||
|
||||
@Search
|
||||
public List<Patient> findPatient(@OptionalParam(name = "_id") StringParam theParam) {
|
||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||
|
||||
Patient patient = ourReturnExtended ? new ExtendedPatient() : new Patient();
|
||||
patient.setId("1");
|
||||
patient.addIdentifier("system", "identifier123");
|
||||
if (theParam != null) {
|
||||
patient.addName().addFamily("id" + theParam.getValue());
|
||||
}
|
||||
retVal.add(patient);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ResourceDef(name="Patient", profile="http://foo/profiles/Profile", id="prof2")
|
||||
public static class ExtendedPatient extends Patient {
|
||||
|
||||
|
@ -211,30 +239,5 @@ public class CustomTypeTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean ourReturnExtended = false;
|
||||
|
||||
public static class DummyPatientResourceProvider implements IResourceProvider {
|
||||
|
||||
@Search
|
||||
public List<Patient> findPatient(@OptionalParam(name = "_id") StringParam theParam) {
|
||||
ArrayList<Patient> retVal = new ArrayList<Patient>();
|
||||
|
||||
Patient patient = ourReturnExtended ? new ExtendedPatient() : new Patient();
|
||||
patient.setId("1");
|
||||
patient.addIdentifier("system", "identifier123");
|
||||
if (theParam != null) {
|
||||
patient.addName().addFamily("id" + theParam.getValue());
|
||||
}
|
||||
retVal.add(patient);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import ca.uhn.fhir.rest.annotation.Search;
|
|||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParamTest;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -36,9 +37,28 @@ import ca.uhn.fhir.util.PortUtil;
|
|||
public class DateRangeParamSearchTest {
|
||||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static DateRangeParam ourLastDateRange;
|
||||
private static int ourPort;
|
||||
|
||||
private static Server ourServer;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ourLastDateRange = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForMultipleUnqualifiedDate() throws Exception {
|
||||
String baseUrl = "http://localhost:" + ourPort + "/Patient?" + Patient.SP_BIRTHDATE + "=";
|
||||
HttpGet httpGet = new HttpGet(baseUrl + "2012-01-01&" + Patient.SP_BIRTHDATE + "=2012-02-03");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchForOneUnqualifiedDate() throws Exception {
|
||||
|
@ -56,27 +76,12 @@ public class DateRangeParamSearchTest {
|
|||
assertEquals(DateRangeParamTest.parseM1("2012-01-02 00:00:00.0000"), ourLastDateRange.getUpperBoundAsInstant());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForMultipleUnqualifiedDate() throws Exception {
|
||||
String baseUrl = "http://localhost:" + ourPort + "/Patient?" + Patient.SP_BIRTHDATE + "=";
|
||||
HttpGet httpGet = new HttpGet(baseUrl + "2012-01-01&" + Patient.SP_BIRTHDATE + "=2012-02-03");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ourLastDateRange = null;
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -103,13 +108,18 @@ public class DateRangeParamSearchTest {
|
|||
|
||||
}
|
||||
|
||||
private static DateRangeParam ourLastDateRange;
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class DummyPatientResourceProvider implements IResourceProvider {
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
|
||||
@Search()
|
||||
public List<Patient> search(@RequiredParam(name=Patient.SP_BIRTHDATE) DateRangeParam theDateRange) {
|
||||
ourLastDateRange = theDateRange;
|
||||
|
@ -123,12 +133,6 @@ public class DateRangeParamSearchTest {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,14 +35,15 @@ import ca.uhn.fhir.model.primitive.IdDt;
|
|||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class DefaultEncodingTest {
|
||||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static int ourPort;
|
||||
private static RestfulServer ourRestfulServer;
|
||||
private static Server ourServer;
|
||||
|
||||
@Test
|
||||
public void testHonoursAcceptHeader() throws Exception {
|
||||
|
@ -174,8 +175,9 @@ public class DefaultEncodingTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -198,11 +200,17 @@ public class DefaultEncodingTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class PatientProvider implements IResourceProvider {
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@Read(version = true)
|
||||
public Patient read(@IdParam IdDt theId) {
|
||||
Patient patient = new Patient();
|
||||
|
@ -211,11 +219,6 @@ public class DefaultEncodingTest {
|
|||
return patient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Arrays;
|
|||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
@ -17,6 +18,7 @@ import ca.uhn.fhir.rest.annotation.Create;
|
|||
import ca.uhn.fhir.rest.annotation.Destroy;
|
||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by Bill de Beaubien on 11/10/2014.
|
||||
|
@ -93,4 +95,10 @@ public class DestroyTest {
|
|||
return new MethodOutcome();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -25,6 +26,7 @@ import ca.uhn.fhir.model.dstu.resource.Observation;
|
|||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.Practitioner;
|
||||
import ca.uhn.fhir.model.dstu.resource.Specimen;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by Bill de Beaubien on 3/3/2015.
|
||||
|
@ -188,4 +190,10 @@ public class Dstu1BundleFactoryTest {
|
|||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import ca.uhn.fhir.rest.param.StringAndListParam;
|
|||
import ca.uhn.fhir.rest.param.StringOrListParam;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -41,18 +42,31 @@ public class DynamicSearchTest {
|
|||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static SearchParameterMap ourLastSearchParams;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DynamicSearchTest.class);
|
||||
|
||||
private static int ourPort;
|
||||
|
||||
private static Server ourServer;
|
||||
|
||||
private static SearchParameterMap ourLastSearchParams;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ourLastSearchParams = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConformance() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata?_pretty=true");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Conformance conf = ourCtx.newXmlParser().parseResource(Conformance.class,responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchOneStringParam() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?param1=param1value");
|
||||
|
@ -72,28 +86,6 @@ public class DynamicSearchTest {
|
|||
assertEquals("param1value", param1.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchOneStringParamWithOr() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?param1=param1value,param1value2");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
assertEquals(1, ourLastSearchParams.size());
|
||||
StringAndListParam andList =(StringAndListParam) ourLastSearchParams.get("param1");
|
||||
assertEquals(1,andList.getValuesAsQueryTokens().size());
|
||||
StringOrListParam orList = andList.getValuesAsQueryTokens().get(0);
|
||||
assertEquals(2,orList.getValuesAsQueryTokens().size());
|
||||
StringParam param1 = orList.getValuesAsQueryTokens().get(0);
|
||||
assertEquals("param1value", param1.getValue());
|
||||
StringParam param1b = orList.getValuesAsQueryTokens().get(1);
|
||||
assertEquals("param1value2", param1b.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchOneStringParamWithAnd() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?param1=param1value¶m1=param1value2");
|
||||
|
@ -119,21 +111,31 @@ public class DynamicSearchTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConformance() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata?_pretty=true");
|
||||
public void testSearchOneStringParamWithOr() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?param1=param1value,param1value2");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Conformance conf = ourCtx.newXmlParser().parseResource(Conformance.class,responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.getEntries().size());
|
||||
|
||||
assertEquals(1, ourLastSearchParams.size());
|
||||
StringAndListParam andList =(StringAndListParam) ourLastSearchParams.get("param1");
|
||||
assertEquals(1,andList.getValuesAsQueryTokens().size());
|
||||
StringOrListParam orList = andList.getValuesAsQueryTokens().get(0);
|
||||
assertEquals(2,orList.getValuesAsQueryTokens().size());
|
||||
StringParam param1 = orList.getValuesAsQueryTokens().get(0);
|
||||
assertEquals("param1value", param1.getValue());
|
||||
StringParam param1b = orList.getValuesAsQueryTokens().get(1);
|
||||
assertEquals("param1value2", param1b.getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -193,4 +195,5 @@ public class DynamicSearchTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
|||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
/**
|
||||
|
@ -53,13 +54,13 @@ public class ExceptionTest {
|
|||
|
||||
private static final String OPERATION_OUTCOME_DETAILS = "OperationOutcomeDetails";
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static Class<? extends Exception> ourExceptionType;
|
||||
private static boolean ourGenerateOperationOutcome;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExceptionTest.class);
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static RestfulServer servlet;
|
||||
private static final FhirContext ourCtx = FhirContext.forDstu1();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
|
@ -67,21 +68,6 @@ public class ExceptionTest {
|
|||
ourExceptionType = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInternalError() throws Exception {
|
||||
{
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?throwInternalError=aaa");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
OperationOutcome oo = (OperationOutcome) servlet.getFhirContext().newXmlParser().parseResource(responseContent);
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), StringContains.containsString("Exception Text"));
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), not(StringContains.containsString("InternalErrorException")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthorizationFailureInPreProcessInterceptor() throws Exception {
|
||||
IServerInterceptor interceptor = new InterceptorAdapter() {
|
||||
|
@ -106,18 +92,17 @@ public class ExceptionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testResourceNotFound() throws Exception {
|
||||
ourExceptionType = ResourceNotFoundException.class;
|
||||
ourGenerateOperationOutcome = false;
|
||||
public void testInternalError() throws Exception {
|
||||
{
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123");
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?throwInternalError=aaa");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals(404, status.getStatusLine().getStatusCode());
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
OperationOutcome oo = (OperationOutcome) servlet.getFhirContext().newXmlParser().parseResource(responseContent);
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), StringContains.containsString("Resource Patient/123 is not known"));
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), StringContains.containsString("Exception Text"));
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), not(StringContains.containsString("InternalErrorException")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,6 +134,36 @@ public class ExceptionTest {
|
|||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), not(StringContains.containsString("InternalErrorException")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodNotAllowed() throws Exception {
|
||||
{
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?throwMethodNotAllowed=aaa&_format=true");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
ourLog.info(status.toString());
|
||||
assertEquals(MethodNotAllowedException.STATUS_CODE, status.getStatusLine().getStatusCode());
|
||||
assertEquals("POST,PUT", status.getFirstHeader(Constants.HEADER_ALLOW).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceNotFound() throws Exception {
|
||||
ourExceptionType = ResourceNotFoundException.class;
|
||||
ourGenerateOperationOutcome = false;
|
||||
{
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals(404, status.getStatusLine().getStatusCode());
|
||||
OperationOutcome oo = (OperationOutcome) servlet.getFhirContext().newXmlParser().parseResource(responseContent);
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), StringContains.containsString("Resource Patient/123 is not known"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceReturning() throws Exception {
|
||||
// No OO
|
||||
|
@ -209,23 +224,11 @@ public class ExceptionTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodNotAllowed() throws Exception {
|
||||
{
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?throwMethodNotAllowed=aaa&_format=true");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
ourLog.info(status.toString());
|
||||
assertEquals(MethodNotAllowedException.STATUS_CODE, status.getStatusLine().getStatusCode());
|
||||
assertEquals("POST,PUT", status.getFirstHeader(Constants.HEADER_ALLOW).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -250,6 +253,7 @@ public class ExceptionTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
|
@ -282,13 +286,13 @@ public class ExceptionTest {
|
|||
}
|
||||
|
||||
@Search()
|
||||
public List<Patient> throwUnprocessableEntity(@RequiredParam(name = "throwUnprocessableEntity") StringParam theParam) {
|
||||
throw new UnprocessableEntityException("Exception Text");
|
||||
public List<Patient> throwMethodNotAllowed(@RequiredParam(name = "throwMethodNotAllowed") StringParam theParam) {
|
||||
throw new MethodNotAllowedException("Exception Text", RequestTypeEnum.POST, RequestTypeEnum.PUT);
|
||||
}
|
||||
|
||||
@Search()
|
||||
public List<Patient> throwMethodNotAllowed(@RequiredParam(name = "throwMethodNotAllowed") StringParam theParam) {
|
||||
throw new MethodNotAllowedException("Exception Text", RequestTypeEnum.POST, RequestTypeEnum.PUT);
|
||||
public List<Patient> throwUnprocessableEntity(@RequiredParam(name = "throwUnprocessableEntity") StringParam theParam) {
|
||||
throw new UnprocessableEntityException("Exception Text");
|
||||
}
|
||||
|
||||
@Search
|
||||
|
|
|
@ -30,6 +30,7 @@ import ca.uhn.fhir.rest.annotation.IdParam;
|
|||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.Since;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -115,8 +116,9 @@ public class HistoryTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -142,7 +144,8 @@ public class HistoryTest {
|
|||
ourClient = builder.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
|
@ -169,8 +172,7 @@ public class HistoryTest {
|
|||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class DummyResourceProvider implements IResourceProvider {
|
||||
|
||||
@Override
|
||||
|
@ -223,4 +225,5 @@ public class HistoryTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import ca.uhn.fhir.rest.annotation.RequiredParam;
|
|||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.util.ElementUtil;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
|
@ -272,9 +273,11 @@ public class IncludeTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -478,6 +481,7 @@ public class IncludeTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@ResourceDef(name = "Patient")
|
||||
public static class ExtPatient extends Patient {
|
||||
@Child(name = "secondOrg")
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue