Author: dblevins
Date: Sun Jun 5 01:45:01 2011
New Revision: 1131511
URL: http://svn.apache.org/viewvc?rev=1131511&view=rev
Log:
Another excellent patch from Vishwa, OPENEJB-1565: OpenEJB Retweet Bot
Looks pretty functional! Very excellent, Vishwa! Thank you!
Added:
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/ContribListStatusRetriever.java
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/JsonResponseParser.java
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetITest.java
Modified:
openejb/trunk/sandbox/tools/pom.xml
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java
openejb/trunk/sandbox/tools/src/main/resources/RetweetTool.properties
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetTest.java
Modified: openejb/trunk/sandbox/tools/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/pom.xml?rev=1131511&r1=1131510&r2=1131511&view=diff
==============================================================================
--- openejb/trunk/sandbox/tools/pom.xml (original)
+++ openejb/trunk/sandbox/tools/pom.xml Sun Jun 5 01:45:01 2011
@@ -66,6 +66,7 @@
<scope>test</scope>
</dependency>
+ <!-- SignPost Dependencies For Signing requests -->
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
@@ -73,12 +74,20 @@
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>oauth.signpost</groupId>
+ <artifactId>signpost-commonshttp4</artifactId>
+ <version>1.2.1.1</version>
+ </dependency>
+
+
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
+<!-- Apache commons compatible with signpost -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
@@ -86,6 +95,21 @@
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>4.1.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- For Parsing JSON response -->
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>1.6.4</version>
+ <scope>compile</scope>
+</dependency>
+
</dependencies>
</project>
Added:
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/ContribListStatusRetriever.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/ContribListStatusRetriever.java?rev=1131511&view=auto
==============================================================================
---
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/ContribListStatusRetriever.java
(added)
+++
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/ContribListStatusRetriever.java
Sun Jun 5 01:45:01 2011
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.tools.twitter;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+
+public class ContribListStatusRetriever {
+
+ public static HttpResponse getStatusesFromOpenEJBContributorsList() {
+ String listName="contributors";
+ String ownerScreenName="OpenEJB";
+ HttpGet httpGet =
getHttpRequestToRetrieveListStatuses(listName, ownerScreenName);
+ HttpResponse contributorsListStatusesResponse =
getContribListStatusesResponse(httpGet);
+
+ return contributorsListStatusesResponse;
+ }
+
+ private static HttpGet getHttpRequestToRetrieveListStatuses(String
listName,
+ String ownerScreenName) {
+ HttpGet httpGet = new
HttpGet("http://api.twitter.com/1/lists/statuses.json?slug="+listName
+ +"&owner_screen_name="+ownerScreenName);
+ System.out.println("Getting list using "+httpGet.getURI());
+ return httpGet;
+ }
+
+
+ private static HttpResponse getContribListStatusesResponse(
+ HttpGet httpGet) {
+ HttpResponse response = null;
+ try {
+ response = Retweet.getHttpClient().execute(httpGet);
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return response;
+ }
+}
Added:
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/JsonResponseParser.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/JsonResponseParser.java?rev=1131511&view=auto
==============================================================================
---
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/JsonResponseParser.java
(added)
+++
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/JsonResponseParser.java
Sun Jun 5 01:45:01 2011
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.tools.twitter;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+
+
+public class JsonResponseParser {
+
+ public static String getResponseBody(HttpResponse response) {
+ ResponseHandler<String> responseHander = new
BasicResponseHandler();
+ String responseBody=null;
+ try {
+ responseBody =
(String)responseHander.handleResponse(response);
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ System.out.println("Response Body Data:"+responseBody);
+
+ return responseBody;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static List<Map> getListFromJson(Reader jsonDataReader) {
+ ObjectMapper mapper = new ObjectMapper();
+ List<Map> result = null;
+ try {
+ result=mapper.readValue(jsonDataReader, new
TypeReference<ArrayList<Map>>() {
+ });
+ } catch (JsonParseException e) {
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Json to List of key value pairs:"+result);
+ return result;
+ }
+
+}
Added:
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java?rev=1131511&view=auto
==============================================================================
---
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java
(added)
+++
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java
Sun Jun 5 01:45:01 2011
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.tools.twitter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+public class OpenEJBMessageFilterUtil {
+
+ @SuppressWarnings("rawtypes")
+ public static List<String> getNonRetweetedOpenEJBStatusIDs( List<Map>
keyValuePairs) {
+
+ List<String> openEJBStatusIDs = new ArrayList<String>();
+
+ for (Object keyValuePair : keyValuePairs) {
+ Map keyValue = (Map) keyValuePair;
+ if (keyValue.containsKey("text")) {
+ String tweet = (String) keyValue.get("text");
+ if(isOpenEJBTweet(tweet) &&
!isRetweeted(keyValue))
+ {
+ System.out.println("Adding
Tweet:"+tweet);
+ Number tweetId=(Number)
keyValue.get("id");
+
openEJBStatusIDs.add(tweetId.toString());
+ }
+ else
+ {
+ System.out.println("Tweet Not
Considered:" +keyValue.get("text"));
+
System.out.println("IsOpenEJBTweet?:"+isOpenEJBTweet(tweet));
+ System.out.println("Was it retweeted
before:"+isRetweeted(keyValue));
+ }
+
+ }
+ }
+
+ return openEJBStatusIDs;
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static boolean isRetweeted( Map keyValue) {
+ Integer retweetCount= new Integer((Integer)
keyValue.get("retweet_count"));
+ if(retweetCount>0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ private static boolean isOpenEJBTweet(String tweet) {
+ String[] words = tweet.split(" ");
+ List<String> wordsAsList = Arrays.asList(words);
+ for (String word : wordsAsList) {
+ if (isOpenEJBMentioned(word))
+ {
+ String mentionName=word.trim().substring(1,8);
+ if(mentionName.equalsIgnoreCase("openejb"))
+ {return true;}
+ }
+ }
+ return false;
+ }
+
+
+ private static boolean isOpenEJBMentioned(String word) {
+ return (word.startsWith("#") || word.startsWith("@"))
&&word.trim().length()>=8;
+ }
+
+
+}
Modified:
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java?rev=1131511&r1=1131510&r2=1131511&view=diff
==============================================================================
---
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java
(original)
+++
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/Retweet.java
Sun Jun 5 01:45:01 2011
@@ -17,18 +17,23 @@
package org.apache.openejb.tools.twitter;
import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+import java.util.Map;
import java.util.Properties;
import oauth.signpost.OAuthConsumer;
-import oauth.signpost.basic.DefaultOAuthConsumer;
+import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
+import oauth.signpost.exception.OAuthCommunicationException;
+import oauth.signpost.exception.OAuthExpectationFailedException;
+import oauth.signpost.exception.OAuthMessageSignerException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.openejb.tools.twitter.util.RetweetAppUtil;
-
/**
*
* We should monitor this feed http://twitter.com/#!/OpenEJB/contributors
@@ -45,96 +50,103 @@ import org.apache.openejb.tools.twitter.
* and get them some followers and help the project at the same time.
*
* The result is we as a community will have more ability overall to get the
word out!
- *
+ *
+ * Implemented using
:http://code.google.com/p/oauth-signpost/wiki/GettingStarted
+ * list - HTTP GET
http://api.twitter.com/1/lists/statuses.xml?slug=contributors&owner_screen_name=OpenEJB
+ * retweet - HTTP POST http://api.twitter.com/1/statuses/retweet/<statusid>.xml
*
* @version $Rev$ $Date$
*/
public class Retweet {
-
- // Implementation ideas
-
- // Seems signpost is just what we need for OAuth
http://code.google.com/p/oauth-signpost/wiki/GettingStarted
-
- // Twitter API
-
- // list - HTTP GET
http://api.twitter.com/1/lists/statuses.xml?slug=contributors&owner_screen_name=OpenEJB
-
- // retweet - HTTP POST
http://api.twitter.com/1/statuses/retweet/<statusid>.xml
-
- // Little bit of Apache Commons HTTPClient and Signpost and we're good to
go
+ public static Properties
retweetToolProperties=RetweetAppUtil.getTwitterAppProperties();
public static OAuthConsumer consumer;
- static Properties
retweetToolProperties=RetweetAppUtil.getTwitterAppProperties();
- public static void main(String[] args) {
-
-
- initConsumer();
- getStatusesFromOpenEJBContributorsList();
+ @SuppressWarnings("rawtypes")
+ public static void main(String[] args) {
+ HttpResponse response =
ContribListStatusRetriever.getStatusesFromOpenEJBContributorsList();
+ String responseBody =
JsonResponseParser.getResponseBody(response);
+ StringReader jsonDataReader = new StringReader(responseBody);
+ //Each status is a entry in the list. Each status has various
properties in the form of key-value pairs
+ List<Map> listFromJson =
JsonResponseParser.getListFromJson(jsonDataReader);
+ List<String> nonRetweetedOpenEJBStatusIDs =
OpenEJBMessageFilterUtil.getNonRetweetedOpenEJBStatusIDs(listFromJson);
+
+ System.out.println("About to
retweet:"+nonRetweetedOpenEJBStatusIDs);
+ retweetIfListIsNotEmpty(nonRetweetedOpenEJBStatusIDs);
- // Scan for new tweets from the last hour
+ }
- // Retweet any tweets that haven't been retweeted
+ private static void retweetIfListIsNotEmpty(
+ List<String> nonRetweetedOpenEJBStatusIDs) {
+ if(!nonRetweetedOpenEJBStatusIDs.isEmpty())
+ {
+ retweetThisListOfStatuses(nonRetweetedOpenEJBStatusIDs);
+ }
+ else
+ {
+ System.out.println("No message to retweet.");
+ }
+ }
- // We could look at the OpenEJB twitter feed itself to determine if a
tweet
-
- // has already been retweeted
-
-
- }
-
+ private static void retweetThisListOfStatuses(
+ List<String> nonRetweetedOpenEJBStatusIDs) {
+ for(String statusIDToRetweet:nonRetweetedOpenEJBStatusIDs)
+ {
+ try {
+ retweet(statusIDToRetweet);
+ pauseBeforeTheNextRetweet();
+ } catch (OAuthMessageSignerException e) {
+ e.printStackTrace();
+ } catch (OAuthExpectationFailedException e) {
+ e.printStackTrace();
+ } catch (OAuthCommunicationException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
public static void initConsumer() {
- consumer=new DefaultOAuthConsumer(
+
+ consumer=new CommonsHttpOAuthConsumer(
retweetToolProperties.getProperty("retweetApp.consumer.key"),
retweetToolProperties
.getProperty("retweetApp.consumerSecret.key"));
+
consumer.setTokenWithSecret(retweetToolProperties.getProperty("retweetApp.authorizedUser.consumer.token"),
retweetToolProperties.getProperty("retweetApp.authorizedUser.consumer.tokenSecret"));
}
- public static HttpResponse getStatusesFromOpenEJBContributorsList() {
- String listName="contributors";
- String ownerScreenName="OpenEJB";
- HttpClient httpClient = new DefaultHttpClient();
- HttpGet httpGet =
getHttpRequestToRetrieveListStatuses(listName, ownerScreenName);
- HttpResponse contributorsListStatusesResponse =
getContribListStatusesResponse(httpClient, httpGet);
-
- return contributorsListStatusesResponse;
- }
-
- private static HttpGet getHttpRequestToRetrieveListStatuses(String
listName,
- String ownerScreenName) {
- HttpGet httpGet = new
HttpGet("http://api.twitter.com/1/lists/statuses.json?slug="+listName
- +"&owner_screen_name="+ownerScreenName);
- System.out.println("Getting list using "+httpGet.getURI());
- return httpGet;
- }
-
- private static HttpResponse getContribListStatusesResponse(HttpClient
httpClient,
- HttpGet httpGet) {
+ public static HttpResponse retweet(String statusIDToRetweet) throws
OAuthMessageSignerException, OAuthExpectationFailedException,
OAuthCommunicationException {
+ HttpPost httpPost = new
HttpPost("http://api.twitter.com/1/statuses/retweet/"+statusIDToRetweet+".json");
+ initConsumer();
+ consumer.sign(httpPost);
HttpResponse response = null;
try {
- response = httpClient.execute(httpGet);
+ response = getHttpClient().execute(httpPost);
+ System.out.println(response.getStatusLine());
+ System.out.println("Retweeted "+statusIDToRetweet);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
+
return response;
}
-
-
-
-
-
-
+ public static HttpClient getHttpClient()
+ {
+ return new DefaultHttpClient();
+ }
-
-
-
+ private static void pauseBeforeTheNextRetweet() {
+ try {
+ Thread.sleep(1000*60*5);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
-
}
Modified: openejb/trunk/sandbox/tools/src/main/resources/RetweetTool.properties
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/main/resources/RetweetTool.properties?rev=1131511&r1=1131510&r2=1131511&view=diff
==============================================================================
--- openejb/trunk/sandbox/tools/src/main/resources/RetweetTool.properties
(original)
+++ openejb/trunk/sandbox/tools/src/main/resources/RetweetTool.properties Sun
Jun 5 01:45:01 2011
@@ -7,5 +7,5 @@ retweetApp.authorize.url=https://api.twi
# Below tokens now reflect a mock twitter account (stratwine2) that authorized
access
# TODO: Change to Open EJB Twitter Account, once this works fine
-retweetApp.authorizedUser.consumer.token=307322883-5jiw2tpV1A5b1487TKHHKPjBjH54m3PZINuiuSyQ
-retweetApp.authorizedUser.consumer.tokenSecret=06fM8tNXGPOhLsFB8QuIlzIhbdriqdE5598pLeJk
+retweetApp.authorizedUser.consumer.token=310745104-M7gs5njthMd5UD4nnwvaAVzsfBLwmyEGUyd7opk
+retweetApp.authorizedUser.consumer.tokenSecret=PZzNv4sLpNAWpCW8TICs5xhrUqjaPr3x83PLjPUoI
Added:
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetITest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetITest.java?rev=1131511&view=auto
==============================================================================
---
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetITest.java
(added)
+++
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetITest.java
Sun Jun 5 01:45:01 2011
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.tools;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.StringReader;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.http.HttpResponse;
+import org.apache.openejb.tools.twitter.ContribListStatusRetriever;
+import org.apache.openejb.tools.twitter.JsonResponseParser;
+import org.junit.Test;
+
+public class RetweetITest {
+
+
+
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void convertJsonResponseToListOfKeyValuePairs()
+ {
+ HttpResponse statusesFromOpenEJBContributorsList =
ContribListStatusRetriever.getStatusesFromOpenEJBContributorsList();
+ String responseBody =
JsonResponseParser.getResponseBody(statusesFromOpenEJBContributorsList);
+
+ assertNotNull(responseBody);
+
+ StringReader jsonDataReader=new StringReader(responseBody);
+ List<Map> listFromJson =
JsonResponseParser.getListFromJson(jsonDataReader);
+
+ assertNotNull(listFromJson);
+ }
+
+
+}
Modified:
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetTest.java?rev=1131511&r1=1131510&r2=1131511&view=diff
==============================================================================
---
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetTest.java
(original)
+++
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/RetweetTest.java
Sun Jun 5 01:45:01 2011
@@ -17,19 +17,12 @@
package org.apache.openejb.tools;
import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-import oauth.signpost.exception.OAuthCommunicationException;
-import oauth.signpost.exception.OAuthExpectationFailedException;
-import oauth.signpost.exception.OAuthMessageSignerException;
-
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.openejb.tools.twitter.ContribListStatusRetriever;
import org.apache.openejb.tools.twitter.Retweet;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -45,29 +38,9 @@ public class RetweetTest {
}
@Test
- public void basicRequestShouldGiveValidResponse() throws
OAuthMessageSignerException, OAuthExpectationFailedException,
OAuthCommunicationException, IOException
- {
- URL url = new URL("http://twitter.com/statuses/mentions.xml");
- HttpURLConnection request = (HttpURLConnection)
url.openConnection();
-
- // sign the request
- Retweet.consumer.sign(request);
-
- // send the request
- request.connect();
-
- // response status should be 200 OK
- int statusCode = request.getResponseCode();
- System.out.println("Status Code:"+statusCode);
-
- assertTrue(statusCode==200);
-
- }
-
- @Test
public void contributorsListStatusesShouldBeRetrieved() throws
ClientProtocolException, IOException
{
- HttpResponse
response=Retweet.getStatusesFromOpenEJBContributorsList();
+ HttpResponse
response=ContribListStatusRetriever.getStatusesFromOpenEJBContributorsList();
assertTrue(response.getStatusLine().getStatusCode()==200);
@@ -75,4 +48,6 @@ public class RetweetTest {
String responseBody =
(String)responseHander.handleResponse(response);
System.out.println(responseBody);
}
+
+
}