Polish
This commit is contained in:
@@ -38,7 +38,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
public class SimpleSingleTaskAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepository() throws Exception {
|
||||
public void testRepository() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -84,7 +84,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoConfigurationDisabled() throws Exception {
|
||||
public void testAutoConfigurationDisabled() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -102,7 +102,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitialized() throws Exception {
|
||||
public void testRepositoryInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -115,7 +115,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() throws Exception {
|
||||
public void testRepositoryNotInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -221,12 +221,12 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource2() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -66,10 +66,9 @@ public class TaskCoreTests {
|
||||
@Test
|
||||
public void successfulTaskTest() {
|
||||
this.applicationContext = SpringApplication.run( TaskConfiguration.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
@@ -86,10 +85,9 @@ public class TaskCoreTests {
|
||||
@Test
|
||||
public void successfulTaskTestWithAnnotation() {
|
||||
this.applicationContext = SpringApplication.run( TaskConfigurationWithAnotation.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
@@ -105,10 +103,9 @@ public class TaskCoreTests {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run( TaskExceptionConfiguration.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
}
|
||||
catch (IllegalStateException exception) {
|
||||
exceptionFired = true;
|
||||
@@ -132,12 +129,11 @@ public class TaskCoreTests {
|
||||
public void invalidExecutionId() {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
applicationContext = this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class, new String[]{
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class, "--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.executionid=55"});
|
||||
"--spring.cloud.task.executionid=55");
|
||||
}
|
||||
catch (ApplicationContextException exception) {
|
||||
exceptionFired = true;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testTablesCreated() throws Exception {
|
||||
public void testTablesCreated() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> rows= jdbcTemplate.queryForList("SHOW TABLES");
|
||||
assertThat(rows.size()).isEqualTo(4);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TaskRepositoryInitializerNoDataSourceTaskConfigurerTests {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testNoTablesCreated() throws Exception {
|
||||
public void testNoTablesCreated() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> rows= jdbcTemplate.queryForList("SHOW TABLES");
|
||||
assertThat(rows.size()).isEqualTo(0);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Date;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
@@ -53,9 +54,9 @@ public class TaskExecutionListenerTests {
|
||||
|
||||
private static final String EXCEPTION_MESSAGE = "This was expected";
|
||||
|
||||
public static boolean beforeTaskDidFireOnError = false;
|
||||
public static boolean endTaskDidFireOnError = false;
|
||||
public static boolean failedTaskDidFireOnError = false;
|
||||
private static boolean beforeTaskDidFireOnError = false;
|
||||
private static boolean endTaskDidFireOnError = false;
|
||||
private static boolean failedTaskDidFireOnError = false;
|
||||
|
||||
@BeforeTask
|
||||
public void setup() {
|
||||
@@ -81,8 +82,8 @@ public class TaskExecutionListenerTests {
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener =
|
||||
context.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, false, false, taskExecution,taskExecutionListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution,taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,8 +131,8 @@ public class TaskExecutionListenerTests {
|
||||
context.getBean(AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
|
||||
assertEquals(true,taskExecutionListener.isTaskStartup());
|
||||
assertEquals(true,taskExecutionListener.isTaskEnd());
|
||||
assertTrue(taskExecutionListener.isTaskStartup());
|
||||
assertTrue(taskExecutionListener.isTaskEnd());
|
||||
assertEquals(TestListener.END_MESSAGE, taskExecutionListener.getTaskExecution().getExitMessage());
|
||||
assertTrue(taskExecutionListener.getTaskExecution().getErrorMessage().contains("Failed to process @BeforeTask or @AfterTask annotation because: AfterTaskFailure"));
|
||||
assertNull(taskExecutionListener.getThrowable());
|
||||
@@ -149,8 +150,8 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, false, taskExecution,taskExecutionListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution,taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,8 +169,8 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, true, taskExecution,taskExecutionListener);
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, true, taskExecution,taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,13 +178,13 @@ public class TaskExecutionListenerTests {
|
||||
* method is called.
|
||||
*/
|
||||
@Test
|
||||
public void testAnnotationCreate() throws Exception {
|
||||
public void testAnnotationCreate() {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener =
|
||||
context.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, false, false, taskExecution,annotatedListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution,annotatedListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +199,8 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, false, taskExecution,annotatedListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution,annotatedListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,14 +218,14 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, true, taskExecution,annotatedListener);
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, true, taskExecution,annotatedListener);
|
||||
}
|
||||
|
||||
private void verifyListenerResults (boolean isTaskStartup, boolean isTaskEnd,
|
||||
boolean isTaskFailed, TaskExecution taskExecution,
|
||||
TestListener actualListener){
|
||||
assertEquals(isTaskStartup,actualListener.isTaskStartup());
|
||||
private void verifyListenerResults(boolean isTaskEnd,
|
||||
boolean isTaskFailed, TaskExecution taskExecution,
|
||||
TestListener actualListener){
|
||||
assertTrue(actualListener.isTaskStartup());
|
||||
assertEquals(isTaskEnd,actualListener.isTaskEnd());
|
||||
assertEquals(isTaskFailed,actualListener.isTaskFailed());
|
||||
if(isTaskFailed){
|
||||
@@ -323,6 +324,11 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner() {
|
||||
return args -> System.out.println("I was run");
|
||||
}
|
||||
|
||||
public static class AnnotatedTaskListener {
|
||||
|
||||
@BeforeTask
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.task.repository.support;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.util.TaskExecutionCreator;
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
@@ -59,9 +57,6 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private TaskExplorer taskExplorer;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateEmptyExecution() {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultContext() throws Exception {
|
||||
public void testDefaultContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register( TestConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
@@ -68,7 +68,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDatabase() throws Exception {
|
||||
public void testNoDatabase() {
|
||||
this.context = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
|
||||
SimpleTaskRepository repository = new SimpleTaskRepository(new TaskExecutionDaoFactoryBean());
|
||||
assertThat(repository.getTaskExecutionDao(), instanceOf(MapTaskExecutionDao.class));
|
||||
@@ -77,7 +77,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTaskConfiguration() throws Exception {
|
||||
public void testNoTaskConfiguration() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(EmptyConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
@@ -87,7 +87,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testMultipleDataSourcesContext() throws Exception {
|
||||
public void testMultipleDataSourcesContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register( SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TestDefaultConfiguration implements InitializingBean {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskExplorer taskExplorer() throws Exception {
|
||||
public TaskExplorer taskExplorer() {
|
||||
return new SimpleTaskExplorer(this.factoryBean);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user