From aaf88ecc7c1e67ebf173d682e3171e52aa936eb2 Mon Sep 17 00:00:00 2001 From: David Liu Date: Fri, 25 Jul 2014 12:56:18 +0300 Subject: [PATCH] INT-3104:Add auto-start attribute to Gemfire Adapters JIRA: https://jira.spring.io/browse/INT-3104 Add phase and remove unnecessary auto-starup INT-3104: Remove reduntant code and format Polishing and fixing parser tests --- .../GemfireCqInboundChannelAdapterParser.java | 23 +++--- .../GemfireInboundChannelAdapterParser.java | 17 +++-- .../GemfireOutboundChannelAdapterParser.java | 12 ++-- .../ContinuousQueryMessageProducer.java | 21 +++--- .../outbound/CacheWritingMessageHandler.java | 18 ++--- .../xml/spring-integration-gemfire-4.1.xsd | 71 ++++++++----------- ...boundChannelAdapterParserTests-context.xml | 41 +++++++++++ ...ireCqInboundChannelAdapterParserTests.java | 61 +++++++++++----- ...boundChannelAdapterParserTests-context.xml | 24 +++++++ ...mfireInboundChannelAdapterParserTests.java | 49 +++++++++---- ...boundChannelAdapterParserTests-context.xml | 23 +++--- ...fireOutboundChannelAdapterParserTests.java | 36 ++++++++-- ...fireInboundChannelAdapterTests-context.xml | 29 ++++---- 13 files changed, 286 insertions(+), 139 deletions(-) create mode 100644 spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests-context.xml create mode 100644 spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests-context.xml diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParser.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParser.java index b90a85acae..d4c427d4bd 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParser.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParser.java @@ -51,30 +51,33 @@ public class GemfireCqInboundChannelAdapterParser extends AbstractChannelAdapter private static final String QUERY_EVENTS_ATTRIBUTE = "query-events"; - @Override protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { - BeanDefinitionBuilder continuousQueryMesageProducer = BeanDefinitionBuilder.genericBeanDefinition(ContinuousQueryMessageProducer.class); - IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, EXPRESSION_ATTRIBUTE,PAYLOAD_EXPRESSION_PROPERTY); - IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, QUERY_EVENTS_ATTRIBUTE, SUPPORTED_EVENT_TYPES_PROPERTY); + BeanDefinitionBuilder continuousQueryMesageProducer = + BeanDefinitionBuilder.genericBeanDefinition(ContinuousQueryMessageProducer.class); + IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, + EXPRESSION_ATTRIBUTE, PAYLOAD_EXPRESSION_PROPERTY); + IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, + QUERY_EVENTS_ATTRIBUTE, SUPPORTED_EVENT_TYPES_PROPERTY); - if (!element.hasAttribute(QUERY_LISTENER_CONTAINER_ATTRIBUTE)){ - parserContext.getReaderContext().error("'" + QUERY_LISTENER_CONTAINER_ATTRIBUTE + "' attribute is required.",element); + if (!element.hasAttribute(QUERY_LISTENER_CONTAINER_ATTRIBUTE)) { + parserContext.getReaderContext() + .error("'" + QUERY_LISTENER_CONTAINER_ATTRIBUTE + "' attribute is required.", element); } - if (!element.hasAttribute(QUERY_ATTRIBUTE)){ - parserContext.getReaderContext().error("'" + QUERY_ATTRIBUTE + "' attribute is required.",element); + if (!element.hasAttribute(QUERY_ATTRIBUTE)) { + parserContext.getReaderContext().error("'" + QUERY_ATTRIBUTE + "' attribute is required.", element); } continuousQueryMesageProducer.addConstructorArgReference(element.getAttribute(QUERY_LISTENER_CONTAINER_ATTRIBUTE)); continuousQueryMesageProducer.addConstructorArgValue(element.getAttribute(QUERY_ATTRIBUTE)); continuousQueryMesageProducer.addPropertyReference(OUTPUT_CHANNEL_PROPERTY, channelName); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(continuousQueryMesageProducer, element, ERROR_CHANNEL_ATTRIBUTE); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(continuousQueryMesageProducer, element, + ERROR_CHANNEL_ATTRIBUTE); IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, QUERY_NAME_ATTRIBUTE); IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, DURABLE_ATTRIBUTE); - return continuousQueryMesageProducer.getBeanDefinition(); } diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParser.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParser.java index b638cfde3c..5b0825314a 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParser.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParser.java @@ -45,19 +45,22 @@ public class GemfireInboundChannelAdapterParser extends AbstractChannelAdapterPa @Override protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { - BeanDefinitionBuilder listeningMessageProducer = BeanDefinitionBuilder.genericBeanDefinition(CacheListeningMessageProducer.class); - IntegrationNamespaceUtils.setValueIfAttributeDefined(listeningMessageProducer, element, EXPRESSION_ATTRIBUTE,PAYLOAD_EXPRESSION_PROPERTY); - IntegrationNamespaceUtils.setValueIfAttributeDefined(listeningMessageProducer, element, CACHE_EVENTS_ATTRIBUTE, SUPPORTED_EVENT_TYPES_PROPERTY); + BeanDefinitionBuilder listeningMessageProducer = + BeanDefinitionBuilder.genericBeanDefinition(CacheListeningMessageProducer.class); + IntegrationNamespaceUtils.setValueIfAttributeDefined(listeningMessageProducer, element, + EXPRESSION_ATTRIBUTE, PAYLOAD_EXPRESSION_PROPERTY); + IntegrationNamespaceUtils.setValueIfAttributeDefined(listeningMessageProducer, element, + CACHE_EVENTS_ATTRIBUTE, SUPPORTED_EVENT_TYPES_PROPERTY); - if (!element.hasAttribute(REGION_ATTRIBUTE)){ - parserContext.getReaderContext().error("'region' attribute is required.",element); + if (!element.hasAttribute(REGION_ATTRIBUTE)) { + parserContext.getReaderContext().error("'region' attribute is required.", element); } listeningMessageProducer.addConstructorArgReference(element.getAttribute(REGION_ATTRIBUTE)); listeningMessageProducer.addPropertyReference(OUTPUT_CHANNEL_PROPERTY, channelName); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(listeningMessageProducer, element, ERROR_CHANNEL_ATTRIBUTE); - + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(listeningMessageProducer, element, + ERROR_CHANNEL_ATTRIBUTE); return listeningMessageProducer.getBeanDefinition(); } diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParser.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParser.java index c7cf10f21c..fcb4d6dfca 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParser.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParser.java @@ -38,24 +38,24 @@ public class GemfireOutboundChannelAdapterParser extends AbstractOutboundChannel private static final String REGION_ATTRIBUTE = "region"; /* (non-Javadoc) - * @see org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser#parseConsumer(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext) + * @see AbstractOutboundChannelAdapterParser#parseConsumer(Element, ParserContext) */ @Override protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { BeanDefinitionBuilder cacheWritingMessageHandler = BeanDefinitionBuilder.genericBeanDefinition( CacheWritingMessageHandler.class); - if (!element.hasAttribute(REGION_ATTRIBUTE)){ - parserContext.getReaderContext().error("'region' attribute is required.",element); + if (!element.hasAttribute(REGION_ATTRIBUTE)) { + parserContext.getReaderContext().error("'region' attribute is required.", element); } cacheWritingMessageHandler.addConstructorArgReference(element.getAttribute(REGION_ATTRIBUTE)); - Element cacheEntries = DomUtils.getChildElementByTagName(element,CACHE_ENTRIES_ELEMENT); + Element cacheEntries = DomUtils.getChildElementByTagName(element, CACHE_ENTRIES_ELEMENT); if (cacheEntries != null) { - Map map = parserContext.getDelegate().parseMapElement(cacheEntries,cacheWritingMessageHandler.getBeanDefinition()); + Map map = parserContext.getDelegate() + .parseMapElement(cacheEntries, cacheWritingMessageHandler.getBeanDefinition()); cacheWritingMessageHandler.addPropertyValue(CACHE_ENTRIES_PROPERTY, map); } - return cacheWritingMessageHandler.getBeanDefinition(); } } diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/inbound/ContinuousQueryMessageProducer.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/inbound/ContinuousQueryMessageProducer.java index 429f5eacb1..043d239da6 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/inbound/ContinuousQueryMessageProducer.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/inbound/ContinuousQueryMessageProducer.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import com.gemstone.gemfire.cache.query.CqEvent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,8 +31,6 @@ import org.springframework.integration.endpoint.ExpressionMessageProducerSupport import org.springframework.messaging.Message; import org.springframework.util.Assert; -import com.gemstone.gemfire.cache.query.CqEvent; - /** * Responds to a Gemfire continuous query (set using the #query field) that is * constantly evaluated against a cache @@ -43,7 +42,9 @@ import com.gemstone.gemfire.cache.query.CqEvent; * @since 2.1 * */ -public class ContinuousQueryMessageProducer extends ExpressionMessageProducerSupport implements ContinuousQueryListener { +public class ContinuousQueryMessageProducer extends ExpressionMessageProducerSupport + implements ContinuousQueryListener { + private static Log logger = LogFactory.getLog(ContinuousQueryMessageProducer.class); private final String query; @@ -102,7 +103,8 @@ public class ContinuousQueryMessageProducer extends ExpressionMessageProducerSup queryListenerContainer.addListener(new ContinuousQueryDefinition(this.query, this, this.durable)); } else { - queryListenerContainer.addListener(new ContinuousQueryDefinition(this.queryName, this.query, this, this.durable)); + queryListenerContainer.addListener(new ContinuousQueryDefinition(this.queryName, this.query, this, + this.durable)); } } @@ -120,17 +122,18 @@ public class ContinuousQueryMessageProducer extends ExpressionMessageProducerSup logger.debug(String.format("processing cq event key [%s] event [%s]", event.getQueryOperation() .toString(), event.getKey())); } - Message cqEventMessage = this.getMessageBuilderFactory().withPayload(evaluatePayloadExpression(event)).build(); + Message cqEventMessage = this.getMessageBuilderFactory().withPayload(evaluatePayloadExpression(event)) + .build(); sendMessage(cqEventMessage); } } private boolean isEventSupported(CqEvent event) { - String eventName = event.getQueryOperation().toString() + - (event.getQueryOperation().toString().endsWith("Y")? "ED" : "D"); - CqEventType eventType = CqEventType.valueOf(eventName); - return supportedEventTypes.contains(eventType); + String eventName = event.getQueryOperation().toString() + + (event.getQueryOperation().toString().endsWith("Y") ? "ED" : "D"); + CqEventType eventType = CqEventType.valueOf(eventName); + return supportedEventTypes.contains(eventType); } } diff --git a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandler.java b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandler.java index 32eaaede76..5641c9d766 100644 --- a/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandler.java +++ b/spring-integration-gemfire/src/main/java/org/springframework/integration/gemfire/outbound/CacheWritingMessageHandler.java @@ -21,6 +21,10 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; +import com.gemstone.gemfire.GemFireCheckedException; +import com.gemstone.gemfire.GemFireException; +import com.gemstone.gemfire.cache.Region; + import org.springframework.data.gemfire.GemfireCallback; import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.expression.Expression; @@ -30,10 +34,6 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.util.Assert; -import com.gemstone.gemfire.GemFireCheckedException; -import com.gemstone.gemfire.GemFireException; -import com.gemstone.gemfire.cache.Region; - /** * A {@link MessageHandler} implementation that writes to a GemFire Region. The * Message's payload must be an instance of java.util.Map. @@ -59,13 +59,15 @@ public class CacheWritingMessageHandler extends AbstractMessageHandler { return "gemfire:outbound-channel-adapter"; } + @SuppressWarnings("unchecked") @Override public void handleMessageInternal(Message message) { Object payload = message.getPayload(); - Map cacheValues = (cacheEntryExpressions.size() > 0)?parseCacheEntries(message):null; + Map cacheValues = (cacheEntryExpressions.size() > 0) ? parseCacheEntries(message) : null; if (cacheValues == null) { - Assert.isTrue(payload instanceof Map, "If cache entry expressions are not configured, then payload must be a Map"); + Assert.isTrue(payload instanceof Map, + "If cache entry expressions are not configured, then payload must be a Map"); cacheValues = (Map) payload; } @@ -73,7 +75,7 @@ public class CacheWritingMessageHandler extends AbstractMessageHandler { this.gemfireTemplate.execute(new GemfireCallback() { @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public Object doInGemfire(Region region) throws GemFireCheckedException, GemFireException { region.putAll(map); return null; @@ -88,7 +90,7 @@ public class CacheWritingMessageHandler extends AbstractMessageHandler { else { Map cacheValues = new HashMap(); for (Entry expressionEntry : cacheEntryExpressions.entrySet()) { - cacheValues.put(expressionEntry.getKey().getValue(message),expressionEntry.getValue().getValue(message)); + cacheValues.put(expressionEntry.getKey().getValue(message), expressionEntry.getValue().getValue(message)); } return cacheValues; } diff --git a/spring-integration-gemfire/src/main/resources/org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.1.xsd b/spring-integration-gemfire/src/main/resources/org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.1.xsd index 514c27558c..9907de7e0d 100644 --- a/spring-integration-gemfire/src/main/resources/org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.1.xsd +++ b/spring-integration-gemfire/src/main/resources/org/springframework/integration/gemfire/config/xml/spring-integration-gemfire-4.1.xsd @@ -1,16 +1,16 @@ + xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:tool="http://www.springframework.org/schema/tool" + xmlns:integration="http://www.springframework.org/schema/integration" + targetNamespace="http://www.springframework.org/schema/integration/gemfire" + elementFormDefault="qualified" attributeFormDefault="unqualified"> - + schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd"/> + + schemaLocation="http://www.springframework.org/schema/integration/spring-integration-4.1.xsd"/> - + + use="optional" default="CREATED,UPDATED"> + type="org.springframework.integration.gemfire.inbound.EventType"/> @@ -70,20 +70,20 @@ - + + type="org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer"/> + use="optional" default="CREATED,UPDATED"> + type="org.springframework.integration.gemfire.inbound.CqEventType"/> - - + - + - - + - + @@ -121,7 +121,7 @@ - + @@ -136,35 +136,25 @@ + minOccurs="0" maxOccurs="1"> A map of SpEL expressions used to create cache entries. If not provided, payload must be a Map - + - + - - - - - - - - - - - + - + @@ -184,8 +174,9 @@ + + use="optional"> @@ -196,7 +187,7 @@ reference to the "nullChannel" here. ]]> + type="org.springframework.messaging.MessageChannel"/> diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests-context.xml b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests-context.xml new file mode 100644 index 0000000000..f26b5c5fe9 --- /dev/null +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests-context.xml @@ -0,0 +1,41 @@ + + + + + + + true + + + + + + + + + + + + + + diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests.java index 2575c515df..8eab84a402 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireCqInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 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. You may obtain a copy of the License at @@ -13,31 +13,56 @@ package org.springframework.integration.gemfire.config.xml; -import org.junit.Test; -import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; -import org.w3c.dom.Element; - +import static org.junit.Assert.assertEquals; import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext; import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.w3c.dom.Element; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; +import org.springframework.integration.gemfire.inbound.ContinuousQueryMessageProducer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + /** * @author Dan Oxlade + * @author Liujiong */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration public class GemfireCqInboundChannelAdapterParserTests { - private GemfireCqInboundChannelAdapterParser underTest = new GemfireCqInboundChannelAdapterParser(); + private GemfireCqInboundChannelAdapterParser underTest = new GemfireCqInboundChannelAdapterParser(); - @Test(expected = BeanDefinitionParsingException.class) - public void cqListenerContainerIsARequiredAttribute() throws Exception { - String xml = ""; - Element element = loadXMLFrom(xml).getDocumentElement(); - underTest.doParse(element, createFakeParserContext(), null); - } + @Autowired + @Qualifier("withDurable") + ContinuousQueryMessageProducer adapter; - @Test(expected = BeanDefinitionParsingException.class) - public void queryIsARequiredAttribute() throws Exception { - String xml = ""; - Element element = loadXMLFrom(xml).getDocumentElement(); - underTest.doParse(element, createFakeParserContext(), null); - } + @Test(expected = BeanDefinitionParsingException.class) + public void cqListenerContainerIsARequiredAttribute() throws Exception { + String xml = ""; + Element element = loadXMLFrom(xml).getDocumentElement(); + underTest.doParse(element, createFakeParserContext(), null); + } + + @Test(expected = BeanDefinitionParsingException.class) + public void queryIsARequiredAttribute() throws Exception { + String xml = ""; + Element element = loadXMLFrom(xml).getDocumentElement(); + underTest.doParse(element, createFakeParserContext(), null); + } + + @Test + public void testPhase() { + assertEquals(2, adapter.getPhase()); + } + + @Test + public void testAutoStartup() { + assertEquals(false, adapter.isAutoStartup()); + } } diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests-context.xml b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests-context.xml new file mode 100644 index 0000000000..d28ee507f6 --- /dev/null +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests-context.xml @@ -0,0 +1,24 @@ + + + + + + + + + + diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests.java index f7eb2c7df2..d1b09c16ab 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 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. You may obtain a copy of the License at @@ -13,24 +13,49 @@ package org.springframework.integration.gemfire.config.xml; -import org.junit.Test; -import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; -import org.w3c.dom.Element; - +import static org.junit.Assert.assertEquals; import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext; import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.w3c.dom.Element; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; +import org.springframework.integration.gemfire.inbound.CacheListeningMessageProducer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + /** * @author Dan Oxlade + * @author Liujiong */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration public class GemfireInboundChannelAdapterParserTests { - private GemfireInboundChannelAdapterParser underTest = new GemfireInboundChannelAdapterParser(); + private GemfireInboundChannelAdapterParser underTest = new GemfireInboundChannelAdapterParser(); - @Test(expected = BeanDefinitionParsingException.class) - public void regionIsARequiredAttribute() throws Exception { - String xml = ""; - Element element = loadXMLFrom(xml).getDocumentElement(); - underTest.doParse(element, createFakeParserContext(), null); - } + @Autowired + @Qualifier("channel1.adapter") + CacheListeningMessageProducer adapter1; + + @Test(expected = BeanDefinitionParsingException.class) + public void regionIsARequiredAttribute() throws Exception { + String xml = ""; + Element element = loadXMLFrom(xml).getDocumentElement(); + underTest.doParse(element, createFakeParserContext(), null); + } + + @Test + public void testPhase() { + assertEquals(2, adapter1.getPhase()); + } + + @Test + public void testAutoStart() { + assertEquals(false, adapter1.isAutoStartup()); + } } diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests-context.xml b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests-context.xml index 6a65112464..1beb540ae9 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests-context.xml +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests-context.xml @@ -1,21 +1,24 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:int-gfe="http://www.springframework.org/schema/integration/gemfire" + xmlns:int="http://www.springframework.org/schema/integration" + xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire + http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd + http://www.springframework.org/schema/integration + http://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> - + - + - + - + diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests.java index 5ce7701ce1..d1a706ac91 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/config/xml/GemfireOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 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. You may obtain a copy of the License at @@ -18,24 +18,40 @@ import static org.springframework.integration.gemfire.config.xml.ParserTestUtil. import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom; import org.junit.Test; +import org.junit.runner.RunWith; +import org.w3c.dom.Element; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.config.ConsumerEndpointFactoryBean; +import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice; import org.springframework.messaging.support.GenericMessage; -import org.w3c.dom.Element; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dan Oxlade + * @author Liujiong */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration public class GemfireOutboundChannelAdapterParserTests { private GemfireOutboundChannelAdapterParser underTest = new GemfireOutboundChannelAdapterParser(); private volatile static int adviceCalled; + @Autowired + @Qualifier("adapter") + ConsumerEndpointFactoryBean adapter1; + + @Autowired + ApplicationContext ctx; + @Test(expected = BeanDefinitionParsingException.class) public void regionIsARequiredAttribute() throws Exception { String xml = ""; @@ -45,12 +61,22 @@ public class GemfireOutboundChannelAdapterParserTests { @Test public void withAdvice() { - ApplicationContext ctx = new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-context.xml", this.getClass()); + adapter1.start(); MessageChannel channel = ctx.getBean("input", MessageChannel.class); channel.send(new GenericMessage("foo")); assertEquals(1, adviceCalled); } + @Test + public void testPhase() { + assertEquals(2, adapter1.getPhase()); + } + + @Test + public void testAutoStart() { + assertEquals(false, adapter1.isAutoStartup()); + } + public static class FooAdvice extends AbstractRequestHandlerAdvice { @Override diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/GemfireInboundChannelAdapterTests-context.xml b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/GemfireInboundChannelAdapterTests-context.xml index 8439b77a53..17dbc2044b 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/GemfireInboundChannelAdapterTests-context.xml +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/inbound/GemfireInboundChannelAdapterTests-context.xml @@ -1,25 +1,26 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:gfe="http://www.springframework.org/schema/gemfire" + xmlns:int-gfe="http://www.springframework.org/schema/integration/gemfire" + xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire + http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd + http://www.springframework.org/schema/gemfire + http://www.springframework.org/schema/gemfire/spring-gemfire.xsd + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd"> - + - + - + - + - + - +