Java Code Examples for org.springframework.boot.test.context.runner.ApplicationContextRunner

The following examples show how to use org.springframework.boot.test.context.runner.ApplicationContextRunner. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testServiceDiscoveryWithEnv() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=env")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesEnvServiceDiscovery.class);
            }
        );
}
 
Example 2
@Test
public void testServiceDiscoveryWithDns() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=dns",
            "camel.cloud.kubernetes.service-discovery.dns-domain=mydomain",
            "camel.cloud.kubernetes.service-discovery.namespace=mynamespace")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesDnsServiceDiscovery.class);
            }
        );
}
 
Example 3
@Test
public void testServiceDiscoveryWithDnsSrv() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=dnssrv",
            "camel.cloud.kubernetes.service-discovery.port-name=myportname",
            "camel.cloud.kubernetes.service-discovery.port-proocole=myportproto",
            "camel.cloud.kubernetes.service-discovery.dns-domain=mydomain",
            "camel.cloud.kubernetes.service-discovery.namespace=mynamespace")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesDnsSrvServiceDiscovery.class);
            }
        );
}
 
Example 4
@Test
public void testServiceDiscoveryWithClient() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=client")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesClientServiceDiscovery.class);
            }
        );
}
 
Example 5
@Test
public void testDatastoreOptionsCorrectlySet() {
	new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					GcpDatastoreEmulatorAutoConfiguration.class))
			.withPropertyValues(
					"spring.cloud.gcp.datastore.emulator.port=8182",
					"spring.cloud.gcp.datastore.emulator.enabled=true",
					"spring.cloud.gcp.datastore.emulator.consistency=0.8")
			.run((context) -> {
				LocalDatastoreHelper helper = context.getBean(LocalDatastoreHelper.class);
				DatastoreOptions datastoreOptions = helper.getOptions();
				assertThat(datastoreOptions.getHost()).isEqualTo("localhost:8182");
				assertThat(helper.getConsistency()).isEqualTo(0.8D);
			});
}
 
Example 6
@Test
public void testInterceptors() {
	new ApplicationContextRunner()
			.withPropertyValues("feign.compression.response.enabled=true",
					"feign.compression.request.enabled=true",
					"feign.okhttp.enabled=false")
			.withConfiguration(AutoConfigurations.of(FeignAutoConfiguration.class,
					FeignContentGzipEncodingAutoConfiguration.class,
					FeignAcceptGzipEncodingAutoConfiguration.class,
					HttpClientConfiguration.class, PlainConfig.class))
			.run(context -> {
				FeignContext feignContext = context.getBean(FeignContext.class);
				Map<String, RequestInterceptor> interceptors = feignContext
						.getInstances("foo", RequestInterceptor.class);
				assertThat(interceptors.size()).isEqualTo(2);
				assertThat(interceptors.get("feignAcceptGzipEncodingInterceptor"))
						.isInstanceOf(FeignAcceptGzipEncodingInterceptor.class);
				assertThat(interceptors.get("feignContentGzipEncodingInterceptor"))
						.isInstanceOf(FeignContentGzipEncodingInterceptor.class);
			});
}
 
Example 7
Source Project: liiklus   Source File: GRPCConfigurationTest.java    License: MIT License 6 votes vote down vote up
@Test
void shouldConsiderTransportConfigurers() {
    var service = ServerServiceDefinition.builder("test").build();

    new ApplicationContextRunner()
            .withInitializer((ApplicationContextInitializer) new GRPCConfiguration())
            .withPropertyValues(
                    "spring.profiles.active: gateway",
                    "grpc.port: 0"
            )
            .withInitializer(ctx -> {
                var context = (GenericApplicationContext) ctx;
                context.registerBean(LiiklusService.class, () -> Mockito.mock(LiiklusService.class));
                context.registerBean(GRPCLiiklusTransportConfigurer.class, () -> builder -> builder.addService(() -> service));
            })
            .run(context -> {
                assertThat(context).getBeans(GRPCLiiklusTransportConfigurer.class).isNotEmpty();

                assertThat(context)
                        .getBean(Server.class)
                        .satisfies(server -> {
                            assertThat(server.getServices()).contains(service);
                        });
            });
}
 
Example 8
private ApplicationContextRunner configuredContext() {
	return this.contextRunner
		.withPropertyValues(
			"spring.cloud.appbroker.services[0].service-name=service1",
			"spring.cloud.appbroker.services[0].plan-name=service1-plan1",

			"spring.cloud.appbroker.services[0].apps[0].path=classpath:app1.jar",
			"spring.cloud.appbroker.services[0].apps[0].name=app1",
			"spring.cloud.appbroker.services[0].apps[0].properties.memory=1G",

			"spring.cloud.appbroker.services[0].apps[1].path=classpath:app2.jar",
			"spring.cloud.appbroker.services[0].apps[1].name=app2",
			"spring.cloud.appbroker.services[0].apps[1].properties.memory=2G",
			"spring.cloud.appbroker.services[0].apps[1].properties.instances=2",

			"spring.cloud.appbroker.services[1].service-name=service2",
			"spring.cloud.appbroker.services[1].plan-name=service2-plan1",

			"spring.cloud.appbroker.services[1].apps[0].path=classpath:app3.jar",
			"spring.cloud.appbroker.services[1].apps[0].name=app3",

			"spring.cloud.appbroker.deployer.cloudfoundry.api-host=https://api.example.local",
			"spring.cloud.appbroker.deployer.cloudfoundry.username=user",
			"spring.cloud.appbroker.deployer.cloudfoundry.password=secret"
		);
}
 
Example 9
@Test
void testDecoratedHikariSpecificPropertiesIsSet() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
            "spring.datasource.type:" + HikariDataSource.class.getName(),
            "spring.datasource.hikari.catalog:test_catalog"
    );

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        assertThat(dataSource).isNotNull();
        assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
        DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
        assertThat(realDataSource).isInstanceOf(HikariDataSource.class);
        assertThat(((HikariDataSource) realDataSource).getCatalog()).isEqualTo("test_catalog");
    });
}
 
Example 10
@Test
void testCustomDataSourceDecoratorApplied() {
    ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(TestDataSourceDecoratorConfiguration.class);

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        assertThat(dataSource).isNotNull();

        DataSource customDataSource = ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        assertThat(customDataSource).isInstanceOf(CustomDataSourceProxy.class);

        DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
        assertThat(realDataSource).isInstanceOf(HikariDataSource.class);

        assertThatDataSourceDecoratingChain(dataSource).containsExactly(CustomDataSourceProxy.class, P6DataSource.class, ProxyDataSource.class,
                FlexyPoolDataSource.class);
    });
}
 
Example 11
@Test
@SuppressWarnings("unchecked")
void testDecoratingHikariDataSourceWithDefaultStrategies() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("spring.datasource.type:" + HikariDataSource.class.getName());

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        assertDataSourceOfType(dataSource, HikariDataSource.class);
        FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
        IncrementPoolOnTimeoutConnectionAcquiringStrategy<HikariDataSource> strategy1 =
                findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
        assertThat(strategy1).isNotNull();
        assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 15);
        assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 500);

        RetryConnectionAcquiringStrategy<HikariDataSource> strategy2 =
                findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
        assertThat(strategy2).isNotNull();
        assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 2);
    });
}
 
Example 12
@Test
@SuppressWarnings("unchecked")
void testDecoratingHikariDataSourceWithCustomPropertyStrategies() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("spring.datasource.type:" + HikariDataSource.class.getName(),
            "decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.max-overflow-pool-size:15",
            "decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.timeout-millis:500",
            "decorator.datasource.flexy-pool.acquiring-strategy.retry.attempts:5")
            .withUserConfiguration(HikariConfiguration.class);

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
        IncrementPoolOnTimeoutConnectionAcquiringStrategy<HikariDataSource> strategy1 =
                findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
        assertThat(strategy1).isNotNull();
        assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 35);
        assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 10000);

        RetryConnectionAcquiringStrategy<HikariDataSource> strategy2 =
                findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
        assertThat(strategy2).isNotNull();
        assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 5);
    });
}
 
