Java Code Examples for org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration

The following examples show how to use org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration. 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 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 2
@Test public void query_canDisable() {
  addEnvironment(context, "zipkin.query.enabled:false");
  context.register(
    PropertyPlaceholderAutoConfiguration.class,
    ZipkinServerConfigurationTest.Config.class,
    ZipkinServerConfiguration.class,
    ZipkinQueryApiV2.class
  );
  context.refresh();

  try {
    context.getBean(ZipkinQueryApiV2.class);
    failBecauseExceptionWasNotThrown(NoSuchBeanDefinitionException.class);
  } catch (NoSuchBeanDefinitionException e) {
  }
}
 
Example 3
@Test
public void testConfiguration() {

	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
					EmbeddedDataSourceConfiguration.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 4
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 5
@Test
public void testZeroCustomTransactionManagerConfiguration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							SimpleTaskAutoConfiguration.class,
							ZeroTransactionManagerConfiguration.class))
			.withPropertyValues("application.name=transactionManagerTask");

	applicationContextRunner.run((context) -> {
		DataSource dataSource = context.getBean("dataSource", DataSource.class);

		int taskExecutionCount = JdbcTestUtils
				.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");

		assertThat(taskExecutionCount).isEqualTo(1);
	});
}
 
Example 6
/**
 * Verify that the verifyEnvironment method skips DataSource Proxy Beans when
 * determining the number of available dataSources.
 */
@Test
public void testWithDataSourceProxy() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(DataSourceProxyConfiguration.class);
	applicationContextRunner.run((context) -> {
		assertThat(context.getBeanNamesForType(DataSource.class).length).isEqualTo(2);
		SimpleTaskAutoConfiguration taskConfiguration = context
				.getBean(SimpleTaskAutoConfiguration.class);
		assertThat(taskConfiguration).isNotNull();
		assertThat(taskConfiguration.taskExplorer()).isNotNull();
	});
}
 
Example 7
@Test
public void providesCollectorComponent_whenKafkaZookeeperSet() {
  addEnvironment(context,
      "zipkin.sparkstreaming.stream.kafka.zookeeper.connect:" + KAFKA_ZOOKEEPER
  );
  context.register(
      PropertyPlaceholderAutoConfiguration.class,
      ZipkinKafkaStreamFactoryAutoConfiguration.class
  );
  context.refresh();

  ZipkinKafkaStreamFactoryProperties props =
      context.getBean(ZipkinKafkaStreamFactoryProperties.class);
  assertThat(props.getZookeeper().getConnect())
      .isEqualTo(KAFKA_ZOOKEEPER);
}
 
Example 8
Source Project: zipkin-aws   Source File: ZipkinSQSCollectorModuleTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void provideCollectorComponent_setsZipkinSqsCollectorProperties() {
  context = new AnnotationConfigApplicationContext();
  TestPropertyValues.of(
      "zipkin.collector.sqs.queue-url:" + sqsRule.queueUrl(),
      "zipkin.collector.sqs.wait-time-seconds:1",
      "zipkin.collector.sqs.parallelism:3",
      "zipkin.collector.sqs.aws-access-key-id: x",
      "zipkin.collector.sqs.aws-secret-access-key: x")
      .applyTo(context);
  context.register(
      PropertyPlaceholderAutoConfiguration.class,
      Region.class,
      ZipkinSQSCollectorModule.class,
      ZipkinSQSCredentialsConfiguration.class,
      InMemoryConfiguration.class);
  context.refresh();

  ZipkinSQSCollectorProperties properties = context.getBean(ZipkinSQSCollectorProperties.class);

  assertThat(properties.getQueueUrl()).isEqualTo(sqsRule.queueUrl());
  assertThat(properties.getWaitTimeSeconds()).isEqualTo(1);
  assertThat(properties.getParallelism()).isEqualTo(3);
}
 
Example 9
private void setup(String... env) {
	AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
	TestPropertyValues.of(env).applyTo(parent);
	parent.register(UtilAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, EnvironmentKnobbler.class,
			ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration.class,
			DiscoveryClientConfigServiceBootstrapConfiguration.class,
			ConfigClientProperties.class);
	parent.refresh();
	this.context = new AnnotationConfigApplicationContext();
	this.context.setParent(parent);
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			ZookeeperConfigServerAutoConfiguration.class,
			ZookeeperAutoConfiguration.class,
			ZookeeperDiscoveryClientConfiguration.class);
	this.context.refresh();
}
 
Example 10
@Test
public void testAutoConfigurationDisabled() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
	Executable executable = () -> {
		applicationContextRunner.run((context) -> {
			context.getBean(TaskRepository.class);
		});
	};
	verifyExceptionThrown(NoSuchBeanDefinitionException.class, "No qualifying "
			+ "bean of type 'org.springframework.cloud.task.repository.TaskRepository' "
			+ "available", executable);
}
 
