User can establish taskNameReslover via configurer vs SimpleTaskAutoConfiguration.

resolves #801
This commit is contained in:
Glenn Renfro
2023-05-15 17:59:16 -04:00
parent 1f39989831
commit dbbae91056
6 changed files with 48 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@ import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
import org.springframework.cloud.task.configuration.TaskConfigurer;
import org.springframework.cloud.task.repository.TaskExplorer;
import org.springframework.cloud.task.repository.TaskNameResolver;
import org.springframework.cloud.task.repository.TaskRepository;
import org.springframework.cloud.task.repository.support.SimpleTaskRepository;
import org.springframework.context.ApplicationContextException;
@@ -131,6 +132,20 @@ public class SimpleTaskAutoConfigurationTests {
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class, applicationContextRunner);
}
@Test
public void testTaskNameResolver() {
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
SingleTaskConfiguration.class))
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
.withPropertyValues("spring.cloud.task.name=myTestName");
applicationContextRunner.run((context) -> {
TaskNameResolver taskNameResolver = context.getBean(TaskNameResolver.class);
assertThat(taskNameResolver.getTaskName()).isEqualTo("myTestName");
});
}
@Test
public void testMultipleConfigurers() {
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,6 +90,14 @@ public class DefaultTaskConfigurerTests {
assertThat(defaultTaskConfigurer.getTaskExplorer()).isNotNull();
}
@Test
public void taskNameResolverTest() {
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource);
assertThat(defaultTaskConfigurer.getTaskNameResolver()).isNotNull();
defaultTaskConfigurer = new DefaultTaskConfigurer();
assertThat(defaultTaskConfigurer.getTaskNameResolver()).isNotNull();
}
@Test
public void taskRepositoryTest() {
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource);