문제

I am using Pax Exam to perform integration tests to my OSGi application. I have a configuration factory in which I specify the Karaf feature of my application to be installed in the test container and then modify some of a proerty of a .cfg file installed as part of my feature.

public class TestConfigurationFactory implements ConfigurationFactory {

@Override
public Option[] createConfiguration() {
    return options(
            karafDistributionConfiguration()
                    .frameworkUrl(
                            maven().groupId("org.apache.karaf")
                                    .artifactId("apache-karaf")
                                    .version("3.0.1").type("tar.gz"))
                    .unpackDirectory(new File("target/exam"))
                    .useDeployFolder(false),
            keepRuntimeFolder(),
            // Karaf (own) features.
            KarafDistributionOption.features(
                    maven().groupId("org.apache.karaf.features")
                            .artifactId("standard").classifier("features")
                            .version("3.0.1").type("xml"), "scr"),
            // CXF features.
            KarafDistributionOption.features(maven()
                    .groupId("org.apache.cxf.karaf")
                    .artifactId("apache-cxf").version("2.7.9")
                    .classifier("features").type("xml")),
            // Application features.
            KarafDistributionOption.features(
                    maven().groupId("com.me.project")
                            .artifactId("my-karaf-features")
                            .version("1.0.0-SNAPSHOT")
                            .classifier("features").type("xml"), "my-feature"),
            KarafDistributionOption.editConfigurationFilePut(
                       "etc/com.me.test.cfg", "key", "value"));
}
}

The property I specify in editConfigurationFilePut is modified correctly, however the rest of the .cfg file's properties are deleted. If I use the editConfigurationFilePut method to edit one of Karaf's configuration files it works as expected (just adds the new property without modifying the existing ones) so I am thinking that perhaps the problem is that Pax Exam attempts to modify the configuration before the .cfg file is installed by my feature and therefore creates a new file to put the property in. If this is the case is there some way to synchronise this process so that the .cfg file is edited only after the feature is properly installed?

도움이 되었습니까?

해결책

There are a two different reasons for this. 1) The feature does get installed after the configfile has been "edited" 2) The feature only contains a config section and not a configfile section

I'd guess reason one is the most likely cause of this since it needs a running Karaf to install a feature through Pax Exam. So to work around reason one, replace the config with a config file present in your test project. For reason two, make sure the feature actually does reference a config instead of a configuration admin config, or add your config to the configuration of the config-admin service. You can achieve this by injecting the ConfigAdmin service in your unit test and add your properties to the configuration pid.

EDIT: Combine both solutions Since because of 1) it takes longer for the config-file to be actually available, let config-admin service do the rest. Make sure your test does retrieve the config-admin service either by injecting it or by waiting for it's availability. Now within a @Before method make sure you wait till your config is complete and change it from there on. This way you don't need to duplicate the config files.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top