JB,
The Camel context is in a different bundle from the bundle containing the Pax
Exam test. It gets injected into a PaxExam test class annotated with
@RunWith(PaxExam.class). The issue is that this injection happens once, but
the bundle containing the Camel context gets restarted during the test, so the
originally injected reference is no longer valid.
For now, I have a workaround using helper class from Camel:
org.apache.camel.karaf.commands.internal.CamelControllerImpl to lookup the
Camel context again after the restart:
CamelControllerImpl camelController = new CamelControllerImpl();
camelController.setBundleContext(bundleContext);
aggregatorContext =
camelController.getLocalCamelContext("ra-aggregator");
I suppose I need something similar to the Declarative Services greedy policy
option:
@Reference(policyOption = ReferencePolicyOption.GREEDY)
So that the injected dependencies get automatically re-injected during the test
execution.
Unless Pax-Exam supports similar semantics in some other way.
Thanks
> On Jan 25, 2017, at 2:10 PM, Jean-Baptiste Onofré <[email protected]> wrote:
>
> Hi Alex
>
> The camel context is in the same bundle or from another bundle ?
>
> Regards
> JB
> On Jan 25, 2017, at 19:21, Alex Soto <[email protected]
> <mailto:[email protected]>> wrote:
> Hello,
>
> I am using PAX-EXAM 4.9.2, and Karaf 4.0.8, my integration test injects a
> Camel Context defined in a Blueprint bundle. During the test, this bundle
> is restarted for other reasons (configuration changes). This is how I
> inject the Camel context:
>
> @Inject
> @Filter(timeout = SERVICE_TIMEOUT, value = "(camel.context.name
> <http://camel.context.name/>=ra-aggregator)")
> protected CamelContext aggregatorContext;
>
>
> Before the bundle restart I have no problem sending messages to the endpoints
> in this context:
>
> template = aggregatorContext.createProducerTemplate();
> template.sendBody("direct:aggregator", null);
>
> However, after the bundle restarts, I am no longer able to send messages to
> an endpoint in the this Camel context. The context appears to say stopped
> after the bundle restarts:
>
> aggregatorContext.getStatus().isStarted() == false
>
> but I know that the bundle has already been
> restarted. The question is:
>
> Is there a way to get the dependencies re-injected after a bundle restart?
>
>
> Best regards,
> Alex soto
>
>
>