Twitter test polishing

This commit is contained in:
Oleg Zhurakousky
2010-11-19 03:48:59 -05:00
parent b3547433fb
commit c57a0067cb
6 changed files with 39 additions and 87 deletions

View File

@@ -34,10 +34,10 @@
<beans:constructor-arg value="${twitter.oauth.accessTokenSecret}"/>
</beans:bean>
<!-- <twitter:mentions-inbound-channel-adapter twitter-template="twitterTemplate" channel="inbound_mentions">-->
<!-- <poller fixed-rate="5000" max-messages-per-poll="3"/>-->
<!-- </twitter:mentions-inbound-channel-adapter>-->
<!-- <service-activator input-channel="inbound_mentions" ref="twitterAnnouncer" method="mention"/>-->
<twitter:mentions-inbound-channel-adapter twitter-template="twitterTemplate" channel="inbound_mentions">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:mentions-inbound-channel-adapter>
<service-activator input-channel="inbound_mentions" ref="twitterAnnouncer" method="mention"/>
<!-- <twitter:dm-inbound-channel-adapter twitter-template="twitterTemplate" channel="inbound_dm">-->
<!-- <poller fixed-rate="5000" max-messages-per-poll="3"/>-->
@@ -49,10 +49,10 @@
<!-- </twitter:search-inbound-channel-adapter>-->
<!-- <service-activator input-channel="inbound_search" ref="twitterAnnouncer" method="search"/>-->
<twitter:inbound-channel-adapter id="twitterInbound" twitter-template="twitterTemplate" channel="inbound_updates">
<poller fixed-rate="1000" max-messages-per-poll="3"/>
</twitter:inbound-channel-adapter>
<service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>
<!-- <twitter:inbound-channel-adapter id="twitterInbound" twitter-template="twitterTemplate" channel="inbound_updates">-->
<!-- <poller fixed-rate="1000" max-messages-per-poll="3"/>-->
<!-- </twitter:inbound-channel-adapter>-->
<!-- <service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>-->
<beans:bean id="twitterAnnouncer" class="org.springframework.integration.twitter.ignored.TwitterAnnouncer"/>
</beans:beans>

View File

