ImranRazaKhan
ImranRazaKhan

Reputation: 2297

how to provide @Property value to karaf bundle with pax-exam

I have my ipojo component like

@Component(immediate = true)
@Provides
public class MyComponent {
    public MyComponent (@Property(mandatory = true, name = "initialDelay", value = "60") Long initialDelay)
    {
        ...
    }

For integration testing using pax-exam i am using test like below using

https://github.com/apache/karaf/blob/master/itests/common/src/main/java/org/apache/karaf/itests/KarafTestSupport.java

@Test
    public void installBundle() throws Exception
    {
        executeCommand("bundle:install mvn:com.my.osgi/MyComponent/2.0.2-SNAPSHOT", ADMIN_ROLES);
        assertBundleInstalled("MyComponent ");
    }

Now my question is how i can pass different values for "initialDelay" property so bundle test with my provided values?

Upvotes: 0

Views: 158

Answers (1)

Christian Schneider
Christian Schneider

Reputation: 19626

The KarafTestSupport class contains some examples for providing configs:

KarafDistributionOption.replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", getConfigFile("/etc/org.ops4j.pax.logging.cfg"))

This is suitable for bigger configs that you provide in src/test/resources.

KarafDistributionOption.editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort)

Using this you can replace individual properties in configs.

Pax exam also provides a way to provision configs that is independent of karaf:

ConfigurationAdminOptions.newConfiguration(TEST_PID)
                .put(TEST_KEY, TEST_PROPERTY)
                .asOption(),

This approach does not change config files and instead directly creates the config in ConfigurationAdmin.

See https://github.com/ops4j/org.ops4j.pax.exam2/blob/master/itest/osgi/src/it/regression-multi/src/test/java/org/ops4j/pax/exam/regression/multi/cm/ConfigurationOptionTest.java#L61-L63

Upvotes: 0

Related Questions