You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2012/09/19 02:40:42 UTC
svn commit: r1387419 - in /camel/trunk:
components/camel-cdi/src/main/java/org/apache/camel/cdi/
tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/
tests/camel-itest-cdi/src/main/resources/
tests/camel-itest-cdi/src/test/java/org/apache/ca...
Author: hadrian
Date: Wed Sep 19 00:40:42 2012
New Revision: 1387419
URL: http://svn.apache.org/viewvc?rev=1387419&view=rev
Log:
CAMEL-5616. Thanks Lukasz for the patch
Added:
camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel1Config.java (with props)
camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel2Config.java (with props)
camel/trunk/tests/camel-itest-cdi/src/main/resources/camel1.properties
camel/trunk/tests/camel-itest-cdi/src/main/resources/camel2.properties
camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java (with props)
Modified:
camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java?rev=1387419&r1=1387418&r2=1387419&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java Wed Sep 19 00:40:42 2012
@@ -24,6 +24,7 @@ import javax.inject.Inject;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.Injector;
import org.apache.camel.spi.Registry;
+import org.apache.deltaspike.core.api.config.ConfigResolver;
/**
* CDI {@link org.apache.camel.CamelContext} class.
@@ -53,6 +54,16 @@ public class CdiCamelContext extends Def
return !instance.isUnsatisfied() && !instance.isAmbiguous();
}
+ @Override
+ public String resolvePropertyPlaceholders(String text) throws Exception {
+ String placeholder = text != null ? ConfigResolver.getPropertyValue(text) : null;
+ if (placeholder == null) {
+ // fallback to standard properties loaded by camel
+ return super.resolvePropertyPlaceholders(text);
+ }
+ return placeholder;
+ }
+
@PostConstruct
@Override
public void start() throws Exception {
Added: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel1Config.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel1Config.java?rev=1387419&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel1Config.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel1Config.java Wed Sep 19 00:40:42 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.itest.cdi;
+
+import org.apache.deltaspike.core.api.config.PropertyFileConfig;
+
+/**
+ * Registers new properties configuration.
+ */
+public class Camel1Config implements PropertyFileConfig {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getPropertyFileName() {
+ return "camel1.properties";
+ };
+
+}
\ No newline at end of file
Propchange: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel1Config.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel2Config.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel2Config.java?rev=1387419&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel2Config.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel2Config.java Wed Sep 19 00:40:42 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.itest.cdi;
+
+import org.apache.deltaspike.core.api.config.PropertyFileConfig;
+
+/**
+ * Registers new properties configuration.
+ */
+public class Camel2Config implements PropertyFileConfig {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getPropertyFileName() {
+ return "camel2.properties";
+ };
+
+}
\ No newline at end of file
Propchange: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Camel2Config.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/tests/camel-itest-cdi/src/main/resources/camel1.properties
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/resources/camel1.properties?rev=1387419&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/resources/camel1.properties (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/resources/camel1.properties Wed Sep 19 00:40:42 2012
@@ -0,0 +1 @@
+property1=value1
\ No newline at end of file
Added: camel/trunk/tests/camel-itest-cdi/src/main/resources/camel2.properties
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/resources/camel2.properties?rev=1387419&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/resources/camel2.properties (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/resources/camel2.properties Wed Sep 19 00:40:42 2012
@@ -0,0 +1 @@
+property2=value2
\ No newline at end of file
Added: camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java?rev=1387419&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java Wed Sep 19 00:40:42 2012
@@ -0,0 +1,59 @@
+/**
+ * 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.itest.cdi;
+
+import javax.inject.Inject;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cdi.internal.CamelExtension;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Verify if {@link CamelExtension} allows to create custom instance of context.
+ */
+@RunWith(Arquillian.class)
+public class PropertiesConfigurationTest {
+
+ @Inject
+ private CamelContext camelContext;
+
+ @Test
+ public void checkContext() throws Exception {
+ assertNotNull(camelContext);
+
+ assertEquals("value1", camelContext.resolvePropertyPlaceholders("property1"));
+ assertEquals("value2", camelContext.resolvePropertyPlaceholders("property2"));
+ }
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+ return ShrinkWrap.create(JavaArchive.class)
+ .addPackage(CamelExtension.class.getPackage())
+ .addClass(Camel1Config.class)
+ .addClass(Camel2Config.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+}
Propchange: camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/PropertiesConfigurationTest.java
------------------------------------------------------------------------------
svn:eol-style = native