Java Code Examples for org.springframework.boot.autoconfigure.AutoConfigurations

The following examples show how to use org.springframework.boot.autoconfigure.AutoConfigurations. 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
Source Project: spring-cloud-task   Source File: TaskEventTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultConfiguration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					TaskEventAutoConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					TestSupportBinderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
					BindingServiceConfiguration.class))
			.withUserConfiguration(TaskEventsConfiguration.class)
			.withPropertyValues("spring.cloud.task.closecontext_enabled=false",
					"spring.main.web-environment=false");
	applicationContextRunner.run((context) -> {
		assertThat(context.getBean("taskEventListener")).isNotNull();
		assertThat(
				context.getBean(TaskEventAutoConfiguration.TaskEventChannels.class))
						.isNotNull();
	});
}
 
Example 2
@Test
public void testRepositoryNotInitialized() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
			.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");

	verifyExceptionThrownDefaultExecutable(ApplicationContextException.class,
			"Failed to start " + "bean 'taskLifecycleListener'; nested exception is "
					+ "org.springframework.dao.DataAccessResourceFailureException: "
					+ "Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: "
					+ "Syntax error in SQL statement \"SELECT FOOBARLESSSEQ.NEXTVAL FROM[*] DUAL\"; "
					+ "expected \"identifier\"; SQL statement:\n"
					+ "select foobarlessSEQ.nextval from dual [42001-200]",
			applicationContextRunner);
}
 
Example 3
@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 4
@Test
public void testMultipleDataSources() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(MultipleDataSources.class);

	verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
			"Error creating bean "
					+ "with name 'simpleTaskAutoConfiguration': Invocation of init method "
					+ "failed; nested exception is java.lang.IllegalStateException: To use "
					+ "the default TaskConfigurer the context must contain no more than "
					+ "one DataSource, found 2",
			applicationContextRunner);

}
 
Example 5
@Test
public void testConfiguration() {

	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
	applicationContextRunner.run((context) -> {
		SingleInstanceTaskListener singleInstanceTaskListener = context
				.getBean(SingleInstanceTaskListener.class);

		assertThat(singleInstanceTaskListener)
				.as("singleInstanceTaskListener should not be null").isNotNull();

		assertThat(SingleInstanceTaskListener.class)
				.isEqualTo(singleInstanceTaskListener.getClass());
	});
}
 
Example 6
@Test
public void test() {
	contextRunner
			.withConfiguration(
					AutoConfigurations.of(GatewayMetricsAutoConfiguration.class))
			.withPropertyValues("spring.cloud.gateway.metrics.tags.foo1=bar1",
					"spring.cloud.gateway.metrics.tags.foo2=bar2")
			.run(context -> {
				PropertiesTagsProvider provider = context
						.getBean(PropertiesTagsProvider.class);
				Tags tags = provider.apply(MockServerWebExchange
						.from(MockServerHttpRequest.get("").build()));
				assertThat(tags).isEqualTo(Tags.of("foo1", "bar1", "foo2", "bar2"));
			});

}
 
Example 7
@Test
public void nettyHttpClientDefaults() {
	new ReactiveWebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class,
					MetricsAutoConfiguration.class,
					SimpleMetricsExportAutoConfiguration.class,
					GatewayAutoConfiguration.class))
			.withPropertyValues("debug=true").run(context -> {
				assertThat(context).hasSingleBean(HttpClient.class);
				assertThat(context).hasBean("gatewayHttpClient");
				HttpClient httpClient = context.getBean(HttpClient.class);
				/*
				 * FIXME: 2.1.0 HttpClientOptions options = httpClient.options();
				 *
				 * PoolResources poolResources = options.getPoolResources();
				 * assertThat(poolResources).isNotNull(); //TODO: howto test
				 * PoolResources
				 *
				 * ClientProxyOptions proxyOptions = options.getProxyOptions();
				 * assertThat(proxyOptions).isNull();
				 *
				 * SslContext sslContext = options.sslContext();
				 * assertThat(sslContext).isNull();
				 */
			});
}
 
Example 8
@Test
public void appEngineWithProcessEngineAndTaskIdGenerator() {
    contextRunner.withUserConfiguration(CustomIdGeneratorConfiguration.class
    ).withConfiguration(AutoConfigurations.of(
        ProcessEngineServicesAutoConfiguration.class,
        ProcessEngineAutoConfiguration.class
    )).run(context -> {
        ProcessEngine processEngine = context.getBean(ProcessEngine.class);
        ProcessEngineConfiguration processEngineConfiguration = processEngine.getProcessEngineConfiguration();
        assertThat(processEngineConfiguration.getIdGenerator().getNextId()).as("Process id generator must be DB id generator").doesNotContain("-");
        
        AppEngine appEngine = context.getBean(AppEngine.class);
        deleteDeployments(appEngine);
        deleteDeployments(processEngine);
    });
}
 
Example 9
Source Project: spring-cloud-task   Source File: TaskEventTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskEventListener() throws Exception {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(TaskEventAutoConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					RabbitServiceAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class,
					BindingServiceConfiguration.class))
			.withUserConfiguration(TaskEventsConfiguration.class)
			.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
					"--spring.cloud.task.name=" + TASK_NAME,
					"--spring.main.web-environment=false",
					"--spring.cloud.stream.defaultBinder=rabbit",
					"--spring.cloud.stream.bindings.task-events.destination=test");
	applicationContextRunner.run((context) -> {
		assertThat(context.getBean("taskEventListener")).isNotNull();
		assertThat(
				context.getBean(TaskEventAutoConfiguration.TaskEventChannels.class))
						.isNotNull();
	});
	assertThat(latch.await(1, TimeUnit.SECONDS)).isTrue();
}
 
Example 10
@Test
public void testDisable() {
    new ApplicationContextRunner()
        .withConfiguration(AutoConfigurations.of(KubernetesClusterServiceAutoConfiguration.class))
        .withUserConfiguration(TestConfiguration.class)
        .run(
            context -> {
                assertThat(context).doesNotHaveBean(KubernetesClusterService.class);
            }
        );
}
 
Example 11
@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 12
@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 13
@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 14
@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)
                );
            }
        );
}
 
Example 15
@Test
public void should_not_create_listener_when_scheduler_bean_is_not_present() {
	new ApplicationContextRunner().withConfiguration(AutoConfigurations
			// given
			.of(TracingConfig.class, TraceQuartzAutoConfiguration.class))

			// when
			.run(context -> {
				// expect
				assertThat(context).doesNotHaveBean(TracingJobListener.class);
			});
}
 
Example 16
@Test
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());
                                   
            }
        );
}
 
Example 17
@Before
public void setUp() {
	contextRunner = new WebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class,
					HttpMessageConvertersAutoConfiguration.class,
					HypermediaAutoConfiguration.class,
					RepositoryRestMvcAutoConfiguration.class,
					FeignHalAutoConfiguration.class))
			.withPropertyValues("debug=true");
}
 
Example 18
@Test
public void testFormattedFieldExtractorFileGeneration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withUserConfiguration(FormattedFieldExtractorJobConfiguration.class)
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							BatchAutoConfiguration.class,
							SingleStepJobAutoConfiguration.class,
							FlatFileItemWriterAutoConfiguration.class))
			.withPropertyValues("spring.batch.job.jobName=job",
					"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
					"spring.batch.job.flatfilewriter.name=fooWriter",
					String.format(
							"spring.batch.job.flatfilewriter.resource=file://%s",
							this.outputFile.getAbsolutePath()),
					"spring.batch.job.flatfilewriter.encoding=UTF-8",
					"spring.batch.job.flatfilewriter.formatted=true",
					"spring.batch.job.flatfilewriter.names=item",
					"spring.batch.job.flatfilewriter.format=item = %s");

	applicationContextRunner.run((context) -> {
		JobLauncher jobLauncher = context.getBean(JobLauncher.class);

		Job job = context.getBean(Job.class);

		JobExecution jobExecution = jobLauncher.run(job, new JobParameters());

		JobExplorer jobExplorer = context.getBean(JobExplorer.class);

		while (jobExplorer.getJobExecution(jobExecution.getJobId()).isRunning()) {
			Thread.sleep(1000);
		}

		AssertFile.assertLineCount(3, this.outputFile);

		String results = FileCopyUtils.copyToString(new InputStreamReader(
				new FileSystemResource(this.outputFile).getInputStream()));
		assertThat(results).isEqualTo("item = f\nitem = b\nitem = b\n");
	});
}
 
Example 19
@Test
public void autoConfigurationDisabledWhenNoMockWebServerRunning() {
	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(XsuaaAutoConfiguration.class, XsuaaMockAutoConfiguration.class));

	contextRunner.withPropertyValues("spring.xsuaa.mock.auto:false").run((context) -> {
		assertThat(context.containsBean("xsuaaMockServiceConfiguration"), is(false));
		assertThat(context.getBean(XsuaaServiceConfiguration.class),
				instanceOf(XsuaaServiceConfigurationDefault.class));
	});
}
 
