Skip to content

Commit

Permalink
Increase FHIR extension test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Mar 11, 2022
1 parent 75a4b1d commit 77d7e8f
Show file tree
Hide file tree
Showing 30 changed files with 6,261 additions and 486 deletions.
Expand Up @@ -17,15 +17,19 @@
package org.apache.camel.quarkus.component.fhir.deployment;

import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.util.jar.DependencyLogImpl;
import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;

final class FhirProcessor {
private static final String FEATURE = "camel-fhir";
Expand Down Expand Up @@ -56,7 +60,16 @@ AdditionalApplicationArchiveMarkerBuildItem hapiArchiveMarker() {
}

@BuildStep()
void processFhir(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
void registerForReflection(
CombinedIndexBuildItem combinedIndex,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {

IndexView index = combinedIndex.getIndex();
index.getAllKnownSubclasses(DotName.createSimple(BaseServerResponseException.class.getName()))
.stream()
.map(classInfo -> new ReflectiveClassBuildItem(false, false, classInfo.name().toString()))
.forEach(reflectiveClass::produce);

reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, true, SchematronBaseValidator.class));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, true, DependencyLogImpl.class));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, ApacheRestfulClientFactory.class));
Expand Down
@@ -0,0 +1,248 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.camel.quarkus.component.fhir.it;

import java.net.MalformedURLException;
import java.net.URL;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.StrictErrorHandler;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.fhir.FhirComponent;
import org.apache.camel.component.fhir.FhirConfiguration;
import org.apache.camel.component.fhir.FhirJsonDataFormat;
import org.apache.camel.component.fhir.FhirXmlDataFormat;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

