INT-1471 went back to direct dependency on twitter4j API. ntroducing our interfaces is meaningless sionce we are not going to be depending on it once SpringSocial GA is out

This commit is contained in:
Oleg Zhurakousky
2010-10-26 13:18:49 -04:00
parent 2e800eb1ba
commit cebc9892b9
30 changed files with 62 additions and 757 deletions

View File

@@ -0,0 +1,11 @@
log4j.rootCategory=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
log4j.category.org.springframework=WARN
# log4j.category.org.springframework.integration=DEBUG
# log4j.category.org.springframework.integration.jdbc=DEBUG
log4j.category.org.springframework.twitter=DEBUG

View File

@@ -1,121 +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;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.twitter.inbound.InboundDirectMessageEndpoint;
import org.springframework.integration.twitter.oauth.OAuthConfiguration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import twitter4j.DirectMessage;
import twitter4j.Paging;
import twitter4j.RateLimitStatus;
import twitter4j.ResponseList;
import twitter4j.Twitter;
/**
* @author Oleg Zhurakousky
*
*/
public class InboundDirectMessageStatusEndpointTests {
private DirectMessage firstMessage;
private DirectMessage secondMessage;
private Twitter twitter;
@Test
@Ignore
/*
* In order to run this test you need to provide values to the twitter.properties file
*/
public void testUpdatesWithRealTwitter() throws Exception{
CountDownLatch latch = new CountDownLatch(1);
new ClassPathXmlApplicationContext("TestReceivingUsingNamespace-context.xml", this.getClass());
latch.await(10000, TimeUnit.SECONDS);
}
@Test
public void testTwitterMockedUpdates() throws Exception{
QueueChannel channel = new QueueChannel();
InboundDirectMessageEndpoint endpoint = new InboundDirectMessageEndpoint();
endpoint.setOutputChannel(channel);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
endpoint.setTaskScheduler(scheduler);
endpoint.setConfiguration(this.getTestConfigurationForDirectMessages());
endpoint.afterPropertiesSet();
endpoint.start();
Message message1 = channel.receive(3000);
assertNotNull(message1);
System.out.println();
assertEquals(secondMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message1.getPayload()).getId());
Message message2 = channel.receive(3000);
assertNotNull(message2);
assertEquals(firstMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message2.getPayload()).getId());
}
@Before
public void prepare(){
twitter = mock(Twitter.class);
firstMessage = mock(DirectMessage.class);
when(firstMessage.getCreatedAt()).thenReturn(new Date(5555555555L));
when(firstMessage.getId()).thenReturn(200);
secondMessage = mock(DirectMessage.class);
when(secondMessage.getCreatedAt()).thenReturn(new Date(2222222222L));
when(secondMessage.getId()).thenReturn(2000);
}
@SuppressWarnings("unchecked")
private OAuthConfiguration getTestConfigurationForDirectMessages() throws Exception{
OAuthConfiguration configuration = mock(OAuthConfiguration.class);
RateLimitStatus rateLimitStatus = mock(RateLimitStatus.class);
when(twitter.getRateLimitStatus()).thenReturn(rateLimitStatus);
when(configuration.getTwitter()).thenReturn(twitter);
when(rateLimitStatus.getSecondsUntilReset()).thenReturn(2464);
when(rateLimitStatus.getRemainingHits()).thenReturn(250);
ResponseList<DirectMessage> responses = mock(ResponseList.class);
List<DirectMessage> testMessages = new ArrayList<DirectMessage>();
testMessages.add(firstMessage);
testMessages.add(secondMessage);
when(responses.iterator()).thenReturn(testMessages.iterator());
when(twitter.getDirectMessages()).thenReturn(responses);
when(twitter.getDirectMessages(Mockito.any(Paging.class))).thenReturn(responses);
return configuration;
}
}

View File

@@ -1,40 +0,0 @@
<?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-1.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">
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="file://${user.home}/Desktop/twitter.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection
id="tc"
access-token="${twitter.oauth.accessToken}"
access-token-secret="${twitter.oauth.accessTokenSecret}"
consumer-key="${twitter.oauth.consumerKey}"
consumer-secret="${twitter.oauth.consumerSecret}"
/>
<beans:bean class="org.springframework.integration.twitter.SimpleTwitterTestClient"/>
</beans:beans>

View File

@@ -1,49 +0,0 @@
/*
* Copyright 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;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* provides a simple example of a command-line client to receive DMs, messages, timeline updates.
*
* @author Josh Long
*/
@ContextConfiguration
public class TestReceivingUsingNamespace
extends AbstractJUnit4SpringContextTests {
@Autowired
private TwitterAnnouncer twitterAnnouncer;
@Test
@Ignore
public void testIt() throws Throwable {
long ctr = 0;
long s = 1000;
while (ctr < (s * 60 * 3)) {
Thread.sleep(s);
ctr += s;
}
}
}

View File

@@ -18,11 +18,8 @@
<message-history/>
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="classpath:twitter.properties"
location="classpath:twitter.receiver.properties"
ignore-unresolvable="true"/>
<channel id="inbound_dm"/>
@@ -45,7 +42,7 @@
<twitter:inbound-update-channel-adapter twitter-connection="tc" channel="inbound_updates"/>
<service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>
<beans:bean id="twitterAnnouncer" class="org.springframework.integration.twitter.config.TwitterAnnouncer"/>
</beans:beans>

View File

@@ -36,6 +36,8 @@ public class TestReceivingUsingNamespace {
public void testUpdatesWithRealTwitter() throws Exception{
CountDownLatch latch = new CountDownLatch(1);
new ClassPathXmlApplicationContext("TestReceivingUsingNamespace-context.xml", this.getClass());
System.out.println("done");
latch.await(10000, TimeUnit.SECONDS);
}
}

View File

@@ -18,7 +18,7 @@
<context:property-placeholder
location="classpath:twitter.properties"
location="classpath:twitter.sender.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection

View File

@@ -21,12 +21,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.core.TwitterFactory;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.util.StringUtils;
import twitter4j.GeoLocation;
/**
* @author Josh Long
* @author Oleg Zhurakouksy
@@ -44,7 +45,7 @@ public class TestSendingDMsUsingNamespace extends AbstractJUnit4SpringContextTes
String dmUsr = "z_oleg";
MessageBuilder<String> mb = MessageBuilder.withPayload("'Hello world!', from the Spring Integration outbound Twitter adapter " + System.currentTimeMillis())
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
if (StringUtils.hasText(dmUsr)) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.twitter;
package org.springframework.integration.twitter.config;
import org.junit.Ignore;
import org.junit.Test;

View File

@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter;
package org.springframework.integration.twitter.config;
import org.springframework.integration.twitter.core.DirectMessage;
import org.springframework.integration.twitter.core.Status;
import org.springframework.stereotype.Component;
import twitter4j.DirectMessage;
import twitter4j.Status;
@Component
public class TwitterAnnouncer {

View File

@@ -1,34 +0,0 @@
/**
*
*/
package org.springframework.integration.twitter.core;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.integration.twitter.core.Twitter4jDecorator;
import twitter4j.Status;
/**
* @author ozhurakousky
*
*/
public class Twitter4jDecoratorTests {
@Test
public void testTwitter4JDecorator(){
Status status = mock(Status.class);
when(status.getSource()).thenReturn("Hello World");
ProxyFactory factory = new ProxyFactory(org.springframework.integration.twitter.core.Status.class, EmptyTargetSource.INSTANCE);
factory.addAdvice(new Twitter4jDecorator(status));
Object decoratedStatus = factory.getProxy();
assertTrue(decoratedStatus instanceof org.springframework.integration.twitter.core.Status);
String source = ((org.springframework.integration.twitter.core.Status)decoratedStatus).getSource();
System.out.println("source: " + source);
}
}

View File

@@ -63,10 +63,10 @@ public class InboundDirectMessageStatusEndpointTests {
Message message1 = channel.receive(3000);
assertNotNull(message1);
System.out.println();
assertEquals(secondMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message1.getPayload()).getId());
assertEquals(secondMessage.getId(), ((DirectMessage)message1.getPayload()).getId());
Message message2 = channel.receive(3000);
assertNotNull(message2);
assertEquals(firstMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message2.getPayload()).getId());
assertEquals(firstMessage.getId(), ((DirectMessage)message2.getPayload()).getId());
}
@Before

View File

@@ -22,10 +22,10 @@ import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.core.TwitterFactory;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.integration.twitter.oauth.OAuthConfiguration;
import twitter4j.GeoLocation;
import twitter4j.Twitter;
/**
@@ -38,7 +38,7 @@ public class OutboundDirectMessageMessageHandlerTests {
@Test
public void validateSendDirectMessage() throws Exception{
MessageBuilder<String> mb = MessageBuilder.withPayload("hello")
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true)
.setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, "foo");
OutboundDirectMessageMessageHandler handler = new OutboundDirectMessageMessageHandler();
@@ -50,7 +50,7 @@ public class OutboundDirectMessageMessageHandlerTests {
verify(twitter, times(1)).sendDirectMessage("foo", "hello");
mb = MessageBuilder.withPayload("hello")
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true)
.setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, 123);

View File

@@ -1,61 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 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.
-->
<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-1.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">
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="file://${user.home}/Desktop/twitter.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection
id="tc"
access-token="${twitter.oauth.accessToken}"
access-token-secret="${twitter.oauth.accessTokenSecret}"
consumer-key="${twitter.oauth.consumerKey}"
consumer-secret="${twitter.oauth.consumerSecret}"
/>
<channel id="inbound_tweets"/>
<twitter:inbound-mention-channel-adapter twitter-connection="tc" channel="inbound_tweets"/>
<service-activator input-channel="inbound_tweets" ref="twitterAnnouncer" method="mention"/>
</beans:beans>

View File

@@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 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.
-->
<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-1.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">
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="file://${user.home}/Desktop/twitter.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection
id="tc"
access-token="${twitter.oauth.accessToken}"
access-token-secret="${twitter.oauth.accessTokenSecret}"
consumer-key="${twitter.oauth.consumerKey}"
consumer-secret="${twitter.oauth.consumerSecret}"
/>
<channel id="inbound_tweets"/>
<twitter:inbound-update-channel-adapter
twitter-connection="tc"
channel="inbound_tweets"
/>
<service-activator input-channel="inbound_tweets"
ref="twitterAnnouncer"
method="friendsTimelineUpdated"/>
</beans:beans>

View File

@@ -0,0 +1,6 @@
# oauth setup for prosibook twitter account
twitter.oauth.consumerKey=
twitter.oauth.consumerSecret=
twitter.oauth.pin=
twitter.oauth.accessToken=
twitter.oauth.accessTokenSecret=