Adding a few more tests.
Added unit tests to classes that had no coverage. Added unit tests to classes bump up coverage.
This commit is contained in:
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package org.springframework.cloud.task.batch.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -29,6 +32,7 @@ import org.springframework.batch.core.configuration.annotation.DefaultBatchConfi
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||
import org.springframework.batch.core.job.SimpleJob;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
@@ -38,6 +42,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration;
|
||||
import org.springframework.cloud.task.batch.configuration.TaskBatchExecutionListenerBeanPostProcessor;
|
||||
import org.springframework.cloud.task.batch.configuration.TaskBatchExecutionListenerFactoryBean;
|
||||
import org.springframework.cloud.task.configuration.DefaultTaskConfigurer;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
@@ -161,6 +166,55 @@ public class TaskBatchExecutionListenerTests {
|
||||
assertEquals(0, (long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchExecutionListenerBeanPostProcessorWithJobNames() {
|
||||
List jobNames = new ArrayList<String>(3);
|
||||
jobNames.add("job1");
|
||||
jobNames.add("job2");
|
||||
jobNames.add("TESTOBJECT");
|
||||
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor =
|
||||
beanPostProcessor(jobNames);
|
||||
|
||||
SimpleJob testObject = new SimpleJob();
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor.
|
||||
postProcessBeforeInitialization(testObject,"TESTOBJECT");
|
||||
assertEquals(testObject,bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchExecutionListenerBeanPostProcessorWithEmptyJobNames() {
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor =
|
||||
beanPostProcessor(Collections.<String>emptyList());
|
||||
|
||||
SimpleJob testObject = new SimpleJob();
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor.
|
||||
postProcessBeforeInitialization(testObject,"TESTOBJECT");
|
||||
assertEquals(testObject,bean);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBatchExecutionListenerBeanPostProcessorNullJobNames() {
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor =
|
||||
beanPostProcessor(null);
|
||||
}
|
||||
|
||||
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(
|
||||
List<String> jobNames) {
|
||||
this.applicationContext = SpringApplication.run(new Object[] {JobConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class,
|
||||
TaskBatchAutoConfiguration.class}, ARGS);
|
||||
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor =
|
||||
this.applicationContext.getBean(
|
||||
TaskBatchExecutionListenerBeanPostProcessor.class);
|
||||
|
||||
beanPostProcessor.setJobNames(jobNames);
|
||||
return beanPostProcessor;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableBatchProcessing
|
||||
@EnableTask
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.configuration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenProperties;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenResourceLoader;
|
||||
import org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {ResourceLoadingAutoConfiguration.class})
|
||||
public class ResourceLoadingAutoConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testTaskLauncher() {
|
||||
MavenResourceLoader mavenResourceLoader =
|
||||
context.getBean(MavenResourceLoader.class);
|
||||
assertNotNull(mavenResourceLoader);
|
||||
|
||||
DelegatingResourceLoader delegatingResourceLoader =
|
||||
context.getBean(DelegatingResourceLoader.class);
|
||||
assertNotNull(delegatingResourceLoader);
|
||||
|
||||
MavenProperties mavenProperties =
|
||||
context.getBean(MavenProperties.class);
|
||||
assertNotNull(mavenProperties);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class TaskExceptionTests {
|
||||
|
||||
private static final String ERROR_MESSAGE = "ERROR MESSAGE";
|
||||
|
||||
@Test
|
||||
public void testTaskException() {
|
||||
TaskException taskException = new TaskException(ERROR_MESSAGE);
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
|
||||
taskException = new TaskException(ERROR_MESSAGE,
|
||||
new IllegalStateException(ERROR_MESSAGE));
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
assertNotNull(taskException.getCause());
|
||||
assertEquals(ERROR_MESSAGE, taskException.getCause().getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskExecutionException() {
|
||||
TaskExecutionException taskException = new TaskExecutionException(ERROR_MESSAGE);
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
|
||||
taskException = new TaskExecutionException(ERROR_MESSAGE,
|
||||
new IllegalStateException(ERROR_MESSAGE));
|
||||
assertEquals(ERROR_MESSAGE, taskException.getMessage());
|
||||
assertNotNull(taskException.getCause());
|
||||
assertEquals(ERROR_MESSAGE, taskException.getCause().getMessage());
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
import org.springframework.cloud.task.batch.listener.support.JobInstanceEvent;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -36,4 +37,23 @@ public class JobInstanceEventTests {
|
||||
assertEquals(INSTANCE_ID, jobInstanceEvent.getInstanceId());
|
||||
assertEquals(JOB_NAME, jobInstanceEvent.getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
JobInstanceEvent jobInstanceEvent = new JobInstanceEvent();
|
||||
assertNull(jobInstanceEvent.getJobName());
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testEmptyConstructorEmptyId() {
|
||||
JobInstanceEvent jobInstanceEvent = new JobInstanceEvent();
|
||||
jobInstanceEvent.getInstanceId();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
JobInstanceEvent jobInstanceEvent = new JobInstanceEvent(INSTANCE_ID, JOB_NAME);
|
||||
assertEquals("JobInstanceEvent: id=1, version=null, Job=[FOOBAR]",
|
||||
jobInstanceEvent.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.launcher;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.deployer.spi.local.LocalTaskLauncher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {TaskLauncherConfiguration.class})
|
||||
public class TaskLaunchConfigurationTests {
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testTaskLauncher() {
|
||||
LocalTaskLauncher taskLauncher =
|
||||
context.getBean(LocalTaskLauncher.class);
|
||||
assertNotNull(taskLauncher);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.launcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class TaskLaunchRequestTests {
|
||||
public static final String URI = "http://myURI";
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
List args = new ArrayList<String>();
|
||||
Map map = new HashMap<String,String>();
|
||||
args.add("foo");
|
||||
map.put("bar", "baz");
|
||||
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP);
|
||||
TaskLaunchRequest request2 = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP);
|
||||
assertFalse(request.equals(null));
|
||||
assertTrue(request.equals(request));
|
||||
assertTrue(request.equals(request2));
|
||||
TaskLaunchRequest requestDiff = new TaskLaunchRequest("http://oops",
|
||||
Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI,
|
||||
args,
|
||||
Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST,
|
||||
map,
|
||||
Collections.EMPTY_MAP);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP,
|
||||
map);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user