Skip to content

Commit

Permalink
INT-3426: Add <r-h-a-c> for all outbound-c-a
Browse files Browse the repository at this point in the history
JIRA: https://jira.spring.io/browse/INT-3426

Provide other fixes for XSD. E.g. not all adapter have had `<poller>`
  • Loading branch information
Artem Bilan committed Jul 2, 2014
1 parent ca0bcf2 commit 58932dc
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@
<xsd:all>
<xsd:element name="poller" type="basePollerType" minOccurs="0" maxOccurs="1" />
<xsd:element ref="beans:bean" minOccurs="0" maxOccurs="1" />
<xsd:element name="request-handler-advice-chain" type="handlerAdviceChainType" minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attributeGroup ref="channelAdapterAttributes" />
<xsd:attribute name="order">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">

<channel id="channel"/>

<channel id="channelB">
<queue capacity="2"/>
</channel>
Expand All @@ -22,10 +22,13 @@

<outbound-channel-adapter id="adapterB" channel="channelB" method="out" order="99" auto-startup="false">
<beans:bean class="org.springframework.integration.config.xml.DefaultOutboundChannelAdapterParserTests$TestBean"/>
<poller task-executor="executor" max-messages-per-poll="5" fixed-delay="20" />
<poller task-executor="executor" max-messages-per-poll="5" fixed-delay="20" />
<request-handler-advice-chain>
<retry-advice/>
</request-handler-advice-chain>
</outbound-channel-adapter>

<task:executor id="executor" pool-size="5" />
<task:executor id="executor" pool-size="5" />

<outbound-channel-adapter id="adapterC" channel="channelC" order="99">
<beans:bean class="org.springframework.integration.config.TestConsumer"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@

package org.springframework.integration.config.xml;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.config.TestConsumer;
import org.springframework.integration.handler.MethodInvokingMessageHandler;
import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down Expand Up @@ -59,14 +63,15 @@ public void checkConfig() {
assertEquals(MethodInvokingMessageHandler.class, handler.getClass());
assertEquals(99, TestUtils.getPropertyValue(handler, "order"));
}

@Test
public void checkConfigWithInnerBeanAndPoller() {
Object adapter = context.getBean("adapterB");
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
Object handler = TestUtils.getPropertyValue(adapter, "handler");
assertEquals(MethodInvokingMessageHandler.class, handler.getClass());
assertEquals(99, TestUtils.getPropertyValue(handler, "order"));
assertTrue(AopUtils.isAopProxy(handler));
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<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:attributeGroup ref="coreMqttComponentAttributes"/>
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
<int:channel id="target"/>

<int-mqtt:outbound-channel-adapter id="withConverter"
client-id="foo"
url="tcp://localhost:1883"
auto-startup="false"
converter="myConverter"
client-factory="clientFactory"
default-topic="bar"
phase="25"
order="1"
channel="target" />
client-id="foo"
url="tcp://localhost:1883"
auto-startup="false"
converter="myConverter"
client-factory="clientFactory"
default-topic="bar"
phase="25"
order="1"
channel="target">
<int-mqtt:request-handler-advice-chain>
<int:retry-advice/>
</int-mqtt:request-handler-advice-chain>
</int-mqtt:outbound-channel-adapter>

<int-mqtt:outbound-channel-adapter id="withDefaultConverter"
client-id="foo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.mqtt.config.xml;

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.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
import org.springframework.integration.mqtt.support.MqttMessageConverter;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
* @author Gary Russell
* @author Artem Bilan
* @since 4.0
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class MqttOutboundChannelAdapterParserTests {

@Autowired @Qualifier("withConverter")
private EventDrivenConsumer withConverterEndpoint;

@Autowired @Qualifier("withConverter.handler")
private MqttPahoMessageHandler withConverterHandler;
private MessageHandler withConverterHandler;

@Autowired @Qualifier("withDefaultConverter.handler")
private MqttPahoMessageHandler withDefaultConverterHandler;
Expand All @@ -55,14 +62,23 @@ public class MqttOutboundChannelAdapterParserTests {
private DefaultMqttPahoClientFactory clientFactory;

@Test
public void testWithConverter() {
public void testWithConverter() throws Exception {
assertEquals("tcp://localhost:1883", TestUtils.getPropertyValue(withConverterHandler, "url"));
assertFalse(TestUtils.getPropertyValue(withConverterHandler, "autoStartup", Boolean.class));
assertEquals(25, TestUtils.getPropertyValue(withConverterHandler, "phase"));
assertEquals("foo", TestUtils.getPropertyValue(withConverterHandler, "clientId"));
assertEquals("bar", TestUtils.getPropertyValue(withConverterHandler, "defaultTopic"));
assertSame(converter, TestUtils.getPropertyValue(withConverterHandler, "converter"));
assertSame(clientFactory, TestUtils.getPropertyValue(withConverterHandler, "clientFactory"));

Object handler = TestUtils.getPropertyValue(this.withConverterEndpoint, "handler");

assertTrue(AopUtils.isAopProxy(handler));

assertSame(((Advised) handler).getTargetSource().getTarget(), this.withConverterHandler);

assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors.first.item.advice"),
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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[
Expand Down Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,20 +16,22 @@

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;
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;
Expand Down Expand Up @@ -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");
Expand All @@ -77,6 +79,13 @@ public void validateConfiguration() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
Loading

0 comments on commit 58932dc

Please sign in to comment.