junitosgiapache-karafkarafpax-exam

@Before can I use it for initialization


In pax exam I want certain things to be common for all the test function. For doing this i have used @Before, problem in using @Before method is that it will get called before each test method. Is there way to tackle this problem. Is there some annotations available in pax exam for solving this issue.

@Before
    public void init() throws Exception{
        featuresService.installFeature("hibernate");
        featuresService.installFeature("hibernate-validator");
        bundleContext.installBundle("wrap:mvn:osgi/osgi/3.0.1").start();
        bundleContext.installBundle("wrap:mvn:javax.xml/xml/3.1.0").start();
        bundleContext.installBundle("wrap:mvn:commons-dbcp/commons-dbcp/1.2.2").start();
        bundleContext.installBundle("wrap:mvn:commons-pool/commons-pool/1.3").start();
        bundleContext.installBundle("wrap:mvn:commons-lang/commons-lang/2.3").start();
    }

Solution

  • It's not possible now to have such behavior in a test run by PaxExam, but your init method could be easyly replaced by Option for the provisionning of your container.

    For example :

    features(maven().groupId("org.apache.karaf.assemblies.features")
           .artifactId("enterprise").type("xml").classifier("features")
           .versionAsInProject(), "hibernate", "hibernate-validator")
    

    or

     wrappedBundle(mavenBundle("commons-dbcp", "commons-dbcp", "1.2.2"))