[CAMEL-8948] Add CamelBlueprintTestSupport tests for update-strategy="none"
(cherry picked from commit 2e502fa02699bc0808179a1f755ed160987d2091) Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/02855659 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/02855659 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/02855659 Branch: refs/heads/camel-2.15.x Commit: 0285565979a465252f9c3b29a4c66dff53270c02 Parents: 35d7ab6 Author: Grzegorz Grzybek <gr.grzy...@gmail.com> Authored: Mon Jul 20 11:05:34 2015 +0200 Committer: Grzegorz Grzybek <gr.grzy...@gmail.com> Committed: Tue Jul 21 09:45:55 2015 +0200 ---------------------------------------------------------------------- ...oadLoadConfigurationFileAndOverrideTest.java | 65 ++++++++++++++++++++ ...gAdminNoReloadLoadConfigurationFileTest.java | 51 +++++++++++++++ ...erridePropertiesOutsideCamelContextTest.java | 57 +++++++++++++++++ .../configadmin-no-reload-loadfile.xml | 45 ++++++++++++++ .../configadmin-no-reload-loadfileoverride.xml | 54 ++++++++++++++++ .../blueprint/configadmin-no-reload-outside.xml | 50 +++++++++++++++ 6 files changed, 322 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/02855659/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileAndOverrideTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileAndOverrideTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileAndOverrideTest.java new file mode 100644 index 0000000..9f7faaa --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileAndOverrideTest.java @@ -0,0 +1,65 @@ +/** + * 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; + +import java.util.Dictionary; + +import org.junit.Test; + +// START SNIPPET: e1 + +/** + * This example will load a Blueprint .cfg file, and also override its property placeholders from this unit test + * source code directly. + * But having <code>update-strategy="none"</code> means that BP container won't be reloaded + */ +public class ConfigAdminNoReloadLoadConfigurationFileAndOverrideTest extends CamelBlueprintTestSupport { + + @Override + protected String getBlueprintDescriptor() { + // which blueprint XML file to use for this test + return "org/apache/camel/test/blueprint/configadmin-no-reload-loadfileoverride.xml"; + } + + @Override + protected String[] loadConfigAdminConfigurationFile() { + // which .cfg file to use, and the name of the persistence-id + return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"}; + } + + @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 { + // regular unit test method + getMockEndpoint("mock:original").expectedBodiesReceived("Hello World", "Hey Hello WorldHey Hello World"); + getMockEndpoint("mock:extra").setExpectedMessageCount(0); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + +} +// END SNIPPET: e1 http://git-wip-us.apache.org/repos/asf/camel/blob/02855659/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileTest.java new file mode 100644 index 0000000..2196c93 --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadLoadConfigurationFileTest.java @@ -0,0 +1,51 @@ +/** + * 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; + +import org.junit.Test; + +/** + * + */ +public class ConfigAdminNoReloadLoadConfigurationFileTest extends CamelBlueprintTestSupport { + + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/configadmin-no-reload-loadfile.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 + return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"}; + } + // END SNIPPET: e1 + + @Test + public void testConfigAdmin() throws Exception { + // Even if we update config admin configuration, update-strategy="none" won't cause reload of BP + // container and reinjection of bean properties + getMockEndpoint("mock:result").expectedBodiesReceived("${greeting} World"); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/02855659/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadOverridePropertiesOutsideCamelContextTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadOverridePropertiesOutsideCamelContextTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadOverridePropertiesOutsideCamelContextTest.java new file mode 100644 index 0000000..b2ac339 --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoReloadOverridePropertiesOutsideCamelContextTest.java @@ -0,0 +1,57 @@ +/** + * 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; + +import java.util.Dictionary; + +import org.junit.Test; + +/** + * + */ +public class ConfigAdminNoReloadOverridePropertiesOutsideCamelContextTest extends CamelBlueprintTestSupport { + + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/configadmin-no-reload-outside.xml"; + } + + // START SNIPPET: e1 + @Override + protected String useOverridePropertiesWithConfigAdmin(Dictionary props) { + // add the properties we want to override + props.put("greeting", "Bye"); + props.put("destination", "mock:extra"); + + // 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 { + // Even if we update config admin configuration, update-strategy="none" won't cause reload of BP + // container and reinjection of bean properties + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:extra").setExpectedMessageCount(0); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/02855659/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfile.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfile.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfile.xml new file mode 100644 index 0000000..b6ffedd --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfile.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<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.1.0" + xsi:schemaLocation=" + http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.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" update-strategy="none"/> + + <!-- 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"/> + <bean ref="myCoolBean" method="saySomething"/> + <to uri="mock:result"/> + </route> + + </camelContext> + <!-- END SNIPPET: e1 --> + +</blueprint> http://git-wip-us.apache.org/repos/asf/camel/blob/02855659/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfileoverride.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfileoverride.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfileoverride.xml new file mode 100644 index 0000000..1d5274d --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-loadfileoverride.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- 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.1.0" + xsi:schemaLocation=" + http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.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, that will use etc/stuff.cfg as the properties file --> + <cm:property-placeholder persistent-id="stuff" update-strategy="none"> + <cm:default-properties> + <cm:property name="say" value="Hello" /> + <cm:property name="echo" value="Hey" /> + <cm:property name="destination" value="mock:original" /> + </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="${say}"/> + <property name="echo" value="${echo}"/> + </bean> + + <camelContext xmlns="http://camel.apache.org/schema/blueprint"> + + <route> + <from uri="direct:start"/> + <bean ref="myCoolBean" method="saySomething"/> + <to uri="{{destination}}"/> + <bean ref="myCoolBean" method="echoSomething"/> + <to uri="{{destination}}"/> + </route> + + </camelContext> + +</blueprint> +<!-- END SNIPPET: e1 --> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/02855659/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-outside.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-outside.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-outside.xml new file mode 100644 index 0000000..e7c8319 --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-no-reload-outside.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<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.1.0" + xsi:schemaLocation=" + http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.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 --> + <cm:property-placeholder persistent-id="my-placeholders" update-strategy="none"> + <cm:default-properties> + <cm:property name="greeting" value="Hello"/> + <cm:property name="destination" value="mock:result"/> + </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"/> + <bean ref="myCoolBean" method="saySomething"/> + <to uri="{{destination}}"/> + </route> + + </camelContext> + <!-- END SNIPPET: e1 --> + +</blueprint>