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 11:57:57 UTC
svn commit: r1443931 - in /camel/trunk/components/camel-test-blueprint/src:
main/java/org/apache/camel/test/blueprint/
test/java/org/apache/camel/test/blueprint/
test/resources/org/apache/camel/test/blueprint/
Author: davsclaus
Date: Fri Feb 8 10:57:57 2013
New Revision: 1443931
URL: http://svn.apache.org/r1443931
Log:
CAMEL-6053: Allow to override blueprint config admin placeholders from unit test.
Added:
camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java
- copied, changed from r1443863, camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesTest.java
camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java (with props)
camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml
- copied, changed from r1443863, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin.xml
Modified:
camel/trunk/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
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=1443931&r1=1443930&r2=1443931&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 10:57:57 2013
@@ -16,6 +16,7 @@
*/
package org.apache.camel.test.blueprint;
+import java.util.Dictionary;
import java.util.Properties;
import org.apache.camel.CamelContext;
@@ -26,6 +27,8 @@ import org.junit.After;
import org.junit.Before;
import org.osgi.framework.BundleContext;
import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
/**
* Base class for OSGi Blueprint unit tests with Camel.
@@ -47,6 +50,19 @@ public abstract class CamelBlueprintTest
bundleContext.registerService(PropertiesComponent.OVERRIDE_PROPERTIES, extra, null);
}
+ // allow end users to override config admin service with extra properties
+ Dictionary props = new Properties();
+ String pid = useOverridePropertiesWithConfigAdmin(props);
+ if (pid != null) {
+ ConfigurationAdmin configAdmin = getOsgiService(ConfigurationAdmin.class);
+ Configuration config = configAdmin.getConfiguration(pid);
+ if (config == null) {
+ throw new IllegalArgumentException("Cannot find configuration with pid " + pid + " in OSGi ConfigurationAdmin service.");
+ }
+ log.info("Updating ConfigAdmin {} by overriding properties {}", config, props);
+ config.update(props);
+ }
+
super.setUp();
// must wait for blueprint container to be published then the namespace parser is complete and we are ready for testing
@@ -54,6 +70,16 @@ public abstract class CamelBlueprintTest
getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + symbolicName + ")");
}
+ /**
+ * Override this method to override config admin properties.
+ *
+ * @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) {
+ return null;
+ }
+
@After
@Override
public void tearDown() throws Exception {
Copied: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java (from r1443863, camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java?p2=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java&p1=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesTest.java&r1=1443863&r2=1443931&rev=1443931&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesTest.java (original)
+++ camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java Fri Feb 8 10:57:57 2013
@@ -16,35 +16,34 @@
*/
package org.apache.camel.test.blueprint;
-import java.util.Properties;
+import java.util.Dictionary;
import org.junit.Test;
/**
*
*/
-public class ConfigAdminOverridePropertiesTest extends CamelBlueprintTestSupport {
+public class ConfigAdminOverridePropertiesOutsideCamelContextTest extends CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
- return "org/apache/camel/test/blueprint/configadmin.xml";
+ return "org/apache/camel/test/blueprint/configadmin-outside.xml";
}
// START SNIPPET: e1
- // override this method to provide our custom properties we use in this unit test
@Override
- protected Properties useOverridePropertiesWithPropertiesComponent() {
- Properties extra = new Properties();
- extra.put("destination", "mock:extra");
- extra.put("greeting", "Bye");
- return extra;
+ 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";
}
// END SNIPPET: e1
@Test
public void testConfigAdmin() throws Exception {
- getMockEndpoint("mock:extra").expectedBodiesReceived("Bye World");
- getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "World");
Added: 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=1443931&view=auto
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java (added)
+++ camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java Fri Feb 8 10:57:57 2013
@@ -0,0 +1,37 @@
+/**
+ * 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.
+ */
+package org.apache.camel.test.blueprint;
+
+/**
+ *
+ */
+public class MyCoolBean {
+
+ private String say;
+
+ public String getSay() {
+ return say;
+ }
+
+ public void setSay(String say) {
+ this.say = say;
+ }
+
+ public String saySomething(String s) {
+ return say + " " + s;
+ }
+}
Propchange: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MyCoolBean.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml (from r1443863, camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml?p2=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml&p1=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin.xml&r1=1443863&r2=1443931&rev=1443931&view=diff
==============================================================================
--- camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin.xml (original)
+++ camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml Fri Feb 8 10:57:57 2013
@@ -30,13 +30,16 @@
</cm:default-properties>
</cm:property-placeholder>
+ <!-- a bean that uses a blueprint property placeholder -->
+ <bean id="myCoolBean" class="org.apache.camel.test.blueprint.MyCoolBean">
+ <property name="say" value="${greeting}"/>
+ </bean>
+
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="direct:start"/>
- <transform>
- <simple>{{greeting}} ${body}</simple>
- </transform>
+ <bean ref="myCoolBean" method="saySomething"/>
<to uri="{{destination}}"/>
</route>