You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/05/19 13:56:46 UTC

[camel] branch master updated (cf74f15 -> b2b9fb6)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from cf74f15  CAMEL-13371: Fixed test
     new 21d38c2  CAMEL-13543: Make CamelSpringTestContextLoader set property overrides before the CamelContext is injected into any other bean
     new b2b9fb6  CAMEL-13453 - Fixed CS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../test/spring/CamelSpringTestContextLoader.java  | 40 +++++++++++++---------
 ...ngOverridePropertiesForPropertyInjectTest.java} | 37 ++++++--------------
 .../spring/TestPropertyInjectRouteBuilder.java}    | 14 +++++---
 ...idePropertiesForPropertyInjectTest-context.xml} | 12 ++-----
 .../org/apache/camel/test/spring/test.properties   |  1 +
 5 files changed, 47 insertions(+), 57 deletions(-)
 copy components/camel-test-spring/src/test/java/org/apache/camel/test/spring/{CamelSpringOverridePropertiesTest.java => CamelSpringOverridePropertiesForPropertyInjectTest.java} (62%)
 copy components/{camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/health/MyCamelRoute.java => camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java} (76%)
 copy components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/{CamelSpringOverridePropertiesTest-context.xml => CamelSpringOverridePropertiesForPropertyInjectTest-context.xml} (88%)


[camel] 02/02: CAMEL-13453 - Fixed CS

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b2b9fb6d2cbfba0ac81876f271021aafff82bea6
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Sun May 19 15:56:24 2019 +0200

    CAMEL-13453 - Fixed CS
---
 .../apache/camel/test/spring/CamelSpringTestContextLoader.java    | 7 +++----
 .../CamelSpringOverridePropertiesForPropertyInjectTest.java       | 8 ++++----
 .../apache/camel/test/spring/TestPropertyInjectRouteBuilder.java  | 2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)

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 23406e5..3548068 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
@@ -26,18 +26,21 @@ import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.api.management.JmxSystemPropertyKeys;
 import org.apache.camel.impl.engine.InterceptSendToMockEndpointStrategy;
 import org.apache.camel.processor.interceptor.DefaultDebugger;
 import org.apache.camel.spi.Breakpoint;
 import org.apache.camel.spi.Debugger;
 import org.apache.camel.spi.EventNotifier;
+import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.camel.test.ExcludingPackageScanClassResolver;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
@@ -53,10 +56,6 @@ import org.springframework.util.StringUtils;
 
 import static org.apache.camel.test.spring.CamelSpringTestHelper.getAllMethods;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.spi.PropertiesComponent;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-
 /**
  * Replacement for the default {@link GenericXmlContextLoader} that provides hooks for
  * processing some class level Camel related test annotations.
diff --git a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest.java b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest.java
index bf79523..493e9a8 100644
--- a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest.java
+++ b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.test.spring;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
 import java.util.Properties;
 
 import org.apache.camel.Produce;
@@ -29,6 +26,9 @@ import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.BootstrapWith;
 import org.springframework.test.context.ContextConfiguration;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
 @RunWith(CamelSpringRunner.class)
 @BootstrapWith(CamelTestContextBootstrapper.class)
 @ContextConfiguration()
diff --git a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java
index b56c94b..62db815 100644
--- a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java
+++ b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.


[camel] 01/02: CAMEL-13543: Make CamelSpringTestContextLoader set property overrides before the CamelContext is injected into any other bean

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 21d38c2a9e7c849ae78f6a2e663feb14fba9b300
Author: Stig Rohde Døssing <st...@gmail.com>
AuthorDate: Fri May 17 15:31:21 2019 +0200

    CAMEL-13543: Make CamelSpringTestContextLoader set property overrides before the CamelContext is injected into any other bean
---
 .../test/spring/CamelSpringTestContextLoader.java  | 41 +++++++++-------
 ...ingOverridePropertiesForPropertyInjectTest.java | 57 ++++++++++++++++++++++
 .../spring/TestPropertyInjectRouteBuilder.java     | 33 +++++++++++++
 ...ridePropertiesForPropertyInjectTest-context.xml | 36 ++++++++++++++
 .../org/apache/camel/test/spring/test.properties   |  1 +
 5 files changed, 151 insertions(+), 17 deletions(-)

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 2bb009f..23406e5 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
@@ -27,7 +27,6 @@ import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.api.management.JmxSystemPropertyKeys;
-import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.impl.engine.InterceptSendToMockEndpointStrategy;
 import org.apache.camel.processor.interceptor.DefaultDebugger;
 import org.apache.camel.spi.Breakpoint;
@@ -54,6 +53,10 @@ import org.springframework.util.StringUtils;
 
 import static org.apache.camel.test.spring.CamelSpringTestHelper.getAllMethods;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.PropertiesComponent;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
 /**
  * Replacement for the default {@link GenericXmlContextLoader} that provides hooks for
  * processing some class level Camel related test annotations.
@@ -146,8 +149,9 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader {
         AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
         
         // Pre CamelContext(s) instantiation setup
-        handleDisableJmx(context, testClass);
-
+        handleDisableJmx(context, testClass);        
+        handleUseOverridePropertiesWithPropertiesComponent(context, testClass);
+        
         // Temporarily disable CamelContext start while the contexts are instantiated.
         SpringCamelContext.setNoStart(true);
         context.refresh();
@@ -161,7 +165,6 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader {
         handleShutdownTimeout(context, testClass);
         handleMockEndpoints(context, testClass);
         handleMockEndpointsAndSkip(context, testClass);
-        handleUseOverridePropertiesWithPropertiesComponent(context, testClass);
 
         // CamelContext(s) startup
         handleCamelContextStartup(context, testClass);
@@ -436,9 +439,9 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader {
     }
     
     /**
-     * Handles override this method to include and override properties with the Camel {@link org.apache.camel.component.properties.PropertiesComponent}.
+     * Sets property overrides for the Camel {@link org.apache.camel.component.properties.PropertiesComponent}.
      *
-     * @param context the initialized Spring context
+     * @param context the pre-refresh Spring context
      * @param testClass the test class being executed
      */
     protected void handleUseOverridePropertiesWithPropertiesComponent(ConfigurableApplicationContext context, Class<?> testClass) throws Exception {
@@ -470,21 +473,25 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader {
                 }
             }
         }