Example 13
@Before
public void setUpPubSubResources() {
	this.topicName = "desafinado-" + UUID.randomUUID();
	this.subscriptionName = "doralice-" + UUID.randomUUID();

	if (pubSubAdmin.getTopic(this.topicName) == null) {
		pubSubAdmin.createTopic(this.topicName);
	}

	if (pubSubAdmin.getSubscription(this.subscriptionName) == null) {
		pubSubAdmin.createSubscription(this.subscriptionName, this.topicName, 10);
	}

	this.contextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					GcpContextAutoConfiguration.class,
					GcpPubSubAutoConfiguration.class))
			.withBean("topicName", String.class, this.topicName)
			.withBean("subscriptionName", String.class, this.subscriptionName);
}
 
Example 14
@Test
public void keepAliveValue_custom() {
	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class))
			.withUserConfiguration(TestConfig.class)
			.withPropertyValues("spring.cloud.gcp.pubsub.keepAliveIntervalMinutes=2");

	contextRunner.run(ctx -> {
		GcpPubSubProperties props = ctx.getBean(GcpPubSubProperties.class);
		assertThat(props.getKeepAliveIntervalMinutes()).isEqualTo(2);

		TransportChannelProvider tcp = ctx.getBean(TransportChannelProvider.class);
		assertThat(((InstantiatingGrpcChannelProvider) tcp).getKeepAliveTime().toMinutes())
				.isEqualTo(2);
	});
}
 
Example 15
Source Project: camel-spring-boot   Source File: DnsServiceDiscoveryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceDiscoveryDisabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.dns.service-discovery.enabled=false")
        .run(
            context -> {
                assertThat(context).doesNotHaveBean(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).doesNotContainKeys("dns-service-discovery");
            }
        );
}
 
Example 16
Source Project: camel-spring-boot   Source File: DnsServiceDiscoveryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceDiscoveryEnabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.dns.service-discovery.enabled=true")
        .run(
            context -> {
                assertThat(context).hasSingleBean(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("dns-service-discovery");
            }
        );
}
 
Example 17
@Test
public void testServiceDiscoveryDisabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=false")
        .run(
            context -> {
                assertThat(context).doesNotHaveBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).doesNotContainKeys("kubernetes-service-discovery");
            }
        );
}
 
Example 18
@Test
public void testServiceDiscoveryEnabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesEnvServiceDiscovery.class);
            }
        );
}
 
Example 19
@Test
public void testDisable() {
    new ApplicationContextRunner()
        .withConfiguration(AutoConfigurations.of(KubernetesClusterServiceAutoConfiguration.class))
        .withUserConfiguration(TestConfiguration.class)
        .run(
            context -> {
                assertThat(context).doesNotHaveBean(KubernetesClusterService.class);
            }
        );
}
 
Example 20
@Test
public void testClusterService() throws Exception {
    final int zkPort =  AvailablePortFinder.getNextAvailable();
    final File zkDir =  temporaryFolder.newFolder();

    final TestingServer zkServer = new TestingServer(zkPort, zkDir);
    zkServer.start();

    try {
        new ApplicationContextRunner()
            .withUserConfiguration(TestConfiguration.class)
            .withPropertyValues(
                "debug=false",
                "spring.main.banner-mode=OFF",
                "spring.application.name=" + UUID.randomUUID().toString(),
                "camel.component.zookeeper.cluster.service.enabled=true",
                "camel.component.zookeeper.cluster.service.nodes=localhost:" + zkPort,
                "camel.component.zookeeper.cluster.service.id=" + UUID.randomUUID().toString(),
                "camel.component.zookeeper.cluster.service.base-path=" + SERVICE_PATH)
            .run(
                context -> {
                    assertThat(context).hasSingleBean(CamelContext.class);
                    assertThat(context).hasSingleBean(CamelClusterService.class);

                    final CamelContext camelContext = context.getBean(CamelContext.class);
                    final CamelClusterService clusterService = camelContext.hasService(CamelClusterService.class);

                    assertThat(clusterService).isNotNull();
                    assertThat(clusterService).isInstanceOf(ZooKeeperClusterService.class);
                }
            );
    } finally {
        zkServer.stop();
    }
}
 
