INTEXT-197: Lifecycle attrs for s3-outbound-c-a

JIRA: https://jira.spring.io/browse/INTEXT-197

* Modified the `org/springframework/integration/aws/config/xml/spring-integration-aws-1.0.xsd` to add `channelAdapterAttributes` to expose
`phase` attribute in `s3 outbound adapter`.
* Modified `AmazonS3OutboundChannelAdapterParserTests` - Added Unit Test Class to test the `channelAdapterAttributes`.
* Modified `s3-valid-outbound-cases.xml` - Added separate definition `withChannelAdapterAttributes` for phase attribute.

Polishing according PR comments
This commit is contained in:
Karthik Palanivelu
2015-10-02 15:48:13 -04:00
committed by Artem Bilan
parent c674a8dace
commit dc66af65eb
3 changed files with 45 additions and 21 deletions

View File

@@ -70,18 +70,10 @@
</xsd:annotation>
<xsd:choice minOccurs="0" maxOccurs="2">
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType" minOccurs="0"
maxOccurs="1"/>
</xsd:choice>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attributeGroup ref="integration:channelAdapterAttributes"/>
<xsd:attributeGroup ref="awsAdaptersCommonAttributes"/>
<xsd:attribute name="bucket" type="xsd:string" use="required">
<xsd:annotation>
@@ -189,7 +181,6 @@
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="auto-startup" type="xsd:string" default="true"/>
<xsd:attribute name="order">
<xsd:annotation>
<xsd:documentation>
@@ -577,7 +568,7 @@
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.messaging.MessageChannel" />
<tool:expected-type type="org.springframework.messaging.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>

View File

@@ -17,6 +17,7 @@
package org.springframework.integration.aws.s3.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.springframework.integration.test.util.TestUtils.getPropertyValue;
@@ -65,7 +66,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
assertNotNull(expression);
assertEquals(LiteralExpression.class, expression.getClass());
assertEquals("/", getPropertyValue(expression, "literalValue", String.class));
ctx.destroy();
ctx.close();
}
/**
@@ -93,7 +94,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
assertEquals(".write", getPropertyValue(handler, "fileNameGenerator.temporarySuffix", String.class));
assertEquals("headers['name']", getPropertyValue(handler, "fileNameGenerator.fileNameExpression", String.class));
assertEquals(ctx.getBean("executor"), getPropertyValue(handler, "operations.threadPoolExecutor"));
ctx.destroy();
ctx.close();
}
/**
@@ -105,7 +106,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
EventDrivenConsumer consumer = ctx.getBean("withCustomNameGenerator", EventDrivenConsumer.class);
AmazonS3MessageHandler handler = getPropertyValue(consumer, "handler", AmazonS3MessageHandler.class);
assertEquals(DummyFileNameGenerator.class, getPropertyValue(handler, "fileNameGenerator").getClass());
ctx.destroy();
ctx.close();
}
/**
@@ -118,7 +119,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
AmazonS3MessageHandler handler = getPropertyValue(consumer, "handler", AmazonS3MessageHandler.class);
assertEquals("http://s3-eu-west-1.amazonaws.com",
getPropertyValue(handler, "operations.client.endpoint", URI.class).toString());
ctx.destroy();
ctx.close();
}
/**
@@ -127,7 +128,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
*/
@Test(expected = BeanCreationException.class)
public void withMultiUploadLessThan5120() {
new ClassPathXmlApplicationContext("s3-multiupload-lessthan-5120.xml");
new ClassPathXmlApplicationContext("s3-multiupload-lessthan-5120.xml").close();
}
/**
@@ -135,7 +136,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
*/
@Test(expected = BeanDefinitionStoreException.class)
public void withBothFileGeneratorAndExpression() {
new ClassPathXmlApplicationContext("s3-both-customfilegenerator-and-expression.xml");
new ClassPathXmlApplicationContext("s3-both-customfilegenerator-and-expression.xml").close();
}
/**
@@ -145,7 +146,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
*/
@Test(expected = BeanDefinitionStoreException.class)
public void withCustomOperationsAndDisallowedAttributes() {
new ClassPathXmlApplicationContext("s3-custom-operations-with-disallowed-attributes.xml");
new ClassPathXmlApplicationContext("s3-custom-operations-with-disallowed-attributes.xml").close();
}
/**
@@ -159,7 +160,23 @@ public class AmazonS3OutboundChannelAdapterParserTests {
MessageHandler handler = getPropertyValue(consumer, "handler", MessageHandler.class);
handler.handleMessage(new GenericMessage<String>("String content: Test AWS advice chain"));
assertEquals(1, adviceCalled);
ctx.destroy();
ctx.close();
}
/**
* Test case for the xml definition with the Channel Attributes.
*/
@Test
public void withChannelAttributeImplementation() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:s3-valid-outbound-cases.xml");
EventDrivenConsumer consumer = ctx.getBean("withChannelAdapterAttributes", EventDrivenConsumer.class);
AmazonS3MessageHandler handler = getPropertyValue(consumer, "handler", AmazonS3MessageHandler.class);
assertEquals(DefaultAmazonS3Operations.class, getPropertyValue(handler, "operations").getClass());
assertEquals("input", getPropertyValue(consumer, "inputChannel.beanName", String.class));
assertEquals("US-ASCII", getPropertyValue(handler, "charset", String.class));
assertEquals(100, getPropertyValue(consumer, "phase"));
assertFalse(getPropertyValue(consumer, "autoStartup", Boolean.class));
ctx.close();
}
public static class DummyFileNameGenerator implements FileNameGenerationStrategy {
@@ -168,6 +185,7 @@ public class AmazonS3OutboundChannelAdapterParserTests {
public String generateFileName(Message<?> message) {
return null;
}
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {

View File

@@ -68,6 +68,21 @@
</int-aws:request-handler-advice-chain>
</int-aws:s3-outbound-channel-adapter>
<int-aws:s3-outbound-channel-adapter
id="withChannelAdapterAttributes"
channel="input"
bucket="TestBucket"
accessKey="dummy"
secretKey="dummy"
remote-directory="/"
charset="US-ASCII"
phase="100"
auto-startup="false"
thread-pool-executor="executor"
multipart-upload-threshold="5120"
temporary-suffix=".write"
file-name-generation-expression="headers['name']"/>
<bean id="queue" class="java.util.concurrent.ArrayBlockingQueue">
<constructor-arg value="10"/>
</bean>