Merge pull request #2429 from hapifhir/modify-conformance-to-support-special-mimetypes
Add custom mimetypes to capability statement
This commit is contained in:
commit
afad037fab
|
@ -59,6 +59,8 @@ public class Constants {
|
|||
*/
|
||||
public static final String CT_FHIR_JSON_NEW = "application/fhir+json";
|
||||
public static final String CT_FHIR_XML = "application/xml+fhir";
|
||||
|
||||
|
||||
/**
|
||||
* The FHIR MimeType for XML encoding in FHIR DSTU3+
|
||||
*/
|
||||
|
|
|
@ -224,6 +224,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState
|
|||
retVal.getSoftware().setVersion(serverConfiguration.getServerVersion());
|
||||
retVal.addFormat(Constants.CT_FHIR_XML_NEW);
|
||||
retVal.addFormat(Constants.CT_FHIR_JSON_NEW);
|
||||
retVal.addFormat(Constants.FORMAT_JSON);
|
||||
retVal.addFormat(Constants.FORMAT_XML);
|
||||
retVal.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
CapabilityStatementRestComponent rest = retVal.addRest();
|
||||
|
|
|
@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -66,7 +67,7 @@ public class ServerMimetypeDstu3Test {
|
|||
String content = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
CapabilityStatement conf = ourCtx.newXmlParser().parseResource(CapabilityStatement.class, content);
|
||||
List<String> strings = toStrings(conf.getFormat());
|
||||
assertThat(strings, contains(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(strings, hasItems(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW, Constants.FORMAT_XML, Constants.FORMAT_JSON));
|
||||
} finally {
|
||||
status.close();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.annotation.Description;
|
|||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
|
@ -47,17 +48,20 @@ import org.junit.jupiter.api.Disabled;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
@ -172,6 +176,26 @@ public class ServerCapabilityStatementProviderDstu3Test {
|
|||
assertTrue(res.getConditionalUpdate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException {
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider();
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs));
|
||||
|
||||
List<String> formatCodes = serverConformance.getFormat().stream().map(c -> c.asStringValue()).collect(Collectors.toList());;
|
||||
|
||||
assertThat(formatCodes, hasItem(Constants.FORMAT_XML));
|
||||
assertThat(formatCodes, hasItem(Constants.FORMAT_JSON));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExtendedOperationReturningBundle() throws Exception {
|
||||
|
||||
|
|
|
@ -172,6 +172,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState
|
|||
retVal.getSoftware().setVersion(configuration.getServerVersion());
|
||||
retVal.addFormat(Constants.CT_FHIR_XML_NEW);
|
||||
retVal.addFormat(Constants.CT_FHIR_JSON_NEW);
|
||||
retVal.addFormat(Constants.FORMAT_JSON);
|
||||
retVal.addFormat(Constants.FORMAT_XML);
|
||||
retVal.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
CapabilityStatementRestComponent rest = retVal.addRest();
|
||||
|
|
|
@ -20,6 +20,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
|
|||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.annotation.Update;
|
||||
import ca.uhn.fhir.rest.annotation.Validate;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
|
@ -40,6 +41,7 @@ import ca.uhn.fhir.util.TestUtil;
|
|||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
|
@ -67,6 +69,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -79,6 +82,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
@ -525,6 +529,26 @@ public class ServerCapabilityStatementProviderR4Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException {
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider();
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs));
|
||||
|
||||
List<String> formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());
|
||||
|
||||
assertThat(formatCodes, hasItem(Constants.FORMAT_XML));
|
||||
assertThat(formatCodes, hasItem(Constants.FORMAT_JSON));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW));
|
||||
}
|
||||
|
||||
/**
|
||||
* See #286
|
||||
*/
|
||||
|
|
|
@ -49,6 +49,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -85,12 +86,13 @@ public class ServerMimetypeR4Test {
|
|||
String content = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
CapabilityStatement conf = ourCtx.newXmlParser().parseResource(CapabilityStatement.class, content);
|
||||
List<String> strings = toStrings(conf.getFormat());
|
||||
assertThat(strings, contains(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(strings, hasItems(Constants.CT_FHIR_XML_NEW, Constants.CT_FHIR_JSON_NEW, Constants.FORMAT_XML, Constants.FORMAT_JSON));
|
||||
} finally {
|
||||
status.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateWithJsonLegacyNoAcceptHeader() throws Exception {
|
||||
Patient p = new Patient();
|
||||
|
|
|
@ -184,6 +184,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState
|
|||
retVal.getSoftware().setVersion(configuration.getServerVersion());
|
||||
retVal.addFormat(Constants.CT_FHIR_XML_NEW);
|
||||
retVal.addFormat(Constants.CT_FHIR_JSON_NEW);
|
||||
retVal.addFormat(Constants.FORMAT_JSON);
|
||||
retVal.addFormat(Constants.FORMAT_XML);
|
||||
retVal.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
CapabilityStatementRestComponent rest = retVal.addRest();
|
||||
|
|
|
@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.annotation.Description;
|
|||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
|
@ -42,17 +43,20 @@ import org.junit.jupiter.api.Disabled;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
@ -197,6 +201,26 @@ public class ServerCapabilityStatementProviderR5Test {
|
|||
assertThat(conf, containsString("<interaction><code value=\"" + TypeRestfulInteraction.HISTORYINSTANCE.toCode() + "\"/></interaction>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException {
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider();
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs));
|
||||
|
||||
List<String> formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());;
|
||||
|
||||
assertThat(formatCodes, hasItem(Constants.FORMAT_XML));
|
||||
assertThat(formatCodes, hasItem(Constants.FORMAT_JSON));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMultiOptionalDocumentation() throws Exception {
|
||||
|
||||
|
|
Loading…
Reference in New Issue