Author: dblevins
Date: Sat Jul 23 21:09:59 2011
New Revision: 1150220

URL: http://svn.apache.org/viewvc?rev=1150220&view=rev
Log:
Patch from Vishwanath, OPENEJB-1565: Retweet anything that contains #TomEE
Thank you, Vishwanath!

Added:
    openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/twitter/
    
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/twitter/RetweetTest.java
   (with props)
Modified:
    
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java

Modified: 
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=1150220&r1=1150219&r2=1150220&view=diff
==============================================================================
--- 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java
 (original)
+++ 
openejb/trunk/sandbox/tools/src/main/java/org/apache/openejb/tools/twitter/OpenEJBMessageFilterUtil.java
 Sat Jul 23 21:09:59 2011
@@ -123,25 +123,43 @@ public class OpenEJBMessageFilterUtil im
     /*
       * tweet.contains(string) can't help since mentions can end with period, 
like "#openejb."
       */
-    private static boolean isOpenEJBTweet(String tweet) {
+     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;
-
-                if (mentionName.equals("TomEE")) return true;
+            if (isOpenEJBMentioned(word) || isTomEEMentioned(word)) {
+               return true;
             }
+            
         }
         return false;
     }
 
 
-    private static boolean isOpenEJBMentioned(String word) {
-        return (word.startsWith("#") || word.startsWith("@")) && 
word.trim().length() >= 8;
+     static boolean isOpenEJBMentioned(String word) {
+        if((word.startsWith("#") || word.startsWith("@")) && 
word.trim().length() >= 8)
+        {
+               if (word.trim().substring(1,8).equalsIgnoreCase("openejb"))
+               {
+                       return true;
+               }
+        }
+        
+        return false;
     }
 
+     static boolean isTomEEMentioned(String word){
+       if( (word.startsWith("#") || word.startsWith("@")) && 
word.trim().length() >=6)
+       {
+               if (word.trim().substring(1,6).equals("TomEE"))
+               {
+                       return true;
+               }
+       }
+       
+       return false;
+    }
 
 }

Added: 
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/twitter/RetweetTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/twitter/RetweetTest.java?rev=1150220&view=auto
==============================================================================
--- 
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/twitter/RetweetTest.java
 (added)
+++ 
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/twitter/RetweetTest.java
 Sat Jul 23 21:09:59 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 static org.junit.Assert.*;
+
+import static org.apache.openejb.tools.twitter.OpenEJBMessageFilterUtil.*;
+import org.apache.openejb.tools.twitter.Retweet;
+import org.apache.openejb.tools.twitter.UserStatusRetriever;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class RetweetTest {
+
+       
+       @BeforeClass
+       public static void setUp()
+       {
+         Retweet.initConsumer();
+       }
+               
+       @Test
+       public void userStatusShouldBeRetrieved()
+       {
+               //UserStatusRetriever.getUserOpenEJBStatus("stratwine");
+               //No asserts. Just to check if it run without exceptions
+       }
+
+       @Test
+       public void tomEEMentionsShouldBeAccepted()
+       {
+               assertTrue(isTomEEMentioned("#TomEE"));
+               
+       }
+       
+       @Test
+       public void openEJBMentionsSHouldBeAccepted()
+       {
+               assertTrue(isOpenEJBMentioned("#openejb"));
+       }
+       
+       
+       @Test
+       public void nonOpenEJBMessageShouldBeRejected()
+       {
+               assertFalse(isOpenEJBTweet("some random message"));
+       }
+       
+       @Test
+       public void openEJBOrTomEEMessagesShouldBeAccepted()
+       {
+               assertTrue(isOpenEJBTweet("this is a @TomEE message"));
+               assertTrue(isOpenEJBTweet("this is a #openejb tweet"));
+       }
+
+}

Propchange: 
openejb/trunk/sandbox/tools/src/test/java/org/apache/openejb/tools/twitter/RetweetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to