Renamed camel package.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/8d79f973 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/8d79f973 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/8d79f973 Branch: refs/heads/master Commit: 8d79f9732d94f3c309f51b8f0474a6bd7f0e8b7f Parents: 0bcff9c Author: anatole <[email protected]> Authored: Tue Feb 28 00:26:50 2017 +0100 Committer: anatole <[email protected]> Committed: Tue Feb 28 00:26:50 2017 +0100 ---------------------------------------------------------------------- camel/bnd.bnd | 3 +- camel/pom.xml | 7 +- .../tamaya/camel/TamayaPropertiesComponent.java | 78 +++++++++++++ .../tamaya/camel/TamayaPropertyResolver.java | 53 +++++++++ .../camel/TamayaPropertiesComponent.java | 78 ------------- .../camel/TamayaPropertyResolver.java | 53 --------- .../camel/TamayaPropertyResolverTest.java | 116 +++++++++++++++++++ .../camel/TamayaPropertyResolverTest.java | 116 ------------------- .../test/resources/META-INF/camelcontext.xml | 2 +- 9 files changed, 254 insertions(+), 252 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/bnd.bnd ---------------------------------------------------------------------- diff --git a/camel/bnd.bnd b/camel/bnd.bnd index 94e84d1..667c00c 100644 --- a/camel/bnd.bnd +++ b/camel/bnd.bnd @@ -1,2 +1,3 @@ Export-Package: \ - org.apache.tamaya.integration.camel \ No newline at end of file + org.apache.tamaya.camel +Bundle-SymbolicName: org.apache.tamaya.camel \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/pom.xml ---------------------------------------------------------------------- diff --git a/camel/pom.xml b/camel/pom.xml index 0e06bd7..52d2bb1 100644 --- a/camel/pom.xml +++ b/camel/pom.xml @@ -27,6 +27,7 @@ under the License. </parent> <artifactId>tamaya-camel</artifactId> + <version>${parent.version}-beta</version> <name>Apache Tamaya Modules - Apache Camel Support</name> <packaging>jar</packaging> @@ -65,18 +66,18 @@ under the License. <dependency> <groupId>org.apache.tamaya</groupId> <artifactId>tamaya-core</artifactId> - <version>${project.version}</version> + <version>${parent.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.tamaya</groupId> <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> + <version>${parent.version}</version> </dependency> <dependency> <groupId>org.apache.tamaya.ext</groupId> <artifactId>tamaya-functions</artifactId> - <version>${project.version}</version> + <version>${parent.version}</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertiesComponent.java ---------------------------------------------------------------------- diff --git a/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertiesComponent.java b/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertiesComponent.java new file mode 100644 index 0000000..e42a5e1 --- /dev/null +++ b/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertiesComponent.java @@ -0,0 +1,78 @@ +/* + * 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.tamaya.camel; + +import java.util.Properties; + +import org.apache.camel.component.properties.PropertiesComponent; +import org.apache.tamaya.ConfigurationProvider; + +/** + * Default Camel PropertiesComponent that additionally has cfg and tamaya prefixes configured for resolution of + * entries from tamaya. + */ +public class TamayaPropertiesComponent extends PropertiesComponent{ + + /** + * Constructor similar to parent. + */ + public TamayaPropertiesComponent(){ + super(); + addFunction(new TamayaPropertyResolver("tamaya")); + addFunction(new TamayaPropertyResolver("cfg")); + setTamayaOverrides(true); + } + + /** + * Constructor similar to parent with additional locations. + * @param locations additional locations for Camel. + */ + public TamayaPropertiesComponent(String ... locations){ + super(locations); + addFunction(new TamayaPropertyResolver("tamaya")); + addFunction(new TamayaPropertyResolver("cfg")); + setTamayaOverrides(true); + } + + /** + * Constructor similar to parent with only one location. + * @param location addition location for Camel. + */ + public TamayaPropertiesComponent(String location){ + super(location); + addFunction(new TamayaPropertyResolver("tamaya")); + addFunction(new TamayaPropertyResolver("cfg")); + setTamayaOverrides(true); + } + + /** + * Apply the current Tamaya properties (configuration) as override properties evaluated first by camel before + * evaluating other uris. + * @param enabled flag to define if tamaya values override everything else. + */ + public void setTamayaOverrides(boolean enabled){ + if(enabled){ + final Properties props = new Properties(); + props.putAll(ConfigurationProvider.getConfiguration().getProperties()); + setOverrideProperties(props); + } else{ + setOverrideProperties(null); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertyResolver.java ---------------------------------------------------------------------- diff --git a/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertyResolver.java b/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertyResolver.java new file mode 100644 index 0000000..7b3f3a3 --- /dev/null +++ b/camel/src/main/java/org/apache/tamaya/camel/TamayaPropertyResolver.java @@ -0,0 +1,53 @@ +/* + * 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.tamaya.camel; + +import org.apache.camel.component.properties.PropertiesFunction; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; + +import java.util.Objects; + + +/** + * Implementation of the Camel Properties SPI using Tamaya configuration. + */ +public class TamayaPropertyResolver implements PropertiesFunction{ + + private final String prefix; + + /** + * Creates a new instance. + * @param configPrefix the prefix to be registered for explicit resolution by this resolver function, not null. + */ + public TamayaPropertyResolver(String configPrefix){ + this.prefix = Objects.requireNonNull(configPrefix); + } + + @Override + public String getName() { + return prefix; + } + + @Override + public String apply(String remainder) { + Configuration config = ConfigurationProvider.getConfiguration(); + return config.get(remainder); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java ---------------------------------------------------------------------- diff --git a/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java b/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java deleted file mode 100644 index 8b776a5..0000000 --- a/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.tamaya.integration.camel; - -import java.util.Properties; - -import org.apache.camel.component.properties.PropertiesComponent; -import org.apache.tamaya.ConfigurationProvider; - -/** - * Default Camel PropertiesComponent that additionally has cfg and tamaya prefixes configured for resolution of - * entries from tamaya. - */ -public class TamayaPropertiesComponent extends PropertiesComponent{ - - /** - * Constructor similar to parent. - */ - public TamayaPropertiesComponent(){ - super(); - addFunction(new TamayaPropertyResolver("tamaya")); - addFunction(new TamayaPropertyResolver("cfg")); - setTamayaOverrides(true); - } - - /** - * Constructor similar to parent with additional locations. - * @param locations additional locations for Camel. - */ - public TamayaPropertiesComponent(String ... locations){ - super(locations); - addFunction(new TamayaPropertyResolver("tamaya")); - addFunction(new TamayaPropertyResolver("cfg")); - setTamayaOverrides(true); - } - - /** - * Constructor similar to parent with only one location. - * @param location addition location for Camel. - */ - public TamayaPropertiesComponent(String location){ - super(location); - addFunction(new TamayaPropertyResolver("tamaya")); - addFunction(new TamayaPropertyResolver("cfg")); - setTamayaOverrides(true); - } - - /** - * Apply the current Tamaya properties (configuration) as override properties evaluated first by camel before - * evaluating other uris. - * @param enabled flag to define if tamaya values override everything else. - */ - public void setTamayaOverrides(boolean enabled){ - if(enabled){ - final Properties props = new Properties(); - props.putAll(ConfigurationProvider.getConfiguration().getProperties()); - setOverrideProperties(props); - } else{ - setOverrideProperties(null); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertyResolver.java ---------------------------------------------------------------------- diff --git a/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertyResolver.java b/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertyResolver.java deleted file mode 100644 index 6b6ada9..0000000 --- a/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertyResolver.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.tamaya.integration.camel; - -import org.apache.camel.component.properties.PropertiesFunction; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; - -import java.util.Objects; - - -/** - * Implementation of the Camel Properties SPI using Tamaya configuration. - */ -public class TamayaPropertyResolver implements PropertiesFunction{ - - private final String prefix; - - /** - * Creates a new instance. - * @param configPrefix the prefix to be registered for explicit resolution by this resolver function, not null. - */ - public TamayaPropertyResolver(String configPrefix){ - this.prefix = Objects.requireNonNull(configPrefix); - } - - @Override - public String getName() { - return prefix; - } - - @Override - public String apply(String remainder) { - Configuration config = ConfigurationProvider.getConfiguration(); - return config.get(remainder); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/src/test/java/org/apache/tamaya/camel/TamayaPropertyResolverTest.java ---------------------------------------------------------------------- diff --git a/camel/src/test/java/org/apache/tamaya/camel/TamayaPropertyResolverTest.java b/camel/src/test/java/org/apache/tamaya/camel/TamayaPropertyResolverTest.java new file mode 100644 index 0000000..10ffa9b --- /dev/null +++ b/camel/src/test/java/org/apache/tamaya/camel/TamayaPropertyResolverTest.java @@ -0,0 +1,116 @@ +/* + * 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.tamaya.camel; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.ProxyBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.model.RouteDefinition; +import org.apache.camel.model.RoutesDefinition; +import org.junit.Test; + +import java.io.InputStream; + +import static org.junit.Assert.*; + +/** + * Tests for integration of Tamaya with Apache Camel using Java DSL and XML DSL. + */ +public class TamayaPropertyResolverTest { + + @Test + public void testJavaDSLWithCfgResolution() throws Exception { + CamelContext camelContext = new DefaultCamelContext(); + camelContext.addComponent("properties", new TamayaPropertiesComponent()); + RouteBuilder builder = new RouteBuilder() { + public void configure() { + from("direct:hello").transform().simple("{{cfg:message}}"); + } + }; + camelContext.addRoutes(builder); + camelContext.start(); + // test configuration is injected right... + Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class); + String greetMessage = proxy.greet(); + assertEquals("Good Bye from Apache Tamaya!", greetMessage); + } + + @Test + public void testJavaDSLWithTamayaResolution() throws Exception { + CamelContext camelContext = new DefaultCamelContext(); + camelContext.addComponent("properties", new TamayaPropertiesComponent()); + RouteBuilder builder = new RouteBuilder() { + public void configure() { + from("direct:hello").transform().simple("{{tamaya:message}}"); + } + }; + camelContext.addRoutes(builder); + camelContext.start(); + // test configuration is injected right... + Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class); + String greetMessage = proxy.greet(); + assertEquals("Good Bye from Apache Tamaya!", greetMessage); + } + + @Test + public void testJavaDSLWithOverrideActive() throws Exception { + CamelContext camelContext = new DefaultCamelContext(); + TamayaPropertiesComponent props = new TamayaPropertiesComponent(); + props.setTamayaOverrides(true); + camelContext.addComponent("properties", props); + RouteBuilder builder = new RouteBuilder() { + public void configure() { + from("direct:hello").transform().simple("{{message}}"); + } + }; + camelContext.addRoutes(builder); + camelContext.start(); + // test configuration is injected right... + Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class); + String greetMessage = proxy.greet(); + assertEquals("Good Bye from Apache Tamaya!", greetMessage); + } + + @Test + public void testXmlDSL() throws Exception { + CamelContext camelContext = new DefaultCamelContext(); + // This is normally done by the Spring implemented registry, we keep it simple here... + TamayaPropertiesComponent props = new TamayaPropertiesComponent(); + props.setTamayaOverrides(true); + camelContext.addComponent("properties", props); + // Read routes from XML DSL + InputStream is = getClass().getResourceAsStream("/META-INF/routes.xml"); + RoutesDefinition routes = camelContext.loadRoutesDefinition(is); + for(RouteDefinition def: routes.getRoutes()) { + camelContext.addRouteDefinition(def); + } + camelContext.start(); + Greeter greeter = new ProxyBuilder(camelContext).endpoint("direct:hello1").build(Greeter.class); + assertEquals("Good Bye from Apache Tamaya!", greeter.greet()); + greeter = new ProxyBuilder(camelContext).endpoint("direct:hello2").build(Greeter.class); + assertEquals("Good Bye from Apache Tamaya!", greeter.greet()); + greeter = new ProxyBuilder(camelContext).endpoint("direct:hello3").build(Greeter.class); + assertEquals("Good Bye from Apache Tamaya!", greeter.greet()); + } + + public interface Greeter { + String greet(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/src/test/java/org/apache/tamaya/integration/camel/TamayaPropertyResolverTest.java ---------------------------------------------------------------------- diff --git a/camel/src/test/java/org/apache/tamaya/integration/camel/TamayaPropertyResolverTest.java b/camel/src/test/java/org/apache/tamaya/integration/camel/TamayaPropertyResolverTest.java deleted file mode 100644 index 0cba47e..0000000 --- a/camel/src/test/java/org/apache/tamaya/integration/camel/TamayaPropertyResolverTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.tamaya.integration.camel; - -import org.apache.camel.CamelContext; -import org.apache.camel.builder.ProxyBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.model.RouteDefinition; -import org.apache.camel.model.RoutesDefinition; -import org.junit.Test; - -import java.io.InputStream; - -import static org.junit.Assert.*; - -/** - * Tests for integration of Tamaya with Apache Camel using Java DSL and XML DSL. - */ -public class TamayaPropertyResolverTest { - - @Test - public void testJavaDSLWithCfgResolution() throws Exception { - CamelContext camelContext = new DefaultCamelContext(); - camelContext.addComponent("properties", new TamayaPropertiesComponent()); - RouteBuilder builder = new RouteBuilder() { - public void configure() { - from("direct:hello").transform().simple("{{cfg:message}}"); - } - }; - camelContext.addRoutes(builder); - camelContext.start(); - // test configuration is injected right... - Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class); - String greetMessage = proxy.greet(); - assertEquals("Good Bye from Apache Tamaya!", greetMessage); - } - - @Test - public void testJavaDSLWithTamayaResolution() throws Exception { - CamelContext camelContext = new DefaultCamelContext(); - camelContext.addComponent("properties", new TamayaPropertiesComponent()); - RouteBuilder builder = new RouteBuilder() { - public void configure() { - from("direct:hello").transform().simple("{{tamaya:message}}"); - } - }; - camelContext.addRoutes(builder); - camelContext.start(); - // test configuration is injected right... - Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class); - String greetMessage = proxy.greet(); - assertEquals("Good Bye from Apache Tamaya!", greetMessage); - } - - @Test - public void testJavaDSLWithOverrideActive() throws Exception { - CamelContext camelContext = new DefaultCamelContext(); - TamayaPropertiesComponent props = new TamayaPropertiesComponent(); - props.setTamayaOverrides(true); - camelContext.addComponent("properties", props); - RouteBuilder builder = new RouteBuilder() { - public void configure() { - from("direct:hello").transform().simple("{{message}}"); - } - }; - camelContext.addRoutes(builder); - camelContext.start(); - // test configuration is injected right... - Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class); - String greetMessage = proxy.greet(); - assertEquals("Good Bye from Apache Tamaya!", greetMessage); - } - - @Test - public void testXmlDSL() throws Exception { - CamelContext camelContext = new DefaultCamelContext(); - // This is normally done by the Spring implemented registry, we keep it simple here... - TamayaPropertiesComponent props = new TamayaPropertiesComponent(); - props.setTamayaOverrides(true); - camelContext.addComponent("properties", props); - // Read routes from XML DSL - InputStream is = getClass().getResourceAsStream("/META-INF/routes.xml"); - RoutesDefinition routes = camelContext.loadRoutesDefinition(is); - for(RouteDefinition def: routes.getRoutes()) { - camelContext.addRouteDefinition(def); - } - camelContext.start(); - Greeter greeter = new ProxyBuilder(camelContext).endpoint("direct:hello1").build(Greeter.class); - assertEquals("Good Bye from Apache Tamaya!", greeter.greet()); - greeter = new ProxyBuilder(camelContext).endpoint("direct:hello2").build(Greeter.class); - assertEquals("Good Bye from Apache Tamaya!", greeter.greet()); - greeter = new ProxyBuilder(camelContext).endpoint("direct:hello3").build(Greeter.class); - assertEquals("Good Bye from Apache Tamaya!", greeter.greet()); - } - - public interface Greeter { - String greet(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8d79f973/camel/src/test/resources/META-INF/camelcontext.xml ---------------------------------------------------------------------- diff --git a/camel/src/test/resources/META-INF/camelcontext.xml b/camel/src/test/resources/META-INF/camelcontext.xml index 6b99d3d..8de05e6 100644 --- a/camel/src/test/resources/META-INF/camelcontext.xml +++ b/camel/src/test/resources/META-INF/camelcontext.xml @@ -45,7 +45,7 @@ under the License. </route> </routeContext> - <bean id="properties" class="org.apache.tamaya.integration.camel.TamayaPropertiesComponent"> + <bean id="properties" class="org.apache.tamaya.camel.TamayaPropertiesComponent"> <property name="tamayaOverrides" value="true"/> </bean>