Example 21
@Test
public void testConsulServiceDiscoveryDisabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.consul.service-discovery.enabled=false")
        .run(
            context -> {
                assertThat(context).doesNotHaveBean(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).doesNotContainKeys("consul-service-discovery");
            }
        );
}
 
Example 22
@Test
public void testConsulServiceDiscoveryEnabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.consul.service-discovery.enabled=true")
        .run(
            context -> {
                assertThat(context).hasSingleBean(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("consul-service-discovery");
            }
        );
}
 
Example 23
Source Project: camel-spring-boot   Source File: RibbonLoadBalancerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadBalancer() throws Exception {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.consul.service-discovery.enabled=false",
            "debug=false",
            "camel.cloud.service-discovery.services[myService]=localhost:" + PORT1 + ",localhost:" + PORT2,
            "camel.cloud.ribbon.load-balancer.enabled=true")
        .run(
            context -> {
                final CamelContext camelContext = context.getBean(CamelContext.class);
                final ProducerTemplate template = camelContext.createProducerTemplate();

                DefaultServiceCallProcessor processor = findServiceCallProcessor(camelContext);
                assertThat(processor.getLoadBalancer()).isNotNull();
                assertThat(processor.getLoadBalancer()).isInstanceOf(RibbonServiceLoadBalancer.class);

                RibbonServiceLoadBalancer loadBalancer = (RibbonServiceLoadBalancer)processor.getLoadBalancer();
                assertThat(loadBalancer.getServiceDiscovery()).isInstanceOf(CamelCloudServiceDiscovery.class);
                assertThat(loadBalancer.getServiceFilter()).isInstanceOf(CamelCloudServiceFilter.class);

                assertThat(template.requestBody("direct:start", null, String.class)).isEqualTo("" + PORT2);
                assertThat(template.requestBody("direct:start", null, String.class)).isEqualTo("" + PORT1);
            }
        );
}
 
Example 24
@Test
public void testRibbonLoadBalancerDisabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.ribbon.load-balancer.enabled=false")
        .run(
            context -> {
                assertThat(context).doesNotHaveBean(RibbonServiceCallServiceLoadBalancerConfigurationProperties.class);
                assertThat(context).getBeans(ServiceLoadBalancer.class).doesNotContainKeys("ribbon-load-balancer");
            }
        );
}
 
Example 25
@Test
public void testRibbonLoadBalancerEnabled() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.ribbon.load-balancer.enabled=true")
        .run(
            context -> {
                assertThat(context).hasSingleBean(RibbonServiceCallServiceLoadBalancerConfigurationProperties.class);
                assertThat(context).getBeans(ServiceLoadBalancer.class).containsKeys("ribbon-load-balancer");
            }
        );
}
 
Example 26
@Test
public void testAutoConfiguration() {
    new ApplicationContextRunner()
        .withConfiguration(
            AutoConfigurations.of(
                CamelAutoConfiguration.class,
                CamelCloudAutoConfiguration.class,
                CamelSpringCloudServiceRegistryAutoConfiguration.class,
                CamelCloudNetflixServiceLoadBalancerAutoConfiguration.class,
                RibbonAutoConfiguration.class,
                RibbonClientConfiguration.class
            ))
        .withUserConfiguration(
            TestConfiguration.class)
        .withPropertyValues(
            "debug=true",
            "spring.main.banner-mode=off",
            "ribbon.client.name=test")
        .run(
            context -> {
                assertThat(context).hasSingleBean(LoadBalancerClient.class);
                assertThat(context).getBean(LoadBalancerClient.class).isInstanceOf(RibbonLoadBalancerClient.class);

                assertThat(context).hasSingleBean(CamelSpringCloudServiceLoadBalancer.LoadBalancerClientAdapter.class);

                LoadBalancerClient client = context.getBean(LoadBalancerClient.class);
                ServiceLoadBalancer balancer = context.getBean(CamelSpringCloudServiceLoadBalancer.LoadBalancerClientAdapter.class).adapt(client);

                assertThat(balancer).isInstanceOf(CamelCloudNetflixServiceLoadBalancer.class);
            }
        );
}
 
