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

@@ -60,6 +60,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Michael Minella
@@ -95,6 +96,17 @@ public class TaskBatchExecutionListenerTests {
assertEquals(1, taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId());
}
@Test
public void testBeanFactoryReturnsSameInstance() throws Exception{
this.applicationContext = SpringApplication.run(new Object[] {JobConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
EmbeddedDataSourceConfiguration.class,
BatchAutoConfiguration.class,
TaskBatchAutoConfiguration.class}, ARGS);
TaskBatchExecutionListenerFactoryBean bean = this.applicationContext.getBean(TaskBatchExecutionListenerFactoryBean.class);
assertTrue(bean.getObject() == bean.getObject());
}
@Test
public void testMultipleDataSources() {
this.applicationContext = SpringApplication.run(new Object[] {JobConfigurationMultipleDataSources.class,

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

View File

@@ -114,23 +114,23 @@ public class TaskLaunchRequest implements Serializable{
if (!uri.equals(that.uri)){
return false;
}
if (!(commandlineArguments != null ? commandlineArguments.equals(that.commandlineArguments) : that.commandlineArguments == null)){
if (!commandlineArguments.equals(that.commandlineArguments)){
return false;
}
if(!(deploymentProperties != null ? deploymentProperties.equals(that.deploymentProperties) : that.deploymentProperties == null))
if(!deploymentProperties.equals(that.deploymentProperties))
{
return false;
}
return environmentProperties != null ? environmentProperties.equals(that.environmentProperties) : that.environmentProperties == null;
return environmentProperties.equals(that.environmentProperties);
}
@Override
public int hashCode() {
int result = uri != null ? uri.hashCode() : 0;
result = 31 * result + (commandlineArguments != null ? commandlineArguments.hashCode() : 0);
result = 31 * result + (environmentProperties != null ? environmentProperties.hashCode() : 0);
result = 31 * result + (deploymentProperties != null ? deploymentProperties.hashCode() : 0);
int result = uri.hashCode();
result = 31 * result + commandlineArguments.hashCode();
result = 31 * result + environmentProperties.hashCode();
result = 31 * result + deploymentProperties.hashCode();
return result;
}
}

View File

@@ -24,6 +24,7 @@ import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -49,6 +50,7 @@ public class TaskLaunchRequestTests {
Collections.EMPTY_MAP,
Collections.EMPTY_MAP);
assertFalse(request.equals(null));
assertFalse(request.equals("nope"));
assertTrue(request.equals(request));
assertTrue(request.equals(request2));
TaskLaunchRequest requestDiff = new TaskLaunchRequest("http://oops",
@@ -63,6 +65,10 @@ public class TaskLaunchRequestTests {
Collections.EMPTY_MAP);
assertFalse(request.equals(requestDiff));
requestDiff = new TaskLaunchRequest(URI,
null, null, null);
assertTrue(request.equals(requestDiff));
requestDiff = new TaskLaunchRequest(URI,
Collections.EMPTY_LIST,
map,
@@ -75,5 +81,7 @@ public class TaskLaunchRequestTests {
map);
assertFalse(request.equals(requestDiff));
assertEquals(request.hashCode(), request.hashCode());
}
}