Results 1 to 3 of 3

Thread: Integration Testing Question

  1. #1

    Default Integration Testing Question

    This may be an obvious question, but nevertheless. In recently working with the AbstractConfigurableBundleCreatorTests, I have been a bit confused on the intent. A test bundle is generated with a manifest that imports required bundles from the bootstrapped OSGi context. This allows the exported packages of the imported bundles to be validated in the test class. Clear so far.

    The question is, what if I have a bean in the project containing the integration test that injects an osgi:reference exported by one of the imported bundles? Is it possible to integration test this bean without breaking it out into a separate bundle? For example, take the following simple case where com.myorg.consumer.ExampleService is exported by an imported bundle:

    bundle-context.xml:

    Code:
    <bean id="exampleConsumer" 
         class="com.myorg.consumer.ExampleConsumer">
      	<property name="exampleService" ref="exampleService" />
    </bean>
    bundle-context-osgi.xml:

    Code:
    <osgi:reference id="exampleService" 
         interface="com.myorg.myService.ExampleService" />
    In the integration test (ServiceTest) in the same project I can do:

    Code:
    ServiceReference serviceRef = bundleContext
      .getServiceReference("com.myorg.myService.ExampleService");
    ExampleService service = 
      (ExampleService) bundleContext.getService(serviceRef);
    System.out.println(service.sayHello("Jacob Orshalick"));
    But I cannot:

    Code:
    ExampleConsumer consumer = (ExampleConsumer) 
      applicationContext.getBean("exampleConsumer");
    consumer.printHelloMessage("Jacob Orshalick");
    It seems that the test bundle generation logic allows only one root.dir to apply include patterns to. The default uses /target/test-classes meaning all classes in /target/classes are ignored. If the applicationContext for the integration test includes any beans contained in the same project (in src/main/java) this fails with a ClassNotFoundException as these classes are not included in the test bundle.

    Is the assumption that a project will always have a multi-module build where all modules under test are generated prior to executing the integration test? This would make sense given the current base functionality, but I was curious if this was the intent.

    Thanks for your help and please let me know if any clarification on the points above is required.

  2. #2

    Default Re: Integration Testing Question

    Makes sense now. I misunderstood the following warning in the documentation, 9.2. Integration Testing on the first read:

    "(!) The testing framework is NOT meant to be used as an OSGi bundle (nor will it work for that matter)."

    In re-reading this would seem to indicate that an integration test should always be a completely separate bundle from the bundles under test.

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    That is correct - I will try to make this point stronger. Basically the integration test should contain just that, the test - all its dependencies should be left outside.
    There is a screencast that covers a basic testing session - try using that for starters (it's a bit outdated in terms of maven dependencies configuration but otherwise it should work just fine).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •