org.springframework.boot.autoconfigure.AutoConfigurations Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.AutoConfigurations. 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 File: GatewayAutoConfigurationTests.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: PropertiesTagsProviderTests.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: TaskEventTests.java    From spring-cloud-task with 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 #4
Source File: SimpleSingleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: TaskEventTests.java    From spring-cloud-task with 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 #7
Source File: AppEngineAutoConfigurationTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: GcpPubSubAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: RefreshScopedAutoConfigurationTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void refreshScopedTimeLimiterRegistry() {
    contextRunner
        .withConfiguration(AutoConfigurations.of(
            RefreshScopedTimeLimiterAutoConfiguration.class, TimeLimiterAutoConfiguration.class))
        .run(context -> testRefreshScoped(context, "timeLimiterRegistry"));
}
 
Example #11
Source File: StackdriverLoggingAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonWebAppConfiguration() {
	new ApplicationContextRunner().withConfiguration(
			AutoConfigurations.of(
					StackdriverLoggingAutoConfiguration.class,
					GcpContextAutoConfiguration.class))
			.run((context) -> assertThat(context
					.getBeansOfType(TraceIdLoggingWebMvcInterceptor.class).size())
							.isEqualTo(0));
}
 
Example #12
Source File: EventRegistryAutoConfigurationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void eventRegistryWithKafka() {
    contextRunner
        .withConfiguration(AutoConfigurations.of(KafkaAutoConfiguration.class))
        .run(context -> {
            assertThat(context)
                .hasSingleBean(KafkaChannelDefinitionProcessor.class)
                .hasBean("kafkaChannelDefinitionProcessor");
            EventRegistryEngine eventRegistryEngine = context.getBean(EventRegistryEngine.class);
            assertThat(eventRegistryEngine).as("Event registry engine").isNotNull();

            IterableAssert<ChannelModelProcessor> channelModelProcessorAssert = assertThat(
                eventRegistryEngine.getEventRegistryEngineConfiguration().getChannelModelProcessors());

            channelModelProcessorAssert
                .hasSize(5);

            channelModelProcessorAssert
                .element(0)
                .isEqualTo(context.getBean("kafkaChannelDefinitionProcessor", ChannelModelProcessor.class));

            channelModelProcessorAssert
                .element(1)
                .isInstanceOf(DelegateExpressionInboundChannelModelProcessor.class);

            channelModelProcessorAssert
                .element(2)
                .isInstanceOf(DelegateExpressionOutboundChannelModelProcessor.class);

            channelModelProcessorAssert
                .element(3)
                .isInstanceOf(InboundChannelModelProcessor.class);

            channelModelProcessorAssert
                .element(4)
                .isInstanceOf(OutboundChannelModelProcessor.class);
        });
}
 
Example #13
Source File: RefreshScopedAutoConfigurationTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void refreshScopedCircuitBreakerRegistry() {
    contextRunner
        .withConfiguration(AutoConfigurations.of(
            RefreshScopedCircuitBreakerAutoConfiguration.class,
            CircuitBreakerAutoConfiguration.class))
        .run(context -> testRefreshScoped(context, "circuitBreakerRegistry"));
}
 
Example #14
Source File: FlowableJpaAutoConfigurationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void withEntityManagerFactoryBeanAndMissingSpringProcessEngineConfigurationClass() {
    contextRunner
        .withConfiguration(AutoConfigurations.of(
            DataSourceAutoConfiguration.class,
            HibernateJpaAutoConfiguration.class
        ))
        .withClassLoader(new FilteredClassLoader(SpringProcessEngineConfiguration.class))
        .run(context -> {
            assertThat(context).doesNotHaveBean(FlowableJpaAutoConfiguration.class);
        });
}
 
Example #15
Source File: SpringSessionFixAutoConfigurationTest.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Test
void withSessionRepository() {
	this.contextRunner.withConfiguration(AutoConfigurations.of(SpringSessionFixAutoConfiguration.class))
		.withUserConfiguration(Config.class)
		.run(context -> {
			assertThat(context).hasBean("springSessionFixFilterRegistrationBean");
		});
}
 
Example #16
Source File: GcpPubSubReactiveAutoConfigurationTest.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultSchedulerUsedWhenNoneProvided() {
	setUpThreadPrefixVerification("parallel");

	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withBean(PubSubSubscriberOperations.class, () -> mockSubscriberTemplate)
			.withConfiguration(AutoConfigurations.of(GcpPubSubReactiveAutoConfiguration.class));

	contextRunner.run(this::pollAndVerify);
}
 
Example #17
Source File: GcpDatastoreAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserDatastoreBeanNamespace() {
	ApplicationContextRunner runner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(GcpDatastoreAutoConfiguration.class,
					GcpContextAutoConfiguration.class))
			.withUserConfiguration(TestConfigurationWithDatastoreBeanNamespaceProvider.class)
			.withPropertyValues("spring.cloud.gcp.datastore.project-id=test-project",
					"spring.cloud.gcp.datastore.namespace=testNamespace",
					"spring.cloud.gcp.datastore.host=localhost:8081",
					"management.health.datastore.enabled=false");

	this.expectedException.expectMessage("failed to start");
	runner.run(context -> getDatastoreBean(context));
}
 
