Author: davsclaus Date: Fri Feb 8 11:54:45 2013 New Revision: 1443964 URL: http://svn.apache.org/r1443964 Log: CAMEL-6053: Allow to load .cfg config admin properties file from camel-test-blueprint.
Added: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java - copied, changed from r1443931, camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java camel/trunk/components/camel-test-blueprint/src/test/resources/etc/ camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml - copied, changed from r1443931, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml Modified: camel/trunk/components/camel-test-blueprint/pom.xml camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java camel/trunk/parent/pom.xml Modified: camel/trunk/components/camel-test-blueprint/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/pom.xml?rev=1443964&r1=1443963&r2=1443964&view=diff ============================================================================== --- camel/trunk/components/camel-test-blueprint/pom.xml (original) +++ camel/trunk/components/camel-test-blueprint/pom.xml Fri Feb 8 11:54:45 2013 @@ -119,6 +119,27 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.fileinstall</artifactId> + <version>${felix-fileinstall-version}</version> + <!-- exclude the following dependency which otherwise would pop up a lot of compilation + errors both by this and the camel-maven-plugin modules under eclipse. --> + <exclusions> + <exclusion> + <groupId>org.apache.felix</groupId> + <artifactId>org.osgi.foundation</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.felix</groupId> + <artifactId>org.osgi.core</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.felix</groupId> + <artifactId>org.osgi.compendium</artifactId> + </exclusion> + </exclusions> + </dependency> <!-- optional dependencies for running tests --> <dependency> Modified: camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java?rev=1443964&r1=1443963&r2=1443964&view=diff ============================================================================== --- camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java (original) +++ camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java Fri Feb 8 11:54:45 2013 @@ -16,9 +16,12 @@ */ package org.apache.camel.test.blueprint; +import java.io.File; import java.util.Dictionary; +import java.util.Map; import java.util.Properties; +import org.apache.aries.blueprint.compendium.cm.CmPropertyPlaceholder; import org.apache.camel.CamelContext; import org.apache.camel.component.properties.PropertiesComponent; import org.apache.camel.model.ModelCamelContext; @@ -50,7 +53,31 @@ public abstract class CamelBlueprintTest bundleContext.registerService(PropertiesComponent.OVERRIDE_PROPERTIES, extra, null); } - // allow end users to override config admin service with extra properties + // load configuration file + String[] file = loadConfigAdminConfigurationFile(); + if (file != null && file.length != 2) { + throw new IllegalArgumentException("The returned String[] from loadConfigAdminConfigurationFile must be of length 2, was " + file.length); + } + if (file != null && file[0] != null) { + Dictionary props = new Properties(); + + File load = new File(file[0]); + log.debug("Loading properties from OSGi config admin file: {}", load); + org.apache.felix.utils.properties.Properties cfg = new org.apache.felix.utils.properties.Properties(load); + for (Map.Entry entry : cfg.entrySet()) { + props.put(entry.getKey(), entry.getValue()); + } + + ConfigurationAdmin configAdmin = getOsgiService(ConfigurationAdmin.class); + if (configAdmin != null) { + // ensure we update + Configuration config = configAdmin.getConfiguration(file[1]); + log.info("Updating ConfigAdmin {} by overriding properties {}", config, props); + config.update(props); + } + } + + // allow end user to override properties Dictionary props = new Properties(); String pid = useOverridePropertiesWithConfigAdmin(props); if (pid != null) { @@ -76,7 +103,17 @@ public abstract class CamelBlueprintTest * @param props properties where you add the properties to override * @return the PID of the OSGi {@link ConfigurationAdmin} which are defined in the Blueprint XML file. */ - protected String useOverridePropertiesWithConfigAdmin(Dictionary props) { + protected String useOverridePropertiesWithConfigAdmin(Dictionary props) throws Exception { + return null; + } + + /** + * Override this method and provide the name of the .cfg configuration file to use for + * Blueprint ConfigAdmin service. + * + * @return the name of the path for the .cfg file to load, and the persistence-id of the property placeholder. + */ + protected String[] loadConfigAdminConfigurationFile() { return null; } Copied: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java (from r1443931, camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java?p2=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java&p1=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java&r1=1443931&r2=1443964&rev=1443964&view=diff ============================================================================== --- camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java (original) +++ camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java Fri Feb 8 11:54:45 2013 @@ -16,28 +16,24 @@ */ package org.apache.camel.test.blueprint; -import java.util.Dictionary; - import org.junit.Test; /** * */ -public class ConfigAdminOverridePropertiesOutsideCamelContextTest extends CamelBlueprintTestSupport { +public class ConfigAdminLoadConfigurationFileTest extends CamelBlueprintTestSupport { @Override protected String getBlueprintDescriptor() { - return "org/apache/camel/test/blueprint/configadmin-outside.xml"; + return "org/apache/camel/test/blueprint/configadmin-loadfile.xml"; } // START SNIPPET: e1 @Override - protected String useOverridePropertiesWithConfigAdmin(Dictionary props) { - // add the properties we want to override - props.put("greeting", "Bye"); - - // return the PID of the config-admin we are using in the blueprint xml file - return "my-placeholders"; + protected String[] loadConfigAdminConfigurationFile() { + // String[0] = tell Camel the path of the .cfg file to use for OSGi ConfigAdmin in the blueprint XML file + // String[1] = tell Camel the persistence-id of the cm:property-placeholder in the blueprint XML file + return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"}; } // END SNIPPET: e1 Added: camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg?rev=1443964&view=auto ============================================================================== --- camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg (added) +++ camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg Fri Feb 8 11:54:45 2013 @@ -0,0 +1,18 @@ +## ------------------------------------------------------------------------ +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## ------------------------------------------------------------------------ + +greeting=Bye \ No newline at end of file Copied: camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml (from r1443931, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml?p2=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml&p1=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml&r1=1443931&r2=1443964&rev=1443964&view=diff ============================================================================== --- camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml (original) +++ camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml Fri Feb 8 11:54:45 2013 @@ -22,13 +22,8 @@ http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> - <!-- blueprint property placeholders --> - <cm:property-placeholder persistent-id="my-placeholders"> - <cm:default-properties> - <cm:property name="greeting" value="Hello"/> - <cm:property name="destination" value="mock:result"/> - </cm:default-properties> - </cm:property-placeholder> + <!-- blueprint property placeholders, that will use etc/stuff.cfg as the properties file --> + <cm:property-placeholder persistent-id="stuff"/> <!-- a bean that uses a blueprint property placeholder --> <bean id="myCoolBean" class="org.apache.camel.test.blueprint.MyCoolBean"> @@ -40,7 +35,7 @@ <route> <from uri="direct:start"/> <bean ref="myCoolBean" method="saySomething"/> - <to uri="{{destination}}"/> + <to uri="mock:result"/> </route> </camelContext> Modified: camel/trunk/parent/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1443964&r1=1443963&r2=1443964&view=diff ============================================================================== --- camel/trunk/parent/pom.xml (original) +++ camel/trunk/parent/pom.xml Fri Feb 8 11:54:45 2013 @@ -118,6 +118,7 @@ <ezmorph-bundle-version>1.0.6_1</ezmorph-bundle-version> <fastinfoset-version>1.2.7_4</fastinfoset-version> <felix-configadmin-version>1.4.0</felix-configadmin-version> + <felix-fileinstall-version>3.2.6</felix-fileinstall-version> <felix-framework-version>3.2.2</felix-framework-version> <findbugs-maven-plugin-version>2.5.2</findbugs-maven-plugin-version> <flatpack-bundle-version>3.2.0_2</flatpack-bundle-version>