camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-11543 Support @TestPropertySource
Date Sun, 16 Jul 2017 19:32:02 GMT
Repository: camel
Updated Branches:
  refs/heads/master 20a9cf7ce -> ddf7c9f7d


CAMEL-11543 Support @TestPropertySource


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9170e199
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9170e199
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9170e199

Branch: refs/heads/master
Commit: 9170e199fa4d96a10f8c3a324a4bde09281b45d8
Parents: 20a9cf7
Author: Marc Carter <drekbour@fastmail.fm>
Authored: Sun Jul 16 16:58:48 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jul 16 21:25:48 2017 +0200

----------------------------------------------------------------------
 .../spring/CamelSpringTestContextLoader.java    |  2 +-
 ...CamelSpringRunnerTestPropertySourceTest.java | 33 ++++++++++++++++
 ...ringRunnerTestPropertySourceTest-context.xml | 41 ++++++++++++++++++++
 3 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9170e199/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
index 2b1a02b..b595ce3 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
@@ -82,7 +82,7 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader
{
         
         try {            
             GenericApplicationContext context = createContext(testClass, mergedConfig);
-            context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
+            prepareContext(context, mergedConfig);
             loadBeanDefinitions(context, mergedConfig);
             return loadContext(context, testClass);
         } finally {

http://git-wip-us.apache.org/repos/asf/camel/blob/9170e199/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest.java
b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest.java
new file mode 100644
index 0000000..3bfdd1e
--- /dev/null
+++ b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest.java
@@ -0,0 +1,33 @@
+package org.apache.camel.test.spring;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.BootstrapWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestPropertySource;
+
+@RunWith(CamelSpringRunner.class)
+@BootstrapWith(CamelTestContextBootstrapper.class)
+@ContextConfiguration
+@TestPropertySource(properties = "fixedBody=Camel")
+public class CamelSpringRunnerTestPropertySourceTest {
+
+    @Produce(uri = "direct:in")
+    private ProducerTemplate start;
+
+    @EndpointInject(uri = "mock:out")
+    private MockEndpoint end;
+
+    @Test
+    public void readsFileAndInlinedPropertiesFromAnnotation() throws Exception {
+        end.expectedBodiesReceived("Camel");
+
+        start.sendBody("Aardvark");
+
+        end.assertIsSatisfied();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9170e199/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest-context.xml
b/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest-context.xml
new file mode 100644
index 0000000..5fd6ec0
--- /dev/null
+++ b/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/CamelSpringRunnerTestPropertySourceTest-context.xml
@@ -0,0 +1,41 @@
+<?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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+		http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+  <!-- Enable PropertySource -->
+  <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"/>
+
+  <bean id="myBean" class="org.apache.camel.util.ValueHolder">
+    <constructor-arg value="${fixedBody}"/> <!-- configured from @TestPropertySource
-->
+  </bean>
+
+  <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" trace="true"
autoStartup="true">
+    <route>
+      <from uri="direct:in"/>
+      <bean ref="myBean" method="get"/>
+      <to uri="mock:out"/>
+    </route>
+  </camelContext>
+
+</beans>
\ No newline at end of file


Mime
View raw message