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

davsclaus pushed a commit to branch CAMEL-13947
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 09b1bd9849899895e5e7db228aee842090d7b869
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 25 19:14:42 2019 +0200

    CAMEL-13947: PropertiesComponent should be a static service and resolved 
like other similar features.
---
 .../apache/camel/test/junit5/CamelTestSupport.java |   4 +-
 .../camel/test/spring/CamelAnnotationsHandler.java |   4 +-
 .../test/spring/CamelSpringTestContextLoader.java  |   2 +-
 .../CamelSpringPropertiesLocationElementTest.java  |   2 +-
 .../apache/camel/test/junit4/CamelTestSupport.java |   4 +-
 .../PropertiesComponentGetOrElseTest.java          | 100 ---------------------
 .../properties/PropertiesComponentRefTest.java     |  76 ----------------
 .../PropertiesEnvironmentVariableOverrideTest.java |  63 -------------
 8 files changed, 8 insertions(+), 247 deletions(-)

diff --git 
a/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
 
b/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
index 5e8c85c..31b45c5 100644
--- 
a/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
+++ 
b/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
@@ -46,7 +46,6 @@ import 
org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.engine.InterceptSendToMockEndpointStrategy;
 import org.apache.camel.model.Model;
@@ -57,6 +56,7 @@ import org.apache.camel.processor.interceptor.DefaultDebugger;
 import org.apache.camel.reifier.RouteReifier;
 import org.apache.camel.spi.CamelBeanPostProcessor;
 import org.apache.camel.spi.Language;
+import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.test.CamelRouteCoverageDumper;
@@ -459,7 +459,7 @@ public abstract class CamelTestSupport implements 
BeforeEachCallback, AfterAllCa
         }
 
         // configure properties component (mandatory for testing)
-        PropertiesComponent pc = context.getComponent("properties", 
PropertiesComponent.class);
+        PropertiesComponent pc = context.getPropertiesComponent();
         if (extra == null) {
             extra = useOverridePropertiesWithPropertiesComponent();
         }
diff --git 
a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
 
b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
index d28eb14..92bbc11 100644
--- 
a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
+++ 
b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
@@ -29,12 +29,12 @@ import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.api.management.JmxSystemPropertyKeys;
 import org.apache.camel.api.management.ManagedCamelContext;
 import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
-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;
 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.junit4.CamelTestSupport;
 import org.apache.camel.util.CollectionStringBuffer;
