Added checkstyle
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.batch.listener;
|
||||
@@ -35,7 +35,7 @@ import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -46,229 +46,247 @@ public class EventListenerTests {
|
||||
private QueueChannel queueChannel;
|
||||
|
||||
private EventEmittingSkipListener eventEmittingSkipListener;
|
||||
|
||||
private EventEmittingItemProcessListener eventEmittingItemProcessListener;
|
||||
|
||||
private EventEmittingItemReadListener eventEmittingItemReadListener;
|
||||
|
||||
private EventEmittingItemWriteListener eventEmittingItemWriteListener;
|
||||
|
||||
private EventEmittingJobExecutionListener eventEmittingJobExecutionListener;
|
||||
|
||||
private EventEmittingStepExecutionListener eventEmittingStepExecutionListener;
|
||||
|
||||
private EventEmittingChunkListener eventEmittingChunkListener;
|
||||
|
||||
@Before
|
||||
public void beforeTests() {
|
||||
queueChannel = new QueueChannel(1);
|
||||
eventEmittingSkipListener = new EventEmittingSkipListener(queueChannel);
|
||||
eventEmittingItemProcessListener = new EventEmittingItemProcessListener(queueChannel);
|
||||
eventEmittingItemReadListener = new EventEmittingItemReadListener(queueChannel);
|
||||
eventEmittingItemWriteListener = new EventEmittingItemWriteListener(queueChannel);
|
||||
eventEmittingJobExecutionListener = new EventEmittingJobExecutionListener(queueChannel);
|
||||
eventEmittingStepExecutionListener = new EventEmittingStepExecutionListener(queueChannel);
|
||||
eventEmittingChunkListener = new EventEmittingChunkListener(queueChannel,0);
|
||||
this.queueChannel = new QueueChannel(1);
|
||||
this.eventEmittingSkipListener = new EventEmittingSkipListener(this.queueChannel);
|
||||
this.eventEmittingItemProcessListener = new EventEmittingItemProcessListener(
|
||||
this.queueChannel);
|
||||
this.eventEmittingItemReadListener = new EventEmittingItemReadListener(
|
||||
this.queueChannel);
|
||||
this.eventEmittingItemWriteListener = new EventEmittingItemWriteListener(
|
||||
this.queueChannel);
|
||||
this.eventEmittingJobExecutionListener = new EventEmittingJobExecutionListener(
|
||||
this.queueChannel);
|
||||
this.eventEmittingStepExecutionListener = new EventEmittingStepExecutionListener(
|
||||
this.queueChannel);
|
||||
this.eventEmittingChunkListener = new EventEmittingChunkListener(
|
||||
this.queueChannel, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventListenerOrderProperty() {
|
||||
assertEquals(eventEmittingSkipListener.getOrder(),Ordered.LOWEST_PRECEDENCE);
|
||||
assertEquals(eventEmittingItemProcessListener.getOrder(), Ordered.LOWEST_PRECEDENCE);
|
||||
assertEquals(eventEmittingItemReadListener.getOrder(), Ordered.LOWEST_PRECEDENCE);
|
||||
assertEquals(eventEmittingItemWriteListener.getOrder(), Ordered.LOWEST_PRECEDENCE);
|
||||
assertEquals(eventEmittingJobExecutionListener.getOrder(), Ordered.LOWEST_PRECEDENCE);
|
||||
assertEquals(eventEmittingStepExecutionListener.getOrder(), Ordered.LOWEST_PRECEDENCE);
|
||||
assertEquals(eventEmittingChunkListener.getOrder(),0);
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingSkipListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingItemProcessListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingItemReadListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingItemWriteListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingJobExecutionListener.getOrder());
|
||||
assertThat(Ordered.LOWEST_PRECEDENCE)
|
||||
.isEqualTo(this.eventEmittingStepExecutionListener.getOrder());
|
||||
assertThat(0).isEqualTo(this.eventEmittingChunkListener.getOrder());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testItemProcessListenerOnProcessorError() {
|
||||
RuntimeException exeption = new RuntimeException("Test Exception");
|
||||
eventEmittingItemProcessListener.onProcessError("HELLO", exeption);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
this.eventEmittingItemProcessListener.onProcessError("HELLO", exeption);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals("Exception while item was being processed", msg.getPayload());
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload())
|
||||
.isEqualTo("Exception while item was being processed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemProcessListenerAfterProcess() {
|
||||
eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS_EQUAL",
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS_EQUAL",
|
||||
"HELLO_AFTER_PROCESS_EQUAL");
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals("item equaled result after processing", msg.getPayload());
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo("item equaled result after processing");
|
||||
|
||||
eventEmittingItemProcessListener.afterProcess("HELLO_NOT_EQUAL", "WORLD");
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
msg = queueChannel.receive();
|
||||
assertEquals("item did not equal result after processing", msg.getPayload());
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_NOT_EQUAL", "WORLD");
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload())
|
||||
.isEqualTo("item did not equal result after processing");
|
||||
|
||||
eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS", null);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
msg = queueChannel.receive();
|
||||
assertEquals("1 item was filtered", msg.getPayload());
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS", null);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo("1 item was filtered");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemProcessBeforeProcessor() {
|
||||
eventEmittingItemProcessListener.beforeProcess("HELLO_BEFORE_PROCESS");
|
||||
assertEquals(0, queueChannel.getQueueSize());
|
||||
this.eventEmittingItemProcessListener.beforeProcess("HELLO_BEFORE_PROCESS");
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingSkipListenerSkipRead() {
|
||||
RuntimeException exeption = new RuntimeException("Text Exception");
|
||||
eventEmittingSkipListener.onSkipInRead(exeption);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals("Skipped when reading.", msg.getPayload());
|
||||
this.eventEmittingSkipListener.onSkipInRead(exeption);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo("Skipped when reading.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingSkipListenerSkipWrite() {
|
||||
final String MESSAGE = "HELLO_SKIP_WRITE";
|
||||
RuntimeException exeption = new RuntimeException("Text Exception");
|
||||
eventEmittingSkipListener.onSkipInWrite(MESSAGE, exeption);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals(MESSAGE, msg.getPayload());
|
||||
this.eventEmittingSkipListener.onSkipInWrite(MESSAGE, exeption);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo(MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingSkipListenerSkipProcess() {
|
||||
final String MESSAGE = "HELLO_SKIP_PROCESS";
|
||||
RuntimeException exeption = new RuntimeException("Text Exception");
|
||||
eventEmittingSkipListener.onSkipInProcess(MESSAGE, exeption);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals(MESSAGE, msg.getPayload());
|
||||
this.eventEmittingSkipListener.onSkipInProcess(MESSAGE, exeption);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo(MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemReadListener() {
|
||||
RuntimeException exeption = new RuntimeException("Text Exception");
|
||||
eventEmittingItemReadListener.onReadError(exeption);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals("Exception while item was being read", msg.getPayload());
|
||||
this.eventEmittingItemReadListener.onReadError(exeption);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo("Exception while item was being read");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemReadListenerBeforeRead() {
|
||||
eventEmittingItemReadListener.beforeRead();
|
||||
assertEquals(0, queueChannel.getQueueSize());
|
||||
this.eventEmittingItemReadListener.beforeRead();
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemReadListenerAfterRead() {
|
||||
eventEmittingItemReadListener.afterRead("HELLO_AFTER_READ");
|
||||
assertEquals(0, queueChannel.getQueueSize());
|
||||
this.eventEmittingItemReadListener.afterRead("HELLO_AFTER_READ");
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemWriteListenerBeforeWrite() {
|
||||
eventEmittingItemWriteListener.beforeWrite(getSampleList());
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals("3 items to be written.", msg.getPayload());
|
||||
this.eventEmittingItemWriteListener.beforeWrite(getSampleList());
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo("3 items to be written.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemWriteListenerAfterWrite() {
|
||||
eventEmittingItemWriteListener.afterWrite(getSampleList());
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals("3 items have been written.", msg.getPayload());
|
||||
this.eventEmittingItemWriteListener.afterWrite(getSampleList());
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo("3 items have been written.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemWriteListenerWriteError() {
|
||||
RuntimeException exeption = new RuntimeException("Text Exception");
|
||||
eventEmittingItemWriteListener.onWriteError(exeption, getSampleList());
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals("Exception while 3 items are attempted to be written.", msg.getPayload());
|
||||
this.eventEmittingItemWriteListener.onWriteError(exeption, getSampleList());
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload())
|
||||
.isEqualTo("Exception while 3 items are attempted to be written.");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void EventEmittingJobExecutionListenerBeforeJob() {
|
||||
JobExecution jobExecution = getJobExecution();
|
||||
eventEmittingJobExecutionListener.beforeJob(jobExecution);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
this.eventEmittingJobExecutionListener.beforeJob(jobExecution);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
JobExecutionEvent jobEvent = (JobExecutionEvent) msg.getPayload();
|
||||
assertEquals(jobExecution.getJobInstance().getJobName(),
|
||||
jobEvent.getJobInstance().getJobName());
|
||||
assertThat(jobEvent.getJobInstance().getJobName())
|
||||
.isEqualTo(jobExecution.getJobInstance().getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingJobExecutionListenerAfterJob() {
|
||||
JobExecution jobExecution = getJobExecution();
|
||||
eventEmittingJobExecutionListener.afterJob(jobExecution);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
this.eventEmittingJobExecutionListener.afterJob(jobExecution);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
JobExecutionEvent jobEvent = (JobExecutionEvent) msg.getPayload();
|
||||
assertEquals(jobExecution.getJobInstance().getJobName(),
|
||||
jobEvent.getJobInstance().getJobName());
|
||||
assertThat(jobEvent.getJobInstance().getJobName())
|
||||
.isEqualTo(jobExecution.getJobInstance().getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingStepExecutionListenerBeforeStep() {
|
||||
final String STEP_MESSAGE = "BEFORE_STEP_MESSAGE";
|
||||
JobExecution jobExecution = getJobExecution();
|
||||
StepExecution stepExecution = new StepExecution(STEP_MESSAGE,jobExecution);
|
||||
eventEmittingStepExecutionListener.beforeStep(stepExecution);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
StepExecution stepExecution = new StepExecution(STEP_MESSAGE, jobExecution);
|
||||
this.eventEmittingStepExecutionListener.beforeStep(stepExecution);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
StepExecutionEvent stepExecutionEvent = (StepExecutionEvent) msg.getPayload();
|
||||
assertEquals(STEP_MESSAGE,
|
||||
stepExecutionEvent.getStepName());
|
||||
assertThat(stepExecutionEvent.getStepName()).isEqualTo(STEP_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingStepExecutionListenerAfterStep() {
|
||||
final String STEP_MESSAGE = "AFTER_STEP_MESSAGE";
|
||||
JobExecution jobExecution = getJobExecution();
|
||||
StepExecution stepExecution = new StepExecution(STEP_MESSAGE,jobExecution);
|
||||
eventEmittingStepExecutionListener.afterStep(stepExecution);
|
||||
assertEquals(1, queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
StepExecution stepExecution = new StepExecution(STEP_MESSAGE, jobExecution);
|
||||
this.eventEmittingStepExecutionListener.afterStep(stepExecution);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
StepExecutionEvent stepExecutionEvent = (StepExecutionEvent) msg.getPayload();
|
||||
assertEquals(STEP_MESSAGE,
|
||||
stepExecutionEvent.getStepName());
|
||||
assertThat(stepExecutionEvent.getStepName()).isEqualTo(STEP_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingChunkExecutionListenerBeforeChunk() {
|
||||
final String CHUNK_MESSAGE = "Before Chunk Processing";
|
||||
ChunkContext chunkContext = getChunkContext();
|
||||
eventEmittingChunkListener.beforeChunk(chunkContext);
|
||||
assertEquals(1,queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals(CHUNK_MESSAGE,msg.getPayload());
|
||||
this.eventEmittingChunkListener.beforeChunk(chunkContext);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo(CHUNK_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingChunkExecutionListenerAfterChunk() {
|
||||
final String CHUNK_MESSAGE = "After Chunk Processing";
|
||||
ChunkContext chunkContext = getChunkContext();
|
||||
eventEmittingChunkListener.afterChunk(chunkContext);
|
||||
assertEquals(1,queueChannel.getQueueSize());
|
||||
Message msg = queueChannel.receive();
|
||||
assertEquals(CHUNK_MESSAGE,msg.getPayload());
|
||||
this.eventEmittingChunkListener.afterChunk(chunkContext);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(1);
|
||||
Message msg = this.queueChannel.receive();
|
||||
assertThat(msg.getPayload()).isEqualTo(CHUNK_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingChunkExecutionListenerAfterChunkError() {
|
||||
ChunkContext chunkContext = getChunkContext();
|
||||
eventEmittingChunkListener.afterChunkError(chunkContext);
|
||||
assertEquals(0,queueChannel.getQueueSize());
|
||||
this.eventEmittingChunkListener.afterChunkError(chunkContext);
|
||||
assertThat(this.queueChannel.getQueueSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
private JobExecution getJobExecution() {
|
||||
final String JOB_NAME = UUID.randomUUID().toString();
|
||||
JobInstance jobInstance = new JobInstance(1L, JOB_NAME);
|
||||
return new JobExecution(jobInstance, 1L,
|
||||
new JobParameters(), UUID.randomUUID().toString());
|
||||
return new JobExecution(jobInstance, 1L, new JobParameters(),
|
||||
UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
private List<String> getSampleList() {
|
||||
List<String> testList = new ArrayList<>(3);
|
||||
testList.add("Hello");
|
||||
@@ -276,9 +294,10 @@ public class EventListenerTests {
|
||||
testList.add("foo");
|
||||
return testList;
|
||||
}
|
||||
|
||||
private ChunkContext getChunkContext() {
|
||||
JobExecution jobExecution = getJobExecution();
|
||||
StepExecution stepExecution = new StepExecution("STEP1",jobExecution);
|
||||
StepExecution stepExecution = new StepExecution("STEP1", jobExecution);
|
||||
StepContext stepContext = new StepContext(stepExecution);
|
||||
ChunkContext chunkContext = new ChunkContext(stepContext);
|
||||
return chunkContext;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.batch.listener;
|
||||
@@ -34,7 +34,6 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
@@ -47,10 +46,7 @@ import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro.
|
||||
@@ -59,67 +55,98 @@ import static org.junit.Assert.assertTrue;
|
||||
public class JobExecutionEventTests {
|
||||
|
||||
private static final String JOB_NAME = "FOODJOB";
|
||||
|
||||
private static final Long JOB_INSTANCE_ID = 1L;
|
||||
|
||||
private static final Long JOB_EXECUTION_ID = 2L;
|
||||
|
||||
private static final String JOB_CONFIGURATION_NAME = "FOO_JOB_CONFIG";
|
||||
private static final String[] LISTENER_BEAN_NAMES = {BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER, BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER, BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER, BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER};
|
||||
|
||||
private static final String[] LISTENER_BEAN_NAMES = {
|
||||
BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER,
|
||||
BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER };
|
||||
|
||||
private JobParameters jobParameters;
|
||||
|
||||
private JobInstance jobInstance;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME);
|
||||
jobParameters = new JobParameters();
|
||||
this.jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME);
|
||||
this.jobParameters = new JobParameters();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic() {
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters, JOB_CONFIGURATION_NAME);
|
||||
JobExecution jobExecution;
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID,
|
||||
this.jobParameters, JOB_CONFIGURATION_NAME);
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution);
|
||||
assertNotNull("jobInstance should not be null", jobExecutionEvent.getJobInstance());
|
||||
assertNotNull("jobParameters should not be null", jobExecutionEvent.getJobParameters());
|
||||
assertEquals("jobConfigurationName did not match expected", JOB_CONFIGURATION_NAME,
|
||||
jobExecutionEvent.getJobConfigurationName());
|
||||
assertThat(jobExecutionEvent.getJobInstance())
|
||||
.as("jobInstance should not be null").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters())
|
||||
.as("jobParameters should not be null").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobConfigurationName())
|
||||
.as("jobConfigurationName did not match expected")
|
||||
.isEqualTo(JOB_CONFIGURATION_NAME);
|
||||
|
||||
assertEquals("jobParameters size did not match", 0, jobExecutionEvent.getJobParameters().getParameters().size());
|
||||
assertEquals("jobInstance name did not match", JOB_NAME, jobExecutionEvent.getJobInstance().getJobName());
|
||||
assertEquals("no step executions were expected", 0, jobExecutionEvent.getStepExecutions().size());
|
||||
assertEquals("exitStatus did not match expected", "UNKNOWN", jobExecutionEvent.getExitStatus().getExitCode());
|
||||
assertThat(jobExecutionEvent.getJobParameters().getParameters().size())
|
||||
.as("jobParameters size did not match").isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName())
|
||||
.as("jobInstance name did not match").isEqualTo(JOB_NAME);
|
||||
assertThat(jobExecutionEvent.getStepExecutions().size())
|
||||
.as("no step executions were expected").isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getExitStatus().getExitCode())
|
||||
.as("exitStatus did not match expected").isEqualTo("UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobParameters() {
|
||||
String[] JOB_PARAM_KEYS = {"A", "B", "C", "D"};
|
||||
String[] JOB_PARAM_KEYS = { "A", "B", "C", "D" };
|
||||
Date testDate = new Date();
|
||||
JobParameter[] PARAMETERS = {new JobParameter("FOO", true), new JobParameter(1L, true),
|
||||
new JobParameter(1D, true), new JobParameter(testDate, false)};
|
||||
JobParameter[] PARAMETERS = { new JobParameter("FOO", true),
|
||||
new JobParameter(1L, true), new JobParameter(1D, true),
|
||||
new JobParameter(testDate, false) };
|
||||
|
||||
Map<String, JobParameter> jobParamMap = new LinkedHashMap<>();
|
||||
for (int paramCount = 0; paramCount < JOB_PARAM_KEYS.length; paramCount++) {
|
||||
jobParamMap.put(JOB_PARAM_KEYS[paramCount], PARAMETERS[paramCount]);
|
||||
}
|
||||
jobParameters = new JobParameters(jobParamMap);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters, JOB_CONFIGURATION_NAME);
|
||||
this.jobParameters = new JobParameters(jobParamMap);
|
||||
JobExecution jobExecution;
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID,
|
||||
this.jobParameters, JOB_CONFIGURATION_NAME);
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution);
|
||||
|
||||
assertNotNull("Job Parameter A was expected", jobExecutionEvent.getJobParameters().getString("A"));
|
||||
assertNotNull("Job Parameter B was expected", jobExecutionEvent.getJobParameters().getLong("B"));
|
||||
assertNotNull("Job Parameter C was expected", jobExecutionEvent.getJobParameters().getDouble("C"));
|
||||
assertNotNull("Job Parameter D was expected", jobExecutionEvent.getJobParameters().getDate("D"));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getString("A"))
|
||||
.as("Job Parameter A was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getLong("B"))
|
||||
.as("Job Parameter B was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDouble("C"))
|
||||
.as("Job Parameter C was expected").isNotNull();
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D"))
|
||||
.as("Job Parameter D was expected").isNotNull();
|
||||
|
||||
assertEquals("Job Parameter A value was not correct", "FOO", jobExecutionEvent.getJobParameters().getString("A"));
|
||||
assertEquals("Job Parameter B value was not correct", new Long(1), jobExecutionEvent.getJobParameters().getLong("B"));
|
||||
assertEquals("Job Parameter C value was not correct", new Double(1), jobExecutionEvent.getJobParameters().getDouble("C"));
|
||||
assertEquals("Job Parameter D value was not correct", testDate, jobExecutionEvent.getJobParameters().getDate("D"));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getString("A"))
|
||||
.as("Job Parameter A value was not correct").isEqualTo("FOO");
|
||||
assertThat(jobExecutionEvent.getJobParameters().getLong("B"))
|
||||
.as("Job Parameter B value was not correct").isEqualTo(new Long(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDouble("C"))
|
||||
.as("Job Parameter C value was not correct").isEqualTo(new Double(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D"))
|
||||
.as("Job Parameter D value was not correct").isEqualTo(testDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStepExecutions() {
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters, JOB_CONFIGURATION_NAME);
|
||||
JobExecution jobExecution;
|
||||
jobExecution = new JobExecution(this.jobInstance, JOB_EXECUTION_ID,
|
||||
this.jobParameters, JOB_CONFIGURATION_NAME);
|
||||
List<StepExecution> stepsExecutions = new ArrayList<>();
|
||||
stepsExecutions.add(new StepExecution("foo", jobExecution));
|
||||
stepsExecutions.add(new StepExecution("bar", jobExecution));
|
||||
@@ -127,11 +154,16 @@ public class JobExecutionEventTests {
|
||||
jobExecution.addStepExecutions(stepsExecutions);
|
||||
|
||||
JobExecutionEvent jobExecutionsEvent = new JobExecutionEvent(jobExecution);
|
||||
assertEquals("stepExecutions count is incorrect", 3, jobExecutionsEvent.getStepExecutions().size());
|
||||
Iterator<StepExecutionEvent> iter = jobExecutionsEvent.getStepExecutions().iterator();
|
||||
assertEquals("foo stepExecution is not present", "foo", iter.next().getStepName());
|
||||
assertEquals("bar stepExecution is not present", "bar", iter.next().getStepName());
|
||||
assertEquals("baz stepExecution is not present", "baz", iter.next().getStepName());
|
||||
assertThat(jobExecutionsEvent.getStepExecutions().size())
|
||||
.as("stepExecutions count is incorrect").isEqualTo(3);
|
||||
Iterator<StepExecutionEvent> iter = jobExecutionsEvent.getStepExecutions()
|
||||
.iterator();
|
||||
assertThat(iter.next().getStepName()).as("foo stepExecution is not present")
|
||||
.isEqualTo("foo");
|
||||
assertThat(iter.next().getStepName()).as("bar stepExecution is not present")
|
||||
.isEqualTo("bar");
|
||||
assertThat(iter.next().getStepName()).as("baz stepExecution is not present")
|
||||
.isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,25 +216,29 @@ public class JobExecutionEventTests {
|
||||
@Test
|
||||
public void testDefaultConstructor() {
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertEquals("UNKNOWN", jobExecutionEvent.getExitStatus().getExitCode());
|
||||
assertThat(jobExecutionEvent.getExitStatus().getExitCode()).isEqualTo("UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailureExceptions() {
|
||||
final String EXCEPTION_MESSAGE = "TEST EXCEPTION";
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertEquals(0, jobExecutionEvent.getFailureExceptions().size());
|
||||
jobExecutionEvent.addFailureException(new IllegalStateException(EXCEPTION_MESSAGE));
|
||||
assertEquals(1, jobExecutionEvent.getFailureExceptions().size());
|
||||
assertEquals(1, jobExecutionEvent.getAllFailureExceptions().size());
|
||||
assertEquals(jobExecutionEvent.getFailureExceptions().get(0).getMessage(), EXCEPTION_MESSAGE);
|
||||
assertEquals(jobExecutionEvent.getAllFailureExceptions().get(0).getMessage(), EXCEPTION_MESSAGE);
|
||||
assertThat(jobExecutionEvent.getFailureExceptions().size()).isEqualTo(0);
|
||||
jobExecutionEvent
|
||||
.addFailureException(new IllegalStateException(EXCEPTION_MESSAGE));
|
||||
assertThat(jobExecutionEvent.getFailureExceptions().size()).isEqualTo(1);
|
||||
assertThat(jobExecutionEvent.getAllFailureExceptions().size()).isEqualTo(1);
|
||||
assertThat(EXCEPTION_MESSAGE)
|
||||
.isEqualTo(jobExecutionEvent.getFailureExceptions().get(0).getMessage());
|
||||
assertThat(EXCEPTION_MESSAGE).isEqualTo(
|
||||
jobExecutionEvent.getAllFailureExceptions().get(0).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertTrue(jobExecutionEvent.toString().startsWith("JobExecutionEvent:"));
|
||||
assertThat(jobExecutionEvent.toString().startsWith("JobExecutionEvent:"))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,40 +246,39 @@ public class JobExecutionEventTests {
|
||||
Date date = new Date();
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
jobExecutionEvent.setLastUpdated(date);
|
||||
assertEquals(date, jobExecutionEvent.getLastUpdated());
|
||||
assertThat(jobExecutionEvent.getLastUpdated()).isEqualTo(date);
|
||||
jobExecutionEvent.setCreateTime(date);
|
||||
assertEquals(date, jobExecutionEvent.getCreateTime());
|
||||
assertThat(jobExecutionEvent.getCreateTime()).isEqualTo(date);
|
||||
jobExecutionEvent.setEndTime(date);
|
||||
assertEquals(date, jobExecutionEvent.getEndTime());
|
||||
assertThat(jobExecutionEvent.getEndTime()).isEqualTo(date);
|
||||
jobExecutionEvent.setStartTime(date);
|
||||
assertEquals(date, jobExecutionEvent.getStartTime());
|
||||
assertThat(jobExecutionEvent.getStartTime()).isEqualTo(date);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExitStatus() {
|
||||
final String EXIT_CODE = "KNOWN";
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertEquals("UNKNOWN", jobExecutionEvent.getExitStatus().getExitCode());
|
||||
org.springframework.cloud.task.batch.listener.support.ExitStatus expectedExitStatus =
|
||||
new org.springframework.cloud.task.batch.listener.support.ExitStatus();
|
||||
assertThat(jobExecutionEvent.getExitStatus().getExitCode()).isEqualTo("UNKNOWN");
|
||||
org.springframework.cloud.task.batch.listener.support.ExitStatus expectedExitStatus;
|
||||
expectedExitStatus = new org.springframework.cloud.task.batch.listener.support.ExitStatus();
|
||||
expectedExitStatus.setExitCode(EXIT_CODE);
|
||||
jobExecutionEvent.setExitStatus(expectedExitStatus);
|
||||
assertEquals(EXIT_CODE, jobExecutionEvent.getExitStatus().getExitCode());
|
||||
assertThat(jobExecutionEvent.getExitStatus().getExitCode()).isEqualTo(EXIT_CODE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobInstance() {
|
||||
final String JOB_NAME = "KNOWN";
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertNull(jobExecutionEvent.getJobInstance());
|
||||
assertNull(jobExecutionEvent.getJobId());
|
||||
JobInstanceEvent expectedJobInstanceEvent = new JobInstanceEvent(1L,
|
||||
JOB_NAME);
|
||||
assertThat(jobExecutionEvent.getJobInstance()).isNull();
|
||||
assertThat(jobExecutionEvent.getJobId()).isNull();
|
||||
JobInstanceEvent expectedJobInstanceEvent = new JobInstanceEvent(1L, JOB_NAME);
|
||||
jobExecutionEvent.setJobInstance(expectedJobInstanceEvent);
|
||||
assertEquals(expectedJobInstanceEvent.getJobName(),
|
||||
jobExecutionEvent.getJobInstance().getJobName());
|
||||
assertEquals(expectedJobInstanceEvent.getId(),
|
||||
jobExecutionEvent.getJobId());
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName())
|
||||
.isEqualTo(expectedJobInstanceEvent.getJobName());
|
||||
assertThat(jobExecutionEvent.getJobId())
|
||||
.isEqualTo(expectedJobInstanceEvent.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -251,27 +286,28 @@ public class JobExecutionEventTests {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.put("hello", "world");
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertNotNull(jobExecutionEvent.getExecutionContext());
|
||||
assertThat(jobExecutionEvent.getExecutionContext()).isNotNull();
|
||||
jobExecutionEvent.setExecutionContext(executionContext);
|
||||
assertEquals("world", jobExecutionEvent.getExecutionContext().getString("hello"));
|
||||
assertThat(jobExecutionEvent.getExecutionContext().getString("hello"))
|
||||
.isEqualTo("world");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchStatus() {
|
||||
public void testBatchStatus() {
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertEquals(BatchStatus.STARTING, jobExecutionEvent.getStatus());
|
||||
assertThat(jobExecutionEvent.getStatus()).isEqualTo(BatchStatus.STARTING);
|
||||
jobExecutionEvent.setStatus(BatchStatus.ABANDONED);
|
||||
assertEquals(BatchStatus.ABANDONED, jobExecutionEvent.getStatus());
|
||||
assertThat(jobExecutionEvent.getStatus()).isEqualTo(BatchStatus.ABANDONED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpgradeBatchStatus() {
|
||||
public void testUpgradeBatchStatus() {
|
||||
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
|
||||
assertEquals(BatchStatus.STARTING, jobExecutionEvent.getStatus());
|
||||
assertThat(jobExecutionEvent.getStatus()).isEqualTo(BatchStatus.STARTING);
|
||||
jobExecutionEvent.upgradeStatus(BatchStatus.FAILED);
|
||||
assertEquals(BatchStatus.FAILED, jobExecutionEvent.getStatus());
|
||||
assertThat(jobExecutionEvent.getStatus()).isEqualTo(BatchStatus.FAILED);
|
||||
jobExecutionEvent.upgradeStatus(BatchStatus.COMPLETED);
|
||||
assertEquals(BatchStatus.FAILED, jobExecutionEvent.getStatus());
|
||||
assertThat(jobExecutionEvent.getStatus()).isEqualTo(BatchStatus.FAILED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,23 +317,24 @@ public class JobExecutionEventTests {
|
||||
EventJobExecutionConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
TestSupportBinderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(
|
||||
BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.batch.events.chunk-order=5",
|
||||
"--spring.cloud.task.batch.events.item-process-order=5",
|
||||
"--spring.cloud.task.batch.events.item-read-order=5",
|
||||
"--spring.cloud.task.batch.events.item-write-order=5",
|
||||
"--spring.cloud.task.batch.events.job-execution-order=5",
|
||||
"--spring.cloud.task.batch.events.skip-order=5",
|
||||
"--spring.cloud.task.batch.events.step-execution-order=5");
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.batch.events.chunk-order=5",
|
||||
"--spring.cloud.task.batch.events.item-process-order=5",
|
||||
"--spring.cloud.task.batch.events.item-read-order=5",
|
||||
"--spring.cloud.task.batch.events.item-write-order=5",
|
||||
"--spring.cloud.task.batch.events.job-execution-order=5",
|
||||
"--spring.cloud.task.batch.events.skip-order=5",
|
||||
"--spring.cloud.task.batch.events.step-execution-order=5");
|
||||
applicationContextRunner.run((context) -> {
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
Ordered ordered = (Ordered)context.getBean(beanName);
|
||||
assertEquals("Expected order value of 5 for " + beanName,ordered.getOrder(),5);
|
||||
}
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
Ordered ordered = (Ordered) context.getBean(beanName);
|
||||
assertThat(5).as("Expected order value of 5 for " + beanName)
|
||||
.isEqualTo(ordered.getOrder());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
@@ -306,37 +343,39 @@ public class JobExecutionEventTests {
|
||||
String disabledPropertyArg = (property != null) ? "--" + property + "=false" : "";
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EventJobExecutionConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
TestSupportBinderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
EventJobExecutionConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
TestSupportBinderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(
|
||||
BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false",
|
||||
disabledPropertyArg);
|
||||
"--spring.main.web-environment=false", disabledPropertyArg);
|
||||
applicationContextRunner.run((context) -> {
|
||||
boolean exceptionThrown = false;
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
if (disabledListener != null && disabledListener.equals(beanName)) {
|
||||
try {
|
||||
context.getBean(disabledListener);
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
if (disabledListener != null && disabledListener.equals(beanName)) {
|
||||
try {
|
||||
context.getBean(disabledListener);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException nsbde) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
assertThat(exceptionThrown).as(
|
||||
String.format("Did not expect %s bean in context", beanName))
|
||||
.isTrue();
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException nsbde) {
|
||||
exceptionThrown = true;
|
||||
else {
|
||||
context.getBean(beanName);
|
||||
}
|
||||
assertTrue(String.format("Did not expect %s bean in context", beanName), exceptionThrown);
|
||||
}
|
||||
else {
|
||||
context.getBean(beanName);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
public static class EventJobExecutionConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.batch.listener;
|
||||
@@ -20,8 +20,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;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -29,19 +28,20 @@ import static org.junit.Assert.assertNull;
|
||||
public class JobInstanceEventTests {
|
||||
|
||||
public static final long INSTANCE_ID = 1;
|
||||
|
||||
public static final String JOB_NAME = "FOOBAR";
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
JobInstanceEvent jobInstanceEvent = new JobInstanceEvent(INSTANCE_ID, JOB_NAME);
|
||||
assertEquals(INSTANCE_ID, jobInstanceEvent.getInstanceId());
|
||||
assertEquals(JOB_NAME, jobInstanceEvent.getJobName());
|
||||
assertThat(jobInstanceEvent.getInstanceId()).isEqualTo(INSTANCE_ID);
|
||||
assertThat(jobInstanceEvent.getJobName()).isEqualTo(JOB_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyConstructor() {
|
||||
JobInstanceEvent jobInstanceEvent = new JobInstanceEvent();
|
||||
assertNull(jobInstanceEvent.getJobName());
|
||||
assertThat(jobInstanceEvent.getJobName()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,7 +53,8 @@ public class JobInstanceEventTests {
|
||||
@Test
|
||||
public void testToString() {
|
||||
JobInstanceEvent jobInstanceEvent = new JobInstanceEvent(INSTANCE_ID, JOB_NAME);
|
||||
assertEquals("JobInstanceEvent: id=1, version=null, Job=[FOOBAR]",
|
||||
jobInstanceEvent.toString());
|
||||
assertThat(jobInstanceEvent.toString())
|
||||
.isEqualTo("JobInstanceEvent: id=1, version=null, Job=[FOOBAR]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.batch.listener;
|
||||
@@ -25,9 +25,7 @@ import org.springframework.cloud.task.batch.listener.support.JobParameterEvent;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -37,10 +35,10 @@ public class JobParameterEventTests {
|
||||
@Test
|
||||
public void testDefaultConstructor() {
|
||||
JobParameterEvent jobParameterEvent = new JobParameterEvent();
|
||||
assertNull(jobParameterEvent.getValue());
|
||||
assertNull(jobParameterEvent.getType());
|
||||
assertThat(jobParameterEvent.getValue()).isNull();
|
||||
assertThat(jobParameterEvent.getType()).isNull();
|
||||
assertFalse(jobParameterEvent.isIdentifying());
|
||||
assertEquals(new JobParameterEvent(), jobParameterEvent);
|
||||
assertThat(jobParameterEvent).isEqualTo(new JobParameterEvent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -49,14 +47,16 @@ public class JobParameterEventTests {
|
||||
final Date EXPECTED_DATE_VALUE = new Date();
|
||||
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
|
||||
JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter);
|
||||
assertEquals(EXPECTED_VALUE, jobParameterEvent.getValue());
|
||||
assertEquals(JobParameterEvent.ParameterType.STRING, jobParameterEvent.getType());
|
||||
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_VALUE);
|
||||
assertThat(jobParameterEvent.getType())
|
||||
.isEqualTo(JobParameterEvent.ParameterType.STRING);
|
||||
assertTrue(jobParameterEvent.isIdentifying());
|
||||
|
||||
jobParameter = new JobParameter(EXPECTED_DATE_VALUE, true);
|
||||
jobParameterEvent = new JobParameterEvent(jobParameter);
|
||||
assertEquals(EXPECTED_DATE_VALUE, jobParameterEvent.getValue());
|
||||
assertEquals(JobParameterEvent.ParameterType.DATE, jobParameterEvent.getType());
|
||||
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_DATE_VALUE);
|
||||
assertThat(jobParameterEvent.getType())
|
||||
.isEqualTo(JobParameterEvent.ParameterType.DATE);
|
||||
assertTrue(jobParameterEvent.isIdentifying());
|
||||
assertTrue(new JobParameterEvent(jobParameter).equals(jobParameterEvent));
|
||||
}
|
||||
@@ -76,11 +76,11 @@ public class JobParameterEventTests {
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testInvalidHashCode() {
|
||||
JobParameterEvent jobParameterEvent = new JobParameterEvent();
|
||||
assertNull(jobParameterEvent.hashCode());
|
||||
assertThat(jobParameterEvent.hashCode()).isNull();
|
||||
final String EXPECTED_VALUE = "FOO";
|
||||
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
|
||||
jobParameterEvent = new JobParameterEvent(jobParameter);
|
||||
assertNotNull(jobParameterEvent.hashCode());
|
||||
assertThat(jobParameterEvent.hashCode()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +88,7 @@ public class JobParameterEventTests {
|
||||
final String EXPECTED_VALUE = "FOO";
|
||||
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
|
||||
JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter);
|
||||
assertNotNull(jobParameterEvent.hashCode());
|
||||
assertThat(jobParameterEvent.hashCode()).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.batch.listener;
|
||||
@@ -28,9 +28,7 @@ import org.springframework.cloud.task.batch.listener.support.JobParametersEvent;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -38,31 +36,40 @@ import static org.junit.Assert.assertNotNull;
|
||||
public class JobParametersEventTests {
|
||||
|
||||
private final static JobParameter STRING_PARAM = new JobParameter("FOO", true);
|
||||
|
||||
private final static JobParameter DATE_PARAM = new JobParameter(new Date(), true);
|
||||
|
||||
private final static JobParameter LONG_PARAM = new JobParameter(1L, true);
|
||||
|
||||
private final static JobParameter DOUBLE_PARAM = new JobParameter(2D, true);
|
||||
|
||||
private final static String DATE_KEY = "DATE_KEY";
|
||||
|
||||
private final static String STRING_KEY = "STRING_KEY";
|
||||
|
||||
private final static String LONG_KEY = "LONG_KEY";
|
||||
|
||||
private final static String DOUBLE_KEY = "DOUBLE_KEY";
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructor() {
|
||||
JobParametersEvent jobParametersEvent = new JobParametersEvent();
|
||||
assertEquals(0, jobParametersEvent.getParameters().size());
|
||||
assertThat(jobParametersEvent.getParameters().size()).isEqualTo(0);
|
||||
assertTrue(jobParametersEvent.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
JobParametersEvent jobParametersEvent = getPopulatedParametersEvent();
|
||||
assertEquals(STRING_PARAM.getValue(), jobParametersEvent.getString(STRING_KEY));
|
||||
assertEquals(LONG_PARAM.getValue(), jobParametersEvent.getLong(LONG_KEY));
|
||||
assertEquals(DATE_PARAM.getValue(), jobParametersEvent.getDate(DATE_KEY));
|
||||
assertEquals(DOUBLE_PARAM.getValue(), jobParametersEvent.getDouble(DOUBLE_KEY));
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY))
|
||||
.isEqualTo(STRING_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getLong(LONG_KEY)).isEqualTo(LONG_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getDate(DATE_KEY)).isEqualTo(DATE_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getDouble(DOUBLE_KEY))
|
||||
.isEqualTo(DOUBLE_PARAM.getValue());
|
||||
|
||||
JobParametersEvent jobParametersEventNew = getPopulatedParametersEvent();
|
||||
assertEquals(jobParametersEventNew, jobParametersEvent);
|
||||
assertThat(jobParametersEvent).isEqualTo(jobParametersEventNew);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,54 +83,62 @@ public class JobParametersEventTests {
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
JobParametersEvent jobParametersEvent = new JobParametersEvent();
|
||||
assertNotNull(jobParametersEvent.hashCode());
|
||||
assertThat(jobParametersEvent.hashCode()).isNotNull();
|
||||
JobParametersEvent jobParametersEventPopulated = getPopulatedParametersEvent();
|
||||
assertNotNull(jobParametersEvent);
|
||||
assertNotEquals(jobParametersEvent.hashCode(), jobParametersEventPopulated.hashCode());
|
||||
assertThat(jobParametersEvent).isNotNull();
|
||||
assertThat(jobParametersEventPopulated.hashCode())
|
||||
.isNotEqualTo(jobParametersEvent.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToProperties() {
|
||||
JobParametersEvent jobParametersEvent = getPopulatedParametersEvent();
|
||||
Properties properties = jobParametersEvent.toProperties();
|
||||
assertEquals(properties.getProperty(DATE_KEY), jobParametersEvent.getString(DATE_KEY));
|
||||
assertEquals(properties.getProperty(STRING_KEY), jobParametersEvent.getString(STRING_KEY));
|
||||
assertEquals(properties.getProperty(LONG_KEY), jobParametersEvent.getString(LONG_KEY));
|
||||
assertEquals(properties.getProperty(DOUBLE_KEY), jobParametersEvent.getString(DOUBLE_KEY));
|
||||
assertThat(jobParametersEvent.getString(DATE_KEY))
|
||||
.isEqualTo(properties.getProperty(DATE_KEY));
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY))
|
||||
.isEqualTo(properties.getProperty(STRING_KEY));
|
||||
assertThat(jobParametersEvent.getString(LONG_KEY))
|
||||
.isEqualTo(properties.getProperty(LONG_KEY));
|
||||
assertThat(jobParametersEvent.getString(DOUBLE_KEY))
|
||||
.isEqualTo(properties.getProperty(DOUBLE_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
JobParametersEvent jobParametersEvent = getPopulatedParametersEvent();
|
||||
assertNotNull(toString());
|
||||
assertThat(toString()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetterSetterDefaults() {
|
||||
JobParametersEvent jobParametersEvent = getPopulatedParametersEvent();
|
||||
assertEquals(new Double(0), jobParametersEvent.getDouble("FOOBAR"));
|
||||
assertEquals(new Long(0), jobParametersEvent.getLong("FOOBAR"));
|
||||
assertEquals(new Double(5), jobParametersEvent.getDouble("FOOBAR", 5));
|
||||
assertEquals(DOUBLE_PARAM.getValue(), jobParametersEvent.getDouble(DOUBLE_KEY, 0));
|
||||
assertEquals(new Long(5), jobParametersEvent.getLong("FOOBAR", 5));
|
||||
assertEquals(LONG_PARAM.getValue(), jobParametersEvent.getLong(LONG_KEY, 5));
|
||||
assertEquals("TESTVAL", jobParametersEvent.getString("FOOBAR","TESTVAL"));
|
||||
assertEquals(STRING_PARAM.getValue(),
|
||||
jobParametersEvent.getString(STRING_KEY,"TESTVAL"));
|
||||
assertThat(jobParametersEvent.getDouble("FOOBAR")).isEqualTo(new Double(0));
|
||||
assertThat(jobParametersEvent.getLong("FOOBAR")).isEqualTo(new Long(0));
|
||||
assertThat(jobParametersEvent.getDouble("FOOBAR", 5)).isEqualTo(new Double(5));
|
||||
assertThat(jobParametersEvent.getDouble(DOUBLE_KEY, 0))
|
||||
.isEqualTo(DOUBLE_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getLong("FOOBAR", 5)).isEqualTo(new Long(5));
|
||||
assertThat(jobParametersEvent.getLong(LONG_KEY, 5))
|
||||
.isEqualTo(LONG_PARAM.getValue());
|
||||
assertThat(jobParametersEvent.getString("FOOBAR", "TESTVAL"))
|
||||
.isEqualTo("TESTVAL");
|
||||
assertThat(jobParametersEvent.getString(STRING_KEY, "TESTVAL"))
|
||||
.isEqualTo(STRING_PARAM.getValue());
|
||||
|
||||
Date date = new Date();
|
||||
assertEquals(date, jobParametersEvent.getDate("FOOBAR", date));
|
||||
assertEquals(DATE_PARAM.getValue(),
|
||||
jobParametersEvent.getDate(DATE_KEY, date));
|
||||
assertThat(jobParametersEvent.getDate("FOOBAR", date)).isEqualTo(date);
|
||||
assertThat(jobParametersEvent.getDate(DATE_KEY, date))
|
||||
.isEqualTo(DATE_PARAM.getValue());
|
||||
|
||||
}
|
||||
|
||||
public JobParametersEvent getPopulatedParametersEvent() {
|
||||
Map<String, JobParameter> jobParameters = new HashMap<>();
|
||||
jobParameters.put(DATE_KEY, DATE_PARAM);
|
||||
jobParameters.put(STRING_KEY,STRING_PARAM);
|
||||
jobParameters.put(LONG_KEY,LONG_PARAM);
|
||||
jobParameters.put(DOUBLE_KEY,DOUBLE_PARAM);
|
||||
jobParameters.put(STRING_KEY, STRING_PARAM);
|
||||
jobParameters.put(LONG_KEY, LONG_PARAM);
|
||||
jobParameters.put(DOUBLE_KEY, DOUBLE_PARAM);
|
||||
return new JobParametersEvent(jobParameters);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.batch.listener;
|
||||
@@ -29,23 +29,25 @@ import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.cloud.task.batch.listener.support.ExitStatus;
|
||||
import org.springframework.cloud.task.batch.listener.support.StepExecutionEvent;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class StepExecutionEventTests {
|
||||
|
||||
private static final String JOB_NAME = "FOO_JOB";
|
||||
|
||||
private static final String STEP_NAME = "STEP_NAME";
|
||||
private static final Long JOB_INSTANCE_ID = 1l;
|
||||
private static final Long JOB_EXECUTION_ID = 2l;
|
||||
|
||||
private static final Long JOB_INSTANCE_ID = 1L;
|
||||
|
||||
private static final Long JOB_EXECUTION_ID = 2L;
|
||||
|
||||
private static final String JOB_CONFIGURATION_NAME = "FOO_JOB_CONFIG";
|
||||
|
||||
@Test
|
||||
public void testBasic(){
|
||||
public void testBasic() {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
stepExecution.setCommitCount(1);
|
||||
stepExecution.setReadCount(2);
|
||||
@@ -54,16 +56,35 @@ public class StepExecutionEventTests {
|
||||
stepExecution.setWriteSkipCount(5);
|
||||
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertEquals("stepName result was not as expected", STEP_NAME, stepExecutionEvent.getStepName());
|
||||
assertEquals("startTime result was not as expected", stepExecution.getStartTime(), stepExecutionEvent.getStartTime());
|
||||
assertEquals("endTime result was not as expected", stepExecution.getEndTime(), stepExecutionEvent.getEndTime());
|
||||
assertEquals("lastUpdated result was not as expected", stepExecution.getLastUpdated(), stepExecutionEvent.getLastUpdated());
|
||||
assertEquals("commitCount result was not as expected", stepExecution.getCommitCount(), stepExecutionEvent.getCommitCount());
|
||||
assertEquals("readCount result was not as expected", stepExecution.getReadCount(), stepExecutionEvent.getReadCount());
|
||||
assertEquals("readSkipCount result was not as expected", stepExecution.getReadSkipCount(), stepExecutionEvent.getReadSkipCount());
|
||||
assertEquals("writeCount result was not as expected", stepExecution.getWriteCount(), stepExecutionEvent.getWriteCount());
|
||||
assertEquals("writeSkipCount result was not as expected", stepExecution.getWriteSkipCount(), stepExecutionEvent.getWriteSkipCount());
|
||||
assertEquals("skipCount result was not as expected", stepExecution.getSkipCount(), stepExecutionEvent.getSkipCount());
|
||||
assertThat(stepExecutionEvent.getStepName())
|
||||
.as("stepName result was not as expected").isEqualTo(STEP_NAME);
|
||||
assertThat(stepExecutionEvent.getStartTime())
|
||||
.as("startTime result was not as expected")
|
||||
.isEqualTo(stepExecution.getStartTime());
|
||||
assertThat(stepExecutionEvent.getEndTime())
|
||||
.as("endTime result was not as expected")
|
||||
.isEqualTo(stepExecution.getEndTime());
|
||||
assertThat(stepExecutionEvent.getLastUpdated())
|
||||
.as("lastUpdated result was not as expected")
|
||||
.isEqualTo(stepExecution.getLastUpdated());
|
||||
assertThat(stepExecutionEvent.getCommitCount())
|
||||
.as("commitCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getCommitCount());
|
||||
assertThat(stepExecutionEvent.getReadCount())
|
||||
.as("readCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getReadCount());
|
||||
assertThat(stepExecutionEvent.getReadSkipCount())
|
||||
.as("readSkipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getReadSkipCount());
|
||||
assertThat(stepExecutionEvent.getWriteCount())
|
||||
.as("writeCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getWriteCount());
|
||||
assertThat(stepExecutionEvent.getWriteSkipCount())
|
||||
.as("writeSkipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getWriteSkipCount());
|
||||
assertThat(stepExecutionEvent.getSkipCount())
|
||||
.as("skipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getSkipCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,37 +93,37 @@ public class StepExecutionEventTests {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
stepExecution.addFailureException(exception);
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertEquals(1, stepExecutionEvent.getFailureExceptions().size());
|
||||
assertEquals(exception, stepExecution.getFailureExceptions().get(0));
|
||||
assertThat(stepExecutionEvent.getFailureExceptions().size()).isEqualTo(1);
|
||||
assertThat(stepExecution.getFailureExceptions().get(0)).isEqualTo(exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSummary() {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertEquals("StepExecutionEvent: id=null, version=null, name=STEP_NAME, status=STARTING,"
|
||||
+ " exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0,"
|
||||
+ " writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0",
|
||||
stepExecutionEvent.getSummary());
|
||||
assertThat(stepExecutionEvent.getSummary()).isEqualTo(
|
||||
"StepExecutionEvent: id=null, version=null, name=STEP_NAME, status=STARTING,"
|
||||
+ " exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0,"
|
||||
+ " writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
StepExecutionEvent stepExecutionEvent =
|
||||
new StepExecutionEvent(stepExecution);
|
||||
assertEquals("StepExecutionEvent: id=null, version=null, "
|
||||
+ "name=STEP_NAME, status=STARTING, exitStatus=EXECUTING, "
|
||||
+ "readCount=0, filterCount=0, writeCount=0 readSkipCount=0, "
|
||||
+ "writeSkipCount=0, processSkipCount=0, commitCount=0, "
|
||||
+ "rollbackCount=0, exitDescription=", stepExecutionEvent.toString());
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertThat(stepExecutionEvent.toString())
|
||||
.isEqualTo("StepExecutionEvent: id=null, version=null, "
|
||||
+ "name=STEP_NAME, status=STARTING, exitStatus=EXECUTING, "
|
||||
+ "readCount=0, filterCount=0, writeCount=0 readSkipCount=0, "
|
||||
+ "writeSkipCount=0, processSkipCount=0, commitCount=0, "
|
||||
+ "rollbackCount=0, exitDescription=");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertNotNull(stepExecutionEvent.hashCode());
|
||||
assertThat(stepExecutionEvent.hashCode()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,63 +131,65 @@ public class StepExecutionEventTests {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
stepExecution.setId(1L);
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertFalse(stepExecutionEvent.equals(getBasicStepExecution()));
|
||||
assertTrue(stepExecutionEvent.equals(stepExecution));
|
||||
assertThat(stepExecutionEvent.equals(getBasicStepExecution())).isFalse();
|
||||
assertThat(stepExecutionEvent.equals(stepExecution)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettersGetters() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
Date date = new Date();
|
||||
stepExecutionEvent.setLastUpdated(date);
|
||||
assertEquals(date, stepExecutionEvent.getLastUpdated());
|
||||
assertThat(stepExecutionEvent.getLastUpdated()).isEqualTo(date);
|
||||
|
||||
stepExecutionEvent.setProcessSkipCount(55);
|
||||
assertEquals(55, stepExecutionEvent.getProcessSkipCount());
|
||||
assertThat(stepExecutionEvent.getProcessSkipCount()).isEqualTo(55);
|
||||
|
||||
stepExecutionEvent.setWriteSkipCount(47);
|
||||
assertEquals(47, stepExecutionEvent.getWriteSkipCount());
|
||||
assertThat(stepExecutionEvent.getWriteSkipCount()).isEqualTo(47);
|
||||
|
||||
stepExecutionEvent.setReadSkipCount(49);
|
||||
assertEquals(49, stepExecutionEvent.getReadSkipCount());
|
||||
assertThat(stepExecutionEvent.getReadSkipCount()).isEqualTo(49);
|
||||
|
||||
assertEquals(0, stepExecutionEvent.getCommitCount());
|
||||
assertThat(stepExecutionEvent.getCommitCount()).isEqualTo(0);
|
||||
stepExecutionEvent.incrementCommitCount();
|
||||
assertEquals(1, stepExecutionEvent.getCommitCount());
|
||||
assertThat(stepExecutionEvent.getCommitCount()).isEqualTo(1);
|
||||
|
||||
assertFalse(stepExecutionEvent.isTerminateOnly());
|
||||
assertThat(stepExecutionEvent.isTerminateOnly()).isFalse();
|
||||
stepExecutionEvent.setTerminateOnly();
|
||||
assertTrue(stepExecutionEvent.isTerminateOnly());
|
||||
assertThat(stepExecutionEvent.isTerminateOnly()).isTrue();
|
||||
|
||||
stepExecutionEvent.setStepName("FOOBAR");
|
||||
assertEquals("FOOBAR", stepExecutionEvent.getStepName());
|
||||
assertThat(stepExecutionEvent.getStepName()).isEqualTo("FOOBAR");
|
||||
|
||||
stepExecutionEvent.setStartTime(date);
|
||||
assertEquals(date, stepExecutionEvent.getStartTime());
|
||||
assertThat(stepExecutionEvent.getStartTime()).isEqualTo(date);
|
||||
|
||||
assertEquals(0, stepExecutionEvent.getRollbackCount());
|
||||
assertThat(stepExecutionEvent.getRollbackCount()).isEqualTo(0);
|
||||
stepExecutionEvent.setRollbackCount(33);
|
||||
assertEquals(33, stepExecutionEvent.getRollbackCount());
|
||||
assertThat(stepExecutionEvent.getRollbackCount()).isEqualTo(33);
|
||||
|
||||
stepExecutionEvent.setFilterCount(23);
|
||||
assertEquals(23, stepExecutionEvent.getFilterCount());
|
||||
assertThat(stepExecutionEvent.getFilterCount()).isEqualTo(23);
|
||||
|
||||
stepExecutionEvent.setWriteCount(11);
|
||||
assertEquals(11,stepExecutionEvent.getWriteCount());
|
||||
assertThat(stepExecutionEvent.getWriteCount()).isEqualTo(11);
|
||||
|
||||
stepExecutionEvent.setReadCount(12);
|
||||
assertEquals(12, stepExecutionEvent.getReadCount());
|
||||
assertThat(stepExecutionEvent.getReadCount()).isEqualTo(12);
|
||||
|
||||
stepExecutionEvent.setEndTime(date);
|
||||
assertEquals(date, stepExecutionEvent.getEndTime());
|
||||
assertThat(stepExecutionEvent.getEndTime()).isEqualTo(date);
|
||||
|
||||
stepExecutionEvent.setCommitCount(29);
|
||||
assertEquals(29, stepExecutionEvent.getCommitCount());
|
||||
assertThat(stepExecutionEvent.getCommitCount()).isEqualTo(29);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExitStatus() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
public void testExitStatus() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
final String EXIT_CODE = "1";
|
||||
final String EXIT_DESCRIPTION = "EXPECTED FAILURE";
|
||||
ExitStatus exitStatus = new ExitStatus();
|
||||
@@ -175,41 +198,48 @@ public class StepExecutionEventTests {
|
||||
|
||||
stepExecutionEvent.setExitStatus(exitStatus);
|
||||
ExitStatus actualExitStatus = stepExecutionEvent.getExitStatus();
|
||||
assertNotNull(actualExitStatus);
|
||||
assertEquals(exitStatus.getExitCode(), actualExitStatus.getExitCode());
|
||||
assertEquals(exitStatus.getExitDescription(), actualExitStatus.getExitDescription());
|
||||
assertThat(actualExitStatus).isNotNull();
|
||||
assertThat(actualExitStatus.getExitCode()).isEqualTo(exitStatus.getExitCode());
|
||||
assertThat(actualExitStatus.getExitDescription())
|
||||
.isEqualTo(exitStatus.getExitDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchStatus() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
assertEquals(BatchStatus.STARTING, stepExecutionEvent.getStatus());
|
||||
public void testBatchStatus() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
assertThat(stepExecutionEvent.getStatus()).isEqualTo(BatchStatus.STARTING);
|
||||
stepExecutionEvent.setStatus(BatchStatus.ABANDONED);
|
||||
assertEquals(BatchStatus.ABANDONED, stepExecutionEvent.getStatus());
|
||||
assertThat(stepExecutionEvent.getStatus()).isEqualTo(BatchStatus.ABANDONED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructor() {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent();
|
||||
assertEquals(BatchStatus.STARTING, stepExecutionEvent.getStatus());
|
||||
assertNotNull(stepExecutionEvent.getExitStatus());
|
||||
assertEquals("EXECUTING", stepExecutionEvent.getExitStatus().getExitCode());
|
||||
assertThat(stepExecutionEvent.getStatus()).isEqualTo(BatchStatus.STARTING);
|
||||
assertThat(stepExecutionEvent.getExitStatus()).isNotNull();
|
||||
assertThat(stepExecutionEvent.getExitStatus().getExitCode())
|
||||
.isEqualTo("EXECUTING");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutionContext() {
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.put("hello", "world");
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(getBasicStepExecution());
|
||||
assertNotNull(stepExecutionEvent.getExecutionContext());
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(
|
||||
getBasicStepExecution());
|
||||
assertThat(stepExecutionEvent.getExecutionContext()).isNotNull();
|
||||
stepExecutionEvent.setExecutionContext(executionContext);
|
||||
assertEquals("world", stepExecutionEvent.getExecutionContext().getString("hello"));
|
||||
assertThat(stepExecutionEvent.getExecutionContext().getString("hello"))
|
||||
.isEqualTo("world");
|
||||
}
|
||||
|
||||
private StepExecution getBasicStepExecution() {
|
||||
JobInstance jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME);
|
||||
JobParameters jobParameters = new JobParameters();
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters, JOB_CONFIGURATION_NAME);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID,
|
||||
jobParameters, JOB_CONFIGURATION_NAME);
|
||||
return new StepExecution(STEP_NAME, jobExecution);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.batch.listener;
|
||||
@@ -40,8 +40,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@@ -51,15 +50,6 @@ import static org.mockito.Mockito.when;
|
||||
@SpringBootTest
|
||||
public class TaskBatchEventListenerBeanPostProcessorTests {
|
||||
|
||||
@MockBean
|
||||
private TaskletStep taskletStep;
|
||||
|
||||
@MockBean
|
||||
private SimpleChunkProvider chunkProvider;
|
||||
|
||||
@MockBean
|
||||
private SimpleChunkProcessor chunkProcessor;
|
||||
|
||||
@MockBean
|
||||
ItemProcessListener itemProcessListener;
|
||||
|
||||
@@ -78,46 +68,63 @@ public class TaskBatchEventListenerBeanPostProcessorTests {
|
||||
@MockBean
|
||||
SkipListener skipListener;
|
||||
|
||||
@MockBean
|
||||
private TaskletStep taskletStep;
|
||||
|
||||
@MockBean
|
||||
private SimpleChunkProvider chunkProvider;
|
||||
|
||||
@MockBean
|
||||
private SimpleChunkProcessor chunkProcessor;
|
||||
|
||||
@Autowired
|
||||
private GenericApplicationContext context;
|
||||
|
||||
|
||||
@Before
|
||||
public void setupMock() {
|
||||
when(taskletStep.getTasklet()).thenReturn(
|
||||
new ChunkOrientedTasklet(chunkProvider, chunkProcessor));
|
||||
when(taskletStep.getName()).thenReturn("FOOOBAR");
|
||||
when(this.taskletStep.getTasklet()).thenReturn(
|
||||
new ChunkOrientedTasklet(this.chunkProvider, this.chunkProcessor));
|
||||
when(this.taskletStep.getName()).thenReturn("FOOOBAR");
|
||||
|
||||
registerAlias(ItemProcessListener.class, BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER);
|
||||
registerAlias(StepExecutionListener.class, BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
registerAlias(ChunkListener.class, BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER);
|
||||
registerAlias(ItemReadListener.class, BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER);
|
||||
registerAlias(ItemWriteListener.class, BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER);
|
||||
registerAlias(SkipListener.class, BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER);
|
||||
registerAlias(ItemProcessListener.class,
|
||||
BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER);
|
||||
registerAlias(StepExecutionListener.class,
|
||||
BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
registerAlias(ChunkListener.class,
|
||||
BatchEventAutoConfiguration.CHUNK_EVENTS_LISTENER);
|
||||
registerAlias(ItemReadListener.class,
|
||||
BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER);
|
||||
registerAlias(ItemWriteListener.class,
|
||||
BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER);
|
||||
registerAlias(SkipListener.class,
|
||||
BatchEventAutoConfiguration.SKIP_EVENTS_LISTENER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostProcessor() {
|
||||
TaskBatchEventListenerBeanPostProcessor postProcessor =
|
||||
context.getBean(TaskBatchEventListenerBeanPostProcessor.class);
|
||||
assertNotNull(postProcessor);
|
||||
TaskletStep updatedTaskletStep = (TaskletStep)
|
||||
postProcessor.postProcessBeforeInitialization(taskletStep, "FOO");
|
||||
assertEquals(taskletStep, updatedTaskletStep);
|
||||
TaskBatchEventListenerBeanPostProcessor postProcessor = this.context
|
||||
.getBean(TaskBatchEventListenerBeanPostProcessor.class);
|
||||
assertThat(postProcessor).isNotNull();
|
||||
TaskletStep updatedTaskletStep = (TaskletStep) postProcessor
|
||||
.postProcessBeforeInitialization(this.taskletStep, "FOO");
|
||||
assertThat(updatedTaskletStep).isEqualTo(this.taskletStep);
|
||||
}
|
||||
|
||||
private void registerAlias(Class clazz, String name) {
|
||||
assertThat(this.context.getBeanNamesForType(clazz).length).isEqualTo(1);
|
||||
this.context.registerAlias(this.context.getBeanNamesForType(clazz)[0], name);
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
public static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskBatchEventListenerBeanPostProcessor taskBatchEventListenerBeanPostProcessor() {
|
||||
return new TaskBatchEventListenerBeanPostProcessor();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerAlias(Class clazz, String name) {
|
||||
assertEquals(1, context.getBeanNamesForType(clazz).length);
|
||||
context.registerAlias(context.getBeanNamesForType(clazz)[0],name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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;
|
||||
@@ -29,42 +29,40 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the TaskLauncherConfiguration in a case where a TaskLauncher is already
|
||||
* present.
|
||||
* Tests the TaskLauncherConfiguration in a case where a TaskLauncher is already present.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes =
|
||||
{TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class})
|
||||
@SpringBootTest(classes = {
|
||||
TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class })
|
||||
public class TaskLaunchConfigurationExistingTests {
|
||||
|
||||
private static TaskLauncher testTaskLauncher;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
private static TaskLauncher testTaskLauncher;
|
||||
|
||||
@Test
|
||||
public void testTaskLauncher() {
|
||||
LocalTaskLauncher taskLauncher =
|
||||
context.getBean(LocalTaskLauncher.class);
|
||||
assertNotNull(testTaskLauncher);
|
||||
assertNotNull(taskLauncher);
|
||||
assertEquals(testTaskLauncher, taskLauncher);
|
||||
LocalTaskLauncher taskLauncher = this.context.getBean(LocalTaskLauncher.class);
|
||||
assertThat(testTaskLauncher).isNotNull();
|
||||
assertThat(taskLauncher).isNotNull();
|
||||
assertThat(taskLauncher).isEqualTo(testTaskLauncher);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class TestTaskDeployerConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskLauncher taskLauncher() {
|
||||
testTaskLauncher =
|
||||
new LocalTaskLauncher(new LocalDeployerProperties());
|
||||
testTaskLauncher = new LocalTaskLauncher(new LocalDeployerProperties());
|
||||
return testTaskLauncher;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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;
|
||||
@@ -24,14 +24,13 @@ 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;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class TaskLaunchRequestTests {
|
||||
|
||||
public static final String URI = "http://myURI";
|
||||
|
||||
public static final String APP_NAME = "MY_APP_NAME";
|
||||
@@ -43,51 +42,47 @@ public class TaskLaunchRequestTests {
|
||||
args.add("foo");
|
||||
map.put("bar", "baz");
|
||||
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
TaskLaunchRequest request2 = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
assertFalse(request.equals(null));
|
||||
assertFalse(request.equals("nope"));
|
||||
assertTrue(request.equals(request));
|
||||
assertTrue(request.equals(request2));
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
TaskLaunchRequest request2 = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
assertThat(request.equals(null)).isFalse();
|
||||
assertThat(request.equals("nope")).isFalse();
|
||||
assertThat(request.equals(request)).isTrue();
|
||||
assertThat(request.equals(request2)).isTrue();
|
||||
TaskLaunchRequest requestDiff = new TaskLaunchRequest("http://oops",
|
||||
Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
Collections.EMPTY_LIST, Collections.EMPTY_MAP, Collections.EMPTY_MAP,
|
||||
null);
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI, args, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI,
|
||||
null, null, null, null);
|
||||
assertTrue(request.equals(requestDiff));
|
||||
requestDiff = new TaskLaunchRequest(URI, null, null, null, null);
|
||||
assertThat(request.equals(requestDiff)).isTrue();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI, Collections.EMPTY_LIST, map,
|
||||
Collections.EMPTY_MAP, null);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
requestDiff = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, map, null);
|
||||
assertFalse(request.equals(requestDiff));
|
||||
assertThat(request.equals(requestDiff)).isFalse();
|
||||
|
||||
assertEquals(request.hashCode(), request.hashCode());
|
||||
assertThat(request.hashCode()).isEqualTo(request.hashCode());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationName() {
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, null);
|
||||
assertTrue(request.getApplicationName().startsWith("Task-"));
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, null);
|
||||
assertThat(request.getApplicationName().startsWith("Task-")).isTrue();
|
||||
|
||||
request = new TaskLaunchRequest(URI,
|
||||
Collections.EMPTY_LIST, Collections.EMPTY_MAP,
|
||||
Collections.EMPTY_MAP, APP_NAME);
|
||||
assertEquals(APP_NAME, request.getApplicationName());
|
||||
request = new TaskLaunchRequest(URI, Collections.EMPTY_LIST,
|
||||
Collections.EMPTY_MAP, Collections.EMPTY_MAP, APP_NAME);
|
||||
assertThat(request.getApplicationName()).isEqualTo(APP_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
* Copyright 2015-2019 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.
|
||||
@@ -36,11 +36,10 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {TaskLauncherSinkApplication.class, TaskConfiguration.class} )
|
||||
@SpringBootTest(classes = { TaskLauncherSinkApplication.class, TaskConfiguration.class })
|
||||
public class TaskLauncherSinkTests {
|
||||
|
||||
private final static String TASK_NAME_PREFIX = "Task-";
|
||||
@@ -57,10 +56,10 @@ public class TaskLauncherSinkTests {
|
||||
private final static String INVALID_URL = "maven://not.real.group:"
|
||||
+ "invalid:jar:1.0.0.BUILD-SNAPSHOT";
|
||||
|
||||
private Map<String, String> properties;
|
||||
|
||||
private final static String DEFAULT_STATUS = "test_status";
|
||||
|
||||
private Map<String, String> properties;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@@ -69,8 +68,8 @@ public class TaskLauncherSinkTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
properties = new HashMap<>();
|
||||
properties.put("server.port", "0");
|
||||
this.properties = new HashMap<>();
|
||||
this.properties.put("server.port", "0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +78,8 @@ public class TaskLauncherSinkTests {
|
||||
commandLineArgs.add(PARAM1);
|
||||
commandLineArgs.add(PARAM2);
|
||||
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL, commandLineArgs, null);
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL,
|
||||
commandLineArgs, null);
|
||||
verifySuccessWithParams(testTaskLauncher);
|
||||
|
||||
testTaskLauncher = launchTaskByteArray(VALID_URL, commandLineArgs, null);
|
||||
@@ -89,17 +89,21 @@ public class TaskLauncherSinkTests {
|
||||
verifySuccessWithParams(testTaskLauncher);
|
||||
}
|
||||
|
||||
private void verifySuccessWithParams(TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertEquals(LaunchState.complete, testTaskLauncher.status(DEFAULT_STATUS).getState());
|
||||
assertEquals(2, testTaskLauncher.getCommandlineArguments().size());
|
||||
assertEquals(PARAM1, testTaskLauncher.getCommandlineArguments().get(0));
|
||||
assertEquals(PARAM2, testTaskLauncher.getCommandlineArguments().get(1));
|
||||
assertTrue(testTaskLauncher.getApplicationName().startsWith(TASK_NAME_PREFIX));
|
||||
private void verifySuccessWithParams(
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.complete);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().size()).isEqualTo(2);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().get(0)).isEqualTo(PARAM1);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().get(1)).isEqualTo(PARAM2);
|
||||
assertThat(testTaskLauncher.getApplicationName().startsWith(TASK_NAME_PREFIX))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessWithAppName() throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL, null, APP_NAME);
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL,
|
||||
null, APP_NAME);
|
||||
verifySuccessWithAppName(testTaskLauncher);
|
||||
|
||||
testTaskLauncher = launchTaskByteArray(VALID_URL, null, APP_NAME);
|
||||
@@ -110,21 +114,24 @@ public class TaskLauncherSinkTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidJar() throws Exception{
|
||||
public void testInvalidJar() throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskTaskLaunchRequest(
|
||||
INVALID_URL, null, APP_NAME);
|
||||
verifySuccessWithAppName(testTaskLauncher);
|
||||
}
|
||||
|
||||
private void verifySuccessWithAppName(TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertEquals(LaunchState.complete, testTaskLauncher.status(DEFAULT_STATUS).getState());
|
||||
assertEquals(0, testTaskLauncher.getCommandlineArguments().size());
|
||||
assertEquals(APP_NAME, testTaskLauncher.getApplicationName());
|
||||
private void verifySuccessWithAppName(
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.complete);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().size()).isEqualTo(0);
|
||||
assertThat(testTaskLauncher.getApplicationName()).isEqualTo(APP_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessNoParams() throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL, null, null);
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL,
|
||||
null, null);
|
||||
verifySuccessWithNoParams(testTaskLauncher);
|
||||
|
||||
testTaskLauncher = launchTaskByteArray(VALID_URL, null, null);
|
||||
@@ -134,23 +141,29 @@ public class TaskLauncherSinkTests {
|
||||
verifySuccessWithNoParams(testTaskLauncher);
|
||||
}
|
||||
|
||||
private void verifySuccessWithNoParams(TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertEquals(LaunchState.complete, testTaskLauncher.status(DEFAULT_STATUS).getState());
|
||||
assertEquals(0, testTaskLauncher.getCommandlineArguments().size());
|
||||
assertTrue(testTaskLauncher.getApplicationName().startsWith(TASK_NAME_PREFIX));
|
||||
private void verifySuccessWithNoParams(
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher) {
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.complete);
|
||||
assertThat(testTaskLauncher.getCommandlineArguments().size()).isEqualTo(0);
|
||||
assertThat(testTaskLauncher.getApplicationName().startsWith(TASK_NAME_PREFIX))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRun() {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher =
|
||||
context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
assertEquals(LaunchState.unknown, testTaskLauncher.status(DEFAULT_STATUS).getState());
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = this.context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState())
|
||||
.isEqualTo(LaunchState.unknown);
|
||||
}
|
||||
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskString(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName) throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs, applicationName);
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = this.context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
applicationName);
|
||||
GenericMessage<String> message = new GenericMessage<>(stringRequest);
|
||||
|
||||
this.sink.input().send(message);
|
||||
@@ -159,9 +172,10 @@ public class TaskLauncherSinkTests {
|
||||
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskByteArray(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName) throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher =
|
||||
context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs, applicationName);
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = this.context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
String stringRequest = getStringTaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
applicationName);
|
||||
GenericMessage<byte[]> message = new GenericMessage<>(stringRequest.getBytes());
|
||||
|
||||
this.sink.input().send(message);
|
||||
@@ -170,21 +184,23 @@ public class TaskLauncherSinkTests {
|
||||
|
||||
private String getStringTaskLaunchRequest(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName) throws Exception {
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL,
|
||||
commandLineArgs, properties, null, applicationName);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
this.properties, null, applicationName);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString(request);
|
||||
}
|
||||
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskTaskLaunchRequest(String artifactURL,
|
||||
List<String> commandLineArgs, String applicationName) throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher =
|
||||
context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL,
|
||||
commandLineArgs, properties, null, applicationName);
|
||||
private TaskConfiguration.TestTaskLauncher launchTaskTaskLaunchRequest(
|
||||
String artifactURL, List<String> commandLineArgs, String applicationName)
|
||||
throws Exception {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = this.context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(artifactURL, commandLineArgs,
|
||||
this.properties, null, applicationName);
|
||||
GenericMessage<TaskLaunchRequest> message = new GenericMessage<>(request);
|
||||
|
||||
this.sink.input().send(message);
|
||||
return testTaskLauncher;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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.
|
||||
@@ -34,11 +34,11 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class TaskConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskLauncher taskLauncher(){
|
||||
public TaskLauncher taskLauncher() {
|
||||
return new TestTaskLauncher();
|
||||
}
|
||||
|
||||
public static class TestTaskLauncher implements TaskLauncher{
|
||||
public static class TestTaskLauncher implements TaskLauncher {
|
||||
|
||||
public static final String LAUNCH_ID = "TEST_LAUNCH_ID";
|
||||
|
||||
@@ -50,7 +50,7 @@ public class TaskConfiguration {
|
||||
|
||||
@Override
|
||||
public String launch(AppDeploymentRequest request) {
|
||||
state = LaunchState.complete;
|
||||
this.state = LaunchState.complete;
|
||||
this.commandlineArguments = request.getCommandlineArguments();
|
||||
this.applicationName = request.getDefinition().getName();
|
||||
return null;
|
||||
@@ -63,7 +63,7 @@ public class TaskConfiguration {
|
||||
|
||||
@Override
|
||||
public TaskStatus status(String id) {
|
||||
return new TaskStatus(LAUNCH_ID, state, null);
|
||||
return new TaskStatus(LAUNCH_ID, this.state, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,11 +82,13 @@ public class TaskConfiguration {
|
||||
}
|
||||
|
||||
public List<String> getCommandlineArguments() {
|
||||
return commandlineArguments;
|
||||
return this.commandlineArguments;
|
||||
}
|
||||
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
return this.applicationName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2015-2019 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.
|
||||
@@ -30,4 +30,5 @@ public class TaskLauncherSinkApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TaskLauncherSinkApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
* Copyright 2015-2019 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.task.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -31,7 +32,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.annotation.BridgeFrom;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
@@ -43,19 +44,21 @@ public class TaskEventTests {
|
||||
@Test
|
||||
public void testDefaultConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
TaskEventAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
TestSupportBinderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
BindingServiceConfiguration.class))
|
||||
.withUserConfiguration(TaskEventsConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.closecontext_enabled=false",
|
||||
"spring.main.web-environment=false");
|
||||
applicationContextRunner.run((context) -> {
|
||||
assertNotNull(context.getBean("taskEventListener"));
|
||||
assertNotNull(context.getBean(TaskEventAutoConfiguration.TaskEventChannels.class));
|
||||
assertThat(context.getBean("taskEventListener")).isNotNull();
|
||||
assertThat(
|
||||
context.getBean(TaskEventAutoConfiguration.TaskEventChannels.class))
|
||||
.isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,6 +71,7 @@ public class TaskEventTests {
|
||||
public NullChannel testEmptyChannel() {
|
||||
return new NullChannel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user