Example 27
@Test
public void testAutoConfiguration() {
    new ApplicationContextRunner()
        .withConfiguration(
            AutoConfigurations.of(
                CamelAutoConfiguration.class,
                CamelCloudAutoConfiguration.class,
                CamelSpringCloudServiceRegistryAutoConfiguration.class
            ))
        .withUserConfiguration(
            TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "ribbon.eureka.enabled=false",
            "ribbon.enabled=false")
        .run(
            context -> {
                // spring cloud registry
                assertThat(context).hasSingleBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class);
                assertThat(context).getBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class).isInstanceOf(MyServiceRegistry.class);

                // camel registry
                assertThat(context).hasSingleBean(org.apache.camel.cloud.ServiceRegistry.class);
                assertThat(context).getBean(org.apache.camel.cloud.ServiceRegistry.class).isInstanceOf(CamelSpringCloudServiceRegistry.class);

                assertThat(context).getBean(org.apache.camel.cloud.ServiceRegistry.class).hasFieldOrPropertyWithValue(
                    "nativeServiceRegistry",
                    context.getBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class)
                );
            }
        );
}
 
Example 28
@Test
public void testDisabledCamelCloud() {
    new ApplicationContextRunner()
        .withConfiguration(
            AutoConfigurations.of(
                CamelAutoConfiguration.class,
                CamelCloudAutoConfiguration.class,
                CamelSpringCloudServiceRegistryAutoConfiguration.class
            ))
        .withUserConfiguration(
            TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "ribbon.eureka.enabled=false",
            "ribbon.enabled=false",
            "camel.cloud.enabled=false")
        .run(
            context -> {
                // spring cloud registry
                assertThat(context).hasSingleBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class);
                assertThat(context).getBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class).isInstanceOf(MyServiceRegistry.class);

                // camel registry
                assertThat(context).doesNotHaveBean(org.apache.camel.cloud.ServiceRegistry.class);
            }
        );
}
 
Example 29
@Test
public void testDisabledCamelServiceRegistry() {
    new ApplicationContextRunner()
        .withConfiguration(
            AutoConfigurations.of(
                CamelAutoConfiguration.class,
                CamelCloudAutoConfiguration.class,
                CamelSpringCloudServiceRegistryAutoConfiguration.class
            ))
        .withUserConfiguration(
            TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "ribbon.eureka.enabled=false",
            "ribbon.enabled=false",
            "camel.cloud.enabled=true",
            "camel.cloud.service-registry.enabled=false")
        .run(
            context -> {
                // spring cloud registry
                assertThat(context).hasSingleBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class);
                assertThat(context).getBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class).isInstanceOf(MyServiceRegistry.class);

                // camel registry
                assertThat(context).doesNotHaveBean(org.apache.camel.cloud.ServiceRegistry.class);
            }
        );
}
 
Example 30
@Test
public void testEnabledCamelServiceRegistry() {
    new ApplicationContextRunner()
        .withConfiguration(
            AutoConfigurations.of(
                CamelAutoConfiguration.class,
                CamelCloudAutoConfiguration.class,
                CamelSpringCloudServiceRegistryAutoConfiguration.class
            ))
        .withUserConfiguration(
            TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "ribbon.eureka.enabled=false",
            "ribbon.enabled=false",
            "camel.cloud.enabled=false",
            "camel.cloud.service-registry.enabled=true")
        .run(
            context -> {
                // spring cloud registry
                assertThat(context).hasSingleBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class);
                assertThat(context).getBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class).isInstanceOf(MyServiceRegistry.class);

                // camel registry
                assertThat(context).hasSingleBean(org.apache.camel.cloud.ServiceRegistry.class);
                assertThat(context).getBean(org.apache.camel.cloud.ServiceRegistry.class).isInstanceOf(CamelSpringCloudServiceRegistry.class);

                assertThat(context).getBean(org.apache.camel.cloud.ServiceRegistry.class).hasFieldOrPropertyWithValue(
                    "nativeServiceRegistry",
                    context.getBean(org.springframework.cloud.client.serviceregistry.ServiceRegistry.class)
                );
            }
        );
}