Example 20
@Test
public void autoConfigurationSkipped_without_RestOperations() {
	new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(XsuaaTokenFlowAutoConfiguration.class))
			.run((context) -> {
				assertThat(context).doesNotHaveBean("xsuaaTokenFlows");
			});
}
 
Example 21
@Before
public void setup() {
	contextRunner = new WebApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(XsuaaResourceServerJwkAutoConfiguration.class,
							XsuaaAutoConfiguration.class));
}
 
Example 22
@Test
public void autoConfigurationDisabledWhenSpringReactorIsActive() {
	ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(XsuaaResourceServerJwkAutoConfiguration.class,
							XsuaaAutoConfiguration.class));

	contextRunner.run((context) -> {
		assertThat(context.containsBean("xsuaaJwtDecoder"), is(false));
	});
}
 
Example 23
@Test
public void createsTracingPostProcessor() {
  final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
      .withPropertyValues("spring.data.mongodb.port=27017") // Otherwise a random embedded mongo port is used
      .withConfiguration(UserConfigurations.of(TracerConfig.class, MongoConfig.class))
      .withConfiguration(AutoConfigurations.of(
          MongoTracingAutoConfiguration.class,
          EmbeddedMongoAutoConfiguration.class
      ));

  contextRunner.run(context -> Assertions.assertThat(context).hasSingleBean(TracingMongoClientPostProcessor.class));
}
 
Example 24
@Before
public void setUp() {
	contextRunner = new WebApplicationContextRunner()
			.withPropertyValues("eureka.client.serviceUrl.defaultZone=" + ZONE_URI,
					"vcap.application.uris[0]=" + HOSTNAME, "vcap.application.instance_id=" + INSTANCE_ID,
					"vcap.application.application_id=" + INSTANCE_GUID, "cf.instance.index=" + INSTANCE_INDEX,
					"cf.instance.internal.ip=" + IP, "port=" + PORT)
			.withConfiguration(AutoConfigurations.of(EurekaInstanceAutoConfiguration.class));
}
 
Example 25
@Test
public void createsTracingPostProcessorWhenAutoConfigured() {
  final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
      .withPropertyValues("spring.data.mongodb.port=27017") // Otherwise a random embedded mongo port is used
      .withConfiguration(AutoConfigurations.of(
          MongoTracingAutoConfiguration.class,
          TracerAutoConfiguration.class,
          MongoAutoConfiguration.class,
          EmbeddedMongoAutoConfiguration.class
      ));

  contextRunner.run(context -> Assertions.assertThat(context).hasSingleBean(TracingMongoClientPostProcessor.class));
}
 
Example 26
@Test
public void oauth2ContextConfiguredWithWebApp() {
	new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(this.configurations))
			.withPropertyValues(this.oAuth2ClientProperties).run((context) -> {
				assertServletOAuth2ContextConfigured(context);
				assertReactiveOAuth2ContextConfigured(context);
			});
}
 
Example 27
@Test
public void oauth2ContextConfiguredWithReactiveWebApp() {
	new ReactiveWebApplicationContextRunner().withConfiguration(AutoConfigurations.of(this.configurations))
			.withPropertyValues(this.oAuth2ClientProperties).run((context) -> {
				assertServletOAuth2ContextConfigured(context);
				assertReactiveOAuth2ContextConfigured(context);
			});
}
 
Example 28
@Test
public void oauth2ContextConfiguredWithReactiveWebAppNoServlet() {
	new ReactiveWebApplicationContextRunner().withClassLoader(new FilteredClassLoader("javax.servlet"))
			.withConfiguration(AutoConfigurations.of(this.configurations))
			.withPropertyValues(this.oAuth2ClientProperties).run((context) -> {
				assertServletOAuth2ContextNotConfigured(context);
				assertReactiveOAuth2ContextConfigured(context);
			});
}
 
Example 29
@Test
public void autoConfiguredWithCustomProperties() {
	this.context.withConfiguration(AutoConfigurations.of(CustomPropertiesConfiguration.class))
			.withPropertyValues("my.custom.credhub.url=https://localhost",
					"my.custom.credhub.oauth2.registration-id=test-client",
					"my.custom.credhub.connection-timeout=30", "my.custom.credhub.read-timeout=60")
			.run(this::assertPropertiesConfigured);
}
 
Example 30
@Test
public void reactiveFactoryAutoconfiguredByDefault() {

	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(TestConfig.class));
	contextRunner.run(ctx -> {
		assertThat(ctx.containsBean("pubSubReactiveFactory")).isTrue();
	});
}