Added More tests.

This commit is contained in:
Glenn Renfro
2016-10-26 15:27:45 -04:00
parent 1611c28768
commit eff83a1897
5 changed files with 76 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.ApplicationArguments;
@@ -32,6 +33,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.cloud.task.configuration.TaskProperties;
import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.cloud.task.repository.TaskExplorer;
import org.springframework.cloud.task.util.TestDefaultConfiguration;
@@ -66,6 +69,9 @@ public class TaskLifecycleListenerTests {
private TaskExplorer taskExplorer;
@Rule
public OutputCapture outputCapture = new OutputCapture();
@Before
public void setUp() {
context = new AnnotationConfigApplicationContext();
@@ -155,6 +161,17 @@ public class TaskLifecycleListenerTests {
context.refresh();
}
@Test
public void testRestartExistingTask() {
context.refresh();
TaskLifecycleListener taskLifecycleListener =
context.getBean(TaskLifecycleListener.class);
taskLifecycleListener.start();
String output = this.outputCapture.toString();
assertTrue("Test results do not show error message: " + output,
output.contains("Multiple start events have been received"));
}
@Test
public void testExternalExecutionId() {
ConfigurableEnvironment environment = new StandardEnvironment();

View File

@@ -19,7 +19,10 @@ package org.springframework.cloud.task.repository.dao;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.junit.Before;
@@ -28,7 +31,9 @@ import org.junit.Test;
import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.cloud.task.util.TestVerifierUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* Executes unit tests on MapTaskExecutionDaoTests.
@@ -105,4 +110,31 @@ public class MapTaskExecutionDaoTests {
taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
}
@Test
public void testJobQueries(){
List<TaskExecution> expectedTaskExecutionList = new ArrayList<TaskExecution>(2);
expectedTaskExecutionList.add(TestVerifierUtils.createSampleTaskExecutionNoArg());
expectedTaskExecutionList.add(TestVerifierUtils.createSampleTaskExecutionNoArg());
for (TaskExecution expectedTaskExecution : expectedTaskExecutionList) {
expectedTaskExecution = this.dao.createTaskExecution(expectedTaskExecution.getTaskName(),
expectedTaskExecution.getStartTime(), expectedTaskExecution.getArguments(),
expectedTaskExecution.getExternalExecutionId());
this.dao.completeTaskExecution(expectedTaskExecution.getExecutionId(),
expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
expectedTaskExecution.getExitMessage());
}
Set jobIds = new HashSet<Long>(2);
jobIds.add(123L);
jobIds.add(456L);
this.dao.getBatchJobAssociations().put(
expectedTaskExecutionList.get(0).getExecutionId(), jobIds);
assertEquals(Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()),
this.dao.getTaskExecutionIdByJobExecutionId(123L));
assertEquals(Long.valueOf(expectedTaskExecutionList.get(0).getExecutionId()),
this.dao.getTaskExecutionIdByJobExecutionId(456L));
assertNull(this.dao.getTaskExecutionIdByJobExecutionId(789L));
}
}