CamelBlueprintTestSupport Issues
Within a maven project that creates bundle I have a test class that extends CamelBlueprintTestSupport with blueprint descriptor under OSGI-INF/blueprint directory. It seems that CamelBlueprintHelper creates two bundles that point to the same Blueprint XML. One bundle is created for Bundle-SymbolicName=testClassName using blueprint under OSGI-INF/blueprint directory and another is created by scanning for bundles in all META-INF/MANIFEST.MF resources, one of these bundles happens to be a bundle for project containing test class and pointing to the same Blueprint XML. This seems to be causing all sorts of issues and I was wondering how to handle this problem. Thanks, Andre -- View this message in context: http://camel.465427.n5.nabble.com/CamelBlueprintTestSupport-Issues-tp5741066.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: CamelBlueprintTestSupport Issues
Hi, CamelBlueprintHelper just creates one test bundle and it will look up the bundles in the class path to install them. I suggest you to massage your class path to exclude the test classes bundle or you just put the test into your test classes bundle. -- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Tuesday, October 8, 2013 at 8:43 AM, Andre Piwoni wrote: > Within a maven project that creates bundle I have a test class that extends > CamelBlueprintTestSupport with blueprint descriptor under OSGI-INF/blueprint > directory. > It seems that CamelBlueprintHelper creates two bundles that point to the > same Blueprint XML. > > One bundle is created for Bundle-SymbolicName=testClassName using blueprint > under OSGI-INF/blueprint directory and another is created by scanning for > bundles in all META-INF/MANIFEST.MF resources, one of these bundles happens > to be a bundle for project containing test class and pointing to the same > Blueprint XML. > > This seems to be causing all sorts of issues and I was wondering how to > handle this problem. > > Thanks, > Andre > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/CamelBlueprintTestSupport-Issues-tp5741066.html > Sent from the Camel - Users mailing list archive at Nabble.com > (http://Nabble.com).
Re: CamelBlueprintTestSupport Issues
Willem, thank you for reply. My point is that with CamelBlueprintTestSupport that utilizes CamelBlueprintHelper I don't have much control over which bundles are included. Here's sample Maven project structure that creates bundle (not test bundle) and contains test case that extends CamelBlueprintTestSupport: ProjectA (bundle) - /src/main/resources/OSGI-INF/blueprint/camel-context.xml - /src/test/java/TestClassThatExtendsCamelBluePrintTestSupport.java public class TestClassThatExtendsCamelBluePrintTestSupport extends CamelBlueprintTestSupport { ... protected String getBlueprintDescriptor() { return "OSGI-INF/blueprint/camel-context.xml"; } ... } When TestClassThatExtendsCamelBluePrintTestSupport is executed CamelBlueprintTestSupport calls CamelBlueprintHelper which includes test bundle and ProjectA bundle. public static BundleContext createBundleContext(String name, String descriptors, boolean includeTestBundle,String bundleFilter, String testBundleVersion, String testBundleDirectives) throws Exception { TinyBundle bundle = null; if (includeTestBundle) { // ALWAYS SET TO TRUE BY CamelBlueprintTestSupport // add ourselves as a bundle bundle = createTestBundle(testBundleDirectives == null ? name : name + ';' + testBundleDirectives, testBundleVersion, descriptors); } return createBundleContext(name, bundleFilter, bundle); } Here's test bundle inclusion code from createTestBundle(): TinyBundle bundle = TinyBundles.newBundle(); for (URL url : getBlueprintDescriptors(descriptors)) { LOG.info("Using Blueprint XML file: " + url.getFile()); bundle.add("OSGI-INF/blueprint/blueprint-" + url.getFile().replace("/", "-"), url); } bundle.set("Manifest-Version", "2") .set("Bundle-ManifestVersion", "2") .set("Bundle-SymbolicName", name) .set("Bundle-Version", version); return bundle; Here's ProjectA bundle inclusion that comes from scan within createBundleContext(): for (Enumeration e = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");e.hasMoreElements();) { URL manifestURL = e.nextElement(); ... bundles.add(new BundleDescriptor(getClass().getClassLoader(), getParentURL(manifestURL), headers)); } Above results in two bundles with OSGI-INF/blueprint/camel-context.xml and I'm not sure how your suggestion would solve this problem? I want to run test case but exclude ProjectA bundle. -- View this message in context: http://camel.465427.n5.nabble.com/CamelBlueprintTestSupport-Issues-tp5741066p5741074.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: CamelBlueprintTestSupport Issues
Hi Andre, I dug the code few hours ago, I think we should provide a option to include the test bundle or not. Here is the JIRA[1] for it. [1]https://issues.apache.org/jira/browse/CAMEL-6835 -- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Tuesday, October 8, 2013 at 1:53 PM, Andre Piwoni wrote: > Willem, thank you for reply. My point is that with CamelBlueprintTestSupport > that utilizes CamelBlueprintHelper I don't have much control over which > bundles are included. > > Here's sample Maven project structure that creates bundle (not test bundle) > and contains test case that extends CamelBlueprintTestSupport: > > ProjectA (bundle) > - /src/main/resources/OSGI-INF/blueprint/camel-context.xml > - /src/test/java/TestClassThatExtendsCamelBluePrintTestSupport.java > > public class TestClassThatExtendsCamelBluePrintTestSupport extends > CamelBlueprintTestSupport { > ... > protected String getBlueprintDescriptor() { > return "OSGI-INF/blueprint/camel-context.xml"; > } > ... > } > When TestClassThatExtendsCamelBluePrintTestSupport is executed > CamelBlueprintTestSupport calls CamelBlueprintHelper which includes test > bundle and ProjectA bundle. > > public static BundleContext createBundleContext(String name, String > descriptors, boolean includeTestBundle,String bundleFilter, String > testBundleVersion, String testBundleDirectives) throws Exception { > TinyBundle bundle = null; > > if (includeTestBundle) { // ALWAYS SET TO TRUE BY > CamelBlueprintTestSupport > // add ourselves as a bundle > bundle = createTestBundle(testBundleDirectives == null ? name : > name + ';' + testBundleDirectives, testBundleVersion, descriptors); > } > > return createBundleContext(name, bundleFilter, bundle); > } > > Here's test bundle inclusion code from createTestBundle(): > > TinyBundle bundle = TinyBundles.newBundle(); > for (URL url : getBlueprintDescriptors(descriptors)) { > LOG.info (http://LOG.info)("Using Blueprint XML file: " + url.getFile()); > bundle.add("OSGI-INF/blueprint/blueprint-" + > url.getFile().replace("/", "-"), url); > } > bundle.set("Manifest-Version", "2") > .set("Bundle-ManifestVersion", "2") > .set("Bundle-SymbolicName", name) > .set("Bundle-Version", version); > return bundle; > > Here's ProjectA bundle inclusion that comes from scan within > createBundleContext(): > > for (Enumeration e = > getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");e.hasMoreElements();) > { > URL manifestURL = e.nextElement(); > ... > bundles.add(new BundleDescriptor(getClass().getClassLoader(), > getParentURL(manifestURL), headers)); > } > > Above results in two bundles with OSGI-INF/blueprint/camel-context.xml and > I'm not sure how your suggestion would solve this problem? I want to run > test case but exclude ProjectA bundle. > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/CamelBlueprintTestSupport-Issues-tp5741066p5741074.html > Sent from the Camel - Users mailing list archive at Nabble.com > (http://Nabble.com).
Re: CamelBlueprintTestSupport Issues
Willem, When I stepped through debugger and set includeTestBundle to false I've got the following error: java.lang.RuntimeException: Gave up waiting for service (&(objectClass=org.osgi.service.blueprint.container.BlueprintContainer)(osgi.blueprint.container.symbolicname=*MyTestBundle*)) at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:203) at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:169) at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.getOsgiService(CamelBlueprintTestSupport.java:237) at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:126) at com.obsglobal.partners.portland.routes.BaseRouteTester.setUp(BaseRouteTester.java:77) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Having said that I'm wondering if this would fix problem. Having two bundles with the same context is causing seemingly undeterministic behavior where mock endpoint assertions fail. This happens when mock:myUri handles received exchange in one context but assertions are run against injected mock:myUri endpoint but from another context. Andre -- View this message in context: http://camel.465427.n5.nabble.com/CamelBlueprintTestSupport-Issues-tp5741066p5742372.html Sent from the Camel - Users mailing list archive at Nabble.com.