@@ -42,7 +42,7 @@ public class TestSendingUpdatesUsingNamespace extends AbstractJUnit4SpringContex
@Test
@Ignore
public void testSendingATweet() throws Throwable {
MessageBuilder<String> mb = MessageBuilder.withPayload("Aligning #springintegration Twitter adapter with #SpringSocial API - "
MessageBuilder<String> mb = MessageBuilder.withPayload("Early start today"
+ new Date(System.currentTimeMillis()));
Message<String> m = mb.build();
this.messagingTemplate.send(this.channel, m);

View File

@@ -17,7 +17,7 @@
package org.springframework.integration.twitter.inbound;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -28,10 +28,8 @@ import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.Queue;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
@@ -44,7 +42,6 @@ import org.springframework.integration.twitter.core.Tweet;
import org.springframework.integration.twitter.core.Twitter4jTemplate;
import org.springframework.integration.twitter.core.TwitterOperations;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.CollectionUtils;
import twitter4j.DirectMessage;
import twitter4j.Paging;
@@ -106,39 +103,28 @@ public class DirectMessageReceivingMessageSourceTests {
DirectMessageReceivingMessageSource source = new DirectMessageReceivingMessageSource(twitter);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
assertEquals("twitter:dm-inbound-channel-adapter.twitterEndpoint.kermit", TestUtils.getPropertyValue(source, "metadataKey"));
//assertTrue(source.isRunning());
//source.stop();
}
@SuppressWarnings("rawtypes")
@SuppressWarnings({ "unchecked" })
@Test
@Ignore
public void testSuccessfullInitializationWithMessages() throws Exception{
this.setUpMockScenarioForMessagePolling();
DirectMessageReceivingMessageSource source = new DirectMessageReceivingMessageSource(twitter);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
Thread.sleep(1000);
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
assertTrue(!CollectionUtils.isEmpty(msg));
assertEquals(1, msg.size());
Tweet message = (Tweet) msg.poll();
Message<Tweet> msg = (Message<Tweet>) source.receive();
assertNotNull(msg);
Tweet message = (Tweet) msg.getPayload();
assertEquals(2000, message.getId());
Thread.sleep(1000);
verify(twitter, times(1)).getDirectMessages();
// 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 initialized from the metadatastore
@@ -146,7 +132,6 @@ public class DirectMessageReceivingMessageSourceTests {
*/
@SuppressWarnings("rawtypes")
@Test
@Ignore
public void testSuccessfullInitializationWithMessagesWithPersistentMetadata() throws Exception{
String fileName = System.getProperty("java.io.tmpdir") + "/spring-integration/metadata-store.properties";
File file = new File(fileName);
@@ -162,21 +147,12 @@ public class DirectMessageReceivingMessageSourceTests {
source.setBeanFactory(bf);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
Thread.sleep(1000);
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
assertTrue(!CollectionUtils.isEmpty(msg));
assertEquals(1, msg.size());
//Thread.sleep(15000);
Message message = source.receive();
Tweet tweet = (Tweet) message.getPayload();
assertEquals(2000, tweet.getId());
//source.stop();
Thread.sleep(3000);
Message msg = source.receive();
assertNotNull(msg);
Tweet tweet = (Tweet) msg.getPayload();
// Resuming
this.prepare();
@@ -190,18 +166,13 @@ public class DirectMessageReceivingMessageSourceTests {
source.setBeanFactory(bf);
scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
Thread.sleep(1000);
msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
assertTrue(!CollectionUtils.isEmpty(msg));
message = source.receive();
tweet = (Tweet) message.getPayload();
msg = source.receive();
tweet = (Tweet) msg.getPayload();
assertEquals(3000, tweet.getId());
message = source.receive();
tweet = (Tweet) message.getPayload();
msg = source.receive();
tweet = (Tweet) msg.getPayload();
assertEquals(4000, tweet.getId());
file.delete();
}

View File

@@ -34,6 +34,11 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
*/
public class SearchReceivingMessageSourceTests {
/**
* THis test is a sample test and wil require connecting to a real Twitter
* however no OAuth is required sincxe uts a search, so simply uncomment and run
* @throws Exception
*/
@Test
@Ignore
public void testSearchReceiving() throws Exception{

View File

@@ -17,6 +17,7 @@
package org.springframework.integration.twitter.inbound;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -105,39 +106,26 @@ public class TimelineReceivingMessageSourceTests {
TimelineReceivingMessageSource source = new TimelineReceivingMessageSource(twitter);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
assertEquals("twitter:inbound-channel-adapter.twitterEndpoint.kermit", TestUtils.getPropertyValue(source, "metadataKey"));
//assertTrue(source.isRunning());
//source.stop();
}
@SuppressWarnings("rawtypes")
@Test
@Ignore
public void testSuccessfulInitializationWithMessages() throws Exception{
this.setUpMockScenarioForMessagePolling();
TimelineReceivingMessageSource source = new TimelineReceivingMessageSource(twitter);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
Thread.sleep(1000);
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
assertTrue(!CollectionUtils.isEmpty(msg));
assertEquals(1, msg.size()); // because the other message has a older timestamp and is assumed to be read by
Tweet message = (Tweet) msg.poll();
Message msg = source.receive();
assertNotNull(msg);
Tweet message = (Tweet) msg.getPayload();
assertEquals(2000, message.getId());
Thread.sleep(1000);
verify(twitter, times(1)).getTimeline(2000);
// based on the Mock, the Queue shoud now have 2 mopre messages third and fourth
assertTrue(((Queue)TestUtils.getPropertyValue(source, "tweets")).size() == 2);
//source.stop();
verify(twitter, times(1)).getTimeline();
}
/**
* This test will validate that last status is initilaized from the metadatastore
@@ -145,7 +133,6 @@ public class TimelineReceivingMessageSourceTests {
*/
@SuppressWarnings("rawtypes")
@Test
@Ignore
public void testSuccessfulInitializationWithMessagesWithPersistentMetadata() throws Exception{
String fileName = System.getProperty("java.io.tmpdir") + "/spring-integration/metadata-store.properties";
File file = new File(fileName);
@@ -161,19 +148,12 @@ public class TimelineReceivingMessageSourceTests {
source.setBeanFactory(bf);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
Thread.sleep(1000);
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
assertTrue(!CollectionUtils.isEmpty(msg));
assertEquals(1, msg.size()); // because the other message has a older timestamp and is assumed to be read by
Message message = source.receive();
Tweet tweet = (Tweet) message.getPayload();
assertEquals(2000, tweet.getId());
//source.stop();
Thread.sleep(2000);
// Resuming
@@ -188,13 +168,9 @@ public class TimelineReceivingMessageSourceTests {
source.setBeanFactory(bf);
scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
//source.setTaskScheduler(scheduler);
source.setBeanName("twitterEndpoint");
source.afterPropertiesSet();
//source.start();
Thread.sleep(1000);
msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
assertTrue(!CollectionUtils.isEmpty(msg));
message = source.receive();
tweet = (Tweet) message.getPayload();
assertEquals(3000, tweet.getId());

View File

@@ -1,5 +1,5 @@
# oauth setup for prosibook twitter account
twitter.oauth.consumerKey=OU4CbkHKIWl1SI0VwiOgAQ
twitter.oauth.consumerSecret=p6pPukUG6d0ebSXuLSI9iaq2MIpzxJoLZyj6ilRmO3o
twitter.oauth.accessToken=61091649-vWVUNginOL069jjpm2lHEuxGXjW163kK3CPNZCdcc
twitter.oauth.accessTokenSecret=dufKyVlcngRitGDFfqiTlJC5leh6lsxPaq8FbeBc
twitter.oauth.consumerKey=
twitter.oauth.consumerSecret=
twitter.oauth.accessToken=
twitter.oauth.accessTokenSecret=