@@ -315,7 +315,7 @@ public final class CamelAnnotationsHandler {
         if (properties.size() != 0) {
             CamelSpringTestHelper.doToSpringCamelContexts(context, new 
CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
                 public void execute(String contextName, SpringCamelContext 
camelContext) throws Exception {
-                    PropertiesComponent pc = 
camelContext.getComponent("properties", PropertiesComponent.class);
+                    PropertiesComponent pc = 
camelContext.getPropertiesComponent();
                     Properties extra = new Properties();
                     for (Properties prop : properties) {
                         extra.putAll(prop);
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 df4d626..7c286b9 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
@@ -485,7 +485,7 @@ public class CamelSpringTestContextLoader extends 
AbstractContextLoader {
                 public Object postProcessAfterInitialization(Object bean, 
String beanName) {
                     if (bean instanceof CamelContext) {
                         CamelContext camelContext = (CamelContext) bean;
-                        PropertiesComponent pc = 
camelContext.getPropertiesComponent(true);
+                        PropertiesComponent pc = 
camelContext.getPropertiesComponent();
                         LOG.info("Using {} properties to override any existing 
properties on the PropertiesComponent on CamelContext with name [{}].", 
extra.size(), camelContext.getName());
                         pc.setOverrideProperties(extra);
                     }
diff --git 
a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringPropertiesLocationElementTest.java
 
b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringPropertiesLocationElementTest.java
index 13389e5..19dff8b 100644
--- 
a/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringPropertiesLocationElementTest.java
+++ 
b/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringPropertiesLocationElementTest.java
@@ -52,7 +52,7 @@ public class CamelSpringPropertiesLocationElementTest {
         mock.expectedHeaderReceived("property-2", "property-value-2");
         mock.expectedHeaderReceived("property-3", "property-value-3");
 
-        PropertiesComponent pc = context.getComponent("properties", 
PropertiesComponent.class);
+        PropertiesComponent pc = (PropertiesComponent) 
context.getPropertiesComponent();
         assertNotNull("Properties component not defined", pc);
 
         List<String> locations = pc.getLocations();
diff --git 
a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
 
b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
index 4e88be7..f5f0f32 100644
--- 
a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
+++ 
b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
@@ -70,7 +70,6 @@ import 
org.apache.camel.api.management.mbean.ManagedRouteMBean;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.impl.engine.InterceptSendToMockEndpointStrategy;
@@ -82,6 +81,7 @@ import org.apache.camel.processor.interceptor.DefaultDebugger;
 import org.apache.camel.reifier.RouteReifier;
 import org.apache.camel.spi.CamelBeanPostProcessor;
 import org.apache.camel.spi.Language;
+import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.util.IOHelper;
@@ -421,7 +421,7 @@ public abstract class CamelTestSupport extends TestSupport {
         }
 
         // configure properties component (mandatory for testing)
-        PropertiesComponent pc = context.getComponent("properties", 
PropertiesComponent.class);
+        PropertiesComponent pc = context.getPropertiesComponent();
         if (extra == null) {
             extra = useOverridePropertiesWithPropertiesComponent();
         }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentGetOrElseTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentGetOrElseTest.java
deleted file mode 100644
index f21bf80..0000000
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentGetOrElseTest.java
+++ /dev/null
@@ -1,100 +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.camel.component.properties;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
-public class PropertiesComponentGetOrElseTest extends ContextTestSupport {
-
-    @Override
-    public boolean isUseRouteBuilder() {
-        return false;
-    }
-
-    @Test
-    public void testPropertiesComponentFoundKey() throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:start").to("properties:{{cool.end:mock:wrong}}");
-            }
-        });
-        context.start();
-
-        getMockEndpoint("mock:result").expectedMessageCount(1);
-
-        template.sendBody("direct:start", "Hello World");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    @Test
-    public void testPropertiesComponentUseDefaultValue() throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:start").to("properties:{{unknown:mock:result}}");
-            }
-        });
-        context.start();
-
-        getMockEndpoint("mock:result").expectedMessageCount(1);
-
-        template.sendBody("direct:start", "Hello World");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    @Test
-    public void testPropertiesComponentSimpleLanguage() throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:start").transform().simple("Hi ${body} do you 
think ${properties:cool.name} rocks?");
-            }
-        });
-        context.start();
-
-        String reply = template.requestBody("direct:start", "Claus", 
String.class);
-        assertEquals("Hi Claus do you think Camel rocks?", reply);
-    }
-
-    @Test
-    public void testPropertiesComponentSimpleLanguageUsingDefaultValue() 
throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:start").transform().simple("Hi ${body} do you 
think ${properties:unknown:Beer} rocks?");
-            }
-        });
-        context.start();
-
-        String reply = template.requestBody("direct:start", "Claus", 
String.class);
-        assertEquals("Hi Claus do you think Beer rocks?", reply);
-    }
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-        
context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties");
-        return context;
-    }
-
-}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRefTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRefTest.java
deleted file mode 100644
index 9dc4c3f..0000000
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentRefTest.java
+++ /dev/null
@@ -1,76 +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.camel.component.properties;
-
-import java.util.Properties;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.JndiRegistry;
-import org.junit.Test;
-
-public class PropertiesComponentRefTest extends ContextTestSupport {
-
-    @Override
-    public boolean isUseRouteBuilder() {
-        return false;
-    }
-
-    @Test
-    public void testPropertiesComponent() throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("{{start}}").to("properties:{{cool.result}}");
-            }
-        });
-        context.start();
-
-        getMockEndpoint("mock:result").expectedMessageCount(1);
-
-        template.sendBody("direct:start", "Hello World");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-
-        Properties cool = new Properties();
-        cool.put("cool.end", "mock:end");
-        cool.put("cool.result", "mock:result");
-        cool.put("start", "direct:start");
-        jndi.bind("myCoolProperties", cool);
-
-        Properties bar = new Properties();
-        bar.put("bar.end", "mock:bar");
-        bar.put("dude", "direct:bar");
-        jndi.bind("coolBar", bar);
-
-        return jndi;
-    }
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-        context.getPropertiesComponent().setLocation("ref:myCoolProperties");
-        return context;
-    }
-
-}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java
deleted file mode 100644
index fc1368b..0000000
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesEnvironmentVariableOverrideTest.java
+++ /dev/null
@@ -1,63 +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.camel.component.properties;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
-public class PropertiesEnvironmentVariableOverrideTest extends 
ContextTestSupport {
-
-    @Override
-    public boolean isUseRouteBuilder() {
-        return false;
-    }
-
-    @Test
-    public void testPropertiesComponentCacheDisabled() throws Exception {
-        System.setProperty("cool.end", "mock:override");
-        System.setProperty("cool.result", "override");
-
-        context.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:start").to("properties:cool.end");
-                from("direct:foo").to("properties:mock:{{cool.result}}");
-            }
-        });
-        context.start();
-
-        getMockEndpoint("mock:override").expectedMessageCount(2);
-
-        template.sendBody("direct:start", "Hello World");
-        template.sendBody("direct:foo", "Hello Foo");
-
-        System.clearProperty("cool.end");
-        System.clearProperty("cool.result");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-        
context.getPropertiesComponent().setLocation("classpath:org/apache/camel/component/properties/myproperties.properties");
-        return context;
-    }
-
-}

Reply via email to