Skip to content

Commit

Permalink
fix: Bind created Camel context to bean registry
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Dec 2, 2024
1 parent 0be1939 commit 6bc8557
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}

public CamelContext getCamelContext() {
return camelContext;
}

public ReferenceResolver getFallback() {
return fallback;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,9 +55,11 @@ protected Endpoint createEndpoint(String resourcePath, Map<String, String> 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());
Expand Down

0 comments on commit 6bc8557

Please sign in to comment.