AbstractTwitterMessageSource no longer implements Lifecycle (no longer extends AbstractEndpoint). @Ignore-d irrelevant tests, and removed the RateLimitStatusTrigger.
This commit is contained in:
@@ -16,18 +16,10 @@
|
||||
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
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.TwitterOperations;
|
||||
|
||||
/**
|
||||
@@ -35,21 +27,23 @@ import org.springframework.integration.twitter.core.TwitterOperations;
|
||||
*/
|
||||
public class TestReceivingMessageSourceParserTests {
|
||||
|
||||
@Test
|
||||
public void testRecievingAdapterConfigurationAutoStartup(){
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("TestReceivingMessageSourceParser-context.xml", this.getClass());
|
||||
SourcePollingChannelAdapter spca = ac.getBean("mentionAdapter", SourcePollingChannelAdapter.class);
|
||||
SmartLifecycle ms = TestUtils.getPropertyValue(spca, "source", SmartLifecycle.class);
|
||||
assertFalse(ms.isAutoStartup());
|
||||
|
||||
spca = ac.getBean("dmAdapter", SourcePollingChannelAdapter.class);
|
||||
ms = TestUtils.getPropertyValue(spca, "source", SmartLifecycle.class);
|
||||
assertFalse(ms.isAutoStartup());
|
||||
|
||||
spca = ac.getBean("updateAdapter", SourcePollingChannelAdapter.class);
|
||||
ms = TestUtils.getPropertyValue(spca, "source", SmartLifecycle.class);
|
||||
assertFalse(ms.isAutoStartup());
|
||||
}
|
||||
|
||||
// NO LONGER RELEVANT...
|
||||
// @Test
|
||||
// public void testRecievingAdapterConfigurationAutoStartup(){
|
||||
// ApplicationContext ac = new ClassPathXmlApplicationContext("TestReceivingMessageSourceParser-context.xml", this.getClass());
|
||||
// SourcePollingChannelAdapter spca = ac.getBean("mentionAdapter", SourcePollingChannelAdapter.class);
|
||||
// SmartLifecycle ms = TestUtils.getPropertyValue(spca, "source", SmartLifecycle.class);
|
||||
// assertFalse(ms.isAutoStartup());
|
||||
//
|
||||
// spca = ac.getBean("dmAdapter", SourcePollingChannelAdapter.class);
|
||||
// ms = TestUtils.getPropertyValue(spca, "source", SmartLifecycle.class);
|
||||
// assertFalse(ms.isAutoStartup());
|
||||
//
|
||||
// spca = ac.getBean("updateAdapter", SourcePollingChannelAdapter.class);
|
||||
// ms = TestUtils.getPropertyValue(spca, "source", SmartLifecycle.class);
|
||||
// assertFalse(ms.isAutoStartup());
|
||||
// }
|
||||
|
||||
|
||||
public static class TwitterTemplateFactoryBean implements FactoryBean<TwitterOperations>{
|
||||
|
||||
@@ -39,8 +39,7 @@ public class TestSearchReceivingMessageSourceParserTests {
|
||||
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());
|
||||
//assertFalse(ms.isAutoStartup());
|
||||
Twitter4jTemplate template = (Twitter4jTemplate) TestUtils.getPropertyValue(ms, "twitterOperations");
|
||||
assertFalse(template.getUnderlyingTwitter().isOAuthEnabled()); // verify anonymous Twitter
|
||||
}
|
||||
@@ -50,8 +49,7 @@ public class TestSearchReceivingMessageSourceParserTests {
|
||||
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());
|
||||
//assertFalse(ms.isAutoStartup());
|
||||
TwitterOperations template = (TwitterOperations) TestUtils.getPropertyValue(ms, "twitterOperations");
|
||||
assertEquals(ac.getBean("twitter"), template);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Date;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -105,27 +106,28 @@ public class DirectMessageReceivingMessageSourceTests {
|
||||
DirectMessageReceivingMessageSource source = new DirectMessageReceivingMessageSource(twitter);
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.afterPropertiesSet();
|
||||
source.setTaskScheduler(scheduler);
|
||||
//source.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
assertEquals("twitter:dm-inbound-channel-adapter.twitterEndpoint.kermit", TestUtils.getPropertyValue(source, "metadataKey"));
|
||||
assertTrue(source.isRunning());
|
||||
source.stop();
|
||||
//assertTrue(source.isRunning());
|
||||
//source.stop();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
@Ignore
|
||||
public void testSuccessfullInitializationWithMessages() throws Exception{
|
||||
this.setUpMockScenarioForMessagePolling();
|
||||
|
||||
DirectMessageReceivingMessageSource source = new DirectMessageReceivingMessageSource(twitter);
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.afterPropertiesSet();
|
||||
source.setTaskScheduler(scheduler);
|
||||
//source.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
Thread.sleep(1000);
|
||||
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
|
||||
assertTrue(!CollectionUtils.isEmpty(msg));
|
||||
@@ -136,7 +138,7 @@ public class DirectMessageReceivingMessageSourceTests {
|
||||
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();
|
||||
//source.stop();
|
||||
}
|
||||
/**
|
||||
* This test will validate that last status is initialized from the metadatastore
|
||||
@@ -144,6 +146,7 @@ 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);
|
||||
@@ -159,10 +162,10 @@ public class DirectMessageReceivingMessageSourceTests {
|
||||
source.setBeanFactory(bf);
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.afterPropertiesSet();
|
||||
source.setTaskScheduler(scheduler);
|
||||
//source.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
Thread.sleep(1000);
|
||||
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
|
||||
assertTrue(!CollectionUtils.isEmpty(msg));
|
||||
@@ -171,7 +174,7 @@ public class DirectMessageReceivingMessageSourceTests {
|
||||
Message message = source.receive();
|
||||
Tweet tweet = (Tweet) message.getPayload();
|
||||
assertEquals(2000, tweet.getId());
|
||||
source.stop();
|
||||
//source.stop();
|
||||
Thread.sleep(3000);
|
||||
|
||||
|
||||
@@ -187,10 +190,10 @@ public class DirectMessageReceivingMessageSourceTests {
|
||||
source.setBeanFactory(bf);
|
||||
scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.afterPropertiesSet();
|
||||
source.setTaskScheduler(scheduler);
|
||||
//source.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
Thread.sleep(1000);
|
||||
msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
|
||||
assertTrue(!CollectionUtils.isEmpty(msg));
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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 static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.twitter.core.TwitterOperations;
|
||||
import org.springframework.scheduling.TriggerContext;
|
||||
|
||||
import twitter4j.RateLimitStatus;
|
||||
import twitter4j.Twitter;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class RateLimitStatusTriggerTests {
|
||||
|
||||
@Test
|
||||
public void testTriggerImediateAndSubsequentExecutionTime() throws Exception{
|
||||
TwitterOperations twitter = mock(TwitterOperations.class);
|
||||
Twitter tw = mock(Twitter.class);
|
||||
when(twitter.getUnderlyingTwitter()).thenReturn(tw);
|
||||
RateLimitStatusTrigger trigger = new RateLimitStatusTrigger(twitter.getUnderlyingTwitter());
|
||||
TriggerContext context = mock(TriggerContext.class);
|
||||
Date currentDate = new Date(System.currentTimeMillis());
|
||||
Date nextDate = trigger.nextExecutionTime(context);
|
||||
// as long as its within 1 msec we can consider it right away for the purpose of testing
|
||||
assertTrue(nextDate.getTime() - currentDate.getTime() < 100);
|
||||
|
||||
|
||||
RateLimitStatus rateLimitStatis = mock(RateLimitStatus.class);
|
||||
when(tw.getRateLimitStatus()).thenReturn(rateLimitStatis);
|
||||
when(rateLimitStatis.getRemainingHits()).thenReturn(2000);
|
||||
when(rateLimitStatis.getSecondsUntilReset()).thenReturn(4000);
|
||||
|
||||
when(context.lastCompletionTime()).thenReturn(nextDate);
|
||||
// based on the above values the next execution time should be at least 2000 msec
|
||||
assertTrue(trigger.nextExecutionTime(context).getTime() - nextDate.getTime() > 2000);
|
||||
}
|
||||
}
|
||||
@@ -56,9 +56,9 @@ public class SearchReceivingMessageSourceTests {
|
||||
adapter.start();
|
||||
ms.setBeanFactory(bf);
|
||||
ms.setQuery("#springintegration");
|
||||
ms.setTaskScheduler(scheduler);
|
||||
//ms.setTaskScheduler(scheduler);
|
||||
ms.afterPropertiesSet();
|
||||
ms.start();
|
||||
//ms.start();
|
||||
System.in.read();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Date;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
@@ -104,27 +105,28 @@ public class TimelineReceivingMessageSourceTests {
|
||||
TimelineReceivingMessageSource source = new TimelineReceivingMessageSource(twitter);
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.afterPropertiesSet();
|
||||
source.setTaskScheduler(scheduler);
|
||||
//source.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
assertEquals("twitter:inbound-channel-adapter.twitterEndpoint.kermit", TestUtils.getPropertyValue(source, "metadataKey"));
|
||||
assertTrue(source.isRunning());
|
||||
source.stop();
|
||||
//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.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
Thread.sleep(1000);
|
||||
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
|
||||
assertTrue(!CollectionUtils.isEmpty(msg));
|
||||
@@ -135,7 +137,7 @@ public class TimelineReceivingMessageSourceTests {
|
||||
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();
|
||||
//source.stop();
|
||||
}
|
||||
/**
|
||||
* This test will validate that last status is initilaized from the metadatastore
|
||||
@@ -143,6 +145,7 @@ 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);
|
||||
@@ -158,10 +161,10 @@ public class TimelineReceivingMessageSourceTests {
|
||||
source.setBeanFactory(bf);
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.afterPropertiesSet();
|
||||
source.setTaskScheduler(scheduler);
|
||||
//source.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
Thread.sleep(1000);
|
||||
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
|
||||
assertTrue(!CollectionUtils.isEmpty(msg));
|
||||
@@ -169,7 +172,7 @@ public class TimelineReceivingMessageSourceTests {
|
||||
Message message = source.receive();
|
||||
Tweet tweet = (Tweet) message.getPayload();
|
||||
assertEquals(2000, tweet.getId());
|
||||
source.stop();
|
||||
//source.stop();
|
||||
Thread.sleep(2000);
|
||||
|
||||
|
||||
@@ -185,10 +188,10 @@ public class TimelineReceivingMessageSourceTests {
|
||||
source.setBeanFactory(bf);
|
||||
scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.afterPropertiesSet();
|
||||
source.setTaskScheduler(scheduler);
|
||||
//source.setTaskScheduler(scheduler);
|
||||
source.setBeanName("twitterEndpoint");
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
//source.start();
|
||||
Thread.sleep(1000);
|
||||
msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
|
||||
assertTrue(!CollectionUtils.isEmpty(msg));
|
||||
|
||||
Reference in New Issue
Block a user