Wait a sec! I think I messed up in eclipse cause cmdline is working now. Ignore this post. Sorry about that :S
Bram On Tue, May 3, 2011 at 4:33 PM, Bram de Kruijff <[email protected]> wrote: > Hi, > > On Mon, May 2, 2011 at 3:05 PM, Toni Menzel <[email protected]> wrote: >> Hi Bram, >> everything that you need should be provided by Options derived from >> CoreOptions.* factory class. >> for example >> url(<String>) >> or >> mavenBundle() >> etc. >> Your test probe (the bundle that contains your test classes) is generated >> out of your test classes only > > Right so now, as Sanjeeb suggested, I explicitly provision the bundle > containing the base package with classes as this makes sense in the > context of your explanation. This is what I get: > > Package headers for the probe: > > Import-Package: org.amdatu.core.itest.base;resolution:=optional,org.ap > ache.felix.dm;resolution:=optional,org.hamcrest;resolution:=optional, > org.hamcrest.core;resolution:=optional,org.junit;resolution:=optional > ,org.junit.runner;resolution:=optional,org.ops4j.pax.exam;resolution: > =optional,org.ops4j.pax.exam.junit;resolution:=optional,org.ops4j.pax > .exam.libraryoptions;resolution:=optional,org.ops4j.pax.exam.options; > resolution:=optional,org.ops4j.pax.exam.spi.reactors;resolution:=opti > onal,org.osgi.framework;resolution:=optional,org.osgi.service.log;res > olution:=optional > Export-Package: org.amdatu.core.itest.mock,org.amdatu.core.itest.test; > uses:="org.amdatu.core.itest.mock,org.ops4j.pax.exam.options,org.ops4 > j.pax.exam,org.apache.felix.dm,org.ops4j.pax.exam.spi.reactors,org.am > datu.core.itest.base,org.ops4j.pax.exam.libraryoptions,org.junit,org. > osgi.service.log,org.hamcrest.core,org.ops4j.pax.exam.junit,org.junit > .runner,org.osgi.framework,org.hamcrest" > > Package headers for the bundle: > > Import-Package: org.amdatu.core.itest.base,org.apache.felix.dm;version > ="3.0",org.ops4j.pax.exam;version="2.0",org.ops4j.pax.exam.options;ve > rsion="2.0",org.osgi.framework;version="1.5",org.osgi.util.tracker;ve > rsion="1.3" > Export-Package: org.amdatu.core.itest.base;uses:="org.ops4j.pax.exam.o > ptions,org.ops4j.pax.exam,org.apache.felix.dm,org.osgi.util.tracker,o > rg.osgi.framework" > > > Looks ok right? The classes are in there and I provision the bundle > mavenBundle() so things should be able to wire up. I am guessing the > resolution optional is used so the probe may resolve before the other > libraries are provisioned? Unfortunately it still fails with messages > on console and in surefire report > > -----> Console message > java.lang.IllegalStateException: Bundle in unexpected state. > at org.apache.felix.framework.Felix.acquireBundleLock(Felix.java:4943) > at > org.apache.felix.framework.Felix.setBundleStartLevel(Felix.java:1315) > at > org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:270) > at java.lang.Thread.run(Thread.java:619) > java.lang.IllegalStateException: Bundle in unexpected state. > [2011-05-03 15:49:39] DEBUG: Scheduling task ManagedService Update: > pid=org.amdatu.core.tenantstore-fs [org.apache.felix.configadmin] > at org.apache.felix.framework.Felix.acquireBundleLock(Felix.java:4943) > at > org.apache.felix.framework.Felix.setBundleStartLevel(Felix.java:1315) > at > org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:270) > at java.lang.Thread.run(Thread.java:619) > ERROR: Bundle > org.ops4j.pax.exam.spi.probesupport.intern.DefaultResourceWriter_19efb05 > [17] Error locking local (java.lang.IllegalStateException: Bundle in > une > pected state.) > [2011-05-03 15:49:39] INFO: BundleEvent STARTED > [org.amdatu.core.tenantstore-fs] > [2011-05-03 15:49:39] DEBUG: Running task ManagedService Update: > pid=org.amdatu.core.tenantstore-fs [org.apache.felix.configadmin] > [2011-05-03 15:49:39] ERROR: FrameworkEvent ERROR > [org.ops4j.pax.exam.spi.probesupport.intern.DefaultResourceWriter_19efb05] > Bundle in unexpected state. > > ----> Surefire report > ------------------------------------------------------------------------------- > Test set: org.amdatu.core.itest.test.InitialTest > ------------------------------------------------------------------------------- > Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.25 > sec <<< FAILURE! > InitialTest.testWithServiceDependencies2:NativeContainer:org.apache.felix.framework.FrameworkFactory@1194a4e(org.amdatu.core.itest.test.InitialTest) > Time elaps > ed: 3.017 sec <<< FAILURE! > java.lang.AssertionError: org.amdatu.core.itest.base.TestContext not > found by > org.ops4j.pax.exam.spi.probesupport.intern.DefaultResourceWriter_19efb05 > [17] > at org.junit.Assert.fail(Assert.java:91) > at > org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:261) > at > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) > at > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) > at > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) > 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.runners.ParentRunner.run(ParentRunner.java:236) > at > org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:83) > at > org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) > at > org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:119) > at > org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:101) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:597) > at > org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103) > at $Proxy0.invoke(Unknown Source) > at > org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150) > at > org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91) > at > org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69) > > >> For a longer explanation, read: >> http://tonimenzel.com/blog/2011/1/18/understanding-pax-exam-1x-part-i.html >> (the mechanics on how a probe is made is still the same in exam2). >> So question: What is your CoreFixture.provisionWithFsStorage() doing exactly >> ? > > It just returns > org.ops4j.pax.exam.CoreOptions.provision(ProvisionOption... urls). > This only point would be that I could reuse that across multiple tests > and it is maintained in a different project. > > So either I'm making a stupid mistake resulting in something not > resolving or I want something that isn't possible. That why I was > asking about the lifecycle of the test/probe. As the import has > resolution optional, it is not a dynamic import, can the probe wire to > a bundle that it provisions itself? > > So confused right now :) > > Thanks, > Bram > > >> Toni >> On Mon, May 2, 2011 at 1:10 PM, Bram de Kruijff <[email protected]> >> wrote: >>> >>> Hi, >>> >>> On Thu, Apr 28, 2011 at 2:05 PM, Toni Menzel <[email protected]> wrote: >>> > Quick annswer (on mobile): >>> > @Inject public BundleContext m_bundleContext; >>> > is not support in 2.0.0. There is just parameter injection into the test >>> > method (see examples). >>> > Same for @Before/After. Its because Exam2 is pretty much independent of >>> > JUnit4 now. >>> > We will add support for @Before in the subsequent release, but not in >>> > stock >>> > 2.0.0. >>> > Long explanation possibly on a real computer later. ;) >>> >>> Thanks for that reply Toni. Working around that I'm running into a >>> strange (to me at least) issue :S The plan was to put some generic >>> provision configuration options in a utility class called CoreFixture >>> is a seperate (reusable) library, so in my test I am able to do... >>> >>> @Configuration >>> public Option[] config() { >>> return options( >>> junitBundles(), >>> CoreFixture.provisionWithFsStorage(), >>> } >>> >>> >>> My maven test project has a dependecy on that library, it compiles but >>> at test time things go bad because the classes can not be found. The >>> problem seems to be that the classes from the library are not included >>> in the probe even though the package is mentioned in both >>> Import-Package and Export-Package statements when it is generated. >>> >>> So, is there a way to include stuff into the probe or am I going about >>> this in the wrong way? >>> >>> >>> Thanks again, >>> Bram de Kruijff >>> >>> > Toni >>> > On Thu, Apr 28, 2011 at 1:56 PM, Bram de Kruijff <[email protected]> >>> > wrote: >>> >> >>> >> Hi list, >>> >> >>> >> trying to get up to speed on paxexam 2 I quickly got hello world to >>> >> run in the native container. Very fast and elegant! Now I would like >>> >> to do some more advanced testing that require more comprehensive >>> >> "fixtures". Eg bundles active, services available, configurations >>> >> registered etc. I'm not entirely clear in the lifecycle yet and am >>> >> wondering what would be the best practice/place of doing so without >>> >> poluting every test with boilerplate. Eg. in the outline of my code >>> >> below I do not seem to have access to the BundleContext in @Before and >>> >> only recieve it in the tests themselves. Any pointers would be much >>> >> appreciated! >>> >> >>> >> thanks, >>> >> Bram de Kruijff >>> >> >>> >> >> sample test code << >>> >> >>> >> @RunWith(JUnit4TestRunner.class) >>> >> @ExamReactorStrategy(AllConfinedStagedReactorFactory.class) >>> >> public class InitialTest { >>> >> >>> >> @Inject >>> >> public BundleContext m_bundleContext; >>> >> >>> >> @Configuration >>> >> public Option[] config() { >>> >> return options( >>> >> junitBundles(), >>> >> provision( >>> >> myLogService(), >>> >> myTestBundle() >>> >> )); >>> >> } >>> >> >>> >> >>> >> @BeforeClass >>> >> public static void setUpOne() throws Exception { >>> >> // no bundleContext here >>> >> } >>> >> >>> >> @Before >>> >> public void setUp() throws Exception { >>> >> // no bundleContext here >>> >> } >>> >> >>> >> @Test >>> >> public void testLogServiceAvailable(BundleContext bundleContext) >>> >> throws Exception { >>> >> assertThat(bundleContext, is(notNullValue())); >>> >> ServiceReference logServiceReference = >>> >> bundleContext.getServiceReference(LogService.class.getName()); >>> >> assertThat(logServiceReference, is(notNullValue())); >>> >> try { >>> >> Object logServiceObject = >>> >> bundleContext.getService(logServiceReference); >>> >> assertThat(logServiceObject, is(notNullValue())); >>> >> assertThat(logServiceObject, >>> >> is(instanceOf(LogService.class))); >>> >> } >>> >> finally { >>> >> bundleContext.ungetService(logServiceReference); >>> >> } >>> >> } >>> >> >>> >> @Test >>> >> public void testMyService1(BundleContext bundleContext) throws >>> >> Exception { >>> >> // how can be sure that services are registered / configuration >>> >> set >>> >> etc? >>> >> } >>> >> >>> >> @Test >>> >> public void testMyService2(BundleContext bundleContext) throws >>> >> Exception { >>> >> // how can be sure that services are registered / configuration >>> >> set >>> >> etc? >>> >> } >>> >> } >>> >> >>> >> _______________________________________________ >>> >> general mailing list >>> >> [email protected] >>> >> http://lists.ops4j.org/mailman/listinfo/general >>> > >>> > >>> > >>> > -- >>> > Toni Menzel Source >>> > >>> > >>> > _______________________________________________ >>> > general mailing list >>> > [email protected] >>> > http://lists.ops4j.org/mailman/listinfo/general >>> > >>> > >>> >>> _______________________________________________ >>> general mailing list >>> [email protected] >>> http://lists.ops4j.org/mailman/listinfo/general >> >> >> >> -- >> Toni Menzel Source >> >> >> _______________________________________________ >> general mailing list >> [email protected] >> http://lists.ops4j.org/mailman/listinfo/general >> >> > _______________________________________________ general mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/general
