Updated all Junit tests to 5.x
resolves TASK-675
This commit is contained in:
committed by
Michael Minella
parent
f3bbc37293
commit
59c9adf047
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user