streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject svn commit: r1556893 [22/25] - in /incubator/streams/branches/sblackmon: ./ streams-config-graph/ streams-config-graph/src/ streams-config-graph/src/main/ streams-config-graph/src/main/java/ streams-config-graph/src/main/java/org/ streams-config-graph/...
Date Thu, 09 Jan 2014 17:27:58 GMT
Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/serializer/TwitterJsonTweetActivitySerializer.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/serializer/TwitterJsonTweetActivitySerializer.java?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/serializer/TwitterJsonTweetActivitySerializer.java
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/serializer/TwitterJsonTweetActivitySerializer.java
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,85 @@
+package org.apache.streams.twitter.serializer;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.streams.data.ActivitySerializer;
+import org.apache.streams.pojo.json.Activity;
+import org.apache.streams.pojo.json.ActivityObject;
+import org.apache.streams.pojo.json.Actor;
+import org.apache.streams.twitter.pojo.Tweet;
+import org.apache.streams.twitter.pojo.User;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.streams.data.util.ActivityUtil.ensureExtensions;
+
+/**
+* Created with IntelliJ IDEA.
+* User: mdelaet
+* Date: 9/30/13
+* Time: 9:24 AM
+* To change this template use File | Settings | File Templates.
+*/
+public class TwitterJsonTweetActivitySerializer extends TwitterJsonEventActivitySerializer
implements ActivitySerializer {
+
+    public Activity convert(ObjectNode event) {
+
+        Tweet tweet = null;
+        try {
+            tweet = mapper.treeToValue(event, Tweet.class);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+        }
+
+        Activity activity = new Activity();
+        activity.setActor(buildActor(tweet));
+        activity.setVerb("post");
+        activity.setObject(buildActivityObject(tweet));
+        activity.setId(formatId(activity.getVerb(), tweet.getIdStr()));
+        activity.setTarget(buildTarget(tweet));
+        activity.setPublished(parse(tweet.getCreatedAt()));
+        activity.setGenerator(buildGenerator(event));
+        activity.setIcon(getIcon(event));
+        activity.setProvider(buildProvider(event));
+        activity.setTitle("");
+        activity.setContent(tweet.getText());
+        activity.setUrl(getUrls(event));
+        activity.setLinks(getLinks(event));
+        addTwitterExtension(activity, event);
+        addLocationExtension(activity, tweet);
+        return activity;
+    }
+
+    public static Actor buildActor(Tweet tweet) {
+        Actor actor = new Actor();
+        User user = tweet.getUser();
+        actor.setId(formatId(user.getIdStr(), tweet.getIdStr()));
+        actor.setDisplayName(user.getScreenName());
+        actor.setId(user.getIdStr());
+        if (user.getUrl()!=null){
+            actor.setUrl(user.getUrl());
+        }
+        return actor;
+    }
+
+    public static ActivityObject buildActivityObject(Tweet tweet) {
+        ActivityObject actObj = new ActivityObject();
+        actObj.setId(formatId(tweet.getIdStr()));
+        actObj.setObjectType("tweet");
+        return actObj;
+    }
+
+    public static ActivityObject buildTarget(Tweet tweet) {
+        return null;
+    }
+
+    public static void addLocationExtension(Activity activity, Tweet tweet) {
+        Map<String, Object> extensions = ensureExtensions(activity);
+        Map<String, Object> location = new HashMap<String, Object>();
+        location.put("id", formatId(tweet.getIdStr()));
+        location.put("coordinates", tweet.getCoordinates());
+        extensions.put("location", location);
+    }
+
+}

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Delete.json
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Delete.json?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Delete.json
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Delete.json
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,33 @@
+{
+    "type": "object",
+    "$schema": "http://json-schema.org/draft-03/schema",
+    "id": "#",
+    "javaType" : "org.apache.streams.twitter.pojo.Delete",
+    "properties": {
+        "delete": {
+            "type": "object",
+            "javaType" : "org.apache.streams.twitter.pojo.DeleteDetails",
+            "properties": {
+                "status": {
+                    "type": "object",
+                    "properties": {
+                        "id": {
+                            "ignore_malformed": false,
+                            "type": "integer"
+                        },
+                        "user_id": {
+                            "ignore_malformed": false,
+                            "type": "integer"
+                        },
+                        "id_str": {
+                            "type": "string"
+                        },
+                        "user_id_str": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Retweet.json
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Retweet.json?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Retweet.json
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/Retweet.json
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,15 @@
+{
+    "type": "object",
+    "$schema": "http://json-schema.org/draft-03/schema",
+    "id": "#",
+    "javaType" : "org.apache.streams.twitter.pojo.Retweet",
+    "extends": {"$ref":"tweet.json"},
+    "properties": {
+        "retweeted_status": {
+            "type": "object",
+            "required" : false,
+            "description" : "Describes the tweet being retweeted.",
+            "$ref" : "tweet.json"
+        }
+    }
+}
\ No newline at end of file

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/TwitterStreamConfiguration.json
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/TwitterStreamConfiguration.json?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/TwitterStreamConfiguration.json
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/TwitterStreamConfiguration.json
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,79 @@
+{
+    "type": "object",
+    "$schema": "http://json-schema.org/draft-03/schema",
+    "id": "#",
+    "javaType" : "org.apache.streams.twitter.TwitterStreamConfiguration",
+    "javaInterfaces": ["java.io.Serializable"],
+    "properties": {
+        "protocol": {
+            "type": "string",
+            "description": "The protocol"
+        },
+        "host": {
+            "type": "string",
+            "description": "The host"
+        },
+        "port": {
+            "type": "integer",
+            "description": "The port"
+        },
+        "version": {
+            "type": "string",
+            "description": "The version"
+        },
+        "endpoint": {
+            "type": "string",
+            "description": "The endpoint"
+        },
+        "includeEntities": {
+            "type": "string"
+        },
+        "jsonStoreEnabled": {
+            "type": "string"
+        },
+        "truncated": {
+            "type": "boolean"
+        },
+        "filter-level": {
+            "type": "string",
+            "description": "Setting this parameter to one of none, low, or medium will set
the minimum value of the filter_level Tweet attribute required to be included in the stream"
+        },
+        "follow": {
+            "type": "array",
+            "description": "A list of user IDs, indicating the users whose Tweets should
be delivered on the stream",
+            "items": {
+                "type": "integer"
+            }
+        },
+        "track": {
+            "type": "array",
+            "description": "A list of phrases which will be used to determine what Tweets
will be delivered on the stream",
+            "items": {
+                "type": "string"
+            }
+        },
+        "oauth": {
+            "type": "object",
+            "dynamic": "true",
+            "javaType" : "org.apache.streams.twitter.TwitterOAuthConfiguration",
+            "javaInterfaces": ["java.io.Serializable"],
+            "properties": {
+                "appName": {
+                    "type": "string"
+                },
+                "consumerKey": {
+                    "type": "string"
+                },
+                "consumerSecret": {
+                    "type": "string"
+                },
+                "accessToken": {
+                    "type": "string"
+                },
+                "accessTokenSecret": {
+                    "type": "string"
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,296 @@
+{
+    "type": "object",
+    "$schema": "http://json-schema.org/draft-03/schema",
+    "id": "#",
+    "javaType" : "org.apache.streams.twitter.pojo.Tweet",
+    "properties": {
+        "text": {
+            "type": "string"
+        },
+        "retweeted": {
+            "type": "boolean"
+        },
+        "in_reply_to_screen_name": {
+            "type": "string"
+        },
+        "truncated": {
+            "type": "boolean"
+        },
+        "filter_level": {
+            "type": "string"
+        },
+        "contributors": {
+            "type": "array",
+            "items": {
+                "type": "object",
+                "javaType" : "org.apache.streams.twitter.pojo.Contributor",
+                "properties": {
+                    "id": {
+                        "ignore_malformed": false,
+                        "type": "integer"
+                    },
+                    "id_str": {
+                        "type": "string"
+                    },
+                    "screen_name": {
+                        "type": "string"
+                    }
+                }
+            }
+        },
+        "coordinates": {
+            "type": "object",
+            "javaType" : "org.apache.streams.twitter.pojo.Coordinates",
+            "items": {
+                "properties": {
+                    "type": {
+                        "type": "string"
+                    },
+                    "coordinates": {
+                        "type": "array",
+                        "items": [
+                            {
+                                "type": "integer"
+                            }
+                        ]
+                    }
+                }
+            }
+        },
+        "entities": {
+            "type": "object",
+            "dynamic": "true",
+            "javaType" : "org.apache.streams.twitter.pojo.Entities",
+            "properties": {
+                "user_mentions": {
+                    "type": "array",
+                    "items": {
+                        "type": "object",
+                        "javaType" : "org.apache.streams.twitter.pojo.UserMentions",
+                        "properties": {
+                            "id": {
+                                "ignore_malformed": false,
+                                "type": "integer"
+                            },
+                            "name": {
+                                "type": "string"
+                            },
+                            "indices": {
+                                "type": "array",
+                                "items": [{
+                                    "type" : "integer"
+                                }]
+                            },
+                            "screen_name": {
+                                "type": "string"
+                            },
+                            "id_str": {
+                                "type": "string"
+                            }
+                        }
+                    }
+                },
+                "hashtags": {
+                    "type": "array",
+                    "items": [
+                        {
+                            "type": "string"
+                        }
+                    ]
+                },
+                "urls": {
+                    "type": "array",
+                    "items": {
+                        "type": "object",
+                        "javaType": "org.apache.streams.twitter.Url",
+                        "properties": {
+                            "expanded_url": {
+                                "type": "string"
+                            },
+                            "indices": {
+                                "type": "array",
+                                "items": [
+                                    {
+                                    "type" : "integer"
+                                    }
+                                ]
+                            },
+                            "display_url": {
+                                "type": "string"
+                            },
+                            "url": {
+                                "type": "string"
+                            }
+                        }
+                    }
+                }
+            }
+        },
+        "in_reply_to_status_id_str": {
+            "type": "string"
+        },
+        "id": {
+            "ignore_malformed": false,
+            "type": "integer"
+        },
+        "in_reply_to_user_id_str": {
+            "type": "string"
+        },
+        "source": {
+            "type": "string"
+        },
+        "lang": {
+            "type": "string"
+        },
+        "favorited": {
+            "type": "boolean"
+        },
+        "possibly_sensitive": {
+            "type": "boolean"
+        },
+        "in_reply_to_status_id": {
+            "ignore_malformed": false,
+            "type": "integer"
+        },
+        "created_at": {
+            "type": "string"
+        },
+        "in_reply_to_user_id": {
+            "ignore_malformed": false,
+            "type": "integer"
+        },
+        "retweet_count": {
+            "ignore_malformed": false,
+            "type": "integer"
+        },
+        "id_str": {
+            "type": "string"
+        },
+        "user": {
+            "id": "user",
+            "type": "object",
+            "javaType" : "org.apache.streams.twitter.pojo.User",
+            "dynamic": "true",
+            "properties": {
+                "location": {
+                    "type": "string"
+                },
+                "default_profile": {
+                    "type": "boolean"
+                },
+                "statuses_count": {
+                    "ignore_malformed": false,
+                    "type": "integer"
+                },
+                "profile_background_tile": {
+                    "type": "boolean"
+                },
+                "lang": {
+                    "type": "string"
+                },
+                "profile_link_color": {
+                    "type": "string"
+                },
+                "id": {
+                    "ignore_malformed": false,
+                    "type": "integer"
+                },
+                "protected": {
+                    "type": "boolean"
+                },
+                "favourites_count": {
+                    "ignore_malformed": false,
+                    "type": "integer"
+                },
+                "profile_text_color": {
+                    "type": "string"
+                },
+                "verified": {
+                    "type": "boolean"
+                },
+                "description": {
+                    "type": "string"
+                },
+                "contributors_enabled": {
+                    "type": "boolean"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "profile_sidebar_border_color": {
+                    "type": "string"
+                },
+                "profile_background_color": {
+                    "type": "string"
+                },
+                "created_at": {
+                    "type": "string"
+                },
+                "default_profile_image": {
+                    "type": "boolean"
+                },
+                "followers_count": {
+                    "ignore_malformed": false,
+                    "type": "integer"
+                },
+                "geo_enabled": {
+                    "type": "boolean"
+                },
+                "profile_image_url_https": {
+                    "type": "string"
+                },
+                "profile_background_image_url": {
+                    "type": "string"
+                },
+                "profile_background_image_url_https": {
+                    "type": "string"
+                },
+                "follow_request_sent": {
+                    "type": "boolean"
+                },
+                "url": {
+                    "type": "string"
+                },
+                "utc_offset": {
+                    "ignore_malformed": false,
+                    "type": "integer"
+                },
+                "time_zone": {
+                    "type": "string"
+                },
+                "profile_use_background_image": {
+                    "type": "boolean"
+                },
+                "friends_count": {
+                    "ignore_malformed": false,
+                    "type": "integer"
+                },
+                "profile_sidebar_fill_color": {
+                    "type": "string"
+                },
+                "screen_name": {
+                    "type": "string"
+                },
+                "id_str": {
+                    "type": "string"
+                },
+                "profile_image_url": {
+                    "type": "string"
+                },
+                "is_translator": {
+                    "type": "boolean"
+                },
+                "listed_count": {
+                    "ignore_malformed": false,
+                    "type": "integer"
+                }
+            }
+        },
+        "retweeted_status": {
+            "type": "object",
+            "required" : false,
+            "description" : "Describes the tweet being retweeted.",
+            "$ref" : "#"
+        }
+    }
+}
\ No newline at end of file

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/resources/reference.conf
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/resources/reference.conf?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/resources/reference.conf
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/main/resources/reference.conf
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,11 @@
+twitter {
+    protocol = "https"
+    host = "stream.twitter.com"
+    port = 443
+    version = "1.1"
+    endpoint = "statuses/sample.json"
+    filter-level = "none"
+    oauth {
+        appName = "Apache Streams"
+    }
+}
\ No newline at end of file

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TweetSerDeTest.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TweetSerDeTest.java?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TweetSerDeTest.java
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TweetSerDeTest.java
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,106 @@
+package org.apache.streams.twitter.test;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.commons.lang.StringUtils;
+import org.apache.streams.pojo.json.Activity;
+import org.apache.streams.twitter.pojo.Delete;
+import org.apache.streams.twitter.pojo.Retweet;
+import org.apache.streams.twitter.pojo.Tweet;
+import org.apache.streams.twitter.provider.TwitterEventClassifier;
+import org.apache.streams.twitter.serializer.TwitterJsonDeleteActivitySerializer;
+import org.apache.streams.twitter.serializer.TwitterJsonRetweetActivitySerializer;
+import org.apache.streams.twitter.serializer.TwitterJsonTweetActivitySerializer;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import static java.util.regex.Pattern.matches;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+/**
+* Created with IntelliJ IDEA.
+* User: sblackmon
+* Date: 8/20/13
+* Time: 5:57 PM
+* To change this template use File | Settings | File Templates.
+*/
+public class TweetSerDeTest {
+
+    private final static Logger LOGGER = LoggerFactory.getLogger(TweetSerDeTest.class);
+    private ObjectMapper mapper = new ObjectMapper();
+
+    private TwitterJsonTweetActivitySerializer twitterJsonTweetActivitySerializer = new TwitterJsonTweetActivitySerializer();
+    private TwitterJsonRetweetActivitySerializer twitterJsonRetweetActivitySerializer = new
TwitterJsonRetweetActivitySerializer();
+    private TwitterJsonDeleteActivitySerializer twitterJsonDeleteActivitySerializer = new
TwitterJsonDeleteActivitySerializer();
+
+    //    @Ignore
+    @Test
+    public void Tests()
+    {
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
+        mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
+        mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
+
+        InputStream is = TweetSerDeTest.class.getResourceAsStream("/twitter_jsons.txt");
+        InputStreamReader isr = new InputStreamReader(is);
+        BufferedReader br = new BufferedReader(isr);
+
+        try {
+            while (br.ready()) {
+                String line = br.readLine();
+                if(!StringUtils.isEmpty(line))
+                {
+                    LOGGER.info("raw: {}", line);
+
+                    Class detected = TwitterEventClassifier.detectClass(line);
+
+                    ObjectNode event = (ObjectNode) mapper.readTree(line);
+
+                    assertThat(event, is(not(nullValue())));
+
+                    String tweetstring = mapper.writeValueAsString(event);
+
+                    LOGGER.info("{}: {}", detected.getName(), tweetstring);
+
+                    Activity activity;
+                    if( detected.equals( Delete.class )) {
+                        activity = twitterJsonDeleteActivitySerializer.convert(event);
+                    } else if ( detected.equals( Retweet.class )) {
+                        activity = twitterJsonRetweetActivitySerializer.convert(event);
+                    } else if ( detected.equals( Tweet.class )) {
+                        activity = twitterJsonTweetActivitySerializer.convert(event);
+                    } else {
+                        Assert.fail();
+                        return;
+                    }
+
+                    String activitystring = mapper.writeValueAsString(activity);
+
+                    LOGGER.info("activity: {}", activitystring);
+
+                    assertThat(activity, is(not(nullValue())));
+                    if(activity.getId() != null) {
+                        assertThat(matches("id:.*:[a-z]*:[a-zA-Z0-9]*", activity.getId()),
is(true));
+                    }
+                    assertThat(activity.getActor(), is(not(nullValue())));
+                    assertThat(activity.getActor().getId(), is(not(nullValue())));
+                    assertThat(activity.getVerb(), is(not(nullValue())));
+                    assertThat(activity.getObject(), is(not(nullValue())));
+                    assertThat(activity.getObject().getObjectType(), is(not(nullValue())));
+                }
+            }
+        } catch( Exception e ) {
+            System.out.println(e);
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterEventClassifierTest.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterEventClassifierTest.java?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterEventClassifierTest.java
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterEventClassifierTest.java
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,39 @@
+package org.apache.streams.twitter.test;
+
+import org.apache.streams.twitter.pojo.Delete;
+import org.apache.streams.twitter.pojo.Retweet;
+import org.apache.streams.twitter.pojo.Tweet;
+import org.apache.streams.twitter.provider.TwitterEventClassifier;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Created by sblackmon on 12/13/13.
+ */
+public class TwitterEventClassifierTest {
+
+    private String tweet = "{\"created_at\":\"Wed Dec 11 22:27:34 +0000 2013\",\"id\":410898682381615105,\"id_str\":\"410898682381615105\",\"text\":\"Men's
Basketball Single-Game Tickets Available - A limited number of tickets remain for Kentucky's
upcoming men's ... http:\\/\\/t.co\\/SH5YZGpdRx\",\"source\":\"\\u003ca href=\\\"http:\\/\\/www.hootsuite.com\\\"
rel=\\\"nofollow\\\"\\u003eHootSuite\\u003c\\/a\\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":91407775,\"id_str\":\"91407775\",\"name\":\"Winchester,
KY\",\"screen_name\":\"winchester_ky\",\"location\":\"\",\"url\":null,\"description\":null,\"protected\":false,\"followers_count\":136,\"friends_count\":0,\"listed_count\":1,\"created_at\":\"Fri
Nov 20 19:29:02 +0000 2009\",\"favourites_count\":0,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":fa
 lse,\"statuses_count\":1793,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_image_url_https\":\"https:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/613854495\\/winchester_sociallogo_normal.jpg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/613854495\\/winchester_sociallogo_normal.jpg\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors
 \":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[{\"url\":\"http:\\/\\/t.co\\/SH5YZGpdRx\",\"expanded_url\":\"http:\\/\\/ow.ly\\/2C2XL1\",\"display_url\":\"ow.ly\\/2C2XL1\",\"indices\":[118,140]}],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"filter_level\":\"medium\",\"lang\":\"en\"}\n";
+    private String retweet = "{\"created_at\":\"Wed Dec 11 22:27:34 +0000 2013\",\"id\":410898682385797121,\"id_str\":\"410898682385797121\",\"text\":\"RT
@hemocional: Cuando te acarici\\u00e9 me di cuenta que hab\\u00eda vivido toda mi vida con
las manos vac\\u00edas.\\nALEJANDRO JODOROWSKY.\",\"source\":\"web\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":163149656,\"id_str\":\"163149656\",\"name\":\"Carolina\",\"screen_name\":\"_titinaok\",\"location\":\"Montevideo\",\"url\":\"http:\\/\\/www.youtube.com\\/watch?v=N3v5vZ-tU1E\",\"description\":\"Tantas
veces me defin\\u00ed ...Soy nada y todo a la vez\",\"protected\":false,\"followers_count\":41,\"friends_count\":75,\"listed_count\":2,\"created_at\":\"Mon
Jul 05 17:35:49 +0000 2010\",\"favourites_count\":4697,\"utc_offset\":-10800,\"time_zone\":\"Buenos
Aires\",\"geo_enabled\":fal
 se,\"verified\":false,\"statuses_count\":5257,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C4A64B\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_background_images\\/378800000096791690\\/f64a07abbaa735b39ad7655fdaa2f416.jpeg\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_background_images\\/378800000096791690\\/f64a07abbaa735b39ad7655fdaa2f416.jpeg\",\"profile_background_tile\":true,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/378800000799213504\\/496d008f457390005825d2eb4ca50a63_normal.jpeg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/378800000799213504\\/496d008f457390005825d2eb4ca50a63_normal.jpeg\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/163149656\\/1379722210\",\"profile_link_color\":\"BF415A\",\"profile_sidebar_border_color\":\"000000\",\"profile_sidebar_fill_color\":\"B17CED\",\"pr
 ofile_text_color\":\"3D1957\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweeted_status\":{\"created_at\":\"Wed
Dec 11 22:25:06 +0000 2013\",\"id\":410898060206960640,\"id_str\":\"410898060206960640\",\"text\":\"Cuando
te acarici\\u00e9 me di cuenta que hab\\u00eda vivido toda mi vida con las manos vac\\u00edas.\\nALEJANDRO
JODOROWSKY.\",\"source\":\"\\u003ca href=\\\"http:\\/\\/bufferapp.com\\\" rel=\\\"nofollow\\\"\\u003eBuffer\\u003c\\/a\\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":552929456,\"id_str\":\"552929456\",\"name\":\"Habilidad
emocional\",\"screen_name\":\"hemocional\",\"location\":\"\",\"url\":\"http:\\/\\/www.hab
 ilidademocional.com\",\"description\":\"Pensamientos y reflexiones para ayudar a mirar la
vida de una manera m\\u00e1s saludable y a crecer interiormente cada d\\u00eda m\\u00e1s.
#InteligenciaEmocional #Psicolog\\u00eda\",\"protected\":false,\"followers_count\":34307,\"friends_count\":325,\"listed_count\":361,\"created_at\":\"Fri
Apr 13 19:00:11 +0000 2012\",\"favourites_count\":44956,\"utc_offset\":3600,\"time_zone\":\"Madrid\",\"geo_enabled\":false,\"verified\":false,\"statuses_count\":24011,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"000000\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_background_images\\/378800000123681920\\/aab7226ae139f0ff93b04a08a8541477.jpeg\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_background_images\\/378800000123681920\\/aab7226ae139f0ff93b04a08a8541477.jpeg\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/pbs.twimg
 .com\\/profile_images\\/2430091220\\/zdkea46xhe3g4e65nuwl_normal.gif\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/2430091220\\/zdkea46xhe3g4e65nuwl_normal.gif\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/552929456\\/1383180255\",\"profile_link_color\":\"FF00E1\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"F3F3F3\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":9,\"favorite_count\":6,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false,\"lang\":\"es\"},\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"symbols\":[],\"urls\":[],\"user_mentions\":[{\"screen_name\":\"he
 mocional\",\"name\":\"Habilidad emocional\",\"id\":552929456,\"id_str\":\"552929456\",\"indices\":[3,14]}]},\"favorited\":false,\"retweeted\":false,\"filter_level\":\"medium\",\"lang\":\"es\"}\n";
+    private String delete = "{\"delete\":{\"status\":{\"id\":377518972486553600,\"user_id\":1249045572,\"id_str\":\"377518972486553600\",\"user_id_str\":\"1249045572\"}}}\n";
+
+    @Test
+    public void testDetectTweet() {
+        Class result = TwitterEventClassifier.detectClass(tweet);
+        if( !result.equals(Tweet.class) )
+            Assert.fail();
+    }
+
+    @Test
+    public void testDetectRetweet() {
+        Class result = TwitterEventClassifier.detectClass(retweet);
+        if( !result.equals(Retweet.class) )
+            Assert.fail();
+    }
+
+    @Test
+    public void testDetectDelete() {
+        Class result = TwitterEventClassifier.detectClass(delete);
+        if( !result.equals(Delete.class) )
+            Assert.fail();
+    }
+}

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterStreamProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterStreamProviderTest.java?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterStreamProviderTest.java
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/TwitterStreamProviderTest.java
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,40 @@
+package org.apache.streams.twitter.test;
+
+import com.google.common.collect.Lists;
+import org.apache.streams.twitter.TwitterOAuthConfiguration;
+import org.apache.streams.twitter.TwitterStreamConfiguration;
+import org.apache.streams.twitter.provider.TwitterStreamProvider;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created by sblackmon on 12/10/13.
+ */
+public class TwitterStreamProviderTest {
+
+    private final static Logger LOGGER = LoggerFactory.getLogger(TwitterStreamProviderTest.class);
+
+    @Ignore
+    @Test
+    public void Tests()
+    {
+        TwitterStreamConfiguration twitterStreamConfiguration = new TwitterStreamConfiguration();
+        TwitterOAuthConfiguration twitterOAuthConfiguration = new TwitterOAuthConfiguration();
+        twitterOAuthConfiguration.setAccessToken("281592383-DMabF7UmiZqDAyzHwNPe09iruBSplrt9nHdavZP4");
+        twitterOAuthConfiguration.setAccessTokenSecret("uA1oJcSEkWB9gAchE3J1FsCZlagxgunVRmfXx62OZU");
+        twitterStreamConfiguration.setOauth(twitterOAuthConfiguration);
+        twitterStreamConfiguration.setTrack(Lists.newArrayList("stream"));
+
+        TwitterStreamProvider stream = new TwitterStreamProvider(twitterStreamConfiguration);
+
+        //Assert.assertEquals(stream.getUrl().substring(0,5), "https");
+        //Assert.assertNotNull(stream.getParams().get("track"));
+        //Assert.assertFalse(stream.getParams().containsKey("follow"));
+        //Assert.assertArrayEquals(Lists.newArrayList("track").toArray(), Lists.newArrayList(stream.getParams().keySet()).toArray());
+
+        // any deterministic test of the stream would go here
+
+    }
+}



Mime
View raw message