diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelContextAction.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelContextAction.java index 741ad619c6..a9fe6ca77f 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelContextAction.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/actions/CreateCamelContextAction.java @@ -46,9 +46,9 @@ public void doExecute(TestContext context) { if (referenceResolver instanceof CamelReferenceResolver camelReferenceResolver) { camelReferenceResolver.setCamelContext(camelContext); - camelReferenceResolver.getFallback().bind(contextName, context); + camelReferenceResolver.getFallback().bind(contextName, camelContext); } else { - referenceResolver.bind(contextName, context); + referenceResolver.bind(contextName, camelContext); context.setReferenceResolver(new CamelReferenceResolver(camelContext) .withFallback(referenceResolver)); } diff --git a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/context/CamelReferenceResolver.java b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/context/CamelReferenceResolver.java index b29e2f4729..f45abf6596 100644 --- a/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/context/CamelReferenceResolver.java +++ b/endpoints/citrus-camel/src/main/java/org/citrusframework/camel/context/CamelReferenceResolver.java @@ -121,6 +121,10 @@ public void setCamelContext(CamelContext camelContext) { this.camelContext = camelContext; } + public CamelContext getCamelContext() { + return camelContext; + } + public ReferenceResolver getFallback() { return fallback; } 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 ffd338022c..8a3d8695bb 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 @@ -21,6 +21,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.impl.DefaultCamelContext; import org.citrusframework.camel.CamelSettings; +import org.citrusframework.camel.context.CamelReferenceResolver; import org.citrusframework.context.TestContext; import org.citrusframework.endpoint.AbstractEndpointComponent; import org.citrusframework.endpoint.Endpoint; @@ -54,9 +55,11 @@ protected Endpoint createEndpoint(String resourcePath, Map param } if (context.getReferenceResolver() != null) { - if (context.getReferenceResolver().resolveAll(CamelContext.class).size() == 1) { + if (context.getReferenceResolver() instanceof CamelReferenceResolver camelReferenceResolver) { + endpoint.getEndpointConfiguration().setCamelContext(camelReferenceResolver.getCamelContext()); + } else if (context.getReferenceResolver().resolveAll(CamelContext.class).size() == 1) { endpoint.getEndpointConfiguration().setCamelContext(context.getReferenceResolver().resolve(CamelContext.class)); - } else if (context.getReferenceResolver().isResolvable(CamelSettings.getContextName())) { + } else if (context.getReferenceResolver().isResolvable(CamelSettings.getContextName(), CamelContext.class)) { endpoint.getEndpointConfiguration().setCamelContext(context.getReferenceResolver().resolve(CamelSettings.getContextName(), CamelContext.class)); } else { endpoint.getEndpointConfiguration().setCamelContext(new DefaultCamelContext());