javaspringosgiintegration-testingspring-dm

OSGi Fragment using Spring Integration Testing


I am posting this question given I haven't found any relevant answer so far. I could not figure out how to run integration tests using Spring-Dynamic Modules.

Problem Definition

Template Application

Versions

Question

How would you best solve this please?

I do appreciate your help in advance.

ps: I had a look at Spring DM Test but did not find anything relevant.

Example

Bundle Manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloWorldDM
Bundle-SymbolicName: HelloWorldDM
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.core.runtime,
 ContactDAO;bundle-version="1.0.0",
 org.springframework.osgi.extensions.annotations;bundle-version="1.2.1"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: ch.xxx.test.contact

Integration Test Fragment Manifest

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloWorldTest
Bundle-SymbolicName: HelloWorldTest
Bundle-Version: 1.0.0.qualifier
Fragment-Host: HelloWorldDM;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.junit4;bundle-version="4.8.1",
 org.springframework.spring-test;bundle-version="3.1.0",
 org.springframework.spring-context;bundle-version="3.1.0",
 org.springframework.spring-beans;bundle-version="3.1.0",
 org.springframework.osgi.test;bundle-version="1.2.1",
 org.springframework.spring-core;bundle-version="3.1.0"

Fragment Application Context

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
  
  <bean class="org.springframework.osgi.extensions.annotation.ServiceReferenceInjectionBeanPostProcessor"/>
  <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
  
</beans>

Test Class

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/context.xml" })
public class TestCase {
    
    private BitemporalityService bitemporalityService;

    @ServiceReference
    public void setBitemporalityService(BitemporalityService service) {
        this.bitemporalityService = service;
    }

    @Test
    public void dummy(){
        System.err.println("in Test: ");
        assertNotNull(bitemporalityService);
    }

}

Solution

  • Take a look at pax exam. It boots up an osgi container and runs your test in it. It is the defacto standard framework for osgi testing and is used in many open source projects for the osgi itests. See https://github.com/apache/karaf/tree/karaf/itests