+        
+        Properties extra = new Properties();
+        for (Properties prop : properties) {
+            extra.putAll(prop);
+        }
 
-        if (properties.size() != 0) {
-            CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {
-                public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
-                    PropertiesComponent pc = camelContext.getComponent("properties", PropertiesComponent.class);
-                    Properties extra = new Properties();
-                    for (Properties prop : properties) {
-                        extra.putAll(prop);
-                    }
-                    if (!extra.isEmpty()) {
-                        LOG.info("Using {} properties to override any existing properties on the PropertiesComponent on CamelContext with name [{}].", extra.size(), contextName);
+        if (!extra.isEmpty()) {
+            context.addBeanFactoryPostProcessor(beanFactory -> beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
+                @Override
+                public Object postProcessAfterInitialization(Object bean, String beanName) {
+                    if (bean instanceof CamelContext) {
+                        CamelContext camelContext = (CamelContext) bean;
+                        PropertiesComponent pc = camelContext.getPropertiesComponent(true);
+                        LOG.info("Using {} properties to override any existing properties on the PropertiesComponent on CamelContext with name [{}].", extra.size(), camelContext.getName());
                         pc.setOverrideProperties(extra);
                     }
+                    return bean;
                 }
-            });
+            }));
         }
     }
 
diff --git a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest.java b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest.java
new file mode 100644
index 0000000..bf79523
--- /dev/null
+++ b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest.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.spring;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Properties;
+
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.BootstrapWith;
+import org.springframework.test.context.ContextConfiguration;
+
+@RunWith(CamelSpringRunner.class)
+@BootstrapWith(CamelTestContextBootstrapper.class)
+@ContextConfiguration()
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
+public class CamelSpringOverridePropertiesForPropertyInjectTest {
+    
+    private static final String EXPECTED_PROPERTY_VALUE = "The value is overriden";
+    
+    @Produce(uri = "direct:start-override-route")
+    private ProducerTemplate start;
+
+    @UseOverridePropertiesWithPropertiesComponent
+    public static Properties override() {
+        Properties answer = new Properties();
+        answer.put("property.to.override", EXPECTED_PROPERTY_VALUE);
+        return answer;
+    }
+
+    @Test
+    public void testOverride() throws Exception {
+        String response = start.requestBody((Object)"ignored", String.class);
+
+        assertThat(response, is(EXPECTED_PROPERTY_VALUE));
+    }
+
+}
diff --git a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java
new file mode 100644
index 0000000..b56c94b
--- /dev/null
+++ b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/TestPropertyInjectRouteBuilder.java
@@ -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.test.spring;
+
+import org.apache.camel.PropertyInject;
+import org.apache.camel.builder.RouteBuilder;
+
+public class TestPropertyInjectRouteBuilder extends RouteBuilder {
+
+    @PropertyInject("{{property.to.override}}")
+    private String propertyToOverride;
+    
+    @Override
+    public void configure() throws Exception {
+        from("direct:start-override-route")
+            .transform(constant(propertyToOverride));
+    }
+
+}
diff --git a/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest-context.xml b/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest-context.xml
new file mode 100644
index 0000000..a757b69
--- /dev/null
+++ b/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/CamelSpringOverridePropertiesForPropertyInjectTest-context.xml
@@ -0,0 +1,36 @@
+<?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 ">
+
+  <bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
+    <property name="location" value="classpath:org/apache/camel/test/spring/test.properties"/>
+  </bean>
+  
+  <bean id="testRouteBuilder" class="org.apache.camel.test.spring.TestPropertyInjectRouteBuilder"></bean>
+
+  <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
+      <routeBuilder ref="testRouteBuilder"/>
+  </camelContext>
+
+</beans>
\ No newline at end of file
diff --git a/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/test.properties b/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/test.properties
index 2d1d49f..e8a539c 100644
--- a/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/test.properties
+++ b/components/camel-test-spring/src/test/resources/org/apache/camel/test/spring/test.properties
@@ -17,3 +17,4 @@
 
 cool.end=mock:test
 mock.skip=seda:*
+property.to.override=This value should be overriden