Example 11
@Test
public void kinesisCollectorConfiguredWithCorrectRegion() {
  TestPropertyValues.of(
      "zipkin.collector.kinesis.stream-name: zipkin-test",
      "zipkin.collector.kinesis.app-name: zipkin",
      "zipkin.collector.kinesis.aws-sts-region: us-east-1",
      "zipkin.collector.kinesis.aws-kinesis-region: us-east-1",
      "zipkin.collector.kinesis.aws-access-key-id: x",
      "zipkin.collector.kinesis.aws-secret-access-key: x",
      "zipkin.collector.kinesis.aws-sts-role-arn: test")
      .applyTo(context);

  context.register(
      PropertyPlaceholderAutoConfiguration.class,
      ZipkinKinesisCollectorModule.class,
      ZipkinKinesisCredentialsConfiguration.class,
      InMemoryConfiguration.class);
  context.refresh();

  KinesisCollector collector = context.getBean(KinesisCollector.class);

  assertThat(collector)
      .extracting("regionName")
      .as("Kinesis region is set from zipkin.collector.kinesis.aws-kinesis-region")
      .isEqualTo("us-east-1");
}
 
Example 12
@Test
public void encoderDirectsEndpoint() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.zipkin.base-url",
			this.server.url("/").toString());
	environment().setProperty("spring.zipkin.encoder", "JSON_V1");
	this.context.register(ZipkinAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
			Config.class);
	this.context.refresh();
	Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
			.tag("foo", "bar").start();

	span.finish();

	Awaitility.await().untilAsserted(
			() -> then(this.server.getRequestCount()).isGreaterThan(0));
	// first request is for health check
	this.server.takeRequest();
	// second request is the span one
	RecordedRequest request = this.server.takeRequest();
	then(request.getPath()).isEqualTo("/api/v1/spans");
	then(request.getBody().readUtf8()).contains("binaryAnnotations");
}
 
Example 13
@Test
public void overrideActiveMqQueue() throws Exception {
	this.context = new AnnotationConfigApplicationContext();
	environment().setProperty("spring.jms.cache.enabled", "false");
	environment().setProperty("spring.zipkin.activemq.queue", "zipkin2");
	environment().setProperty("spring.zipkin.activemq.message-max-bytes", "50");
	environment().setProperty("spring.zipkin.sender.type", "activemq");
	this.context.register(PropertyPlaceholderAutoConfiguration.class,
			ActiveMQAutoConfiguration.class, ZipkinAutoConfiguration.class,
			TraceAutoConfiguration.class);
	this.context.refresh();

	then(this.context.getBean(Sender.class)).isInstanceOf(ActiveMQSender.class);

	this.context.close();
}
 
Example 14
@Test
public void echoEndpoint() {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
        PropertyPlaceholderAutoConfiguration.class)
        .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket")
        .run("--spring.main.web-application-type=none");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();
    assertThat(count).isEqualTo(0);
    assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?");
}
 
Example 15
@Test
public void reverseEndpoint() {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
        PropertyPlaceholderAutoConfiguration.class)
        .properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
        .run("--spring.main.web-application-type=none");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();
    assertThat(count).isEqualTo(0);
    assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
}
 
Example 16
private void testConfiguration(Class configurationClass) {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							SimpleTaskAutoConfiguration.class, configurationClass))
			.withPropertyValues("application.name=transactionManagerTask");

	applicationContextRunner.run((context) -> {
		DataSource dataSource = context.getBean("dataSource", DataSource.class);

		int taskExecutionCount = JdbcTestUtils
				.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");

		// Verify that the create call was rolled back
		assertThat(taskExecutionCount).isEqualTo(0);

		// Execute a new create call so that things close cleanly
		TaskRepository taskRepository = context.getBean("taskRepository",
				TaskRepository.class);

		TaskExecution taskExecution = taskRepository
				.createTaskExecution("transactionManagerTask");
		taskExecution = taskRepository.startTaskExecution(
				taskExecution.getExecutionId(), taskExecution.getTaskName(),
				new Date(), new ArrayList<>(0), null);

		TaskLifecycleListener listener = context.getBean(TaskLifecycleListener.class);

		ReflectionTestUtils.setField(listener, "taskExecution", taskExecution);
	});
}
 
Example 17
@Test
public void reverseEndpoint() {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
        PropertyPlaceholderAutoConfiguration.class)
        .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse")
        .run("--spring.main.web-application-type=none");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();
    assertThat(count).isEqualTo(0);
    assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
}
 
Example 18
@Test public void httpCollector_enabledByDefault() {
  context.register(
    PropertyPlaceholderAutoConfiguration.class,
    ZipkinServerConfigurationTest.Config.class,
    ZipkinServerConfiguration.class,
    ZipkinHttpCollector.class
  );
  context.refresh();

  assertThat(context.getBean(ZipkinHttpCollector.class)).isNotNull();
}
 
