[ 
https://issues.apache.org/jira/browse/CAMEL-12494?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16480416#comment-16480416
 ] 

ASF GitHub Bot commented on CAMEL-12494:
----------------------------------------

oscerd closed pull request #2343: CAMEL-12494:spring-boot: use 
ApplicationContextRunner in spring-boot …
URL: https://github.com/apache/camel/pull/2343
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationWithContextRunnerTest.java
 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationWithContextRunnerTest.java
new file mode 100644
index 00000000000..d08fe4cc91d
--- /dev/null
+++ 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationWithContextRunnerTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.spring.boot;
+
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CamelAutoConfigurationWithContextRunnerTest {
+    @Test
+    public void testCamelAnnotationsAutoConfigurationBean() {
+        new ApplicationContextRunner()
+            .withConfiguration(
+                AutoConfigurations.of(
+                        CamelAutoConfigurationTest.class,
+                        RouteConfigWithCamelContextInjected.class,
+                        CamelAutoConfigurationWithContextRunnerTest.class
+                )
+            )
+            .withPropertyValues(
+                    "camel.springboot.consumerTemplateCacheSize=100",
+                    "camel.springboot.jmxEnabled=true",
+                    "camel.springboot.name=customName",
+                    "camel.springboot.typeConversion=true",
+                    "camel.springboot.threadNamePattern=customThreadName 
#counter#"
+            )
+            .run((context) -> {
+                    
assertThat(context).doesNotHaveBean(CamelAnnotationsTest.TestConfig.class);
+                    
assertThat(context).doesNotHaveBean(CamelAnnotationsTest.class);
+                    
assertThat(context).getBeanNames(CamelAutoConfigurationTest.class).hasSize(1);
+                    
assertThat(context).hasSingleBean(RouteConfigWithCamelContextInjected.class);
+                    
assertThat(context).getBean(CamelAutoConfigurationTest.class).hasNoNullFieldsOrProperties();
+                                       
+                }
+            );
+    }
+
+}
diff --git 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java
 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java
index 42263230458..952ac0ce607 100644
--- 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java
+++ 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/cloud/CamelCloudServiceCallConfigurationTest.java
@@ -22,55 +22,50 @@
 import org.apache.camel.cloud.ServiceFilter;
 import org.apache.camel.cloud.ServiceLoadBalancer;
 import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.context.ApplicationContext;
