The business module is done to make computation and processing on your datas. You’ll be able to test it (unitary or in its full environment), export its services (synchronously or asynchronously), use functional programing.
Referencing services
You can reference OSGI services via two ways: via annotations or xml.
Service reference via annotation
You inject your services via Annotations (Pax-CDI).
In order to do this, you’ve to tweak you pom.xml adding this feature:
You can also consume or produce asynchronous messages.
You can consume queued messages and send to with the Camel JMS template (take care, with CDI, @Consume doesn’t work):
Validation
You can use JSR303 bean validation to validate your fields.
I will pass through the unit testing case (you can use Mockito…) to jump to the integration tests part.
First, you have to define an integration test feature on the feature module (available from the parent archetype) referencing all the underlying dependencies:
You can now make your integration test prefixing it by IT (failsafe convention).
12345678910111213141516171819
@RunWith(PaxExam.class)@ExamReactorStrategy(PerClass.class)publicclassITHelloServiceJaxRSextendsAbstractKarafPaxExamConfiguration{@Inject//Waiting for the OSGI service before starting the tests@Filter(timeout=40000)privateHelloServicehelloService;@TestpublicvoidtestSayHello()throwsException{helloService.sayHello("bob");}@OverrideprotectedOptionfeatureToTest(){returnfeatures(maven().groupId(System.getProperty(MODULE_GROUP_ID)).artifactId(System.getProperty(MODULE_GROUP_ID)+".features").type("xml").classifier("features").versionAsInProject(),"mybundle.business.impl.itests");}}