Updated all Junit tests to 5.x
resolves TASK-675
This commit is contained in:
committed by
Michael Minella
parent
f3bbc37293
commit
59c9adf047
@@ -21,7 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
|
||||
@@ -23,9 +23,9 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -62,12 +62,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
private File outputFile;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
this.outputFile = File.createTempFile("flatfile-config-test-output", ".tmp");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
this.outputFile.delete();
|
||||
}
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.autoconfigure;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.item.file.transform.Range;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
@@ -54,18 +55,22 @@ public class RangeConverterTests {
|
||||
assertThat(range.getMax()).isEqualTo(25);
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test
|
||||
public void testIllegalValue() {
|
||||
RangeConverter converter = new RangeConverter();
|
||||
|
||||
converter.convert("invalid");
|
||||
assertThatExceptionOfType(NumberFormatException.class).isThrownBy(() -> {
|
||||
converter.convert("invalid");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testTooManyValues() {
|
||||
RangeConverter converter = new RangeConverter();
|
||||
|
||||
converter.convert("1-2-3-4");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
converter.convert("1-2-3-4");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
|
||||
@@ -55,16 +55,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
@@ -91,5 +81,15 @@
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.configuration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.handler;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -49,7 +49,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { TaskJobLauncherCommandLineRunnerCoreTests.BatchConfiguration.class })
|
||||
public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
@@ -85,7 +85,7 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
|
||||
private Step step;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
this.jobs = new JobBuilderFactory(this.jobRepository);
|
||||
this.steps = new StepBuilderFactory(this.jobRepository, this.transactionManager);
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Set;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
@@ -74,7 +74,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
@@ -48,7 +48,7 @@ public class PrefixTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
@@ -63,6 +63,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
@@ -74,7 +75,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
@@ -87,25 +88,31 @@ public class TaskBatchExecutionListenerTests {
|
||||
validateContext();
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
@Test
|
||||
public void testNoAutoConfigurationEnabled() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class,
|
||||
"--spring.cloud.task.batch.listener.enabled=false");
|
||||
validateContext();
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
|
||||
validateContext();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
@Test
|
||||
public void testNoAutoConfigurationEnable() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class,
|
||||
"--spring.cloud.task.batch.listener.enable=false");
|
||||
validateContext();
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
|
||||
validateContext();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
@Test
|
||||
public void testNoAutoConfigurationBothDisabled() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class,
|
||||
"--spring.cloud.task.batch.listener.enable=false --spring.cloud.task.batch.listener.enabled=false");
|
||||
validateContext();
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
|
||||
validateContext();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,9 +252,11 @@ public class TaskBatchExecutionListenerTests {
|
||||
assertThat(bean).isEqualTo(testObject);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testBatchExecutionListenerBeanPostProcessorNullJobNames() {
|
||||
beanPostProcessor(null);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
beanPostProcessor(null);
|
||||
});
|
||||
}
|
||||
|
||||
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(
|
||||
|
||||
@@ -29,11 +29,12 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -52,6 +53,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -84,13 +86,14 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.environment = new MockEnvironment();
|
||||
TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(),
|
||||
new Date(), "", Collections.emptyList(), null, null, null);
|
||||
when(taskRepository.createTaskExecution()).thenReturn(taskExecution);
|
||||
Mockito.lenient().when(taskRepository.createTaskExecution())
|
||||
.thenReturn(taskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -695,7 +698,7 @@ public class DeployerPartitionHandlerTests {
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = TimeoutException.class)
|
||||
@Test
|
||||
public void testTimeout() throws Exception {
|
||||
|
||||
StepExecution masterStepExecution = createMasterStepExecution();
|
||||
@@ -727,14 +730,16 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
Mockito.lenient().when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
handler.handle(this.splitter, masterStepExecution);
|
||||
assertThatExceptionOfType(TimeoutException.class).isThrownBy(() -> {
|
||||
handler.handle(this.splitter, masterStepExecution);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.partition;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -39,7 +39,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@@ -67,7 +67,7 @@ public class DeployerStepExecutionHandlerTests {
|
||||
|
||||
private DeployerStepExecutionHandler handler;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
@@ -192,7 +192,7 @@ public class DeployerStepExecutionHandlerTests {
|
||||
this.handler.run();
|
||||
|
||||
verify(this.step).execute(workerStep);
|
||||
verifyZeroInteractions(this.jobRepository);
|
||||
verifyNoMoreInteractions(this.jobRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cloud.task.batch.partition;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class NoOpEnvironmentVariablesProviderTests {
|
||||
|
||||
private NoOpEnvironmentVariablesProvider provider;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.provider = new NoOpEnvironmentVariablesProvider();
|
||||
}
|
||||
|
||||
@@ -19,18 +19,21 @@ package org.springframework.cloud.task.batch.partition;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class PassThroughCommandLineArgsProviderTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testNull() {
|
||||
new PassThroughCommandLineArgsProvider(null);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
new PassThroughCommandLineArgsProvider(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
|
||||
|
||||
@@ -115,9 +115,13 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cloud.task;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
|
||||
import org.springframework.aop.framework.AopProxyUtils;
|
||||
@@ -61,7 +61,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
|
||||
package org.springframework.cloud.task;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
@@ -38,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class TaskCoreTests {
|
||||
|
||||
private static final String TASK_NAME = "taskEventTest";
|
||||
@@ -58,15 +60,9 @@ public class TaskCoreTests {
|
||||
private static final String ERROR_MESSAGE = "errorMessage='java.lang.IllegalStateException: "
|
||||
+ "Failed to execute CommandLineRunner";
|
||||
|
||||
/**
|
||||
* Used to capture the log output from the test task.
|
||||
*/
|
||||
@Rule
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void teardown() {
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
@@ -74,13 +70,13 @@ public class TaskCoreTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successfulTaskTest() {
|
||||
public void successfulTaskTest(CapturedOutput capturedOutput) {
|
||||
this.applicationContext = SpringApplication.run(TaskConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
@@ -93,14 +89,14 @@ public class TaskCoreTests {
|
||||
* Test to verify that deprecated annotation does not affect task execution.
|
||||
*/
|
||||
@Test
|
||||
public void successfulTaskTestWithAnnotation() {
|
||||
public void successfulTaskTestWithAnnotation(CapturedOutput capturedOutput) {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskConfigurationWithAnotation.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
@@ -110,7 +106,7 @@ public class TaskCoreTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionTaskTest() {
|
||||
public void exceptionTaskTest(CapturedOutput capturedOutput) {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
@@ -125,7 +121,7 @@ public class TaskCoreTests {
|
||||
assertThat(exceptionFired).as("An IllegalStateException should have been thrown")
|
||||
.isTrue();
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
@@ -139,7 +135,7 @@ public class TaskCoreTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidExecutionId() {
|
||||
public void invalidExecutionId(CapturedOutput capturedOutput) {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
@@ -155,7 +151,7 @@ public class TaskCoreTests {
|
||||
assertThat(exceptionFired)
|
||||
.as("An ApplicationContextException should have been thrown").isTrue();
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(EXCEPTION_INVALID_TASK_EXECUTION_ID))
|
||||
.as("Test results do not show the correct exception message: " + output)
|
||||
.isTrue();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
@@ -31,7 +31,7 @@ import org.springframework.cloud.task.configuration.TaskConfigurer;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @author Glenn Renfro
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class })
|
||||
@DirtiesContext
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
@@ -32,7 +32,7 @@ import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
import org.springframework.cloud.task.configuration.TaskConfigurer;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @author Glenn Renfro
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class, DefaultTaskConfigurer.class })
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.cloud.task.configuration;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
@@ -29,7 +29,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { EmbeddedDataSourceConfiguration.class })
|
||||
public class DefaultTaskConfigurerTests {
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Date;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
|
||||
@@ -16,25 +16,22 @@
|
||||
|
||||
package org.springframework.cloud.task.configuration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ TaskPropertiesTests.CloseContextEnabledTest.class
|
||||
|
||||
})
|
||||
|
||||
@DirtiesContext
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(
|
||||
classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class },
|
||||
properties = { "spring.cloud.task.closecontextEnabled=false",
|
||||
"spring.cloud.task.initialize-enabled=false" })
|
||||
public class TaskPropertiesTests {
|
||||
|
||||
@Autowired
|
||||
@@ -46,20 +43,4 @@ public class TaskPropertiesTests {
|
||||
assertThat(this.taskProperties.isInitializeEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
classes = { TaskPropertiesTests.Config.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class },
|
||||
properties = { "spring.cloud.task.closecontextEnabled=false",
|
||||
"spring.cloud.task.initialize-enabled=false" })
|
||||
@DirtiesContext
|
||||
public static class CloseContextEnabledTest extends TaskPropertiesTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class Config {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.cloud.task.listener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -64,7 +64,7 @@ public class TaskExecutionListenerTests {
|
||||
failedTaskDidFireOnError = false;
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.context != null && this.context.isActive()) {
|
||||
this.context.close();
|
||||
|
||||
@@ -23,10 +23,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ExitCodeEvent;
|
||||
@@ -34,7 +34,8 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.util.TestDefaultConfiguration;
|
||||
@@ -52,6 +53,7 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Verifies that the TaskLifecycleListener Methods record the appropriate log header
|
||||
@@ -60,19 +62,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Glenn Renfro
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class TaskLifecycleListenerTests {
|
||||
|
||||
/**
|
||||
* Used to capture the log output from the test task.
|
||||
*/
|
||||
@Rule
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
private TaskExplorer taskExplorer;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setId("testTask");
|
||||
@@ -84,7 +81,7 @@ public class TaskLifecycleListenerTests {
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.context != null && this.context.isActive()) {
|
||||
this.context.close();
|
||||
@@ -175,25 +172,27 @@ public class TaskLifecycleListenerTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ApplicationContextException.class)
|
||||
@Test
|
||||
public void testInvalidTaskExecutionId() {
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
Map<String, Object> myMap = new HashMap<>();
|
||||
myMap.put("spring.cloud.task.executionid", "55");
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
Map<String, Object> myMap = new HashMap<>();
|
||||
myMap.put("spring.cloud.task.executionid", "55");
|
||||
propertySources
|
||||
.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
|
||||
this.context.setEnvironment(environment);
|
||||
this.context.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartExistingTask() {
|
||||
public void testRestartExistingTask(CapturedOutput capturedOutput) {
|
||||
this.context.refresh();
|
||||
TaskLifecycleListener taskLifecycleListener = this.context
|
||||
.getBean(TaskLifecycleListener.class);
|
||||
taskLifecycleListener.start();
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains("Multiple start events have been received"))
|
||||
.as("Test results do not show error message: " + output).isTrue();
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.springframework.cloud.task.listener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.task.listener.annotation.AfterTask;
|
||||
@@ -34,7 +34,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Glenn Renfro
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
TaskListenerExecutorObjectFactoryTests.TaskExecutionListenerConfiguration.class })
|
||||
@DirtiesContext
|
||||
@@ -78,7 +78,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
|
||||
private TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
taskExecutionListenerResults.clear();
|
||||
this.taskListenerExecutorObjectFactory = new TaskListenerExecutorObjectFactory(
|
||||
|
||||
@@ -25,10 +25,10 @@ import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.simple.SimpleConfig;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import io.pivotal.cfenv.test.CfEnvTestUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -39,7 +39,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Christian Tzolov
|
||||
* @author Soby Chacko
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = { AbstractMicrometerTest.AutoConfigurationApplication.class })
|
||||
@DirtiesContext
|
||||
public class AbstractMicrometerTest {
|
||||
@@ -61,7 +61,7 @@ public class AbstractMicrometerTest {
|
||||
|
||||
protected Meter meter;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove);
|
||||
assertThat(simpleMeterRegistry).isNotNull();
|
||||
@@ -70,12 +70,12 @@ public class AbstractMicrometerTest {
|
||||
"The spring.integration.handlers meter must be present in SpringBoot apps!");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws IOException {
|
||||
String serviceJson = StreamUtils.copyToString(new DefaultResourceLoader()
|
||||
.getResource("classpath:/micrometer/pcf-scs-info.json").getInputStream(),
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.task.micrometer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.runners.Enclosed;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
@@ -28,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
@RunWith(Enclosed.class)
|
||||
@Nested
|
||||
public class CloudFoundryMicrometerTagsConfigurationTest {
|
||||
|
||||
@ActiveProfiles("cloud")
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.task.micrometer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.runners.Enclosed;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
@@ -27,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
@RunWith(Enclosed.class)
|
||||
@Nested
|
||||
public class SpringCloudTaskMicrometerCommonTagsConfigurationTest {
|
||||
|
||||
public static class TestDefaultTagValues extends AbstractMicrometerTest {
|
||||
|
||||
@@ -23,9 +23,9 @@ import io.micrometer.core.instrument.LongTaskTimer;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.listener.TaskMetrics;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
@@ -41,7 +41,7 @@ public class TaskMetricsTests {
|
||||
|
||||
private SimpleMeterRegistry simpleMeterRegistry;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove);
|
||||
simpleMeterRegistry = new SimpleMeterRegistry();
|
||||
@@ -49,7 +49,7 @@ public class TaskMetricsTests {
|
||||
taskMetrics = new TaskMetrics();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@@ -24,9 +24,9 @@ import java.util.UUID;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -42,9 +42,10 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Executes unit tests on JdbcTaskExecutionDao.
|
||||
@@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Glenn Renfro
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@@ -64,7 +65,7 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
final JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(this.dataSource);
|
||||
dao.setTaskIncrementer(TestDBUtils.getIncrementer(this.dataSource));
|
||||
@@ -135,16 +136,19 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void completeTaskExecutionWithNoCreate() {
|
||||
JdbcTaskExecutionDao dao = new JdbcTaskExecutionDao(this.dataSource);
|
||||
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.endSampleTaskExecutionNoArg();
|
||||
dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,13 +25,14 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.util.TestVerifierUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Executes unit tests on MapTaskExecutionDaoTests.
|
||||
@@ -43,7 +44,7 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
|
||||
private MapTaskExecutionDao mapTaskExecutionDao;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.mapTaskExecutionDao = new MapTaskExecutionDao();
|
||||
super.dao = this.mapTaskExecutionDao;
|
||||
@@ -81,13 +82,16 @@ public class MapTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void completeTaskExecutionWithNoCreate() {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExitCode(),
|
||||
expectedTaskExecution.getEndTime(),
|
||||
expectedTaskExecution.getExitMessage());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,9 +19,8 @@ package org.springframework.cloud.task.repository.database.support;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -32,23 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class FindAllPagingQueryProviderTests {
|
||||
|
||||
private String databaseProductName;
|
||||
|
||||
private String expectedQuery;
|
||||
|
||||
private Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
public FindAllPagingQueryProviderTests(String databaseProductName,
|
||||
String expectedQuery) {
|
||||
this.databaseProductName = databaseProductName;
|
||||
this.expectedQuery = expectedQuery;
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ "Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
@@ -82,16 +68,17 @@ public class FindAllPagingQueryProviderTests {
|
||||
+ "WHERE TMP_ROW_NUM >= 1 AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, "
|
||||
+ "TASK_EXECUTION_ID DESC" } });
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@Test
|
||||
public void testGeneratedQuery() throws Exception {
|
||||
String actualQuery = TestDBUtils.getPagingQueryProvider(this.databaseProductName)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testGeneratedQuery(String databaseProductName, String expectedQuery)
|
||||
throws Exception {
|
||||
String actualQuery = TestDBUtils.getPagingQueryProvider(databaseProductName)
|
||||
.getPageQuery(this.pageable);
|
||||
assertThat(actualQuery).as(
|
||||
String.format("the generated query for %s, was not the expected query",
|
||||
this.databaseProductName))
|
||||
.isEqualTo(this.expectedQuery);
|
||||
databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,21 +16,25 @@
|
||||
|
||||
package org.springframework.cloud.task.repository.database.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class InvalidPagingQueryProviderTests {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testInvalidDatabase() throws Exception {
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
TestDBUtils.getPagingQueryProvider("Invalid").getPageQuery(pageable);
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
TestDBUtils.getPagingQueryProvider("Invalid").getPageQuery(pageable);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.cloud.task.repository.database.support;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao;
|
||||
@@ -36,7 +36,7 @@ public class SqlPagingQueryProviderFactoryBeanTests {
|
||||
|
||||
private SqlPagingQueryProviderFactoryBean factoryBean;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
this.factoryBean = new SqlPagingQueryProviderFactoryBean();
|
||||
this.factoryBean.setDataSource(TestDBUtils.getMockDataSource("MySQL"));
|
||||
|
||||
@@ -19,9 +19,8 @@ package org.springframework.cloud.task.repository.database.support;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.cloud.task.repository.database.PagingQueryProvider;
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
@@ -33,23 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class WhereClausePagingQueryProviderTests {
|
||||
|
||||
private String databaseProductName;
|
||||
|
||||
private String expectedQuery;
|
||||
|
||||
private Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
public WhereClausePagingQueryProviderTests(String databaseProductName,
|
||||
String expectedQuery) {
|
||||
this.databaseProductName = databaseProductName;
|
||||
this.expectedQuery = expectedQuery;
|
||||
}
|
||||
|
||||
// @checkstyle:off
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ "Oracle", "SELECT TASK_EXECUTION_ID, START_TIME, END_TIME, TASK_NAME, "
|
||||
@@ -87,17 +73,18 @@ public class WhereClausePagingQueryProviderTests {
|
||||
+ "'0000') TASK_EXECUTION_PAGE WHERE TMP_ROW_NUM >= 1 "
|
||||
+ "AND TMP_ROW_NUM < 11 ORDER BY START_TIME DESC, TASK_EXECUTION_ID DESC" } });
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@Test
|
||||
public void testGeneratedQuery() throws Exception {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void testGeneratedQuery(String databaseProductName, String expectedQuery)
|
||||
throws Exception {
|
||||
PagingQueryProvider pagingQueryProvider = TestDBUtils.getPagingQueryProvider(
|
||||
this.databaseProductName, "TASK_EXECUTION_ID = '0000'");
|
||||
databaseProductName, "TASK_EXECUTION_ID = '0000'");
|
||||
String actualQuery = pagingQueryProvider.getPageQuery(this.pageable);
|
||||
assertThat(actualQuery).as(
|
||||
String.format("the generated query for %s, was not the expected query",
|
||||
this.databaseProductName))
|
||||
.isEqualTo(this.expectedQuery);
|
||||
databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@ package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.HSQL;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.MYSQL;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.ORACLE;
|
||||
@@ -48,9 +49,10 @@ public class DatabaseTypeTests {
|
||||
assertThat(fromProductName("MariaDB")).isEqualTo(MYSQL);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testInvalidProductName() {
|
||||
fromProductName("bad product name");
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> fromProductName("bad product name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,13 +29,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
@@ -58,19 +54,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Glenn Renfro
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class SimpleTaskExplorerTests {
|
||||
|
||||
private final static String TASK_NAME = "FOOBAR";
|
||||
|
||||
private final static String EXTERNAL_EXECUTION_ID = "123ABC";
|
||||
|
||||
/**
|
||||
* Establishes that a Exception is not expected.
|
||||
*/
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
@@ -79,21 +68,12 @@ public class SimpleTaskExplorerTests {
|
||||
@Autowired
|
||||
private TaskRepository taskRepository;
|
||||
|
||||
private DaoType testType;
|
||||
|
||||
public SimpleTaskExplorerTests(DaoType testType) {
|
||||
this.testType = testType;
|
||||
}
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object> data() {
|
||||
return Arrays.asList(new Object[] { DaoType.jdbc, DaoType.map });
|
||||
}
|
||||
|
||||
@Before
|
||||
public void testDefaultContext() throws Exception {
|
||||
|
||||
if (this.testType == DaoType.jdbc) {
|
||||
public void testDefaultContext(DaoType testType) {
|
||||
if (testType == DaoType.jdbc) {
|
||||
initializeJdbcExplorerTest();
|
||||
}
|
||||
else {
|
||||
@@ -101,70 +81,80 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTaskExecution() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void getTaskExecution(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Long taskExecutionId : expectedResults.keySet()) {
|
||||
TaskExecution actualTaskExecution = this.taskExplorer
|
||||
.getTaskExecution(taskExecutionId);
|
||||
assertThat(actualTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s",
|
||||
this.testType)).isNotNull();
|
||||
"expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(taskExecutionId),
|
||||
actualTaskExecution);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExecutionNotFound() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void taskExecutionNotFound(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
createSampleDataSet(5);
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskExplorer.getTaskExecution(-5);
|
||||
assertThat(actualTaskExecution).as(
|
||||
String.format("expected null for actualTaskExecution %s", this.testType))
|
||||
assertThat(actualTaskExecution)
|
||||
.as(String.format("expected null for actualTaskExecution %s", testType))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTaskCountByTaskName() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void getTaskCountByTaskName(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> entry : expectedResults.entrySet()) {
|
||||
String taskName = entry.getValue().getTaskName();
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByTaskName(taskName))
|
||||
.as(String.format(
|
||||
"task count for task name did not match expected result for testType %s",
|
||||
this.testType))
|
||||
testType))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTaskCount() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void getTaskCount(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
createSampleDataSet(33);
|
||||
assertThat(this.taskExplorer.getTaskExecutionCount()).as(
|
||||
String.format("task count did not match expected result for test Type %s",
|
||||
this.testType))
|
||||
assertThat(this.taskExplorer.getTaskExecutionCount()).as(String.format(
|
||||
"task count did not match expected result for test Type %s", testType))
|
||||
.isEqualTo(33);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRunningTaskCount() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void getRunningTaskCount(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
createSampleDataSet(33);
|
||||
assertThat(this.taskExplorer.getRunningTaskExecutionCount()).as(
|
||||
String.format("task count did not match expected result for test Type %s",
|
||||
this.testType))
|
||||
assertThat(this.taskExplorer.getRunningTaskExecutionCount()).as(String.format(
|
||||
"task count did not match expected result for test Type %s", testType))
|
||||
.isEqualTo(33);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findRunningTasks() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findRunningTasks(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
final int TEST_COUNT = 2;
|
||||
final int COMPLETE_COUNT = 5;
|
||||
|
||||
@@ -187,21 +177,23 @@ public class SimpleTaskExplorerTests {
|
||||
.findRunningTaskExecutions(TASK_NAME, pageable);
|
||||
assertThat(actualResults.getNumberOfElements()).as(String.format(
|
||||
"Running task count for task name did not match expected result for testType %s",
|
||||
this.testType)).isEqualTo(TEST_COUNT);
|
||||
testType)).isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : actualResults) {
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId())).as(String
|
||||
.format("result returned from repo %s not expected for testType %s",
|
||||
result.getExecutionId(), this.testType))
|
||||
result.getExecutionId(), testType))
|
||||
.isTrue();
|
||||
assertThat(result.getEndTime()).as(String.format(
|
||||
"result had non null for endTime for the testType %s", this.testType))
|
||||
"result had non null for endTime for the testType %s", testType))
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTasksByName() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findTasksByName(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
final int TEST_COUNT = 5;
|
||||
final int COMPLETE_COUNT = 7;
|
||||
|
||||
@@ -223,21 +215,23 @@ public class SimpleTaskExplorerTests {
|
||||
.findTaskExecutionsByName(TASK_NAME, pageable);
|
||||
assertThat(resultSet.getNumberOfElements()).as(String.format(
|
||||
"Running task count for task name did not match expected result for testType %s",
|
||||
this.testType)).isEqualTo(TEST_COUNT);
|
||||
testType)).isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : resultSet) {
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId()))
|
||||
.as(String.format("result returned from %s repo %s not expected",
|
||||
this.testType, result.getExecutionId()))
|
||||
testType, result.getExecutionId()))
|
||||
.isTrue();
|
||||
assertThat(result.getTaskName()).as(String.format(
|
||||
"taskName for taskExecution is incorrect for testType %s",
|
||||
this.testType)).isEqualTo(TASK_NAME);
|
||||
"taskName for taskExecution is incorrect for testType %s", testType))
|
||||
.isEqualTo(TASK_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTaskNames() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void getTaskNames(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
final int TEST_COUNT = 5;
|
||||
Set<String> expectedResults = new HashSet<>();
|
||||
for (int i = 0; i < TEST_COUNT; i++) {
|
||||
@@ -246,50 +240,63 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
List<String> actualTaskNames = this.taskExplorer.getTaskNames();
|
||||
for (String taskName : actualTaskNames) {
|
||||
assertThat(expectedResults.contains(taskName)).as(
|
||||
String.format("taskName was not in expected results for testType %s",
|
||||
this.testType))
|
||||
assertThat(expectedResults.contains(taskName)).as(String.format(
|
||||
"taskName was not in expected results for testType %s", testType))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllExecutionsOffBoundry() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findAllExecutionsOffBoundry(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
verifyPageResults(pageable, 103);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllExecutionsOffBoundryByOne() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findAllExecutionsOffBoundryByOne(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
verifyPageResults(pageable, 101);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllExecutionsOnBoundry() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findAllExecutionsOnBoundry(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
verifyPageResults(pageable, 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllExecutionsNoResult() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findAllExecutionsNoResult(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
verifyPageResults(pageable, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTasksForInvalidJob() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findTasksForInvalidJob(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
assertThat(this.taskExplorer.getTaskExecutionIdByJobExecutionId(55555L)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findJobsExecutionIdsForInvalidTask() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void findJobsExecutionIdsForInvalidTask(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
assertThat(this.taskExplorer.getJobExecutionIdsByTaskExecutionId(555555L).size())
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestTaskExecutionForTaskName() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void getLatestTaskExecutionForTaskName(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry : expectedResults
|
||||
.entrySet()) {
|
||||
@@ -297,16 +304,18 @@ public class SimpleTaskExplorerTests {
|
||||
.getLatestTaskExecutionForTaskName(
|
||||
taskExecutionMapEntry.getValue().getTaskName());
|
||||
assertThat(latestTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s",
|
||||
this.testType)).isNotNull();
|
||||
"expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLatestTaskExecutionsByTaskNames() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data")
|
||||
public void getLatestTaskExecutionsByTaskNames(DaoType testType) {
|
||||
testDefaultContext(testType);
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
|
||||
final List<String> taskNamesAsList = new ArrayList<>();
|
||||
@@ -321,8 +330,8 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
for (TaskExecution latestTaskExecution : latestTaskExecutions) {
|
||||
assertThat(latestTaskExecution).as(String.format(
|
||||
"expected a taskExecution but got null for test type %s",
|
||||
this.testType)).isNotNull();
|
||||
"expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(
|
||||
expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.UUID;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -36,9 +36,10 @@ import org.springframework.cloud.task.util.TestDBUtils;
|
||||
import org.springframework.cloud.task.util.TestVerifierUtils;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for the SimpleTaskRepository that uses JDBC as a datastore.
|
||||
@@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Michael Minella
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { EmbeddedDataSourceConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
@DirtiesContext
|
||||
@@ -153,13 +154,15 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testInvalidExecutionIdForExternalExecutionIdUpdate() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -260,7 +263,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testMaxTaskNameSizeForConstructor() {
|
||||
final int MAX_EXIT_MESSAGE_SIZE = 10;
|
||||
final int MAX_ERROR_MESSAGE_SIZE = 20;
|
||||
@@ -271,10 +274,12 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
TaskExecution expectedTaskExecution = TestVerifierUtils
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution.setTaskName(new String(new char[MAX_TASK_NAME_SIZE + 1]));
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testDefaultMaxTaskNameSizeForConstructor() {
|
||||
SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
|
||||
new TaskExecutionDaoFactoryBean(this.dataSource), null, null, null);
|
||||
@@ -282,7 +287,9 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
.createSampleTaskExecutionNoArg();
|
||||
expectedTaskExecution.setTaskName(
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
simpleTaskRepository.createTaskExecution(expectedTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -304,17 +311,19 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE, simpleTaskRepository);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxTaskName() {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(
|
||||
new String(new char[SimpleTaskRepository.MAX_TASK_NAME_SIZE + 1]));
|
||||
taskExecution.setStartTime(new Date());
|
||||
this.taskRepository.createTaskExecution(taskExecution);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
this.taskRepository.createTaskExecution(taskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNegativeException() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
@@ -322,19 +331,24 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
expectedTaskExecution.setEndTime(new Date());
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator
|
||||
.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
actualTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNullEndTime() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution,
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
@@ -30,6 +30,7 @@ import org.springframework.cloud.task.repository.dao.MapTaskExecutionDao;
|
||||
import org.springframework.cloud.task.util.TaskExecutionCreator;
|
||||
import org.springframework.cloud.task.util.TestVerifierUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -42,7 +43,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
|
||||
private TaskRepository taskRepository;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.taskRepository = new SimpleTaskRepository(new TaskExecutionDaoFactoryBean());
|
||||
}
|
||||
@@ -91,13 +92,15 @@ public class SimpleTaskRepositoryMapTests {
|
||||
expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testInvalidExecutionIdForExternalExecutionIdUpdate() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
this.taskRepository.updateExternalExecutionId(-1,
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,13 +186,15 @@ public class SimpleTaskRepositoryMapTests {
|
||||
return taskMap.get(taskExecutionId);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCreateTaskExecutionNullEndTime() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
expectedTaskExecution);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -34,6 +32,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -43,15 +42,9 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class TaskDatabaseInitializerTests {
|
||||
|
||||
/**
|
||||
* Establishes that a Exception is not expected.
|
||||
*/
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
@@ -91,7 +84,7 @@ public class TaskDatabaseInitializerTests {
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
@Test
|
||||
public void testMultipleDataSourcesContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(SimpleTaskAutoConfiguration.class,
|
||||
@@ -99,7 +92,9 @@ public class TaskDatabaseInitializerTests {
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
this.context.getBeanFactory().registerSingleton("mockDataSource", dataSource);
|
||||
this.context.refresh();
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> {
|
||||
this.context.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cloud.task.repository.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao;
|
||||
import org.springframework.cloud.task.repository.dao.MapTaskExecutionDao;
|
||||
@@ -33,6 +33,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
@@ -41,7 +42,7 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
@@ -59,9 +60,11 @@ public class TaskExecutionDaoFactoryBeanTests {
|
||||
assertThat(new TaskExecutionDaoFactoryBean().isSingleton()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testConstructorValidation() {
|
||||
new TaskExecutionDaoFactoryBean(null);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
new TaskExecutionDaoFactoryBean(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-task-integration-tests</artifactId>
|
||||
|
||||
<properties>
|
||||
<test.containers.version>1.9.1</test.containers.version>
|
||||
<test.rabbit.containers.version>1.12.5</test.rabbit.containers.version>
|
||||
<test.ducttape.version>1.0.8</test.ducttape.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -95,6 +101,24 @@
|
||||
<artifactId>spring-integration-jdbc</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<version>${test.containers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>rabbitmq</artifactId>
|
||||
<version>${test.rabbit.containers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.rnorth.duct-tape</groupId>
|
||||
<artifactId>duct-tape</artifactId>
|
||||
<version>${test.ducttape.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -28,10 +28,10 @@ import java.util.UUID;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.tools.Server;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -58,12 +58,13 @@ import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = { TaskStartTests.TaskLauncherConfiguration.class })
|
||||
public class TaskStartTests {
|
||||
|
||||
@@ -102,7 +103,7 @@ public class TaskStartTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
@@ -118,7 +119,7 @@ public class TaskStartTests {
|
||||
this.taskRepository = new SimpleTaskRepository(factoryBean);
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.properties = new HashMap<>();
|
||||
this.properties.put("spring.datasource.url", DATASOURCE_URL);
|
||||
@@ -196,18 +197,22 @@ public class TaskStartTests {
|
||||
.isEqualTo("batchEvents");
|
||||
}
|
||||
|
||||
@Test(expected = ApplicationContextException.class)
|
||||
@Test
|
||||
public void testWithNoTaskExecution() throws Exception {
|
||||
this.applicationContext = getTaskApplication(55).run(new String[0]);
|
||||
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {
|
||||
this.applicationContext = getTaskApplication(55).run(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = ApplicationContextException.class)
|
||||
@Test
|
||||
public void testCompletedTaskExecution() throws Exception {
|
||||
this.taskRepository.createTaskExecution();
|
||||
assertThat(this.taskExplorer.getTaskExecutionCount())
|
||||
.as("Only one row is expected").isEqualTo(1);
|
||||
this.taskRepository.completeTaskExecution(1, 0, new Date(), "");
|
||||
this.applicationContext = getTaskApplication(1).run(new String[0]);
|
||||
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {
|
||||
this.applicationContext = getTaskApplication(1).run(new String[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,10 +23,10 @@ import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.tools.Server;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -44,12 +44,13 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = { TaskInitializerTests.TaskLauncherConfiguration.class })
|
||||
public class TaskInitializerTests {
|
||||
|
||||
@@ -84,7 +85,7 @@ public class TaskInitializerTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
@@ -99,7 +100,7 @@ public class TaskInitializerTests {
|
||||
this.taskExplorer = new SimpleTaskExplorer(factoryBean);
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource);
|
||||
@@ -120,11 +121,13 @@ public class TaskInitializerTests {
|
||||
template.execute("DROP SEQUENCE IF EXISTS TASK_SEQ");
|
||||
}
|
||||
|
||||
@Test(expected = ApplicationContextException.class)
|
||||
@Test
|
||||
public void testNotInitialized() throws Exception {
|
||||
SpringApplication myapp = new SpringApplication(TaskStartApplication.class);
|
||||
String[] properties = { "--spring.cloud.task.initialize-enabled=false" };
|
||||
this.applicationContext = myapp.run(properties);
|
||||
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {
|
||||
this.applicationContext = myapp.run(properties);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,11 +146,13 @@ public class TaskInitializerTests {
|
||||
.as("return code should be 0").isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test(expected = ApplicationContextException.class)
|
||||
@Test
|
||||
public void testNotInitializedOriginalProperty() throws Exception {
|
||||
SpringApplication myapp = new SpringApplication(TaskStartApplication.class);
|
||||
String[] properties = { "--spring.cloud.task.initialize.enable=false" };
|
||||
this.applicationContext = myapp.run(properties);
|
||||
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {
|
||||
this.applicationContext = myapp.run(properties);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,17 +25,16 @@ import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.tools.Server;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.deployer.spi.local.LocalDeployerProperties;
|
||||
import org.springframework.cloud.deployer.spi.local.LocalTaskLauncher;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.launcher.app.TaskLauncherSinkApplication;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
@@ -52,12 +51,12 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(
|
||||
classes = { TaskLauncherSinkApplication.class,
|
||||
TaskLauncherSinkTests.TaskLauncherConfiguration.class },
|
||||
@@ -82,15 +81,17 @@ public class TaskLauncherSinkTests {
|
||||
|
||||
private final static String TASK_NAME = "TASK_LAUNCHER_SINK_TEST";
|
||||
|
||||
@ClassRule
|
||||
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();
|
||||
|
||||
private static int randomPort;
|
||||
|
||||
static {
|
||||
randomPort = SocketUtils.findAvailableTcpPort();
|
||||
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort
|
||||
+ "/mem:dataflow;DB_CLOSE_DELAY=-1;" + "DB_CLOSE_ON_EXIT=FALSE";
|
||||
GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3")
|
||||
.withExposedPorts(5672);
|
||||
rabbitmq.start();
|
||||
final Integer mappedPort = rabbitmq.getMappedPort(5672);
|
||||
System.setProperty("spring.rabbitmq.test.port", mappedPort.toString());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -109,7 +110,7 @@ public class TaskLauncherSinkTests {
|
||||
new TaskExecutionDaoFactoryBean(dataSource));
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.properties = new HashMap<>();
|
||||
this.properties.put("spring.datasource.url", DATASOURCE_URL);
|
||||
|
||||
@@ -23,16 +23,15 @@ import java.util.concurrent.TimeUnit;
|
||||
import configuration.JobConfiguration;
|
||||
import configuration.JobSkipConfiguration;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.After;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.batch.listener.BatchEventAutoConfiguration;
|
||||
import org.springframework.cloud.task.batch.listener.support.JobExecutionEvent;
|
||||
@@ -50,8 +49,13 @@ public class BatchExecutionEventTests {
|
||||
|
||||
private static final String TASK_NAME = "jobEventTest";
|
||||
|
||||
@ClassRule
|
||||
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();
|
||||
static {
|
||||
GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3")
|
||||
.withExposedPorts(5672);
|
||||
rabbitmq.start();
|
||||
final Integer mappedPort = rabbitmq.getMappedPort(5672);
|
||||
System.setProperty("spring.rabbitmq.test.port", mappedPort.toString());
|
||||
}
|
||||
|
||||
// Count for two job execution events per job
|
||||
static CountDownLatch jobExecutionLatch = new CountDownLatch(2);
|
||||
@@ -80,7 +84,7 @@ public class BatchExecutionEventTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.applicationContext != null && this.applicationContext.isActive()) {
|
||||
this.applicationContext.close();
|
||||
|
||||
@@ -20,9 +20,9 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
@@ -33,7 +33,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration;
|
||||
import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport;
|
||||
import org.springframework.cloud.stream.config.BindingServiceConfiguration;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
@@ -42,7 +41,7 @@ import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -50,14 +49,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Michael Minella
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = { TaskEventTests.ListenerBinding.class })
|
||||
public class TaskEventTests {
|
||||
|
||||
private static final String TASK_NAME = "taskEventTest";
|
||||
|
||||
@ClassRule
|
||||
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();
|
||||
static {
|
||||
GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3")
|
||||
.withExposedPorts(5672);
|
||||
rabbitmq.start();
|
||||
final Integer mappedPort = rabbitmq.getMappedPort(5672);
|
||||
System.setProperty("spring.rabbitmq.test.port", mappedPort.toString());
|
||||
}
|
||||
|
||||
// Count for two task execution events per task
|
||||
static CountDownLatch latch = new CountDownLatch(2);
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<test.containers.version>1.9.1</test.containers.version>
|
||||
<test.rabbit.containers.version>1.12.5</test.rabbit.containers.version>
|
||||
<test.ducttape.version>1.0.8</test.ducttape.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -75,6 +78,24 @@
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<version>${test.containers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>rabbitmq</artifactId>
|
||||
<version>${test.rabbit.containers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.rnorth.duct-tape</groupId>
|
||||
<artifactId>duct-tape</artifactId>
|
||||
<version>${test.ducttape.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -20,13 +20,12 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.batch.listener.support.JobExecutionEvent;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -36,12 +35,20 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BatchEventsApplicationTests {
|
||||
|
||||
@ClassRule
|
||||
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();
|
||||
static {
|
||||
GenericContainer rabbitmq = new GenericContainer("rabbitmq:3.5.3")
|
||||
.withExposedPorts(5672);
|
||||
rabbitmq.start();
|
||||
final Integer mappedPort = rabbitmq.getMappedPort(5672);
|
||||
System.setProperty("spring.rabbitmq.test.port", mappedPort.toString());
|
||||
rabbitPort = mappedPort.toString();
|
||||
}
|
||||
|
||||
// Count for two job execution events per task
|
||||
static CountDownLatch jobExecutionLatch = new CountDownLatch(2);
|
||||
|
||||
private static String rabbitPort;
|
||||
|
||||
@Test
|
||||
public void testExecution() throws Exception {
|
||||
SpringApplication
|
||||
@@ -49,7 +56,8 @@ public class BatchEventsApplicationTests {
|
||||
SpringApplication.run(BatchEventsApplication.class, "--server.port=0",
|
||||
"--spring.cloud.stream.bindings.output.producer.requiredGroups=testgroup",
|
||||
"--spring.jmx.default-domain=fakedomain",
|
||||
"--spring.main.webEnvironment=false");
|
||||
"--spring.main.webEnvironment=false",
|
||||
"--spring.rabbitmq.port=" + rabbitPort);
|
||||
assertThat(jobExecutionLatch.await(60, TimeUnit.SECONDS))
|
||||
.as("The latch did not count down to zero before timeout").isTrue();
|
||||
}
|
||||
|
||||
@@ -19,11 +19,12 @@ package io.spring;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
@@ -34,13 +35,12 @@ import static org.junit.Assert.assertEquals;
|
||||
*
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class BatchJobApplicationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
@Test
|
||||
public void testBatchJobApp() throws Exception {
|
||||
public void testBatchJobApp(CapturedOutput capturedOutput) throws Exception {
|
||||
final String JOB_RUN_MESSAGE = " was run";
|
||||
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
|
||||
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
|
||||
@@ -49,7 +49,7 @@ public class BatchJobApplicationTests {
|
||||
|
||||
SpringApplication.run(BatchJobApplication.class);
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertTrue("Unable to find the timestamp: " + output,
|
||||
output.contains(JOB_RUN_MESSAGE));
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
|
||||
@@ -22,13 +22,15 @@ import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.tools.Server;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
@@ -41,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class JpaApplicationTests {
|
||||
|
||||
private final static String DATASOURCE_URL;
|
||||
@@ -59,13 +62,11 @@ public class JpaApplicationTests {
|
||||
+ "DB_CLOSE_ON_EXIT=FALSE";
|
||||
}
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
private ConfigurableApplicationContext context;
|
||||
private DataSource dataSource;
|
||||
private Server server;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
|
||||
@@ -84,7 +85,7 @@ public class JpaApplicationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.context != null && this.context.isActive()) {
|
||||
this.context.close();
|
||||
@@ -93,14 +94,14 @@ public class JpaApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchJobApp() {
|
||||
public void testBatchJobApp(CapturedOutput capturedOutput) {
|
||||
final String INSERT_MESSAGE = "Hibernate: insert into task_run_output (";
|
||||
this.context = SpringApplication
|
||||
.run(JpaApplication.class, "--spring.datasource.url=" + DATASOURCE_URL,
|
||||
"--spring.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
"--spring.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME,
|
||||
"--spring.jpa.database-platform=org.hibernate.dialect.H2Dialect");
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output
|
||||
.contains(INSERT_MESSAGE)).as("Unable to find the insert message: " + output)
|
||||
.isTrue();
|
||||
|
||||
@@ -16,28 +16,28 @@
|
||||
|
||||
package io.spring;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class MultiDataSourcesApplicationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
@Test
|
||||
public void testTimeStampApp() throws Exception {
|
||||
public void testTimeStampApp(CapturedOutput capturedOutput) throws Exception {
|
||||
|
||||
SpringApplication.run(MultipleDataSourcesApplication.class, new String[0]);
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
|
||||
assertThat(output.contains("There are 2 DataSources within this application"))
|
||||
.as("Unable to find CommandLineRunner output: " + output).isTrue();
|
||||
|
||||
@@ -23,9 +23,9 @@ import javax.sql.DataSource;
|
||||
|
||||
import io.spring.PartitionedBatchJobApplication;
|
||||
import org.h2.tools.Server;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -40,12 +40,12 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = {TaskPartitionerTests.TaskLauncherConfiguration.class})
|
||||
public class TaskPartitionerTests {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TaskPartitionerTests {
|
||||
this.taskExplorer = new SimpleTaskExplorer(new TaskExecutionDaoFactoryBean(dataSource));
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource);
|
||||
template.execute("DROP TABLE IF EXISTS TASK_TASK_BATCH");
|
||||
|
||||
@@ -21,8 +21,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -31,14 +32,14 @@ import org.springframework.cloud.stream.test.binder.MessageCollector;
|
||||
import org.springframework.cloud.task.launcher.TaskLaunchRequest;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = TaskProcessorApplication.class)
|
||||
public class TaskProcessorApplicationTests {
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -32,7 +33,7 @@ import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.launcher.TaskLaunchRequest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -40,7 +41,7 @@ import static org.mockito.Mockito.verify;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = TaskSinkApplication.class)
|
||||
public class TaskSinkApplicationTests {
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ package org.springframework.cloud.task.timestamp;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,13 +33,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class TaskApplicationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
@Test
|
||||
public void testTimeStampApp() throws Exception {
|
||||
public void testTimeStampApp(CapturedOutput capturedOutput) throws Exception {
|
||||
final String TEST_DATE_DOTS = ".......";
|
||||
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
|
||||
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
|
||||
@@ -47,7 +47,7 @@ public class TaskApplicationTests {
|
||||
|
||||
SpringApplication.run(TaskApplication.class, args);
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(TEST_DATE_DOTS))
|
||||
.as("Unable to find the timestamp: " + output).isTrue();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.task.timestamp;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
@@ -24,13 +25,14 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class TimestampTaskPropertiesTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testEmptyFormat() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues testPropertyValues = TestPropertyValues.of("format:");
|
||||
@@ -39,7 +41,9 @@ public class TimestampTaskPropertiesTests {
|
||||
context.refresh();
|
||||
TimestampTaskProperties properties = context
|
||||
.getBean(TimestampTaskProperties.class);
|
||||
properties.getFormat();
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
properties.getFormat();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
@@ -59,7 +59,7 @@ public class EventListenerTests {
|
||||
|
||||
private EventEmittingChunkListener eventEmittingChunkListener;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void beforeTests() {
|
||||
this.queueChannel = new QueueChannel(1);
|
||||
this.eventEmittingSkipListener = new EventEmittingSkipListener(this.queueChannel);
|
||||
|
||||
@@ -23,8 +23,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -75,7 +75,7 @@ public class JobExecutionEventTests {
|
||||
|
||||
private JobInstance jobInstance;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME);
|
||||
this.jobParameters = new JobParameters();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.task.batch.listener.support.JobInstanceEvent;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.cloud.task.batch.listener;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.JobParameter;
|
||||
import org.springframework.cloud.task.batch.listener.support.JobParameterEvent;
|
||||
@@ -73,16 +73,6 @@ public class JobParameterEventTests {
|
||||
assertTrue(jobParameterEvent.equals(anotherJobParameterEvent));
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testInvalidHashCode() {
|
||||
JobParameterEvent jobParameterEvent = new JobParameterEvent();
|
||||
assertThat(jobParameterEvent.hashCode()).isNull();
|
||||
final String EXPECTED_VALUE = "FOO";
|
||||
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
|
||||
jobParameterEvent = new JobParameterEvent(jobParameter);
|
||||
assertThat(jobParameterEvent.hashCode()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidHashCode() {
|
||||
final String EXPECTED_VALUE = "FOO";
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.JobParameter;
|
||||
import org.springframework.cloud.task.batch.listener.support.JobParametersEvent;
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.cloud.task.batch.listener;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.task.batch.listener;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.batch.core.ChunkListener;
|
||||
import org.springframework.batch.core.ItemProcessListener;
|
||||
@@ -38,7 +38,7 @@ import org.springframework.cloud.task.batch.listener.support.TaskBatchEventListe
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -46,7 +46,7 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
public class TaskBatchEventListenerBeanPostProcessorTests {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class TaskBatchEventListenerBeanPostProcessorTests {
|
||||
@Autowired
|
||||
private GenericApplicationContext context;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setupMock() {
|
||||
when(this.taskletStep.getTasklet()).thenReturn(
|
||||
new ChunkOrientedTasklet(this.chunkProvider, this.chunkProcessor));
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.task.launcher;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -27,7 +27,7 @@ import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = {
|
||||
TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class })
|
||||
public class TaskLaunchConfigurationExistingTests {
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -34,11 +34,11 @@ import org.springframework.cloud.task.launcher.app.TaskLauncherSinkApplication;
|
||||
import org.springframework.cloud.task.launcher.configuration.TaskConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = { TaskLauncherSinkApplication.class, TaskConfiguration.class })
|
||||
public class TaskLauncherSinkTests {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TaskLauncherSinkTests {
|
||||
@Autowired
|
||||
private Sink sink;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.properties = new HashMap<>();
|
||||
this.properties.put("server.port", "0");
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
|
||||
Reference in New Issue
Block a user