public abstract class AbstractFhirRouteBuilder extends RouteBuilder {

abstract String getFhirVersion();

abstract FhirContext getFhirContext();

abstract boolean isEnabled();

@Override
public void configure() throws Exception {
if (isEnabled()) {
Config config = ConfigProvider.getConfig();
String fhirVersion = getFhirVersion();
String serverUrl = config.getValue("camel.fhir." + fhirVersion + ".test-url", String.class);

FhirContext fhirContext = getFhirContext();

FhirConfiguration configuration = new FhirConfiguration();
configuration.setLog(false);
configuration.setFhirContext(fhirContext);
configuration.setServerUrl(serverUrl);
configuration.setCompress(true);

FhirComponent component = new FhirComponent();
component.setConfiguration(configuration);
getContext().addComponent("fhir-" + fhirVersion, component);

fhirContext.setParserErrorHandler(new StrictErrorHandler());
try {
URL url = new URL(serverUrl);
fhirContext.getRestfulClientFactory().setProxy(url.getHost(), url.getPort());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}

FhirJsonDataFormat fhirJsonDataFormat = new FhirJsonDataFormat();
fhirJsonDataFormat.setFhirContext(fhirContext);
fhirJsonDataFormat.setParserErrorHandler(new StrictErrorHandler());

FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat();
fhirXmlDataFormat.setFhirContext(fhirContext);
fhirXmlDataFormat.setParserErrorHandler(new StrictErrorHandler());

// Capabilities
fromF("direct:capabilities-%s", fhirVersion)
.toF("fhir-%s://capabilities/ofType?inBody=type", fhirVersion);

// Create
fromF("direct:createResource-%s", fhirVersion)
.toF("fhir-%s://create/resource?inBody=resource", fhirVersion);

fromF("direct:createResourceAsString-%s", fhirVersion)
.toF("fhir-%s://create/resource?inBody=resourceAsString", fhirVersion);

// Dataformats
fromF("direct:json-to-%s", fhirVersion)
.unmarshal(fhirJsonDataFormat)
.marshal(fhirJsonDataFormat);

fromF("direct:xml-to-%s", fhirVersion)
.unmarshal(fhirXmlDataFormat)
.marshal(fhirXmlDataFormat);

// Delete
fromF("direct:delete-%s", fhirVersion)
.toF("fhir-%s://delete/resource?inBody=resource", fhirVersion);

fromF("direct:deleteById-%s", fhirVersion)
.toF("fhir-%s://delete/resourceById?inBody=id", fhirVersion);

fromF("direct:deleteByStringId-%s", fhirVersion)
.toF("fhir-%s://delete/resourceById", fhirVersion);

fromF("direct:deleteConditionalByUrl-%s", fhirVersion)
.toF("fhir-%s://delete/resourceConditionalByUrl?inBody=url", fhirVersion);

// History
fromF("direct:historyOnInstance-%s", fhirVersion)
.toF("fhir-%s://history/onInstance", fhirVersion);

fromF("direct:historyOnServer-%s", fhirVersion)
.toF("fhir-%s://history/onServer", fhirVersion);

fromF("direct:historyOnType-%s", fhirVersion)
.toF("fhir-%s://history/onType", fhirVersion);

// Load page
fromF("direct:loadPageByUrl-%s", fhirVersion)
.toF("fhir-%s://load-page/byUrl", fhirVersion);

fromF("direct:loadPageNext-%s", fhirVersion)
.toF("fhir-%s://load-page/next?inBody=bundle", fhirVersion);

fromF("direct:loadPagePrevious-%s", fhirVersion)
.toF("fhir-%s://load-page/previous?inBody=bundle", fhirVersion);

// Meta
fromF("direct:metaAdd-%s", fhirVersion)
.toF("fhir-%s://meta/add", fhirVersion);

fromF("direct:metaDelete-%s", fhirVersion)
.toF("fhir-%s://meta/delete", fhirVersion);

fromF("direct:metaGetFromResource-%s", fhirVersion)
.toF("fhir-%s://meta/getFromResource", fhirVersion);

fromF("direct:metaGetFromServer-%s", fhirVersion)
.toF("fhir-%s://meta/getFromServer?inBody=metaType", fhirVersion);

fromF("direct:metaGetFromType-%s", fhirVersion)
.toF("fhir-%s://meta/getFromType", fhirVersion);

// Operation
fromF("direct:operationOnInstance-%s", fhirVersion)
.toF("fhir-%s://operation/onInstance", fhirVersion);

fromF("direct:operationOnInstanceVersion-%s", fhirVersion)
.toF("fhir-%s://operation/onInstanceVersion", fhirVersion);

fromF("direct:operationOnServer-%s", fhirVersion)
.toF("fhir-%s://operation/onServer", fhirVersion);

fromF("direct:operationOnType-%s", fhirVersion)
.toF("fhir-%s://operation/onType", fhirVersion);

fromF("direct:operationProcessMessage-%s", fhirVersion)
.toF("fhir-%s://operation/processMessage", fhirVersion);

// Patch
fromF("direct:patchById-%s", fhirVersion)
.toF("fhir-%s://patch/patchById", fhirVersion);

fromF("direct:patchBySid-%s", fhirVersion)
.toF("fhir-%s://patch/patchById", fhirVersion);

fromF("direct:patchByUrl-%s", fhirVersion)
.toF("fhir-%s://patch/patchByUrl", fhirVersion);

// Read
fromF("direct:readById-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByLongId-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByStringId-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByIdAndStringResource-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByLongIdAndStringResource-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByStringIdAndStringResource-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByStringIdAndVersion-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByStringIdAndVersionAndStringResource-%s", fhirVersion)
.toF("fhir-%s://read/resourceById", fhirVersion);

fromF("direct:readByIUrl-%s", fhirVersion)
.toF("fhir-%s://read/resourceByUrl", fhirVersion);

fromF("direct:readByUrl-%s", fhirVersion)
.toF("fhir-%s://read/resourceByUrl", fhirVersion);

fromF("direct:readByStringUrlAndStringResource-%s", fhirVersion)
.toF("fhir-%s://read/resourceByUrl", fhirVersion);

fromF("direct:readByUrlAndStringResource-%s", fhirVersion)
.toF("fhir-%s://read/resourceByUrl", fhirVersion);

// Search
fromF("direct:searchByUrl-%s", fhirVersion)
.toF("fhir-%s://search/searchByUrl?inBody=url", fhirVersion);

// Transaction
fromF("direct:transactionWithBundle-%s", fhirVersion)
.toF("fhir-%s://transaction/withBundle?inBody=bundle", fhirVersion);

fromF("direct:transactionWithStringBundle-%s", fhirVersion)
.toF("fhir-%s://transaction/withBundle?inBody=stringBundle", fhirVersion);

fromF("direct:transactionWithResources-%s", fhirVersion)
.toF("fhir-%s://transaction/withResources?inBody=resources", fhirVersion);

// Update
fromF("direct:updateResource-%s", fhirVersion)
.toF("fhir-%s://update/resource", fhirVersion);

fromF("direct:updateResourceWithStringId-%s", fhirVersion)
.toF("fhir-%s://update/resource", fhirVersion);

fromF("direct:updateResourceAsString-%s", fhirVersion)
.toF("fhir-%s://update/resource", fhirVersion);

fromF("direct:updateResourceAsStringWithStringId-%s", fhirVersion)
.toF("fhir-%s://update/resource", fhirVersion);

fromF("direct:updateResourceBySearchUrl-%s", fhirVersion)
.toF("fhir-%s://update/resourceBySearchUrl", fhirVersion);

fromF("direct:updateResourceBySearchUrlAndResourceAsString-%s", fhirVersion)
.toF("fhir-%s://update/resourceBySearchUrl", fhirVersion);

// Validate
fromF("direct:validateResource-%s", fhirVersion)
.toF("fhir-%s://validate/resource?inBody=resource", fhirVersion);

fromF("direct:validateResourceAsString-%s", fhirVersion)
.toF("fhir-%s://validate/resource?inBody=resourceAsString", fhirVersion);
}
}
}
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.camel.quarkus.component.fhir.it;

public interface FhirConstants {
String PATIENT_ADDRESS = "221b Baker St, Marylebone, London NW1 6XE, UK";
String PATIENT_FIRST_NAME = "Sherlock";
String PATIENT_GENDER_PATCH = "[ { \"op\":\"add\", \"path\":\"/gender\", \"value\":\"female\" } ]";
String PATIENT_LAST_NAME = "Holmes";
}

0 comments on commit 77d7e8f

Please sign in to comment.