Skip to content

Commit

Permalink
Merge pull request quarkusio#1404 from lburgazzoli/camel-it
Browse files Browse the repository at this point in the history
camel: enable integration tests
  • Loading branch information
stuartwdouglas authored Mar 12, 2019
2 parents 6e4b16d + 9f48741 commit a0b7bac
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ AdditionalBeanBuildItem camelRuntimeProducer(BuildProducer<BeanContainerListener
CamelRuntimeBuildItem createInitTask(RecorderContext recorderContext, CamelTemplate template) {
Properties properties = new Properties();
Config config = ConfigProvider.getConfig();
for (String i : config.getPropertyNames()) {
properties.put(i, config.getValue(i, String.class));
for (String property : config.getPropertyNames()) {
if (property.startsWith("camel.")) {
properties.put(property, config.getValue(property, String.class));
}
if (property.startsWith("integration.")) {
properties.put(property.substring("integration.".length()), config.getValue(property, String.class));
}
}

String clazz = properties.getProperty(CamelRuntime.PROP_CAMEL_RUNTIME, CamelRuntime.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.impl.AbstractCamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.ModelHelper;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.support.ResourceHelper;
Expand All @@ -37,20 +38,18 @@
public class CamelRuntime extends ServiceSupport {

public static final String PFX_CAMEL = "camel.";
public static final String PFX_CAMEL_PROPERTIES = PFX_CAMEL + "properties.";
public static final String PFX_CAMEL_PROPERTIES = PFX_CAMEL + "component.properties.";
public static final String PFX_CAMEL_CONTEXT = PFX_CAMEL + "context.";

public static final String PROP_CAMEL_RUNTIME = PFX_CAMEL + "runtime";
public static final String PROP_CAMEL_CONF = PFX_CAMEL + "conf";
public static final String PROP_CAMEL_CONFD = PFX_CAMEL + "confd";
public static final String PROP_CAMEL_DUMP = PFX_CAMEL + "dump";
public static final String PROP_CAMEL_DEFER = PFX_CAMEL + "defer";
public static final String PROP_CAMEL_ROUTES = PFX_CAMEL + "routes.";
public static final String PROP_CAMEL_ROUTES_DUMP = PROP_CAMEL_ROUTES + "dump";
public static final String PROP_CAMEL_ROUTES_LOCATIONS = PROP_CAMEL_ROUTES + "locations";

protected RuntimeRegistry registry;
protected Properties properties;
protected AbstractCamelContext context;
protected List<RoutesBuilder> builders;
protected PropertiesComponent propertiesComponent;

public void bind(String name, Object object) {
registry.bind(name, object);
Expand All @@ -62,27 +61,17 @@ 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:
//
// camel.context.${name} = ${value}
//
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);
}
Expand All @@ -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();
}
}

Expand All @@ -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() {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Path> 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 += ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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}}
2 changes: 0 additions & 2 deletions integration-tests/camel-salesforce/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
</plugin>
</plugins>
</build>
<!--
<profiles>
<profile>
<id>native-image</id>
Expand Down Expand Up @@ -181,6 +180,5 @@
</build>
</profile>
</profiles>
-->

</project>
3 changes: 0 additions & 3 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@
<module>spring-di</module>
<module>infinispan-cache-jpa</module>
<module>infinispan-cache-jpa-stress</module>
<!-- Camel tests are not working on Fedora + Bash
see https://github.com/quarkusio/quarkus/issues/1130
<module>camel-core</module>
<module>camel-salesforce</module>
-->
</modules>
</project>

0 comments on commit a0b7bac

Please sign in to comment.