@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -54,227 +54,6 @@ import static org.junit.Assert.fail;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RemoteChunkingParserTests {
|
||||
|
||||
/* TODO delete the following deprecated tests when related APIs are removed
|
||||
* /!\ Deliberately not using parametrized tests as it will be easier to delete
|
||||
* the following tests afterwards
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testRemoteChunkingSlaveParserWithProcessorDefined() {
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserTests.xml");
|
||||
|
||||
ChunkHandler chunkHandler = applicationContext.getBean(ChunkProcessorChunkHandler.class);
|
||||
ChunkProcessor chunkProcessor = (SimpleChunkProcessor) TestUtils.getPropertyValue(chunkHandler, "chunkProcessor");
|
||||
assertNotNull("ChunkProcessor must not be null", chunkProcessor);
|
||||
|
||||
ItemWriter<String> itemWriter = (ItemWriter<String>) TestUtils.getPropertyValue(chunkProcessor, "itemWriter");
|
||||
assertNotNull("ChunkProcessor ItemWriter must not be null", itemWriter);
|
||||
assertTrue("Got wrong instance of ItemWriter", itemWriter instanceof Writer);
|
||||
|
||||
ItemProcessor<String, String> itemProcessor = (ItemProcessor<String, String>) TestUtils.getPropertyValue(chunkProcessor, "itemProcessor");
|
||||
assertNotNull("ChunkProcessor ItemWriter must not be null", itemProcessor);
|
||||
assertTrue("Got wrong instance of ItemProcessor", itemProcessor instanceof Processor);
|
||||
|
||||
FactoryBean serviceActivatorFactoryBean = applicationContext.getBean(ServiceActivatorFactoryBean.class);
|
||||
assertNotNull("ServiceActivatorFactoryBean must not be null", serviceActivatorFactoryBean);
|
||||
assertNotNull("Output channel name must not be null", TestUtils.getPropertyValue(serviceActivatorFactoryBean, "outputChannelName"));
|
||||
|
||||
MessageChannel inputChannel = applicationContext.getBean("requests", MessageChannel.class);
|
||||
assertNotNull("Input channel must not be null", inputChannel);
|
||||
|
||||
String targetMethodName = (String) TestUtils.getPropertyValue(serviceActivatorFactoryBean, "targetMethodName");
|
||||
assertNotNull("Target method name must not be null", targetMethodName);
|
||||
assertTrue("Target method name must be handleChunk, got: " + targetMethodName, "handleChunk".equals(targetMethodName));
|
||||
|
||||
ChunkHandler targetObject = (ChunkHandler) TestUtils.getPropertyValue(serviceActivatorFactoryBean, "targetObject");
|
||||
assertNotNull("Target object must not be null", targetObject);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testRemoteChunkingSlaveParserWithProcessorNotDefined() {
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserNoProcessorTests.xml");
|
||||
|
||||
ChunkHandler chunkHandler = applicationContext.getBean(ChunkProcessorChunkHandler.class);
|
||||
ChunkProcessor chunkProcessor = (SimpleChunkProcessor) TestUtils.getPropertyValue(chunkHandler, "chunkProcessor");
|
||||
assertNotNull("ChunkProcessor must not be null", chunkProcessor);
|
||||
|
||||
ItemProcessor<String, String> itemProcessor = (ItemProcessor<String, String>) TestUtils.getPropertyValue(chunkProcessor, "itemProcessor");
|
||||
assertNotNull("ChunkProcessor ItemWriter must not be null", itemProcessor);
|
||||
assertTrue("Got wrong instance of ItemProcessor", itemProcessor instanceof PassThroughItemProcessor);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testRemoteChunkingMasterParser() {
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserTests.xml");
|
||||
|
||||
ItemWriter itemWriter = applicationContext.getBean("itemWriter", ChunkMessageChannelItemWriter.class);
|
||||
assertNotNull("Messaging template must not be null", TestUtils.getPropertyValue(itemWriter, "messagingGateway"));
|
||||
assertNotNull("Reply channel must not be null", TestUtils.getPropertyValue(itemWriter, "replyChannel"));
|
||||
|
||||
FactoryBean<ChunkHandler> remoteChunkingHandlerFactoryBean = applicationContext.getBean(RemoteChunkHandlerFactoryBean.class);
|
||||
assertNotNull("Chunk writer must not be null", TestUtils.getPropertyValue(remoteChunkingHandlerFactoryBean, "chunkWriter"));
|
||||
assertNotNull("Step must not be null", TestUtils.getPropertyValue(remoteChunkingHandlerFactoryBean, "step"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingMasterIdAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingIdAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The id attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The id attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingMasterMessageTemplateAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingMessageTemplateAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The message-template attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The message-template attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingMasterStepAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingStepAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The step attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The step attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingMasterReplyChannelAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingReplyChannelAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The reply-channel attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The reply-channel attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingSlaveIdAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingIdAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The id attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The id attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingSlaveInputChannelAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingInputChannelAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The input-channel attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The input-channel attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingSlaveItemWriterAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingItemWriterAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The item-writer attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The item-writer attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoteChunkingSlaveOutputChannelAttrAssert() throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
|
||||
applicationContext.setValidating(false);
|
||||
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingOutputChannelAttrTests.xml");
|
||||
|
||||
try {
|
||||
applicationContext.refresh();
|
||||
fail();
|
||||
} catch (BeanDefinitionStoreException e) {
|
||||
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
|
||||
|
||||
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
|
||||
|
||||
assertTrue("Expected: " + "The output-channel attribute must be specified" + " but got: " + iae.getMessage(),
|
||||
"The output-channel attribute must be specified".equals(iae.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO end of deprecated tests to remove */
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testRemoteChunkingWorkerParserWithProcessorDefined() {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
@Test
|
||||
public void inputChannelMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningMasterStepBuilder builder = new RemotePartitioningMasterStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
|
||||
// when
|
||||
final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class,
|
||||
@@ -68,7 +68,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
@Test
|
||||
public void outputChannelMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningMasterStepBuilder builder = new RemotePartitioningMasterStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
|
||||
// when
|
||||
final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class,
|
||||
@@ -81,7 +81,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
@Test
|
||||
public void messagingTemplateMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningMasterStepBuilder builder = new RemotePartitioningMasterStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
|
||||
// when
|
||||
final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class,
|
||||
@@ -94,7 +94,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
@Test
|
||||
public void jobExplorerMustNotBeNull() {
|
||||
// given
|
||||
final RemotePartitioningMasterStepBuilder builder = new RemotePartitioningMasterStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
|
||||
// when
|
||||
final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class,
|
||||
@@ -107,7 +107,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
@Test
|
||||
public void pollIntervalMustBeGreaterThanZero() {
|
||||
// given
|
||||
final RemotePartitioningMasterStepBuilder builder = new RemotePartitioningMasterStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
|
||||
// when
|
||||
final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class,
|
||||
@@ -120,7 +120,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
@Test
|
||||
public void eitherOutputChannelOrMessagingTemplateMustBeProvided() {
|
||||
// given
|
||||
RemotePartitioningMasterStepBuilder builder = new RemotePartitioningMasterStepBuilder("step")
|
||||
RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step")
|
||||
.outputChannel(new DirectChannel())
|
||||
.messagingTemplate(new MessagingTemplate());
|
||||
|
||||
@@ -136,15 +136,15 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
public void testUnsupportedOperationExceptionWhenSpecifyingPartitionHandler() {
|
||||
// given
|
||||
PartitionHandler partitionHandler = Mockito.mock(PartitionHandler.class);
|
||||
final RemotePartitioningMasterStepBuilder builder = new RemotePartitioningMasterStepBuilder("step");
|
||||
final RemotePartitioningManagerStepBuilder builder = new RemotePartitioningManagerStepBuilder("step");
|
||||
|
||||
// when
|
||||
final Exception expectedException = Assert.assertThrows(UnsupportedOperationException.class,
|
||||
() -> builder.partitionHandler(partitionHandler));
|
||||
|
||||
// then
|
||||
assertThat(expectedException).hasMessage("When configuring a master step " +
|
||||
"for remote partitioning using the RemotePartitioningMasterStepBuilder, " +
|
||||
assertThat(expectedException).hasMessage("When configuring a manager step " +
|
||||
"for remote partitioning using the RemotePartitioningManagerStepBuilder, " +
|
||||
"the partition handler will be automatically set to an instance " +
|
||||
"of MessageChannelPartitionHandler. The partition handler must " +
|
||||
"not be provided in this case.");
|
||||
@@ -162,7 +162,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
StepExecutionAggregator stepExecutionAggregator = (result, executions) -> { };
|
||||
|
||||
// when
|
||||
Step step = new RemotePartitioningMasterStepBuilder("masterStep")
|
||||
Step step = new RemotePartitioningManagerStepBuilder("masterStep")
|
||||
.repository(jobRepository)
|
||||
.outputChannel(outputChannel)
|
||||
.partitioner("workerStep", partitioner)
|
||||
@@ -205,7 +205,7 @@ public class RemotePartitioningMasterStepBuilderTests {
|
||||
StepExecutionAggregator stepExecutionAggregator = (result, executions) -> { };
|
||||
|
||||
// when
|
||||
Step step = new RemotePartitioningMasterStepBuilder("masterStep")
|
||||
Step step = new RemotePartitioningManagerStepBuilder("masterStep")
|
||||
.repository(jobRepository)
|
||||
.outputChannel(outputChannel)
|
||||
.partitioner("workerStep", partitioner)
|
||||
|
||||
Reference in New Issue
Block a user