You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/02/08 15:55:19 UTC
svn commit: r1444034 - in /camel/trunk/components/camel-test-blueprint/src:
main/java/org/apache/camel/test/blueprint/
test/java/org/apache/camel/test/blueprint/ test/resources/etc/
test/resources/org/apache/camel/test/blueprint/
Author: davsclaus
Date: Fri Feb 8 14:55:19 2013
New Revision: 1444034
URL: http://svn.apache.org/r1444034
Log:
CAMEL-6053: Added example for both load .cfg file and override properties for testing with camel-test-blueprint.
Added:
camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java
- copied, changed from r1444018, camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java
camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml
- copied, changed from r1444024, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml
Modified:
camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java
camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg
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=1444034&r1=1444033&r2=1444034&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 14:55:19 2013
@@ -53,15 +53,20 @@ public abstract class CamelBlueprintTest
bundleContext.registerService(PropertiesComponent.OVERRIDE_PROPERTIES, extra, null);
}
+ // must reuse props as we can do both load from .cfg file and override afterwards
+ Dictionary props = new 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]);
+ if (file != null) {
+ String fileName = file[0];
+ String pid = file[1];
+
+ File load = new File(fileName);
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()) {
@@ -71,14 +76,13 @@ public abstract class CamelBlueprintTest
ConfigurationAdmin configAdmin = getOsgiService(ConfigurationAdmin.class);
if (configAdmin != null) {
// ensure we update
- Configuration config = configAdmin.getConfiguration(file[1]);
+ Configuration config = configAdmin.getConfiguration(pid);
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) {
ConfigurationAdmin configAdmin = getOsgiService(ConfigurationAdmin.class);
Copied: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java (from r1444018, camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java?p2=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java&p1=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java&r1=1444018&r2=1444034&rev=1444034&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java (original)
+++ camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java Fri Feb 8 14:55:19 2013
@@ -16,30 +16,42 @@
*/
package org.apache.camel.test.blueprint;
+import java.util.Dictionary;
+
import org.junit.Test;
+// START SNIPPET: e1
/**
- *
+ * This example will load a Blueprint .cfdg file, and also override its property placeholders from this unit test
+ * source code directly.
*/
-public class ConfigAdminLoadConfigurationFileTest extends CamelBlueprintTestSupport {
+public class ConfigAdminLoadConfigurationFileAndOverrideTest extends CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
- return "org/apache/camel/test/blueprint/configadmin-loadfile.xml";
+ // which blueprint XML file to use for this test
+ return "org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml";
}
- // START SNIPPET: e1
@Override
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
+ // which .cfg file to use, and the name of the persistence-id
return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"};
}
- // END SNIPPET: e1
+
+ @Override
+ protected String useOverridePropertiesWithConfigAdmin(Dictionary props) throws Exception {
+ // override / add extra properties
+ props.put("destination", "mock:extra");
+
+ // return the persistence-id to use
+ return "stuff";
+ }
@Test
public void testConfigAdmin() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+ // regular unit test method
+ getMockEndpoint("mock:extra").expectedBodiesReceived("Bye World", "Yay Bye WorldYay Bye World");
template.sendBody("direct:start", "World");
@@ -47,3 +59,4 @@ public class ConfigAdminLoadConfiguratio
}
}
+// END SNIPPET: e1
Modified: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java?rev=1444034&r1=1444033&r2=1444034&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java (original)
+++ camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java Fri Feb 8 14:55:19 2013
@@ -22,6 +22,7 @@ package org.apache.camel.test.blueprint;
public class MyCoolBean {
private String say;
+ private String echo;
public String getSay() {
return say;
@@ -31,7 +32,21 @@ public class MyCoolBean {
this.say = say;
}
+ public String getEcho() {
+ return echo;
+ }
+
+ public void setEcho(String echo) {
+ this.echo = echo;
+ }
+
public String saySomething(String s) {
return say + " " + s;
}
+
+ public String echoSomething(String s) {
+ return echo + " " + s + echo + " " + s;
+ }
+
+
}
Modified: 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=1444034&r1=1444033&r2=1444034&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg (original)
+++ camel/trunk/components/camel-test-blueprint/src/test/resources/etc/stuff.cfg Fri Feb 8 14:55:19 2013
@@ -15,4 +15,6 @@
## limitations under the License.
## ------------------------------------------------------------------------
-greeting=Bye
\ No newline at end of file
+greeting=Bye
+echo=Yay
+destination=mock:result
\ No newline at end of file
Copied: camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml (from r1444024, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml?p2=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml&p1=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml&r1=1444024&r2=1444034&rev=1444034&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml (original)
+++ camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml Fri Feb 8 14:55:19 2013
@@ -15,6 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
+<!-- START SNIPPET: e1 -->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
@@ -22,13 +23,13 @@
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">
- <!-- START SNIPPET: e1 -->
<!-- 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">
<property name="say" value="${greeting}"/>
+ <property name="echo" value="${echo}"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
@@ -36,10 +37,12 @@
<route>
<from uri="direct:start"/>
<bean ref="myCoolBean" method="saySomething"/>
- <to uri="mock:result"/>
+ <to uri="{{destination}}"/>
+ <bean ref="myCoolBean" method="echoSomething"/>
+ <to uri="{{destination}}"/>
</route>
</camelContext>
- <!-- END SNIPPET: e1 -->
</blueprint>
+<!-- END SNIPPET: e1 -->
\ No newline at end of file