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

Reply via email to