Example #18
Source File: FlatFileItemWriterAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: GcpDatastoreAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserDatastoreBean() {
	ApplicationContextRunner runner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(GcpDatastoreAutoConfiguration.class))
			.withUserConfiguration(TestConfigurationWithDatastoreBean.class)
			.withPropertyValues("spring.cloud.gcp.datastore.project-id=test-project",
					"spring.cloud.gcp.datastore.namespace=testNamespace",
					"spring.cloud.gcp.datastore.host=localhost:8081",
					"management.health.datastore.enabled=false");

	runner.run(context -> {
		assertThat(getDatastoreBean(context))
				.isSameAs(MOCK_CLIENT);
	});
}
 
Example #20
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepositoryInitialized() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
	applicationContextRunner.run((context) -> {
		TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
		assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1L);
	});
}
 
Example #21
Source File: SpringSessionFixAutoConfigurationTest.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Test
void noSessionRepository() {
	this.contextRunner.withConfiguration(AutoConfigurations.of(SpringSessionFixAutoConfiguration.class))
		.run(context -> {
			assertThat(context).doesNotHaveBean("springSessionFixFilterRegistrationBean");
		});
}
 
Example #22
Source File: StackdriverLoggingAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSleuth() {
	this.contextRunner
			.withConfiguration(AutoConfigurations.of(StackdriverTraceAutoConfiguration.class,
					TraceAutoConfiguration.class))
			.withUserConfiguration(Configuration.class)
			.withPropertyValues("spring.cloud.gcp.project-id=pop-1")
			.run((context) -> assertThat(context
					.getBeansOfType(TraceIdLoggingWebMvcInterceptor.class).size())
							.isEqualTo(0));
}
 
Example #23
Source File: FlatFileItemWriterAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomLineAggregatorFileGeneration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withUserConfiguration(LineAggregatorConfiguration.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");

	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=foo}\n{item=bar}\n{item=baz}\n");
	});
}
 
Example #24
Source File: GcpDatastoreEmulatorAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testDisabledAutoEmulator() {
	new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					GcpDatastoreEmulatorAutoConfiguration.class))
			.run((context) -> assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
					.isThrownBy(() -> context.getBean(LocalDatastoreHelper.class)));
}
 
Example #25
Source File: GcpPubSubAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void healthIndicatorPresent() {
	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(PubSubHealthIndicatorAutoConfiguration.class,
					GcpPubSubAutoConfiguration.class))
			.withUserConfiguration(TestConfig.class)
			.withPropertyValues("spring.cloud.gcp.datastore.project-id=test-project",
					"management.health.pubsub.enabled=true");
	contextRunner.run(ctx -> {
		PubSubHealthIndicator healthIndicator = ctx.getBean(PubSubHealthIndicator.class);
		assertThat(healthIndicator).isNotNull();
	});
}
 
Example #26
Source File: GcpPubSubAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void keepAliveValue_default() {
	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class))
			.withUserConfiguration(TestConfig.class);

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

		TransportChannelProvider tcp = ctx.getBean(TransportChannelProvider.class);
		assertThat(((InstantiatingGrpcChannelProvider) tcp).getKeepAliveTime().toMinutes())
				.isEqualTo(5);
	});
}
 
Example #27
Source File: RefreshScopedAutoConfigurationTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void refreshScopedBulkheadRegistry() {
    contextRunner
        .withConfiguration(AutoConfigurations.of(
            RefreshScopedBulkheadAutoConfiguration.class, BulkheadAutoConfiguration.class))
        .run(context -> {
            testRefreshScoped(context, "bulkheadRegistry");
            testRefreshScoped(context, "threadPoolBulkheadRegistry");
        });
}
 
Example #28
Source File: RepositoryTransactionManagerConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
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 #29
Source File: FlatFileItemReaderAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomLineMapper() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withUserConfiguration(CustomLineMapperConfiguration.class)
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							BatchAutoConfiguration.class,
							SingleStepJobAutoConfiguration.class,
							FlatFileItemReaderAutoConfiguration.class))
			.withPropertyValues("spring.batch.job.jobName=job",
					"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
					"spring.batch.job.flatfilereader.name=fixedWidthConfiguration",
					"spring.batch.job.flatfilereader.resource=/test.txt",
					"spring.batch.job.flatfilereader.strict=true");

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

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

		ListItemWriter itemWriter = context.getBean(ListItemWriter.class);

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

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

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

		List writtenItems = itemWriter.getWrittenItems();

		assertThat(writtenItems.size()).isEqualTo(8);
	});
}
 
Example #30
Source File: GcpPubSubReactiveAutoConfigurationTest.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void reactiveConfigDisabledWhenReactivePubSubDisabled() {

	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(TestConfig.class))
			.withPropertyValues("spring.cloud.gcp.pubsub.reactive.enabled=false");

	contextRunner.run(ctx -> {
		assertThat(ctx.containsBean("pubSubReactiveFactory")).isFalse();
	});
}