INT-1902 polished Twitter upgrade to make sure it is still backward compatible, also upgraded to the latest version 2.1.12

This commit is contained in:
Oleg Zhurakousky
2011-05-11 18:26:10 -04:00
parent 3f91ba3064
commit b3c427ed0c
5 changed files with 18 additions and 12 deletions

View File

@@ -385,7 +385,7 @@ project('spring-integration-twitter') {
dependencies {
compile project(":spring-integration-core")
compile "org.springframework:spring-context-support:$springVersion"
compile "org.twitter4j:twitter4j-core:2.1.10"
compile "org.twitter4j:twitter4j-core:2.1.12"
compile("javax.activation:activation:$javaxActivationVersion") { optional = true }
testCompile project(":spring-integration-test")
}

View File

@@ -103,7 +103,7 @@
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>2.1.10</version>
<version>2.1.12</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@@ -63,17 +63,25 @@ public class Twitter4jTemplate implements TwitterOperations {
* @param accessToken
* @param accessTokenSecret
*/
@SuppressWarnings("deprecation")
public Twitter4jTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) {
Assert.hasText(consumerKey, "'consumerKey' must be provided");
Assert.hasText(consumerSecret, "'consumerSecret' must be provided");
Assert.hasText(accessToken, "'accessToken' must be provided");
Assert.hasText(accessTokenSecret, "'accessTokenSecret' must be provided");
AccessToken token = new AccessToken(accessToken, accessTokenSecret);
Properties properties = new Properties();
properties.put("oauth.consumerKey", consumerKey);
properties.put("oauth.consumerSecret", consumerSecret);
Configuration configuration = new PropertyConfiguration(properties);
this.twitter = new TwitterFactory(configuration).getInstance(token);
this.twitter = new TwitterFactory().getOAuthAuthorizedInstance(consumerKey, consumerSecret, token);
/*
* We are aware of the fact that the above method is deprecated and the code should really look
* like the one below, but we are keeping the deprecated call to address backwards compatibility.
* In future versions we won't be relying on Twitter4J in favor of SpringSocial API.
*/
// Properties properties = new Properties();
// properties.put("oauth.consumerKey", consumerKey);
// properties.put("oauth.consumerSecret", consumerSecret);
// Configuration configuration = new PropertyConfiguration(properties);
// this.twitter = new TwitterFactory(configuration).getInstance(token);
}

View File

@@ -61,12 +61,12 @@ public class Twitter4jTemplateTests {
}
@Test
public void testOauthConstructor() throws Exception{
template = new Twitter4jTemplate("a", "b", "c", "d");
template = new Twitter4jTemplate("a", "b", "1234-c", "d");
Twitter twitter = (Twitter) TestUtils.getPropertyValue(template, "twitter");
Authorization auth = twitter.getAuthorization();
assertTrue(twitter.getAuthorization() instanceof OAuthAuthorization);
AccessToken accessToken = ((OAuthAuthorization)auth).getOAuthAccessToken();
assertEquals("c", accessToken.getToken());
assertEquals("1234-c", accessToken.getToken());
assertEquals("d", accessToken.getTokenSecret());
}

View File

@@ -34,15 +34,13 @@ public class TwitterOperationExceptionTests {
@Test
public void test401(){
// will result in exception since a,b,c,d are invalid credentials
Twitter4jTemplate template = new Twitter4jTemplate("a", "b", "c", "d");
Twitter4jTemplate template = new Twitter4jTemplate("a", "b", "1234-c", "d");
try {
template.getProfileId();
fail();
} catch (Exception e) {
assertTrue(e instanceof TwitterOperationException);
assertEquals(401, ((TwitterOperationException)e).getTwitterStatusCode());
assertTrue(e.getMessage().contains("401:Authentication credentials were missing or incorrect"));
System.out.println(e.getMessage());
}
}
@Test