INT-3426: Add <r-h-a-c> for all outbound-c-a

JIRA: https://jira.spring.io/browse/INT-3426

Provide other fixes for XSD. E.g. not all adapter have had `<poller>`
This commit is contained in:
Artem Bilan
2014-07-02 16:02:55 +03:00
parent ca0bcf2174
commit 58932dc31f
16 changed files with 187 additions and 77 deletions

View File

@@ -203,9 +203,11 @@
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="redisAdapterType">
<xsd:sequence>
<xsd:all>
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType"
minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attribute name="topic" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -296,6 +298,11 @@
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="redisAdapterType">
<xsd:all>
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1" />
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType"
minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attributeGroup ref="storeAdapterAttributeGroup"/>
<xsd:attribute name="redis-template" type="xsd:string">
<xsd:annotation>
@@ -410,9 +417,11 @@
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="redisAdapterType">
<xsd:sequence>
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:all>
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1" />
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType"
minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attribute name="queue" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -472,7 +481,8 @@
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="2">
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
<xsd:element name="request-handler-advice-chain" type="integration:adviceChainType" minOccurs="0" maxOccurs="1" />
<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType"
minOccurs="0" maxOccurs="1" />
</xsd:choice>
<xsd:attributeGroup ref="integration:smartLifeCycleAttributeGroup"/>
<xsd:attribute name="connection-factory" type="xsd:string">

View File

@@ -10,10 +10,14 @@
<int:channel id="sendChannel"/>
<int-redis:outbound-channel-adapter id="outboundAdapter"
channel="sendChannel"
topic-expression="headers['topic'] ?: 'foo'"
message-converter="testConverter"
serializer="serializer"/>
channel="sendChannel"
topic-expression="headers['topic'] ?: 'foo'"
message-converter="testConverter"
serializer="serializer">
<int-redis:request-handler-advice-chain>
<int:retry-advice/>
</int-redis:request-handler-advice-chain>
</int-redis:outbound-channel-adapter>
<int-redis:inbound-channel-adapter id="fooInbound" channel="receiveChannel" topics="foo"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -16,13 +16,14 @@
package org.springframework.integration.redis.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.*;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -30,6 +31,7 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.expression.Expression;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
import org.springframework.integration.redis.inbound.RedisInboundChannelAdapter;
import org.springframework.integration.redis.outbound.RedisPublishingMessageHandler;
import org.springframework.integration.redis.rules.RedisAvailable;
@@ -65,8 +67,8 @@ public class RedisOutboundChannelAdapterParserTests extends RedisAvailableTests
@RedisAvailable
public void validateConfiguration() {
EventDrivenConsumer adapter = context.getBean("outboundAdapter", EventDrivenConsumer.class);
RedisPublishingMessageHandler handler = (RedisPublishingMessageHandler)
new DirectFieldAccessor(adapter).getPropertyValue("handler");
Object handler = context.getBean("outboundAdapter.handler");
assertEquals("outboundAdapter", adapter.getComponentName());
DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
Object topicExpression = accessor.getPropertyValue("topicExpression");
@@ -77,6 +79,13 @@ public class RedisOutboundChannelAdapterParserTests extends RedisAvailableTests
assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer"));
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
assertSame(mbf, TestUtils.getPropertyValue(handler, "messageConverter.messageBuilderFactory"));
Object endpointHandler = TestUtils.getPropertyValue(adapter, "handler");
assertTrue(AopUtils.isAopProxy(endpointHandler));
assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors.first.item.advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}
@Test

View File

@@ -16,7 +16,11 @@
<int:channel id="sendChannel"/>
<int-redis:queue-outbound-channel-adapter id="defaultAdapter" channel="sendChannel" queue="foo"/>
<int-redis:queue-outbound-channel-adapter id="defaultAdapter" channel="sendChannel" queue="foo">
<int-redis:request-handler-advice-chain>
<int:retry-advice/>
</int-redis:request-handler-advice-chain>
</int-redis:queue-outbound-channel-adapter>
<int-redis:queue-outbound-channel-adapter id="customAdapter" channel="sendChannel"
queue-expression="headers['redis_queue']"

View File

