diff --git a/core/citrus-base/src/main/java/org/citrusframework/common/JavaTestLoader.java b/core/citrus-base/src/main/java/org/citrusframework/common/JavaTestLoader.java index f423ea19ed..b928e6e6d1 100644 --- a/core/citrus-base/src/main/java/org/citrusframework/common/JavaTestLoader.java +++ b/core/citrus-base/src/main/java/org/citrusframework/common/JavaTestLoader.java @@ -18,9 +18,13 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Path; import java.nio.file.Paths; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; @@ -36,6 +40,7 @@ */ public class JavaTestLoader extends DefaultTestLoader implements TestSourceAware { + private static final Pattern packageNamePattern = Pattern.compile("^package\\s+([a-zA-Z_][.a-zA-Z_]+);$", Pattern.MULTILINE); private String source; @Override @@ -50,9 +55,12 @@ public void doLoad() { throw new CitrusRuntimeException("Failed to compile Java source file: %s".formatted(javaSource.getFile().getAbsolutePath())); } + String packageName = extractPackageName(javaSource); + String qualifiedClassName = StringUtils.hasText(packageName) ? packageName + "." + getClassName() : getClassName(); + // Load and instantiate compiled class. - URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { Paths.get(javaSource.getURI()).getParent().toUri().toURL() }); - Class cls = Class.forName(getClassName(), true, classLoader); + URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { getClassLoaderBaseURL(packageName, javaSource) }); + Class cls = Class.forName(qualifiedClassName, true, classLoader); Object instance = cls.getDeclaredConstructor().newInstance(); CitrusAnnotations.injectAll(instance, citrus, context); @@ -100,6 +108,36 @@ public String getClassName() { return FileUtils.getBaseName(testName.endsWith(FileUtils.FILE_EXTENSION_JAVA) ? testName : testName + FileUtils.FILE_EXTENSION_JAVA); } + private static String extractPackageName(Resource javaSource) throws IOException { + String content = FileUtils.readToString(javaSource); + Matcher matcher = packageNamePattern.matcher(content); + if (matcher.find()) { + return matcher.group(1); + } + + return ""; + } + + /** + * Get Class loader base URL for given Java file resource path. + * The package name of the class must be taken into account when walking the parent tree of the folder structure upwards. + * @param packageName + * @param javaSource + * @return + * @throws MalformedURLException + */ + private static URL getClassLoaderBaseURL(String packageName, Resource javaSource) throws MalformedURLException { + Path clBase = Paths.get(javaSource.getURI()).getParent(); + + if (StringUtils.hasText(packageName)) { + for (int i = 0; i < packageName.split("\\.").length; i++) { + clBase = clBase.getParent(); + } + } + + return clBase.toUri().toURL(); + } + /** * Sets custom Spring application context file for Java test case. * @param source diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/CamelSettings.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/CamelSettings.java index 315084f0ca..9ef9f1387b 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/CamelSettings.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/CamelSettings.java @@ -26,7 +26,7 @@ public final class CamelSettings { private static final String CONTEXT_NAME_PROPERTY = CAMEL_PROPERTY_PREFIX + "context.name"; private static final String CONTEXT_NAME_ENV = CAMEL_ENV_PREFIX + "CONTEXT_NAME"; - private static final String CONTEXT_NAME_DEFAULT = "citrusCamelContext"; + private static final String CONTEXT_NAME_DEFAULT = "camelContext"; private static final String TIMEOUT_PROPERTY = CAMEL_PROPERTY_PREFIX + "timeout"; private static final String TIMEOUT_ENV = CAMEL_ENV_PREFIX + "TIMEOUT"; diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/AbstractCamelAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/AbstractCamelAction.java index 2925327ba6..3d88e77dbe 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/AbstractCamelAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/AbstractCamelAction.java @@ -17,6 +17,7 @@ package org.citrusframework.camel.actions; import org.apache.camel.CamelContext; +import org.apache.camel.impl.DefaultCamelContext; import org.citrusframework.AbstractTestActionBuilder; import org.citrusframework.actions.AbstractTestAction; import org.citrusframework.camel.CamelSettings; @@ -82,8 +83,16 @@ public final T build() { if (referenceResolver.isResolvable(CamelSettings.getContextName())) { camelContext = referenceResolver.resolve(CamelSettings.getContextName(), CamelContext.class); - } else { + } else if (referenceResolver.isResolvable(CamelContext.class)) { camelContext = referenceResolver.resolve(CamelContext.class); + } else { + camelContext = new DefaultCamelContext(); + try { + camelContext.start(); + } catch (Exception e) { + throw new IllegalStateException("Failed to start Camel context '%s'".formatted(CamelSettings.getContextName()), e); + } + referenceResolver.bind(CamelSettings.getContextName(), camelContext); } } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java index ae5b6ce30d..9984ed1d55 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelRunIntegrationAction.java @@ -20,7 +20,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -52,9 +55,15 @@ public class CamelRunIntegrationAction extends AbstractCamelJBangAction { /** Camel integration resource */ private final Resource integrationResource; + /** Optional list of resource files to include */ + private final List resourceFiles; + /** Source code to run as a Camel integration */ private final String sourceCode; + /** Camel Jbang command arguments */ + private final List args; + /** Environment variables set on the Camel JBang process */ private final Map envVars; @@ -63,6 +72,8 @@ public class CamelRunIntegrationAction extends AbstractCamelJBangAction { private final boolean autoRemoveResources; + private final boolean waitForRunningState; + /** * Default constructor. */ @@ -71,10 +82,13 @@ public CamelRunIntegrationAction(Builder builder) { this.integrationName = builder.integrationName; this.integrationResource = builder.integrationResource; + this.resourceFiles = builder.resourceFiles; this.sourceCode = builder.sourceCode; + this.args = builder.args; this.envVars = builder.envVars; this.systemProperties = builder.systemProperties; this.autoRemoveResources = builder.autoRemoveResources; + this.waitForRunningState = builder.waitForRunningState; } @Override @@ -102,7 +116,7 @@ public void doExecute(TestContext context) { camelJBang().camelApp().withEnvs(context.resolveDynamicValuesInMap(envVars)); camelJBang().camelApp().withSystemProperties(context.resolveDynamicValuesInMap(systemProperties)); - ProcessAndOutput pao = camelJBang().run(name, integrationToRun); + ProcessAndOutput pao = camelJBang().run(name, integrationToRun, resourceFiles, args.toArray(String[]::new)); if (!pao.getProcess().isAlive()) { logger.info("Failed to start Camel integration '%s'".formatted(name)); @@ -122,6 +136,16 @@ public void doExecute(TestContext context) { .jbang() .stop(name)); } + + logger.info("Waiting for the Camel integration '%s' (%s) to be running ...".formatted(name, pid)); + + if (waitForRunningState) { + new CamelVerifyIntegrationAction.Builder() + .integrationName(name) + .isRunning() + .build() + .execute(context); + } } catch (IOException e) { throw new CitrusRuntimeException("Failed to create temporary file from Camel integration"); } @@ -157,13 +181,16 @@ public static final class Builder extends AbstractCamelJBangAction.Builder resourceFiles = new ArrayList<>(); + private final List args = new ArrayList<>(); private final Map envVars = new HashMap<>(); private Resource envVarsFile; private final Map systemProperties = new HashMap<>(); private Resource systemPropertiesFile; private boolean autoRemoveResources = CamelJBangSettings.isAutoRemoveResources(); + private boolean waitForRunningState = CamelJBangSettings.isWaitForRunningState(); /** * Runs Camel integration from given source code. @@ -188,6 +215,26 @@ public Builder integration(Resource resource) { return this; } + /** + * Add resource file to the integration run. + * @param resource + * @return + */ + public Builder addResource(Resource resource) { + this.resourceFiles.add(resource.getFile().getAbsolutePath()); + return this; + } + + /** + * Construct resource from given path and add file as resource to the integration run. + * @param resourcePath + * @return + */ + public Builder addResource(String resourcePath) { + this.resourceFiles.add(resourcePath); + return this; + } + /** * Adds route using one of the supported languages XML or Groovy. * @param name @@ -210,6 +257,38 @@ public Builder integrationName(String name) { return this; } + /** + * Adds a command argument. + * @param arg + * @return + */ + public Builder withArg(String arg) { + this.args.add(arg); + return this; + } + + /** + * Adds a command argument with name and value. + * @param name + * @param value + * @return + */ + public Builder withArg(String name, String value) { + this.args.add(name); + this.args.add(value); + return this; + } + + /** + * Adds command arguments. + * @param args + * @return + */ + public Builder withArgs(String... args) { + this.args.addAll(Arrays.asList(args)); + return this; + } + /** * Adds an environment variable. * @param key @@ -277,6 +356,11 @@ public Builder autoRemove(boolean enabled) { return this; } + public Builder waitForRunningState(boolean enabled) { + this.waitForRunningState = enabled; + return this; + } + @Override public CamelRunIntegrationAction build() { if (systemPropertiesFile != null) { @@ -301,5 +385,6 @@ public CamelRunIntegrationAction build() { return new CamelRunIntegrationAction(this); } + } } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java index 8bd7436b4a..9ea5efe286 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CamelVerifyIntegrationAction.java @@ -74,7 +74,7 @@ public void doExecute(TestContext context) { Long pid = verifyRouteStatus(name, context.replaceDynamicContentInString(phase), context); if (logMessage != null) { - verifyRouteLogs(pid, name, context.replaceDynamicContentInString(logMessage), context); + verifyRouteLogs(pid, name, context.replaceDynamicContentInString(logMessage.trim()), context); } logger.info("Successfully verified Camel integration '%s'".formatted(name)); diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java index 0fa2bad113..e71d9c7313 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelComponentAction.java @@ -26,6 +26,7 @@ import org.citrusframework.spi.ReferenceResolverAware; import org.citrusframework.spi.Resource; import org.citrusframework.util.FileUtils; +import org.citrusframework.util.StringUtils; /** * Creates component and binds it to the given Camel context. @@ -88,6 +89,11 @@ public static Builder bind() { return new Builder(); } + public Builder componentName(String componentName) { + this.name = componentName; + return this; + } + public Builder component(String name, Object component) { if (component instanceof String) { return component(name, component.toString()); @@ -99,7 +105,12 @@ public Builder component(String name, Object component) { } public Builder component(Resource resource) { - return component(FileUtils.getBaseName(FileUtils.getFileName(resource.getLocation())), resource); + if (StringUtils.hasText(this.name)) { + return component(this.name, resource); + } else { + return component(FileUtils.getBaseName(FileUtils.getFileName(resource.getLocation())), resource); + + } } public Builder component(String name, Resource resource) { @@ -116,6 +127,11 @@ public Builder component(String name, String script) { return this; } + public Builder component(String script) { + this.script = script; + return this; + } + @Override public CreateCamelComponentAction doBuild() { return new CreateCamelComponentAction(this); diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java index e91e28a3a2..eccdcba60e 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParser.java @@ -18,6 +18,7 @@ import org.apache.camel.CamelContext; import org.citrusframework.TestActor; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.camel.endpoint.CamelEndpoint; import org.citrusframework.camel.endpoint.CamelEndpointBuilder; import org.citrusframework.camel.message.CamelMessageConverter; @@ -35,8 +36,8 @@ public CamelEndpoint parse(CamelEndpointConfig annotation, ReferenceResolver ref if (StringUtils.hasText(annotation.camelContext())) { builder.camelContext(referenceResolver.resolve(annotation.camelContext(), CamelContext.class)); - } else if (referenceResolver.isResolvable("camelContext")) { - builder.camelContext(referenceResolver.resolve("camelContext", CamelContext.class)); + } else if (referenceResolver.isResolvable(CamelSettings.getContextName())) { + builder.camelContext(referenceResolver.resolve(CamelSettings.getContextName(), CamelContext.class)); } else { builder.camelContext(referenceResolver.resolve(CamelContext.class)); } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java index 36397aacc1..772b583fc4 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParser.java @@ -18,6 +18,7 @@ import org.apache.camel.CamelContext; import org.citrusframework.TestActor; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.camel.endpoint.CamelSyncEndpoint; import org.citrusframework.camel.endpoint.CamelSyncEndpointBuilder; import org.citrusframework.camel.message.CamelMessageConverter; @@ -36,8 +37,8 @@ public CamelSyncEndpoint parse(CamelSyncEndpointConfig annotation, ReferenceReso if (StringUtils.hasText(annotation.camelContext())) { builder.camelContext(referenceResolver.resolve(annotation.camelContext(), CamelContext.class)); - } else if (referenceResolver.isResolvable("camelContext")) { - builder.camelContext(referenceResolver.resolve("camelContext", CamelContext.class)); + } else if (referenceResolver.isResolvable(CamelSettings.getContextName())) { + builder.camelContext(referenceResolver.resolve(CamelSettings.getContextName(), CamelContext.class)); } else { builder.camelContext(referenceResolver.resolve(CamelContext.class)); } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelConsumer.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelConsumer.java index 9ef430c804..605dcba225 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelConsumer.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelConsumer.java @@ -17,14 +17,15 @@ package org.citrusframework.camel.endpoint; import org.apache.camel.CamelContext; +import org.apache.camel.ConsumerTemplate; +import org.apache.camel.Exchange; import org.apache.camel.impl.DefaultCamelContext; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.exceptions.MessageTimeoutException; import org.citrusframework.message.Message; import org.citrusframework.messaging.Consumer; -import org.apache.camel.ConsumerTemplate; -import org.apache.camel.Exchange; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -106,8 +107,8 @@ protected ConsumerTemplate getConsumerTemplate(TestContext context) { } else { if (context.getReferenceResolver().resolveAll(CamelContext.class).size() == 1) { endpointConfiguration.setCamelContext(context.getReferenceResolver().resolve(CamelContext.class)); - } else if (context.getReferenceResolver().isResolvable("camelContext")) { - endpointConfiguration.setCamelContext(context.getReferenceResolver().resolve("camelContext", CamelContext.class)); + } else if (context.getReferenceResolver().isResolvable(CamelSettings.getContextName())) { + endpointConfiguration.setCamelContext(context.getReferenceResolver().resolve(CamelSettings.getContextName(), CamelContext.class)); } else { endpointConfiguration.setCamelContext(new DefaultCamelContext()); } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelEndpointComponent.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelEndpointComponent.java index 6a3cf05a0a..ffd338022c 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelEndpointComponent.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelEndpointComponent.java @@ -18,11 +18,12 @@ import java.util.Map; +import org.apache.camel.CamelContext; +import org.apache.camel.impl.DefaultCamelContext; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.context.TestContext; import org.citrusframework.endpoint.AbstractEndpointComponent; import org.citrusframework.endpoint.Endpoint; -import org.apache.camel.CamelContext; -import org.apache.camel.impl.DefaultCamelContext; /** * @since 1.4.1 @@ -55,8 +56,8 @@ protected Endpoint createEndpoint(String resourcePath, Map param if (context.getReferenceResolver() != null) { if (context.getReferenceResolver().resolveAll(CamelContext.class).size() == 1) { endpoint.getEndpointConfiguration().setCamelContext(context.getReferenceResolver().resolve(CamelContext.class)); - } else if (context.getReferenceResolver().isResolvable("camelContext")) { - endpoint.getEndpointConfiguration().setCamelContext(context.getReferenceResolver().resolve("camelContext", CamelContext.class)); + } else if (context.getReferenceResolver().isResolvable(CamelSettings.getContextName())) { + endpoint.getEndpointConfiguration().setCamelContext(context.getReferenceResolver().resolve(CamelSettings.getContextName(), CamelContext.class)); } else { endpoint.getEndpointConfiguration().setCamelContext(new DefaultCamelContext()); } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelProducer.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelProducer.java index 3121d80426..0c5bde3f90 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelProducer.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/endpoint/CamelProducer.java @@ -16,12 +16,15 @@ package org.citrusframework.camel.endpoint; +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.ProducerTemplate; import org.apache.camel.impl.DefaultCamelContext; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.message.Message; import org.citrusframework.messaging.Producer; -import org.apache.camel.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,8 +103,8 @@ protected ProducerTemplate getProducerTemplate(TestContext context) { } else if (context.getReferenceResolver() != null) { if (context.getReferenceResolver().resolveAll(CamelContext.class).size() == 1) { endpointConfiguration.setCamelContext(context.getReferenceResolver().resolve(CamelContext.class)); - } else if (context.getReferenceResolver().isResolvable("camelContext")) { - endpointConfiguration.setCamelContext(context.getReferenceResolver().resolve("camelContext", CamelContext.class)); + } else if (context.getReferenceResolver().isResolvable(CamelSettings.getContextName())) { + endpointConfiguration.setCamelContext(context.getReferenceResolver().resolve(CamelSettings.getContextName(), CamelContext.class)); } else { endpointConfiguration.setCamelContext(new DefaultCamelContext()); } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBang.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBang.java index 6891df2b30..3aed456c11 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBang.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBang.java @@ -86,21 +86,23 @@ public JBangSupport camelApp() { * Run given integration with JBang Camel app. * @param name * @param path + * @param resources * @param args * @return */ - public ProcessAndOutput run(String name, Path path, String... args) { - return run(name, path.toAbsolutePath().toString(), args); + public ProcessAndOutput run(String name, Path path, List resources, String... args) { + return run(name, path.toAbsolutePath().toString(), resources, args); } /** * Run given integration with JBang Camel app. * @param name * @param file + * @param resources * @param args * @return */ - public ProcessAndOutput run(String name, String file, String... args) { + public ProcessAndOutput run(String name, String file, List resources, String... args) { List runArgs = new ArrayList<>(); runArgs.add("--name"); runArgs.add(name); @@ -113,6 +115,7 @@ public ProcessAndOutput run(String name, String file, String... args) { runArgs.addAll(Arrays.asList(args)); runArgs.add(file); + runArgs.addAll(resources); if (CamelJBangSettings.isCamelDumpIntegrationOutput()) { Path workDir = CamelJBangSettings.getWorkDir(); diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java index 70808711ba..02ea705691 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/jbang/CamelJBangSettings.java @@ -58,6 +58,10 @@ public final class CamelJBangSettings { private static final String AUTO_REMOVE_RESOURCES_ENV = JBANG_ENV_PREFIX + "AUTO_REMOVE_RESOURCES"; private static final String AUTO_REMOVE_RESOURCES_DEFAULT = "false"; + private static final String WAIT_FOR_RUNNING_STATE_PROPERTY = JBANG_PROPERTY_PREFIX + "wait.for.running.state"; + private static final String WAIT_FOR_RUNNING_STATE_ENV = JBANG_ENV_PREFIX + "WAIT_FOR_RUNNING_STATE"; + private static final String WAIT_FOR_RUNNING_STATE_DEFAULT = "true"; + private CamelJBangSettings() { // prevent instantiation of utility class } @@ -152,5 +156,12 @@ public static boolean isAutoRemoveResources() { System.getenv(AUTO_REMOVE_RESOURCES_ENV) != null ? System.getenv(AUTO_REMOVE_RESOURCES_ENV) : AUTO_REMOVE_RESOURCES_DEFAULT)); } - + /** + * When set to true Camel JBang will automatically wait for each integration created to be in running state. + * @return + */ + public static boolean isWaitForRunningState() { + return Boolean.parseBoolean(System.getProperty(WAIT_FOR_RUNNING_STATE_PROPERTY, + System.getenv(WAIT_FOR_RUNNING_STATE_ENV) != null ? System.getenv(WAIT_FOR_RUNNING_STATE_ENV) : WAIT_FOR_RUNNING_STATE_DEFAULT)); + } } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/Camel.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/Camel.java index 6f77da8a6f..74f997c8ea 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/Camel.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/Camel.java @@ -33,6 +33,7 @@ import org.citrusframework.camel.actions.CamelRunIntegrationAction; import org.citrusframework.camel.actions.CamelStopIntegrationAction; import org.citrusframework.camel.actions.CamelVerifyIntegrationAction; +import org.citrusframework.camel.actions.CreateCamelComponentAction; import org.citrusframework.camel.actions.CreateCamelContextAction; import org.citrusframework.camel.actions.CreateCamelRouteAction; import org.citrusframework.camel.actions.RemoveCamelRouteAction; @@ -45,6 +46,7 @@ import org.citrusframework.spi.ReferenceResolver; import org.citrusframework.spi.ReferenceResolverAware; import org.citrusframework.spi.Resources; +import org.citrusframework.util.StringUtils; @XmlRootElement(name = "camel") public class Camel implements TestActionBuilder, ReferenceResolverAware { @@ -92,6 +94,24 @@ public Camel setControlBus(ControlBus controlBus) { return this; } + @XmlElement(name = "create-component") + public Camel setCreateComponent(Component component) { + CreateCamelComponentAction.Builder builder = new CreateCamelComponentAction.Builder(); + + builder.componentName(component.getName()); + + if (StringUtils.hasText(component.getScript())) { + builder.component(component.getScript()); + } + + if (StringUtils.hasText(component.getFile())) { + builder.component(Resources.create(component.getFile())); + } + + this.builder = builder; + return this; + } + @XmlElement(name = "create-context") public Camel setCreateContext(CamelContext createContext) { CreateCamelContextAction.Builder builder = new CreateCamelContextAction.Builder(); @@ -153,7 +173,20 @@ public Camel setJBang(JBang jbang) { builder.integration(jbang.getRun().getIntegration().getSource()); } - builder.autoRemove(jbang.getRun().getIntegration().isAutoRemove()); + builder.autoRemove(jbang.getRun().isAutoRemove()); + builder.waitForRunningState(jbang.getRun().isWaitForRunningState()); + + if (jbang.getRun().getArgLine() != null) { + builder.withArgs(jbang.getRun().getArgLine().split(" ")); + } + + if (jbang.getRun().getArgs() != null) { + builder.withArgs(jbang.getRun().getArgs().getArgs().toArray(String[]::new)); + } + + if (jbang.getRun().getResources() != null) { + jbang.getRun().getResources().getResources().forEach(builder::addResource); + } if (jbang.getRun().getIntegration().getFile() != null) { builder.integration(Resources.create(jbang.getRun().getIntegration().getFile())); diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/CamelContext.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/CamelContext.java index 92ac1583bf..6c9ba670bb 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/CamelContext.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/CamelContext.java @@ -22,14 +22,12 @@ import jakarta.xml.bind.annotation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "name" -}) +@XmlType(name = "") public class CamelContext { @XmlAttribute(required = true) protected String name; - @XmlAttribute() + @XmlAttribute protected boolean autoStart = true; public String getName() { diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/Component.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/Component.java new file mode 100644 index 0000000000..7838206495 --- /dev/null +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/Component.java @@ -0,0 +1,61 @@ +/* + * Copyright the original author or authors. + * + * Licensed 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.citrusframework.camel.xml; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlAttribute; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "script" +}) +public class Component { + @XmlAttribute(required = true) + protected String name; + + @XmlAttribute + protected String file; + @XmlElement + protected String script; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFile() { + return file; + } + + public void setFile(String file) { + this.file = file; + } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } +} diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/JBang.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/JBang.java index 00ca334f01..484e5c055e 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/JBang.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/xml/JBang.java @@ -25,6 +25,7 @@ import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; import org.citrusframework.camel.CamelSettings; +import org.citrusframework.camel.jbang.CamelJBangSettings; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { @@ -91,13 +92,30 @@ public VerifyIntegration getVerify() { @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { - "integration" + "args", + "integration", + "resources" }) public static class RunIntegration { @XmlElement(required = true) private Integration integration; + @XmlAttribute(name = "auto-remove") + protected boolean autoRemove; + + @XmlAttribute(name = "args") + protected String argLine; + + @XmlAttribute(name = "wait-for-running-state") + protected boolean waitForRunningState = CamelJBangSettings.isWaitForRunningState(); + + @XmlElement + protected Args args; + + @XmlElement + protected Resources resources; + public Integration getIntegration() { return integration; } @@ -106,6 +124,88 @@ public void setIntegration(Integration integration) { this.integration = integration; } + public boolean isAutoRemove() { + return autoRemove; + } + + public void setAutoRemove(boolean autoRemove) { + this.autoRemove = autoRemove; + } + + public boolean isWaitForRunningState() { + return waitForRunningState; + } + + public void setWaitForRunningState(boolean waitForRunningState) { + this.waitForRunningState = waitForRunningState; + } + + public void setResources(Resources resources) { + this.resources = resources; + } + + public Resources getResources() { + return resources; + } + + public String getArgLine() { + return argLine; + } + + public void setArgLine(String argLine) { + this.argLine = argLine; + } + + public Args getArgs() { + return args; + } + + public void setArgs(Args args) { + this.args = args; + } + + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "args", + }) + public static class Args { + + @XmlElement(name = "argument") + protected List args; + + public List getArgs() { + if (args == null) { + args = new ArrayList<>(); + } + return args; + } + + public void setArgs(List args) { + this.args = args; + } + } + + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "resources", + }) + public static class Resources { + + @XmlElement(name = "resource") + protected List resources; + + public List getResources() { + if (resources == null) { + resources = new ArrayList<>(); + } + return resources; + } + + public void setResources(List resources) { + this.resources = resources; + } + } + @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "environment", @@ -119,9 +219,6 @@ public static class Integration { @XmlAttribute protected String file; - @XmlAttribute(name = "auto-remove") - protected boolean autoRemove; - @XmlElement protected String source; @@ -139,14 +236,6 @@ public String getName() { return name; } - public boolean isAutoRemove() { - return autoRemove; - } - - public void setAutoRemove(boolean autoRemove) { - this.autoRemove = autoRemove; - } - public void setFile(String file) { this.file = file; } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/Camel.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/Camel.java index 06de9ddff2..4bfa5820f5 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/Camel.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/Camel.java @@ -53,6 +53,10 @@ public void setControlBus(ControlBus builder) { this.delegate = builder; } + public void setCreateComponent(CreateComponent builder) { + this.delegate = builder; + } + public void setCreateContext(CreateContext builder) { this.delegate = builder; } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/CreateComponent.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/CreateComponent.java new file mode 100644 index 0000000000..73c6528238 --- /dev/null +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/CreateComponent.java @@ -0,0 +1,41 @@ +/* + * Copyright the original author or authors. + * + * Licensed 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.citrusframework.camel.yaml; + +import org.citrusframework.camel.actions.CreateCamelComponentAction; +import org.citrusframework.spi.Resources; + +public class CreateComponent implements CamelActionBuilderWrapper { + private final CreateCamelComponentAction.Builder builder = new CreateCamelComponentAction.Builder(); + + public void setName(String componentName) { + builder.componentName(componentName); + } + + public void setFile(String file) { + builder.component(Resources.create(file)); + } + + public void setScript(String script) { + builder.component(script); + } + + @Override + public CreateCamelComponentAction.Builder getBuilder() { + return builder; + } +} diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/JBang.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/JBang.java index c6addb97f7..3b4516911f 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/JBang.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/yaml/JBang.java @@ -98,6 +98,22 @@ public static class RunIntegration implements CamelActionBuilderWrapper args) { + builder.withArgs(args.toArray(String[]::new)); + } + + public void setResources(List resources) { + resources.forEach(builder::addResource); + } + public void setIntegration(Integration integration) { builder.integrationName(integration.name); @@ -105,8 +121,6 @@ public void setIntegration(Integration integration) { builder.integration(Resources.create(integration.file)); } - builder.autoRemove(integration.autoRemove); - if (integration.sourceCode != null) { builder.integration(integration.sourceCode); } @@ -139,8 +153,6 @@ public static class Integration { private String file; private String sourceCode; - private boolean autoRemove; - protected Environment environment; protected SystemProperties systemProperties; @@ -173,14 +185,6 @@ public void setSystemProperties(SystemProperties systemProperties) { this.systemProperties = systemProperties; } - public void setAutoRemove(boolean autoRemove) { - this.autoRemove = autoRemove; - } - - public boolean isAutoRemove() { - return autoRemove; - } - public static class Environment { protected String file; diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParserTest.java index 81d4008b9a..f1f156537d 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelEndpointConfigParserTest.java @@ -18,9 +18,11 @@ import java.util.Map; +import org.apache.camel.CamelContext; import org.citrusframework.TestActor; import org.citrusframework.annotations.CitrusAnnotations; import org.citrusframework.annotations.CitrusEndpoint; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.camel.endpoint.CamelEndpoint; import org.citrusframework.camel.message.CamelMessageConverter; import org.citrusframework.config.annotation.AnnotationConfigParser; @@ -28,7 +30,6 @@ import org.citrusframework.endpoint.direct.annotation.DirectSyncEndpointConfigParser; import org.citrusframework.spi.ReferenceResolver; import org.citrusframework.testng.AbstractTestNGUnitTest; -import org.apache.camel.CamelContext; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.testng.Assert; @@ -69,8 +70,8 @@ public class CamelEndpointConfigParserTest extends AbstractTestNGUnitTest { public void setup() { MockitoAnnotations.openMocks(this); - when(referenceResolver.isResolvable("camelContext")).thenReturn(true); - when(referenceResolver.resolve("camelContext", CamelContext.class)).thenReturn(camelContext); + when(referenceResolver.isResolvable(CamelSettings.getContextName())).thenReturn(true); + when(referenceResolver.resolve(CamelSettings.getContextName(), CamelContext.class)).thenReturn(camelContext); when(referenceResolver.resolve("messageConverter", CamelMessageConverter.class)).thenReturn(messageConverter); when(referenceResolver.resolve("testActor", TestActor.class)).thenReturn(testActor); } diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParserTest.java index 96d17ab8af..8ac62f13d1 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/annotation/CamelSyncEndpointConfigParserTest.java @@ -16,9 +16,11 @@ package org.citrusframework.camel.config.annotation; +import org.apache.camel.CamelContext; import org.citrusframework.TestActor; import org.citrusframework.annotations.CitrusAnnotations; import org.citrusframework.annotations.CitrusEndpoint; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.camel.endpoint.CamelSyncEndpoint; import org.citrusframework.camel.message.CamelMessageConverter; import org.citrusframework.config.annotation.AnnotationConfigParser; @@ -26,7 +28,6 @@ import org.citrusframework.message.MessageCorrelator; import org.citrusframework.spi.ReferenceResolver; import org.citrusframework.testng.AbstractTestNGUnitTest; -import org.apache.camel.CamelContext; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.testng.Assert; @@ -71,8 +72,8 @@ public class CamelSyncEndpointConfigParserTest extends AbstractTestNGUnitTest { public void setup() { MockitoAnnotations.openMocks(this); - when(referenceResolver.isResolvable("camelContext")).thenReturn(true); - when(referenceResolver.resolve("camelContext", CamelContext.class)).thenReturn(camelContext); + when(referenceResolver.isResolvable(CamelSettings.getContextName())).thenReturn(true); + when(referenceResolver.resolve(CamelSettings.getContextName(), CamelContext.class)).thenReturn(camelContext); when(referenceResolver.resolve("messageConverter", CamelMessageConverter.class)).thenReturn(messageConverter); when(referenceResolver.resolve("messageCorrelator", MessageCorrelator.class)).thenReturn(messageCorrelator); when(referenceResolver.resolve("testActor", TestActor.class)).thenReturn(testActor); diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest.java index ca88046406..9906aa0aa5 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest.java @@ -39,7 +39,7 @@ public void testCreateRouteActionParser() { action = getNextTestActionFromTest(); Assert.assertNotNull(action.getCamelContext()); - Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("camelContext", CamelContext.class)); + Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("citrusCamelContext", CamelContext.class)); Assert.assertEquals(action.getRouteId(), "route_2"); Assert.assertEquals(action.getAction(), "status"); Assert.assertEquals(action.getResult(), "Stopped"); @@ -53,7 +53,7 @@ public void testCreateRouteActionParser() { action = getNextTestActionFromTest(); Assert.assertNotNull(action.getCamelContext()); - Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("camelContext", CamelContext.class)); + Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("citrusCamelContext", CamelContext.class)); Assert.assertEquals(action.getLanguageType(), "simple"); Assert.assertEquals(action.getLanguageExpression(), "${camelContext.getRouteController().getRouteStatus('route_3')}"); Assert.assertEquals(action.getResult(), "Started"); diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelEndpointParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelEndpointParserTest.java index dd2c829ab4..1ba1edbe5a 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelEndpointParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelEndpointParserTest.java @@ -16,14 +16,15 @@ package org.citrusframework.camel.config.xml; +import java.util.Map; + import org.citrusframework.TestActor; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.camel.endpoint.CamelEndpoint; import org.citrusframework.testng.AbstractBeanDefinitionParserTest; import org.testng.Assert; import org.testng.annotations.Test; -import java.util.Map; - /** * @since 1.4.1 */ @@ -37,7 +38,7 @@ public void testCamelEndpointParser() { // 1st message receiver CamelEndpoint camelEndpoint = endpoints.get("camelEndpoint1"); - Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getCamelContext(), beanDefinitionContext.getBean("camelContext")); + Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getCamelContext(), beanDefinitionContext.getBean(CamelSettings.getContextName())); Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getEndpointUri(), "direct:news-feed1"); Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getTimeout(), 5000L); diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelSyncEndpointParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelSyncEndpointParserTest.java index 1d721f5da2..9d2563c46d 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelSyncEndpointParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CamelSyncEndpointParserTest.java @@ -16,15 +16,16 @@ package org.citrusframework.camel.config.xml; +import java.util.Map; + import org.citrusframework.TestActor; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.camel.endpoint.CamelSyncEndpoint; import org.citrusframework.message.DefaultMessageCorrelator; import org.citrusframework.testng.AbstractBeanDefinitionParserTest; import org.testng.Assert; import org.testng.annotations.Test; -import java.util.Map; - /** * @since 1.4.1 */ @@ -38,7 +39,7 @@ public void testCamelSyncEndpointParser() { // 1st message receiver CamelSyncEndpoint camelEndpoint = endpoints.get("camelSyncEndpoint1"); - Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getCamelContext(), beanDefinitionContext.getBean("camelContext")); + Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getCamelContext(), beanDefinitionContext.getBean(CamelSettings.getContextName())); Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getCorrelator().getClass(), DefaultMessageCorrelator.class); Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getEndpointUri(), "direct:news-feed1"); Assert.assertEquals(camelEndpoint.getEndpointConfiguration().getPollingInterval(), 500L); diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java index e1153eeb7a..0a37a58b87 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest.java @@ -48,7 +48,7 @@ public void testCreateRouteActionParser() { action = getNextTestActionFromTest(); Assert.assertNotNull(action.getCamelContext()); - Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("camelContext", CamelContext.class)); + Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("citrusCamelContext", CamelContext.class)); Assert.assertEquals(action.getRouteSpec().replaceAll("\\s", ""), ("" + "" + "" + diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest.java index 86e6d47d9c..6a1efb1093 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest.java @@ -37,7 +37,7 @@ public void testRemoveRouteActionParser() { action = getNextTestActionFromTest(); Assert.assertNotNull(action.getCamelContext()); - Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("camelContext", CamelContext.class)); + Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("citrusCamelContext", CamelContext.class)); Assert.assertEquals(action.getRouteIds().size(), 2); } } diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest.java index d7711fa4b7..9a68973a75 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest.java @@ -37,7 +37,7 @@ public void testStartRouteActionParser() { action = getNextTestActionFromTest(); Assert.assertNotNull(action.getCamelContext()); - Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("camelContext", CamelContext.class)); + Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("citrusCamelContext", CamelContext.class)); Assert.assertEquals(action.getRouteIds().size(), 2); } } diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest.java index c379c104f7..2102c7886e 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest.java @@ -37,7 +37,7 @@ public void testStopRouteActionParser() { action = getNextTestActionFromTest(); Assert.assertNotNull(action.getCamelContext()); - Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("camelContext", CamelContext.class)); + Assert.assertEquals(action.getCamelContext(), beanDefinitionContext.getBean("citrusCamelContext", CamelContext.class)); Assert.assertEquals(action.getRouteIds().size(), 2); } } diff --git a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/endpoint/CamelEndpointComponentTest.java b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/endpoint/CamelEndpointComponentTest.java index dc57ca3df8..42fe6232d6 100644 --- a/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/endpoint/CamelEndpointComponentTest.java +++ b/endpoints/citrus-camel/src/test/java/org/citrusframework/camel/endpoint/CamelEndpointComponentTest.java @@ -20,12 +20,13 @@ import java.util.HashMap; import java.util.Map; +import org.apache.camel.CamelContext; +import org.citrusframework.camel.CamelSettings; import org.citrusframework.context.TestContext; import org.citrusframework.endpoint.Endpoint; import org.citrusframework.endpoint.EndpointComponent; import org.citrusframework.endpoint.direct.DirectEndpointComponent; import org.citrusframework.spi.ReferenceResolver; -import org.apache.camel.CamelContext; import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.BeforeClass; @@ -39,9 +40,9 @@ */ public class CamelEndpointComponentTest { - private ReferenceResolver referenceResolver = Mockito.mock(ReferenceResolver.class); - private CamelContext camelContext = Mockito.mock(CamelContext.class); - private TestContext context = new TestContext(); + private final ReferenceResolver referenceResolver = Mockito.mock(ReferenceResolver.class); + private final CamelContext camelContext = Mockito.mock(CamelContext.class); + private final TestContext context = new TestContext(); @BeforeClass public void setup() { @@ -70,7 +71,6 @@ public void testCreateEndpoint() throws Exception { Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "seda:news-feed"); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); - } @Test @@ -95,7 +95,6 @@ public void testCreateSyncEndpoint() throws Exception { Assert.assertEquals(((CamelSyncEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "seda:news-feed"); Assert.assertEquals(((CamelSyncEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelSyncEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); - } @Test @@ -108,7 +107,7 @@ public void testCreateEndpointWithParameters() throws Exception { reset(referenceResolver); when(referenceResolver.resolveAll(CamelContext.class)).thenReturn(camelContextMap); - when(referenceResolver.isResolvable("camelContext")).thenReturn(false); + when(referenceResolver.isResolvable(CamelSettings.getContextName())).thenReturn(false); when(referenceResolver.isResolvable("myCamelContext")).thenReturn(true); when(referenceResolver.resolve("myCamelContext", CamelContext.class)).thenReturn(camelContext); Endpoint endpoint = component.createEndpoint("camel:direct:news-feed?timeout=10000&camelContext=myCamelContext", context); @@ -118,7 +117,6 @@ public void testCreateEndpointWithParameters() throws Exception { Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "direct:news-feed"); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 10000L); - } @Test @@ -131,7 +129,7 @@ public void testCreateEndpointWithCamelParameters() throws Exception { reset(referenceResolver); when(referenceResolver.resolveAll(CamelContext.class)).thenReturn(camelContextMap); - when(referenceResolver.isResolvable("camelContext")).thenReturn(false); + when(referenceResolver.isResolvable(CamelSettings.getContextName())).thenReturn(false); when(referenceResolver.isResolvable("myCamelContext")).thenReturn(true); when(referenceResolver.resolve("myCamelContext", CamelContext.class)).thenReturn(camelContext); Endpoint endpoint = component.createEndpoint("camel:controlbus:route?routeId=news&timeout=10000&camelContext=myCamelContext&action=stats", context); @@ -141,7 +139,22 @@ public void testCreateEndpointWithCamelParameters() throws Exception { Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "controlbus:route?routeId=news&action=stats"); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 10000L); + } + + @Test + public void testCreateEndpointWithBeanReference() throws Exception { + CamelEndpointComponent component = new CamelEndpointComponent(); + reset(referenceResolver); + when(referenceResolver.resolveAll(CamelContext.class)).thenReturn(Collections.singletonMap("myCamelContext", camelContext)); + when(referenceResolver.resolve(CamelContext.class)).thenReturn(camelContext); + Endpoint endpoint = component.createEndpoint("camel:direct:news?provider=#newsProvider", context); + + Assert.assertEquals(endpoint.getClass(), CamelEndpoint.class); + + Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "direct:news?provider=#newsProvider"); + Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); + Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); } @Test diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest-context.xml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest-context.xml index 656140b6f6..7f0e8bf03e 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest-context.xml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CamelControlBusActionParserTest-context.xml @@ -14,7 +14,7 @@ - + Stopped @@ -23,7 +23,7 @@ ${camelContext.stop()} - + ${camelContext.getRouteController().getRouteStatus('route_3')} Started diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest-context.xml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest-context.xml index ca52614fd4..3c28847ecd 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest-context.xml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/CreateCamelRouteActionParserTest-context.xml @@ -24,7 +24,7 @@ - + diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest-context.xml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest-context.xml index f570ca9f2b..a213d51706 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest-context.xml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/RemoveCamelRouteActionParserTest-context.xml @@ -14,7 +14,7 @@ - + diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest-context.xml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest-context.xml index 4fc0ed9df9..c7da9e96eb 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest-context.xml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StartCamelRouteActionParserTest-context.xml @@ -14,7 +14,7 @@ - + diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest-context.xml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest-context.xml index 539bcc96dc..411c0496b2 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest-context.xml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/config/xml/StopCamelRouteActionParserTest-context.xml @@ -14,7 +14,7 @@ - + diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml index 1234e17707..9cbfa789bc 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/xml/camel-jbang-test.xml @@ -22,7 +22,7 @@ - + diff --git a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml index b5eed30f4b..60379b164c 100644 --- a/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml +++ b/endpoints/citrus-camel/src/test/resources/org/citrusframework/camel/yaml/camel-jbang-test.yaml @@ -5,6 +5,8 @@ actions: - camel: jbang: run: + args: + - "--verbose" integration: name: "hello-yaml" file: "classpath:org/citrusframework/camel/integration/route.yaml" diff --git a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd index c1a51f2ef2..fa6ccf047f 100644 --- a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd +++ b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase-4.4.0-SNAPSHOT.xsd @@ -863,6 +863,18 @@ + + + Creates new Camel component and binds to Camel registry + + + + + + + + + Creates new Camel context on the fly @@ -993,6 +1005,13 @@ + + + + + + + @@ -1026,10 +1045,19 @@ - + + + + + + + + + + diff --git a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd index c1a51f2ef2..fa6ccf047f 100644 --- a/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd +++ b/runtime/citrus-xml/src/main/resources/org/citrusframework/schema/xml/testcase/citrus-testcase.xsd @@ -863,6 +863,18 @@ + + + Creates new Camel component and binds to Camel registry + + + + + + + + + Creates new Camel context on the fly @@ -993,6 +1005,13 @@ + + + + + + + @@ -1026,10 +1045,19 @@ - + + + + + + + + + +