Example 19
@Test
public void testFieldExtractorFileGeneration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withUserConfiguration(FieldExtractorConfiguration.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.delimited=true");

	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("f\nb\nb\n");
	});
}
 
Example 20
@Test public void query_enabledByDefault() {
  context.register(
    PropertyPlaceholderAutoConfiguration.class,
    ZipkinServerConfigurationTest.Config.class,
    ZipkinServerConfiguration.class,
    ZipkinQueryApiV2.class
  );
  context.refresh();

  assertThat(context.getBean(ZipkinQueryApiV2.class)).isNotNull();
}
 
Example 21
@Test public void selfTracing_canEnable() {
  addEnvironment(context, "zipkin.self-tracing.enabled:true");
  context.register(
    PropertyPlaceholderAutoConfiguration.class,
    ZipkinServerConfigurationTest.Config.class,
    ZipkinServerConfiguration.class,
    TracingConfiguration.class
  );
  context.refresh();

  context.getBean(Tracing.class).close();
}
 
Example 22
@Test public void search_canDisable() {
  addEnvironment(context, "zipkin.storage.search-enabled:false");
  context.register(
    PropertyPlaceholderAutoConfiguration.class,
    ZipkinServerConfigurationTest.Config.class,
    ZipkinServerConfiguration.class
  );
  context.refresh();

  StorageComponent v2Storage = context.getBean(StorageComponent.class);
  assertThat(v2Storage)
    .extracting("searchEnabled")
    .containsExactly(false);
}
 
Example 23
private void setupContextForGraph(String[] args) {
	this.applicationContext = SpringApplication.run(new Class[]{ComposedRunnerVisitorConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			BatchAutoConfiguration.class,
			TaskBatchAutoConfiguration.class,
			SimpleTaskAutoConfiguration.class}, args);
}
 
Example 24
@Test
public void providesSparkStreaming() throws IOException {
  context.register(PropertyPlaceholderAutoConfiguration.class,
      DummyConfiguration.class,
      ZipkinSparkStreamingConfiguration.class);
  context.refresh();

  job = context.getBean(SparkStreamingJob.class);
  assertThat(job).isNotNull();
}
 
Example 25
@Test
public void providesAdjusters() throws IOException {
  context.register(PropertyPlaceholderAutoConfiguration.class,
      DummyConfiguration.class,
      AdjusterConfiguration.class,
      ZipkinSparkStreamingConfiguration.class);
  context.refresh();

  job = context.getBean(SparkStreamingJob.class);
  assertThat(job).isNotNull();
  assertThat(job.adjusters())
      .contains(AdjusterConfiguration.one, AdjusterConfiguration.two);
}
 
Example 26
@Test
public void defaultConf() {
  context.register(PropertyPlaceholderAutoConfiguration.class,
      DummyConfiguration.class,
      AdjusterConfiguration.class,
      ZipkinSparkStreamingConfiguration.class);
  context.refresh();

  job = context.getBean(SparkStreamingJob.class);
  assertThat(job.conf()).containsExactly(
      entry("spark.ui.enabled", "false")
  );
}
 
Example 27
@Test
public void canOverrideConf() {
  addEnvironment(context,
      "zipkin.sparkstreaming.conf.spark.ui.enabled:" + true);
  context.register(PropertyPlaceholderAutoConfiguration.class,
      DummyConfiguration.class,
      AdjusterConfiguration.class,
      ZipkinSparkStreamingConfiguration.class);
  context.refresh();

  job = context.getBean(SparkStreamingJob.class);
  assertThat(job.conf()).containsEntry(
      "spark.ui.enabled", "true"
  );
}
 
Example 28
@Test(expected = BeanCreationException.class)
public void testMultipleDataSourcesContext() {
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(SimpleTaskAutoConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	DataSource dataSource = mock(DataSource.class);
	this.context.getBeanFactory().registerSingleton("mockDataSource", dataSource);
	this.context.refresh();
}
 
Example 29
@Test
public void canOverrideJars() {
  addEnvironment(context,
      "zipkin.sparkstreaming.jars:foo.jar,bar.jar");
  context.register(PropertyPlaceholderAutoConfiguration.class,
      DummyConfiguration.class,
      AdjusterConfiguration.class,
      ZipkinSparkStreamingConfiguration.class);
  context.refresh();

  job = context.getBean(SparkStreamingJob.class);
  assertThat(job.jars()).containsExactly(
      "foo.jar", "bar.jar"
  );
}
 
Example 30
@Test
public void doesntProvideAdjusterWhenDisabled() {
  context.register(PropertyPlaceholderAutoConfiguration.class,
      ZipkinFinagleAdjusterProperties.class,
      ZipkinFinagleAdjusterAutoConfiguration.class);
  context.refresh();

  thrown.expect(NoSuchBeanDefinitionException.class);
  context.getBean(FinagleAdjuster.class);
}