@@ -16,19 +16,21 @@
package org.springframework.integration.redis.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.expression.Expression;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
import org.springframework.integration.redis.outbound.RedisQueueOutboundChannelAdapter;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
@@ -50,6 +52,10 @@ public class RedisQueueOutboundChannelAdapterParserTests {
@Qualifier("customRedisConnectionFactory")
private RedisConnectionFactory customRedisConnectionFactory;
@Autowired
@Qualifier("defaultAdapter")
private EventDrivenConsumer defaultEndpoint;
@Autowired
@Qualifier("defaultAdapter.handler")
private RedisQueueOutboundChannelAdapter defaultAdapter;
@@ -62,11 +68,20 @@ public class RedisQueueOutboundChannelAdapterParserTests {
private RedisSerializer<?> serializer;
@Test
public void testInt3017DefaultConfig() {
public void testInt3017DefaultConfig() throws Exception {
assertSame(this.connectionFactory, TestUtils.getPropertyValue(this.defaultAdapter, "template.connectionFactory"));
assertEquals("foo", TestUtils.getPropertyValue(this.defaultAdapter, "queueNameExpression", Expression.class).getExpressionString());
assertTrue(TestUtils.getPropertyValue(this.defaultAdapter, "extractPayload", Boolean.class));
assertFalse(TestUtils.getPropertyValue(this.defaultAdapter, "serializerExplicitlySet", Boolean.class));
Object handler = TestUtils.getPropertyValue(this.defaultEndpoint, "handler");
assertTrue(AopUtils.isAopProxy(handler));
assertSame(((Advised) handler).getTargetSource().getTarget(), this.defaultAdapter);
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}
@Test

View File

@@ -22,7 +22,11 @@
<int-redis:store-outbound-channel-adapter id="withStringTemplate"
collection-type="${collection.type}"
key="pepboys"
auto-startup="false"/>
auto-startup="false">
<int-redis:request-handler-advice-chain>
<int:retry-advice/>
</int-redis:request-handler-advice-chain>
</int-redis:store-outbound-channel-adapter>
<int-redis:store-outbound-channel-adapter id="withStringObjectTemplate"
collection-type="PROPERTIES"
@@ -40,9 +44,9 @@
<property name="keySerializer" ref="keySerializer"/>
<property name="valueSerializer" ref="valueSerializer"/>
<property name="hashKeySerializer" ref="hashKeySerializer"/>
<property name="hashValueSerializer" ref="hashValueSerializer"/>
<property name="hashValueSerializer" ref="hashValueSerializer"/>
</bean>
<bean id="redisConnectionFactory" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.data.redis.connection.RedisConnectionFactory"/>
</bean>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007-2012 the original author or authors
* Copyright 2007-2014 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.
@@ -16,21 +16,22 @@
package org.springframework.integration.redis.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.support.collections.RedisCollectionFactoryBean.CollectionType;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
import org.springframework.integration.redis.outbound.RedisStoreWritingMessageHandler;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
@@ -39,6 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -51,33 +53,52 @@ public class RedisStoreOutboundChannelAdapterParserTests {
private RedisTemplate<?,?> redisTemplate;
@Test
public void validateWithStringTemplate(){
RedisStoreWritingMessageHandler withStringTemplate =
TestUtils.getPropertyValue(context.getBean("withStringTemplate.adapter"), "handler", RedisStoreWritingMessageHandler.class);
assertEquals("pepboys", ((LiteralExpression)TestUtils.getPropertyValue(withStringTemplate, "keyExpression")).getExpressionString());
assertEquals("PROPERTIES", ((CollectionType)TestUtils.getPropertyValue(withStringTemplate, "collectionType")).toString());
public void validateWithStringTemplate() throws Exception {
RedisStoreWritingMessageHandler withStringTemplate = context.getBean("withStringTemplate.handler",
RedisStoreWritingMessageHandler.class);
assertEquals("pepboys", ((LiteralExpression)TestUtils.getPropertyValue(withStringTemplate,
"keyExpression")).getExpressionString());
assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringTemplate, "collectionType")).toString());
assertTrue(TestUtils.getPropertyValue(withStringTemplate, "redisTemplate") instanceof StringRedisTemplate);
Object handler = TestUtils.getPropertyValue(context.getBean("withStringTemplate.adapter"), "handler");
assertTrue(AopUtils.isAopProxy(handler));
assertSame(((Advised) handler).getTargetSource().getTarget(), withStringTemplate);
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}
@Test
public void validateWithStringObjectTemplate(){
RedisStoreWritingMessageHandler withStringObjectTemplate =
TestUtils.getPropertyValue(context.getBean("withStringObjectTemplate.adapter"), "handler", RedisStoreWritingMessageHandler.class);
assertEquals("pepboys", ((LiteralExpression)TestUtils.getPropertyValue(withStringObjectTemplate, "keyExpression")).getExpressionString());
assertEquals("PROPERTIES", ((CollectionType)TestUtils.getPropertyValue(withStringObjectTemplate, "collectionType")).toString());
TestUtils.getPropertyValue(context.getBean("withStringObjectTemplate.adapter"), "handler",
RedisStoreWritingMessageHandler.class);
assertEquals("pepboys", ((LiteralExpression)TestUtils.getPropertyValue(withStringObjectTemplate,
"keyExpression")).getExpressionString());
assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringObjectTemplate, "collectionType")).toString());
assertFalse(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate") instanceof StringRedisTemplate);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.keySerializer") instanceof StringRedisSerializer);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashKeySerializer") instanceof StringRedisSerializer);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.valueSerializer") instanceof JdkSerializationRedisSerializer);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashValueSerializer") instanceof JdkSerializationRedisSerializer);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
"redisTemplate.keySerializer") instanceof StringRedisSerializer);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
"redisTemplate.hashKeySerializer") instanceof StringRedisSerializer);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
"redisTemplate.valueSerializer") instanceof JdkSerializationRedisSerializer);
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
"redisTemplate.hashValueSerializer") instanceof JdkSerializationRedisSerializer);
}
@Test
public void validateWithExternalTemplate(){
RedisStoreWritingMessageHandler withExternalTemplate =
TestUtils.getPropertyValue(context.getBean("withExternalTemplate.adapter"), "handler", RedisStoreWritingMessageHandler.class);
assertEquals("pepboys", ((LiteralExpression)TestUtils.getPropertyValue(withExternalTemplate, "keyExpression")).getExpressionString());
assertEquals("PROPERTIES", ((CollectionType)TestUtils.getPropertyValue(withExternalTemplate, "collectionType")).toString());
TestUtils.getPropertyValue(context.getBean("withExternalTemplate.adapter"), "handler",
RedisStoreWritingMessageHandler.class);
assertEquals("pepboys", ((LiteralExpression)TestUtils.getPropertyValue(withExternalTemplate,
"keyExpression")).getExpressionString());
assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withExternalTemplate, "collectionType")).toString());
assertSame(redisTemplate, TestUtils.getPropertyValue(withExternalTemplate, "redisTemplate"));
}
}