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