INT-1603 added namespace support for SearchInboundMessageSource
This commit is contained in:
@@ -34,6 +34,7 @@ public class TwitterNamespaceHandler extends AbstractIntegrationNamespaceHandler
|
||||
registerBeanDefinitionParser("inbound-channel-adapter", new TwitterReceivingMessageSourceParser());
|
||||
registerBeanDefinitionParser("dm-inbound-channel-adapter", new TwitterReceivingMessageSourceParser());
|
||||
registerBeanDefinitionParser("mentions-inbound-channel-adapter", new TwitterReceivingMessageSourceParser());
|
||||
registerBeanDefinitionParser("search-inbound-channel-adapter", new TwitterReceivingMessageSourceParser());
|
||||
|
||||
// outbound
|
||||
registerBeanDefinitionParser("outbound-channel-adapter", new TwitterSendingMessageHandlerParser());
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.twitter.core.Twitter4jTemplate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for inbound Twitter Channel Adapters.
|
||||
@@ -49,12 +51,25 @@ public class TwitterReceivingMessageSourceParser extends AbstractPollingInboundC
|
||||
else if ("mentions-inbound-channel-adapter".equals(elementName)) {
|
||||
className = BASE_PACKAGE + ".inbound.MentionsReceivingMessageSource";
|
||||
}
|
||||
else if ("search-inbound-channel-adapter".equals(elementName)){
|
||||
className = BASE_PACKAGE + ".inbound.SearchReceivingMessageSource";
|
||||
}
|
||||
else {
|
||||
parserContext.getReaderContext().error("element '" + elementName + "' is not supported by this parser.", element);
|
||||
}
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(className);
|
||||
builder.addConstructorArgReference(element.getAttribute("twitter-template"));
|
||||
String templateBeanName = element.getAttribute("twitter-template");
|
||||
|
||||
if (!StringUtils.hasText(templateBeanName)){
|
||||
BeanDefinitionBuilder templateBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.twitter.core.Twitter4jTemplate");
|
||||
builder.addConstructorArgValue(templateBuilder.getBeanDefinition());
|
||||
} else {
|
||||
builder.addConstructorArgReference(templateBeanName);
|
||||
}
|
||||
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "query");
|
||||
String name = BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
|
||||
return new RuntimeBeanReference(name);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,30 @@
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
<xsd:element name="search-inbound-channel-adapter">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Configures an inbound channel adapter that consumes message (representing mentions of your handle)
|
||||
from twitter and sends Messages whose payloads are Status objects.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="inbound-twitter-type">
|
||||
<xsd:attribute name="query" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Twitter search query (e.g, #springintegration .
|
||||
For more info on Twitter queries please refer to this site: http://search.twitter.com/operators)
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="dm-inbound-channel-adapter">
|
||||
<xsd:annotation>
|
||||
@@ -95,7 +119,7 @@
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="twitter-template" use="required" type="xsd:string">
|
||||
<xsd:attribute name="twitter-template" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xmlns:twitter="http://www.springframework.org/schema/integration/twitter"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
|
||||
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter.xsd">
|
||||
|
||||
|
||||
<channel id="searchChannel"/>
|
||||
|
||||
<twitter:search-inbound-channel-adapter id="searchAdapter"
|
||||
channel="searchChannel"
|
||||
query="#springintegration"
|
||||
auto-startup="false">
|
||||
<poller fixed-rate="5000" max-messages-per-poll="3"/>
|
||||
</twitter:search-inbound-channel-adapter>
|
||||
|
||||
|
||||
<beans:bean id="twitter" class="org.springframework.integration.twitter.config.TestReceivingMessageSourceParserTests.TwitterTemplateFactoryBean"/>
|
||||
|
||||
|
||||
<twitter:search-inbound-channel-adapter id="searchAdapterWithTemplate"
|
||||
channel="searchChannel"
|
||||
twitter-template="twitter"
|
||||
query="#springintegration"
|
||||
auto-startup="false">
|
||||
<poller fixed-rate="5000" max-messages-per-poll="3"/>
|
||||
</twitter:search-inbound-channel-adapter>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.twitter.core.Twitter4jTemplate;
|
||||
import org.springframework.integration.twitter.core.TwitterOperations;
|
||||
import org.springframework.integration.twitter.inbound.AbstractTwitterMessageSource;
|
||||
import org.springframework.integration.twitter.inbound.SearchReceivingMessageSource;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class TestSearchReceivingMessageSourceParserTests {
|
||||
|
||||
@Test
|
||||
public void testSearchReceivingDefaultTemplate(){
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("TestSearchReceivingMessageSourceParser-context.xml", this.getClass());
|
||||
SourcePollingChannelAdapter spca = ac.getBean("searchAdapter", SourcePollingChannelAdapter.class);
|
||||
SearchReceivingMessageSource ms = (SearchReceivingMessageSource) TestUtils.getPropertyValue(spca, "source");
|
||||
assertFalse(ms.isAutoStartup());
|
||||
|
||||
assertFalse(ms.isAutoStartup());
|
||||
Twitter4jTemplate template = (Twitter4jTemplate) TestUtils.getPropertyValue(ms, "twitter");
|
||||
|
||||
assertFalse(template.getUnderlyingTwitter().isOAuthEnabled()); // verify that anonymous Twitte
|
||||
}
|
||||
@Test
|
||||
public void testSearchReceivingCustomTemplate(){
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("TestSearchReceivingMessageSourceParser-context.xml", this.getClass());
|
||||
SourcePollingChannelAdapter spca = ac.getBean("searchAdapterWithTemplate", SourcePollingChannelAdapter.class);
|
||||
SearchReceivingMessageSource ms = (SearchReceivingMessageSource) TestUtils.getPropertyValue(spca, "source");
|
||||
assertFalse(ms.isAutoStartup());
|
||||
|
||||
assertFalse(ms.isAutoStartup());
|
||||
TwitterOperations template = (TwitterOperations) TestUtils.getPropertyValue(ms, "twitter");
|
||||
assertEquals(ac.getBean("twitter"), template);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user