From 9f487410867a47c8d17eb6cd0ca5f54ad0e01b2e Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Mon, 11 Mar 2019 18:43:03 +0100 Subject: [PATCH] camel: enable integration tests --- .../core/deployment/CamelInitProcessor.java | 9 +- .../camel/core/runtime/CamelRuntime.java | 87 +++++++++---------- .../camel/core/runtime/RuntimeSupport.java | 38 -------- .../quarkus/camel/it/core/CamelServlet.java | 4 - .../src/main/resources/application.properties | 29 +++++-- integration-tests/camel-salesforce/pom.xml | 2 - integration-tests/pom.xml | 3 - 7 files changed, 68 insertions(+), 104 deletions(-) diff --git a/extensions/camel/camel-core/deployment/src/main/java/io/quarkus/camel/core/deployment/CamelInitProcessor.java b/extensions/camel/camel-core/deployment/src/main/java/io/quarkus/camel/core/deployment/CamelInitProcessor.java index 716a55e305e77..f02889005a703 100644 --- a/extensions/camel/camel-core/deployment/src/main/java/io/quarkus/camel/core/deployment/CamelInitProcessor.java +++ b/extensions/camel/camel-core/deployment/src/main/java/io/quarkus/camel/core/deployment/CamelInitProcessor.java @@ -57,8 +57,13 @@ AdditionalBeanBuildItem camelRuntimeProducer(BuildProducer builders; - protected PropertiesComponent propertiesComponent; public void bind(String name, Object object) { registry.bind(name, object); @@ -62,10 +61,8 @@ public void bind(String name, Class type, Object object) { public void doInit() { try { - AbstractCamelContext context = createContext(); - context.setRegistry(registry); - context.setAutoStartup(false); - this.context = context; + this.context = createContext(); + this.context.setRegistry(registry); // Configure the camel context using properties in the form: // @@ -73,16 +70,8 @@ public void doInit() { // RuntimeSupport.bindProperties(properties, context, PFX_CAMEL_CONTEXT); + context.setLoadTypeConverters(false); context.getModelJAXBContextFactory().newJAXBContext(); - - propertiesComponent = new PropertiesComponent(); - propertiesComponent.setInitialProperties(properties); - RuntimeSupport.bindProperties(properties, propertiesComponent, PFX_CAMEL_PROPERTIES); - context.addComponent("properties", propertiesComponent); - - loadRoutesFromBuilders(true); - - context.start(); } catch (Exception e) { throw RuntimeCamelException.wrapRuntimeCamelException(e); } @@ -91,21 +80,17 @@ public void doInit() { public void doStart() throws Exception { log.info("Apache Camel {} (CamelContext: {}) is starting", context.getVersion(), context.getName()); - String conf = getProperty(PROP_CAMEL_CONF); - String confd = getProperty(PROP_CAMEL_CONFD); - log.info("confPath: {}", conf); - log.info("confDPath: {}", confd); - RuntimeSupport.loadConfigSources(properties, conf, confd); + PropertiesComponent pc = createPropertiesComponent(properties); + RuntimeSupport.bindProperties(pc.getInitialProperties(), pc, PFX_CAMEL_PROPERTIES); + context.addComponent("properties", pc); - loadRoutesFromBuilders(false); - loadRoutes(); + configureContext(context); + loadRoutes(context); - if (Boolean.parseBoolean(getProperty(PROP_CAMEL_DUMP))) { - dumpRoutes(); - } + context.start(); - for (Route route : getContext().getRoutes()) { - getContext().getRouteController().startRoute(route.getId()); + if (Boolean.parseBoolean(getProperty(PROP_CAMEL_ROUTES_DUMP))) { + dumpRoutes(); } } @@ -114,32 +99,28 @@ protected void doStop() throws Exception { context.shutdown(); } - protected void loadRoutesFromBuilders(boolean initPhase) throws Exception { - if (builders != null && !builders.isEmpty()) { - boolean defer = Boolean.parseBoolean(getProperty(PROP_CAMEL_DEFER)); - if (defer ^ initPhase) { - for (RoutesBuilder b : builders) { - if (b instanceof RouteBuilderExt) { - ((RouteBuilderExt) b).setRegistry(registry); - } - context.addRoutes(b); - } + protected void loadRoutes(CamelContext context) throws Exception { + for (RoutesBuilder b : builders) { + if (b instanceof RouteBuilderExt) { + ((RouteBuilderExt) b).setRegistry(registry); } + context.addRoutes(b); } - } - protected void loadRoutes() throws Exception { - String routesUri = getProperty("camel.routesUri"); - log.info("routesUri: {}", routesUri); + String routesUri = getProperty(PROP_CAMEL_ROUTES_LOCATIONS); if (ObjectHelper.isNotEmpty(routesUri)) { + log.info("routesUri: {}", routesUri); + + ModelCamelContext mcc = context.adapt(ModelCamelContext.class); + try (InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getContext(), routesUri)) { - context.addRouteDefinitions(context.loadRoutesDefinition(is).getRoutes()); + mcc.addRouteDefinitions(mcc.loadRoutesDefinition(is).getRoutes()); } } } protected String getProperty(String name) throws Exception { - return propertiesComponent.parseUri(propertiesComponent.getPrefixToken() + name + propertiesComponent.getSuffixToken()); + return context.resolvePropertyPlaceholders(context.getPropertyPrefixToken() + name + context.getPropertySuffixToken()); } protected DefaultCamelContext createContext() { @@ -162,6 +143,18 @@ public CamelContext getContext() { return context; } + protected PropertiesComponent createPropertiesComponent(Properties initialPoperties) { + PropertiesComponent pc = new PropertiesComponent(); + pc.setInitialProperties(initialPoperties); + + RuntimeSupport.bindProperties(properties, pc, PFX_CAMEL_PROPERTIES); + + return pc; + } + + protected void configureContext(CamelContext context) { + } + protected void dumpRoutes() { long t0 = System.nanoTime(); try { diff --git a/extensions/camel/camel-core/runtime/src/main/java/io/quarkus/camel/core/runtime/RuntimeSupport.java b/extensions/camel/camel-core/runtime/src/main/java/io/quarkus/camel/core/runtime/RuntimeSupport.java index 2bc51dfb90193..b470b5061a290 100644 --- a/extensions/camel/camel-core/runtime/src/main/java/io/quarkus/camel/core/runtime/RuntimeSupport.java +++ b/extensions/camel/camel-core/runtime/src/main/java/io/quarkus/camel/core/runtime/RuntimeSupport.java @@ -16,18 +16,10 @@ */ package io.quarkus.camel.core.runtime; -import java.io.IOException; -import java.io.Reader; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; import java.util.Properties; -import java.util.stream.Collectors; import org.apache.camel.CamelContext; import org.apache.camel.support.IntrospectionSupport; -import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,36 +29,6 @@ public final class RuntimeSupport { private RuntimeSupport() { } - public static void loadConfigSources(Properties properties, String conf, String confd) { - // Main location - if (ObjectHelper.isNotEmpty(conf)) { - try (Reader reader = Files.newBufferedReader(Paths.get(conf))) { - properties.load(reader); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - // Additional locations - if (ObjectHelper.isNotEmpty(confd)) { - Path root = Paths.get(confd); - if (Files.exists(root)) { - try { - List paths = Files.walk(root) - .filter(p -> p.getFileSystem().toString().endsWith(".properties")) - .collect(Collectors.toList()); - for (Path path : paths) { - try (Reader reader = Files.newBufferedReader(path)) { - properties.load(reader); - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - } - public static void bindProperties(CamelContext context, Properties properties, Object target, String prefix) { if (!prefix.endsWith(".")) { prefix += "."; diff --git a/integration-tests/camel-core/src/main/java/io/quarkus/camel/it/core/CamelServlet.java b/integration-tests/camel-core/src/main/java/io/quarkus/camel/it/core/CamelServlet.java index 82283e7afacd0..8ad5b70171e8d 100644 --- a/integration-tests/camel-core/src/main/java/io/quarkus/camel/it/core/CamelServlet.java +++ b/integration-tests/camel-core/src/main/java/io/quarkus/camel/it/core/CamelServlet.java @@ -12,16 +12,12 @@ import javax.ws.rs.core.MediaType; import org.apache.camel.Route; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import io.quarkus.camel.core.runtime.CamelRuntime; @Path("/") @ApplicationScoped public class CamelServlet { - private static final Logger LOGGER = LoggerFactory.getLogger(CamelServlet.class); - @Inject CamelRuntime runtime; diff --git a/integration-tests/camel-core/src/main/resources/application.properties b/integration-tests/camel-core/src/main/resources/application.properties index 845dbb6d8023b..f9215ab432c4e 100644 --- a/integration-tests/camel-core/src/main/resources/application.properties +++ b/integration-tests/camel-core/src/main/resources/application.properties @@ -1,9 +1,22 @@ +# +# Quarkus +# +quarkus.log.file.enable = false + +# +# Camel +# camel.context.name=quarkus-camel-example -camel.properties.prefixToken={{ -camel.properties.suffixToken=}} -camel.conf={{env:CAMEL_CONF:}} -camel.confd={{env:CAMEL_CONFD:}} -camel.dump=false -camel.defer=false -camel.routesUri= -folder={{sys:folder:./target/orders}} +camel.context.loadTypeConverters=false + +camel.routes.dump=true +camel.routes.defer=true +camel.routes.locations= + +camel.component.properties.prefixToken={{ +camel.component.properties.suffixToken=}} + +# +# Integration +# +integration.folder={{sys:folder:./target/orders}} diff --git a/integration-tests/camel-salesforce/pom.xml b/integration-tests/camel-salesforce/pom.xml index 15335333cd08f..74ec0d1ea2185 100644 --- a/integration-tests/camel-salesforce/pom.xml +++ b/integration-tests/camel-salesforce/pom.xml @@ -127,7 +127,6 @@ - diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 5bf9fd4ecb2eb..325d13e099a0d 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -51,10 +51,7 @@ spring-di infinispan-cache-jpa infinispan-cache-jpa-stress -