Updated all Junit tests to 5.x

resolves TASK-675
This commit is contained in:
Glenn Renfro
2020-06-17 16:38:20 -04:00
committed by Michael Minella
parent f3bbc37293
commit 59c9adf047
74 changed files with 617 additions and 534 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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();

View File

@@ -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();

View File

@@ -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

View File

@@ -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 })

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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 {
}
}

View File

@@ -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;

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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(

View File

@@ -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(),

View File

@@ -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")

View File

@@ -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 {

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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);
});
}
}

View File

@@ -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"));

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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,

View File

@@ -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);
});
}
}

View File

@@ -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

View File

@@ -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