INT-1604 encapsulation

This commit is contained in:
Mark Fisher
2010-11-11 17:44:48 -05:00
parent 79b8b6b8b5
commit 4f3b887ddd
9 changed files with 103 additions and 95 deletions

View File

@@ -13,32 +13,24 @@
* 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 {
@@ -48,23 +40,20 @@ public class TestSearchReceivingMessageSourceParserTests {
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
Twitter4jTemplate template = (Twitter4jTemplate) TestUtils.getPropertyValue(ms, "twitterOperations");
assertFalse(template.getUnderlyingTwitter().isOAuthEnabled()); // verify anonymous Twitter
}
@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");
TwitterOperations template = (TwitterOperations) TestUtils.getPropertyValue(ms, "twitterOperations");
assertEquals(ac.getBean("twitter"), template);
}
}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.ignored;
import org.springframework.integration.Message;
@@ -20,28 +21,29 @@ import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.twitter.core.Tweet;
import org.springframework.stereotype.Component;
@Component
public class TwitterAnnouncer {
public void dm(Tweet directMessage) {
System.out.println("A direct message has been received from " +
directMessage.getFromUser() + " with text " + directMessage.getText());
}
public void search(Message search) {
public void search(Message<?> search) {
MessageHistory history = MessageHistory.read(search);
System.out.println(history);
Tweet tweet = (Tweet) search.getPayload();
System.out.println("A search item was received " +
tweet.getCreatedAt() + " with text " + tweet.getText());
}
public void mention(Tweet s) {
System.out.println("A tweet mentioning (or replying) to " + "you was received having text " + s.getFromUser() + "-" + s.getText() + " from " + s.getSource());
System.out.println("A tweet mentioning (or replying) to you was received having text "
+ s.getFromUser() + "-" + s.getText() + " from " + s.getSource());
}
public void updates(Tweet t) {
System.out.println("Received timeline update: " + t.getText() + " from " + t.getSource());
}
}

View File

@@ -134,12 +134,12 @@ public class DirectMessageReceivingMessageSourceTests {
assertEquals(2000, message.getId());
Thread.sleep(1000);
verify(twitter, times(1)).getDirectMessages();
// based on the Mock, the Queue shoud now have 1 more messages third and fourth
// based on the Mock, the Queue should now have 2 more messages third and fourth
assertTrue(((Queue)TestUtils.getPropertyValue(source, "tweets")).size() == 2);
source.stop();
}
/**
* This test will validate that last status is initilaized from the metadatastore
* This test will validate that last status is initialized from the metadatastore
* @throws Exception
*/
@SuppressWarnings("rawtypes")

View File

@@ -1,6 +1,19 @@
/**
*
/*
* 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.inbound;
import org.junit.Ignore;
@@ -8,7 +21,6 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessagingException;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageHandler;
@@ -19,7 +31,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/**
* @author ozhurakousky
*
*/
public class SearchReceivingMessageSourceTests {
@@ -30,9 +41,7 @@ public class SearchReceivingMessageSourceTests {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
bf.registerSingleton("taskScheduler", scheduler);
SearchReceivingMessageSource ms = new SearchReceivingMessageSource(new Twitter4jTemplate());
DirectChannel channel = new DirectChannel();
channel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) throws MessagingException {
@@ -45,14 +54,12 @@ public class SearchReceivingMessageSourceTests {
adapter.setOutputChannel(channel);
adapter.afterPropertiesSet();
adapter.start();
ms.setBeanFactory(bf);
ms.setQuery("#springintegration");
ms.setTaskScheduler(scheduler);
ms.afterPropertiesSet();
ms.start();
System.in.read();
}
}