More travis cleanup
This commit is contained in:
parent
9c5a5dc248
commit
a54cb06c03
|
@ -13,6 +13,7 @@
|
|||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
|
|
@ -15,6 +15,18 @@
|
|||
<name>HAPI FHIR - Android</name>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--
|
||||
This is here, at the top, for the unit tests because otherwise the
|
||||
logger spews out all kinds of junk during unit tests
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||
<artifactId>hapi-fhir-base</artifactId>
|
||||
|
|
|
@ -54,6 +54,9 @@ public class BuiltJarIT {
|
|||
|
||||
@Test
|
||||
public void testParserJson() {
|
||||
ourLog.info("AAAAA");
|
||||
ourLog.info("AAAAA");
|
||||
|
||||
FhirContext ctx = FhirContext.forDstu2();
|
||||
|
||||
Observation o = new Observation();
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>TRACE</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator" additivity="false" level="debug">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<logger name="ca.uhn.fhir.jpa.dao.FhirResourceDaoSubscriptionDstu2" additivity="false" level="debug">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.eclipse.jetty.websocket" additivity="false" level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.eclipse" additivity="false" level="error">
|
||||
</logger>
|
||||
|
||||
<logger name="ca.uhn.fhir.rest.client" additivity="false" level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<logger name="ca.uhn.fhir.jpa.dao" additivity="false" level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<!-- Set to 'trace' to enable SQL logging -->
|
||||
<logger name="org.hibernate.SQL" additivity="false" level="trace">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
<!-- Set to 'trace' to enable SQL Value logging -->
|
||||
<logger name="org.hibernate.type" additivity="false" level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
|
@ -9,6 +9,7 @@ import org.apache.commons.lang3.Validate;
|
|||
import org.apache.commons.lang3.text.StrLookup;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
|
@ -34,27 +35,28 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseValidatingInterceptor.class);
|
||||
|
||||
private Integer myAddResponseHeaderOnSeverity = ResultSeverityEnum.INFORMATION.ordinal();
|
||||
private Integer myAddResponseIssueHeaderOnSeverity = null;
|
||||
private Integer myAddResponseOutcomeHeaderOnSeverity = null;
|
||||
private Integer myFailOnSeverity = ResultSeverityEnum.ERROR.ordinal();
|
||||
private String myResponseHeaderName = provideDefaultResponseHeaderName();
|
||||
private String myResponseHeaderValue = DEFAULT_RESPONSE_HEADER_VALUE;
|
||||
private String myResponseHeaderValueNoIssues = null;
|
||||
|
||||
private String myResponseIssueHeaderName = provideDefaultResponseHeaderName();
|
||||
private String myResponseIssueHeaderValue = DEFAULT_RESPONSE_HEADER_VALUE;
|
||||
private String myResponseIssueHeaderValueNoIssues = null;
|
||||
private String myResponseOutcomeHeaderName = provideDefaultResponseHeaderName();
|
||||
private List<IValidatorModule> myValidatorModules;
|
||||
|
||||
private void addResponseHeader(RequestDetails theRequestDetails, SingleValidationMessage theNext) {
|
||||
private void addResponseIssueHeader(RequestDetails theRequestDetails, SingleValidationMessage theNext) {
|
||||
// Perform any string substitutions from the message format
|
||||
StrLookup<?> lookup = new MyLookup(theNext);
|
||||
StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');
|
||||
|
||||
// Log the header
|
||||
String headerValue = subs.replace(myResponseHeaderValue);
|
||||
String headerValue = subs.replace(myResponseIssueHeaderValue);
|
||||
ourLog.trace("Adding header to response: {}", headerValue);
|
||||
|
||||
theRequestDetails.getResponse().addHeader(myResponseHeaderName, headerValue);
|
||||
theRequestDetails.getResponse().addHeader(myResponseIssueHeaderName, headerValue);
|
||||
}
|
||||
|
||||
public BaseValidatingInterceptor addValidatorModule(IValidatorModule theModule) {
|
||||
public BaseValidatingInterceptor<T> addValidatorModule(IValidatorModule theModule) {
|
||||
Validate.notNull(theModule, "theModule must not be null");
|
||||
if (getValidatorModules() == null) {
|
||||
setValidatorModules(new ArrayList<IValidatorModule>());
|
||||
|
@ -64,7 +66,7 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
}
|
||||
|
||||
abstract ValidationResult doValidate(FhirValidator theValidator, T theRequest);
|
||||
|
||||
|
||||
/**
|
||||
* Fail the request by throwing an {@link UnprocessableEntityException} as a result of a validation failure.
|
||||
* Subclasses may change this behaviour by providing alternate behaviour.
|
||||
|
@ -73,10 +75,26 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
throw new UnprocessableEntityException(theRequestDetails.getServer().getFhirContext(), theValidationResult.toOperationOutcome());
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the header specified by {@link #setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)}
|
||||
*/
|
||||
public String getResponseOutcomeHeaderName() {
|
||||
return myResponseOutcomeHeaderName;
|
||||
}
|
||||
|
||||
public List<IValidatorModule> getValidatorModules() {
|
||||
return myValidatorModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the validation produces a result with at least the given severity, a header with the name
|
||||
* specified by {@link #setResponseOutcomeHeaderName(String)} will be added containing a JSON encoded
|
||||
* OperationOutcome resource containing the validation results.
|
||||
*/
|
||||
public ResultSeverityEnum getAddResponseOutcomeHeaderOnSeverity() {
|
||||
return myAddResponseOutcomeHeaderOnSeverity != null ? ResultSeverityEnum.values()[myAddResponseOutcomeHeaderOnSeverity] : null;
|
||||
}
|
||||
|
||||
abstract String provideDefaultResponseHeaderName();
|
||||
|
||||
/**
|
||||
|
@ -87,7 +105,16 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
* @see #setResponseHeaderValue(String)
|
||||
*/
|
||||
public void setAddResponseHeaderOnSeverity(ResultSeverityEnum theSeverity) {
|
||||
myAddResponseHeaderOnSeverity = theSeverity != null ? theSeverity.ordinal() : null;
|
||||
myAddResponseIssueHeaderOnSeverity = theSeverity != null ? theSeverity.ordinal() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the validation produces a result with at least the given severity, a header with the name
|
||||
* specified by {@link #setResponseOutcomeHeaderName(String)} will be added containing a JSON encoded
|
||||
* OperationOutcome resource containing the validation results.
|
||||
*/
|
||||
public void setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum theAddResponseOutcomeHeaderOnSeverity) {
|
||||
myAddResponseOutcomeHeaderOnSeverity = theAddResponseOutcomeHeaderOnSeverity != null ? theAddResponseOutcomeHeaderOnSeverity.ordinal() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +132,7 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
*/
|
||||
protected void setResponseHeaderName(String theResponseHeaderName) {
|
||||
Validate.notBlank(theResponseHeaderName, "theResponseHeaderName must not be blank or null");
|
||||
myResponseHeaderName = theResponseHeaderName;
|
||||
myResponseIssueHeaderName = theResponseHeaderName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,7 +174,7 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
*/
|
||||
public void setResponseHeaderValue(String theResponseHeaderValue) {
|
||||
Validate.notBlank(theResponseHeaderValue, "theResponseHeaderValue must not be blank or null");
|
||||
myResponseHeaderValue = theResponseHeaderValue;
|
||||
myResponseIssueHeaderValue = theResponseHeaderValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +182,15 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
* threshold specified by {@link #setAddResponseHeaderOnSeverity(ResultSeverityEnum)}
|
||||
*/
|
||||
public void setResponseHeaderValueNoIssues(String theResponseHeaderValueNoIssues) {
|
||||
myResponseHeaderValueNoIssues = theResponseHeaderValueNoIssues;
|
||||
myResponseIssueHeaderValueNoIssues = theResponseHeaderValueNoIssues;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the header specified by {@link #setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)}
|
||||
*/
|
||||
public void setResponseOutcomeHeaderName(String theResponseOutcomeHeaderName) {
|
||||
Validate.notEmpty(theResponseOutcomeHeaderName, "theResponseOutcomeHeaderName can not be empty or null");
|
||||
myResponseOutcomeHeaderName = theResponseOutcomeHeaderName;
|
||||
}
|
||||
|
||||
public void setValidatorModules(List<IValidatorModule> theValidatorModules) {
|
||||
|
@ -172,17 +207,17 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
|
||||
ValidationResult validationResult = doValidate(validator, theRequest);
|
||||
|
||||
if (myAddResponseHeaderOnSeverity != null) {
|
||||
if (myAddResponseIssueHeaderOnSeverity != null) {
|
||||
boolean found = false;
|
||||
for (SingleValidationMessage next : validationResult.getMessages()) {
|
||||
if (next.getSeverity().ordinal() >= myAddResponseHeaderOnSeverity) {
|
||||
addResponseHeader(theRequestDetails, next);
|
||||
if (next.getSeverity().ordinal() >= myAddResponseIssueHeaderOnSeverity) {
|
||||
addResponseIssueHeader(theRequestDetails, next);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (isNotBlank(myResponseHeaderValueNoIssues)) {
|
||||
theRequestDetails.getResponse().addHeader(myResponseHeaderName, myResponseHeaderValueNoIssues);
|
||||
if (isNotBlank(myResponseIssueHeaderValueNoIssues)) {
|
||||
theRequestDetails.getResponse().addHeader(myResponseIssueHeaderName, myResponseIssueHeaderValueNoIssues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,6 +230,21 @@ abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (myAddResponseOutcomeHeaderOnSeverity != null) {
|
||||
boolean add = false;
|
||||
for (SingleValidationMessage next : validationResult.getMessages()) {
|
||||
if (next.getSeverity().ordinal() >= myAddResponseOutcomeHeaderOnSeverity) {
|
||||
add = true;
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
IParser parser = theRequestDetails.getServer().getFhirContext().newJsonParser().setPrettyPrint(false);
|
||||
String encoded = parser.encodeResourceToString(validationResult.toOperationOutcome());
|
||||
theRequestDetails.getResponse().addHeader(myResponseOutcomeHeaderName, encoded);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class MyLookup extends StrLookup<String> {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class RequestValidatingInterceptor extends BaseValidatingInterceptor<Stri
|
|||
/**
|
||||
* X-HAPI-Request-Validation
|
||||
*/
|
||||
public static final String DEFAULT_RESPONSE_HEADER_NAME = "X-HAPI-Request-Validation";
|
||||
public static final String DEFAULT_RESPONSE_HEADER_NAME = "X-FHIR-Request-Validation";
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RequestValidatingInterceptor.class);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ResponseValidatingInterceptor extends BaseValidatingInterceptor<IBa
|
|||
/**
|
||||
* X-HAPI-Request-Validation
|
||||
*/
|
||||
public static final String DEFAULT_RESPONSE_HEADER_NAME = "X-HAPI-Response-Validation";
|
||||
public static final String DEFAULT_RESPONSE_HEADER_NAME = "X-FHIR-Response-Validation";
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResponseValidatingInterceptor.class);
|
||||
|
||||
|
|
|
@ -335,7 +335,7 @@
|
|||
<configuration>
|
||||
<!-- These tests all use a shared database, so it's easier if they run in a predictable order -->
|
||||
<runOrder>alphabetical</runOrder>
|
||||
<reuseForks>false</reuseForks>
|
||||
<!--<reuseForks>false</reuseForks>-->
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -29,6 +29,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
|||
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
|
||||
import ca.uhn.fhir.validation.IValidatorModule;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
|
||||
@Configuration
|
||||
@Import(CommonConfig.class)
|
||||
|
@ -107,7 +108,10 @@ public class TestDstu21Config extends BaseJavaConfigDstu21 {
|
|||
RequestValidatingInterceptor requestValidator = new RequestValidatingInterceptor();
|
||||
requestValidator.addValidatorModule(myInstanceValidatorDstu21);
|
||||
requestValidator.addValidatorModule(myQuestionnaireResponseValidatorDstu21);
|
||||
requestValidator.setResponseHeaderValueNoIssues("Validation did not detect any issues");
|
||||
requestValidator.setFailOnSeverity(ResultSeverityEnum.ERROR);
|
||||
requestValidator.setAddResponseHeaderOnSeverity(null);
|
||||
requestValidator.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
return requestValidator;
|
||||
}
|
||||
|
||||
|
@ -121,7 +125,18 @@ public class TestDstu21Config extends BaseJavaConfigDstu21 {
|
|||
responseValidator.addValidatorModule(myQuestionnaireResponseValidatorDstu21);
|
||||
responseValidator.setResponseHeaderValueNoIssues("Validation did not detect any issues");
|
||||
responseValidator.setFailOnSeverity(null);
|
||||
responseValidator.setAddResponseHeaderOnSeverity(null);
|
||||
responseValidator.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.METADATA);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.EXTENDED_OPERATION_SERVER);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.GET_PAGE);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.HISTORY_INSTANCE);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.HISTORY_SYSTEM);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.HISTORY_TYPE);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.SEARCH_SYSTEM);
|
||||
responseValidator.addExcludeOperationType(RestOperationTypeEnum.SEARCH_TYPE);
|
||||
return responseValidator;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import ca.uhn.fhir.rest.param.StringParam;
|
|||
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.validation.IValidatorModule;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
|
||||
public class RequestValidatingInterceptorDstu21Test {
|
||||
private static CloseableHttpClient ourClient;
|
||||
|
@ -79,6 +80,8 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
|
||||
@Test
|
||||
public void testCreateJsonInvalidNoValidatorsSpecified() throws Exception {
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
|
@ -97,14 +100,15 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(422, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-HAPI-Request-Validation"));
|
||||
assertThat(status.toString(), containsString("X-FHIR-Request-Validation"));
|
||||
assertThat(responseContent, containsString("<severity value=\"error\"/>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJsonInvalidNoFailure() throws Exception {
|
||||
myInterceptor.setFailOnSeverity(null);
|
||||
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
|
@ -123,7 +127,7 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(201, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-HAPI-Request-Validation"));
|
||||
assertThat(status.toString(), containsString("X-FHIR-Request-Validation"));
|
||||
assertThat(responseContent, not(containsString("<severity value=\"error\"/>")));
|
||||
}
|
||||
|
||||
|
@ -146,13 +150,14 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.trace("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(201, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), not(containsString("X-HAPI-Request-Validation")));
|
||||
assertThat(status.toString(), not(containsString("X-FHIR-Request-Validation")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJsonValidNoValidatorsSpecifiedDefaultMessage() throws Exception {
|
||||
myInterceptor.setResponseHeaderValueNoIssues("NO ISSUES");
|
||||
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
|
@ -170,11 +175,13 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.trace("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(201, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), (containsString("X-HAPI-Request-Validation: NO ISSUES")));
|
||||
assertThat(status.toString(), (containsString("X-FHIR-Request-Validation: NO ISSUES")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateXmlInvalidNoValidatorsSpecified() throws Exception {
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
|
@ -193,14 +200,44 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(422, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-HAPI-Request-Validation"));
|
||||
assertThat(status.toString(), containsString("X-FHIR-Request-Validation"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateXmlInvalidNoValidatorsSpecifiedOutcomeHeader() throws Exception {
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(null);
|
||||
myInterceptor.setFailOnSeverity(null);
|
||||
myInterceptor.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
patient.addContact().addRelationship().setText("FOO");
|
||||
String encoded = ourCtx.newXmlParser().encodeResourceToString(patient);
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
|
||||
httpPost.setEntity(new StringEntity(encoded, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info("Response was:\n{}", status);
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(201, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-FHIR-Request-Validation: {\"resourceType\":\"OperationOutcome"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateXmlInvalidInstanceValidator() throws Exception {
|
||||
IValidatorModule module = new FhirInstanceValidator();
|
||||
myInterceptor.addValidatorModule(module);
|
||||
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
|
@ -219,7 +256,7 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(422, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-HAPI-Request-Validation"));
|
||||
assertThat(status.toString(), containsString("X-FHIR-Request-Validation"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -235,7 +272,7 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), not(containsString("X-HAPI-Request-Validation")));
|
||||
assertThat(status.toString(), not(containsString("X-FHIR-Request-Validation")));
|
||||
assertEquals(true, ourLastRequestWasSearch);
|
||||
}
|
||||
|
||||
|
@ -258,7 +295,7 @@ public class RequestValidatingInterceptorDstu21Test {
|
|||
ourLog.trace("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(201, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), not(containsString("X-HAPI-Request-Validation")));
|
||||
assertThat(status.toString(), not(containsString("X-FHIR-Request-Validation")));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
|
@ -35,6 +35,7 @@ import ca.uhn.fhir.rest.param.StringParam;
|
|||
import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.validation.IValidatorModule;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
|
||||
public class ResponseValidatingInterceptorDstu21Test {
|
||||
private static CloseableHttpClient ourClient;
|
||||
|
@ -86,7 +87,7 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(422, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-HAPI-Response-Validation"));
|
||||
assertThat(status.toString(), containsString("X-FHIR-Response-Validation"));
|
||||
assertThat(responseContent, containsString("<severity value=\"error\"/>"));
|
||||
}
|
||||
|
||||
|
@ -109,14 +110,15 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.trace("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), not(containsString("X-HAPI-Response-Validation")));
|
||||
assertThat(status.toString(), not(containsString("X-FHIR-Response-Validation")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchJsonValidNoValidatorsSpecifiedDefaultMessage() throws Exception {
|
||||
myInterceptor.setResponseHeaderValueNoIssues("NO ISSUES");
|
||||
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
|
@ -133,7 +135,7 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.trace("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), (containsString("X-HAPI-Response-Validation: NO ISSUES")));
|
||||
assertThat(status.toString(), (containsString("X-FHIR-Response-Validation: NO ISSUES")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,14 +161,15 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(422, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-HAPI-Response-Validation"));
|
||||
assertThat(status.toString(), containsString("X-FHIR-Response-Validation"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchXmlInvalidInstanceValidator() throws Exception {
|
||||
IValidatorModule module = new FhirInstanceValidator();
|
||||
myInterceptor.addValidatorModule(module);
|
||||
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setValue("002");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
|
@ -184,7 +187,7 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(422, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), containsString("X-HAPI-Response-Validation"));
|
||||
assertThat(status.toString(), containsString("X-FHIR-Response-Validation"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -204,7 +207,7 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), not(containsString("X-HAPI-Response-Validation")));
|
||||
assertThat(status.toString(), not(containsString("X-FHIR-Response-Validation")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -212,6 +215,7 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
IValidatorModule module = new FhirInstanceValidator();
|
||||
myInterceptor.addValidatorModule(module);
|
||||
myInterceptor.setResponseHeaderValueNoIssues("No issues");
|
||||
myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
|
||||
|
||||
HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/metadata");
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
@ -223,7 +227,7 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), (containsString("X-HAPI-Response-Validation")));
|
||||
assertThat(status.toString(), (containsString("X-FHIR-Response-Validation")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -244,7 +248,7 @@ public class ResponseValidatingInterceptorDstu21Test {
|
|||
ourLog.trace("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertThat(status.toString(), not(containsString("X-HAPI-Response-Validation")));
|
||||
assertThat(status.toString(), not(containsString("X-FHIR-Response-Validation")));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
Loading…
Reference in New Issue