-import org.springframework.core.env.Environment;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
 
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.core.env.Environment;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-@DirtiesContext
-@RunWith(SpringRunner.class)
-@SpringBootApplication()
-@SpringBootTest(
-    classes = {
-        CamelAutoConfiguration.class,
-        CamelCloudAutoConfiguration.class,
-        CamelCloudServiceChooserAutoConfiguration.class
-    },
-    properties = {
-        "camel.cloud.enabled=false",
-        "camel.cloud.service-discovery.enabled=false",
-        "camel.cloud.service-filter.enabled=false",
-        "camel.cloud.service-chooser.enabled=true",
-        "camel.cloud.load-balancer.enabled=false",
-        "debug=false"
-    }
-)
-public class CamelCloudServiceCallConfigurationTest {
-    @Autowired
-    private ApplicationContext ctx;
 
+public class CamelCloudServiceCallConfigurationTest {
     @Test
-    public void testConfiguration() throws Exception {
-        Environment env = ctx.getEnvironment();
-
-        assertFalse(env.getProperty("camel.cloud.enabled", Boolean.class));
-        assertFalse(env.getProperty("camel.cloud.service-discovery.enabled", 
Boolean.class));
-        assertFalse(env.getProperty("camel.cloud.service-filter.enabled", 
Boolean.class));
-        assertTrue(env.getProperty("camel.cloud.service-chooser.enabled", 
Boolean.class));
-        assertFalse(env.getProperty("camel.cloud.load-balancer.enabled", 
Boolean.class));
-
-        assertTrue(ctx.getBeansOfType(ServiceDiscovery.class).isEmpty());
-        assertTrue(ctx.getBeansOfType(ServiceFilter.class).isEmpty());
-        assertTrue(ctx.getBeansOfType(ServiceChooser.class).isEmpty());
-        assertTrue(ctx.getBeansOfType(ServiceLoadBalancer.class).isEmpty());
+    public void testConfiguration() {
+        new ApplicationContextRunner()
+            .withConfiguration(
+                AutoConfigurations.of(
+                        CamelAutoConfiguration.class,
+                        CamelCloudAutoConfiguration.class,
+                        CamelCloudServiceChooserAutoConfiguration.class
+                )
+            )
+            .withPropertyValues(
+                    "camel.cloud.enabled=false",
+                    "camel.cloud.service-discovery.enabled=false",
+                    "camel.cloud.service-filter.enabled=false",
+                    "camel.cloud.service-chooser.enabled=true",
+                    "camel.cloud.load-balancer.enabled=false",
+                    "debug=false"
+            )
+            .run((context) -> {
+                    Environment env = context.getEnvironment();
+                    assertFalse(env.getProperty("camel.cloud.enabled", 
Boolean.class));
+                    
assertFalse(env.getProperty("camel.cloud.service-discovery.enabled", 
Boolean.class));
+                    
assertFalse(env.getProperty("camel.cloud.service-filter.enabled", 
Boolean.class));
+                    
assertTrue(env.getProperty("camel.cloud.service-chooser.enabled", 
Boolean.class));
+                    
assertFalse(env.getProperty("camel.cloud.load-balancer.enabled", 
Boolean.class));
+            
+                    
assertTrue(context.getBeansOfType(ServiceDiscovery.class).isEmpty());
+                    
assertTrue(context.getBeansOfType(ServiceFilter.class).isEmpty());
+                    
assertTrue(context.getBeansOfType(ServiceChooser.class).isEmpty());
+                    
assertTrue(context.getBeansOfType(ServiceLoadBalancer.class).isEmpty());
+                                       
+                }
+            );
     }
-}
 
+}
diff --git 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java
 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java
index 3a6b1ad1063..f26bac9b60f 100644
--- 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java
+++ 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/security/CamelSSLAutoConfigurationTest.java
@@ -19,50 +19,52 @@
 import org.apache.camel.spring.boot.CamelAutoConfiguration;
 import org.apache.camel.util.jsse.GlobalSSLContextParametersSupplier;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
 
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 /**
  * Testing the ssl configuration
  */
-@RunWith(SpringRunner.class)
-@SpringBootApplication
-@DirtiesContext
-@ContextConfiguration(classes = {CamelSSLAutoConfiguration.class, 
CamelAutoConfiguration.class})
-@SpringBootTest(properties = {
-        "camel.ssl.config.cert-alias=web",
-        "camel.ssl.config.key-managers.key-password=changeit",
-        "camel.ssl.config.key-managers.key-store.password=changeit",
-        "camel.ssl.config.key-managers.key-store.type=PKCS12",
-        "camel.ssl.config.trust-managers.key-store.password=changeit",
-        "camel.ssl.config.trust-managers.key-store.type=jks"
-})
-public class CamelSSLAutoConfigurationTest {
-
-    @Autowired
-    private ApplicationContext applicationContext;
 
+public class CamelSSLAutoConfigurationTest {
     @Test
     public void checkSSLPropertiesPresent() {
-        GlobalSSLContextParametersSupplier supplier = 
applicationContext.getBean(GlobalSSLContextParametersSupplier.class);
-        assertNotNull(supplier);
-        assertNotNull(supplier.get());
-        assertEquals("web", supplier.get().getCertAlias());
-        assertNotNull(supplier.get().getKeyManagers());
-        assertEquals("changeit", 
supplier.get().getKeyManagers().getKeyPassword());
-        assertNotNull(supplier.get().getTrustManagers());
-        assertNotNull(supplier.get().getTrustManagers().getKeyStore());
-        assertEquals("jks", 
supplier.get().getTrustManagers().getKeyStore().getType());
+        new ApplicationContextRunner()
+            .withConfiguration(
+                AutoConfigurations.of(
+                        CamelSSLAutoConfiguration.class,
+                        CamelAutoConfiguration.class
+                )
+            )
+            .withPropertyValues(
+                    "camel.ssl.config.cert-alias=web",
+                    "camel.ssl.config.key-managers.key-password=changeit",
+                    
"camel.ssl.config.key-managers.key-store.password=changeit",
+                    "camel.ssl.config.key-managers.key-store.type=PKCS12",
+                    
"camel.ssl.config.trust-managers.key-store.password=changeit",
+                    "camel.ssl.config.trust-managers.key-store.type=jks"
+            )
+            .run((context) -> {
+                    GlobalSSLContextParametersSupplier supplier = 
context.getBean(GlobalSSLContextParametersSupplier.class);
+                    
assertThat(context).hasSingleBean(CamelSSLAutoConfiguration.class);
+                    assertNotNull(supplier);
+                    assertNotNull(supplier.get());
+                    assertEquals("web", supplier.get().getCertAlias());
+                    assertNotNull(supplier.get().getKeyManagers());
+                    assertEquals("changeit", 
supplier.get().getKeyManagers().getKeyPassword());
+                    assertNotNull(supplier.get().getTrustManagers());
+                    
assertNotNull(supplier.get().getTrustManagers().getKeyStore());
+                    assertEquals("jks", 
supplier.get().getTrustManagers().getKeyStore().getType());
+                                       
+                }
+            );
     }
 
 }
 
+
+   
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> spring-boot: use ApplicationContextRunner in spring-boot test to test 
> AutoConfigurations
> ----------------------------------------------------------------------------------------
>
>                 Key: CAMEL-12494
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12494
>             Project: Camel
>          Issue Type: Task
>          Components: camel-spring-boot, camel-spring-boot-starters
>            Reporter: Luca Burgazzoli
>            Assignee: Andrea Cosentino
>            Priority: Minor
>             Fix For: 2.22.0
>
>
> We should migrate AutoConfigurations related test to use 
> ApplicationContextRunner, see: 
> https://spring.io/blog/2018/03/07/testing-auto-configurations-with-spring-boot-2-0



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to