streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfrank...@apache.org
Subject [2/4] git commit: STREAMS-139 | Updated the buildProvider method in the SyndEntry Serializer to ensure that we use a valid URI for the link attribute
Date Tue, 12 Aug 2014 21:44:36 GMT
STREAMS-139 | Updated the buildProvider method in the SyndEntry Serializer to ensure that we
use a valid URI for the link attribute


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/9e72ae74
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/9e72ae74
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/9e72ae74

Branch: refs/heads/master
Commit: 9e72ae74154eb942d3e12ab183cc25540a7bfbcc
Parents: a22a99c
Author: Robert Douglas <rdouglas@w2odigital.com>
Authored: Tue Aug 5 16:29:40 2014 -0500
Committer: Robert Douglas <rdouglas@w2odigital.com>
Committed: Tue Aug 5 16:29:40 2014 -0500

----------------------------------------------------------------------
 .../serializer/SyndEntryActivitySerializer.java |  2 +-
 .../test/SyndEntryActivitySerizlizerTest.java   | 27 ++++++++++++++++----
 .../src/test/resources/TestSyndEntryJson.txt    |  1 +
 3 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/9e72ae74/streams-contrib/streams-provider-rss/src/main/java/org/apache/streams/rss/serializer/SyndEntryActivitySerializer.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-rss/src/main/java/org/apache/streams/rss/serializer/SyndEntryActivitySerializer.java
b/streams-contrib/streams-provider-rss/src/main/java/org/apache/streams/rss/serializer/SyndEntryActivitySerializer.java
index ace10dc..9edcd12 100644
--- a/streams-contrib/streams-provider-rss/src/main/java/org/apache/streams/rss/serializer/SyndEntryActivitySerializer.java
+++ b/streams-contrib/streams-provider-rss/src/main/java/org/apache/streams/rss/serializer/SyndEntryActivitySerializer.java
@@ -179,7 +179,7 @@ public class SyndEntryActivitySerializer implements ActivitySerializer<ObjectNod
             uri = entry.get("uri").textValue();
 
         if (uri != null) {
-            if((uri.contains("http") || uri.contains("www")) || (link == null || !(link.contains("http")
|| link.contains("www")))) {
+            if((uri.startsWith("http") || uri.startsWith("www")) || (link == null || !(link.startsWith("http")
|| link.startsWith("www")))) {
                 resourceLocation = uri;
             } else {
                 resourceLocation = link;

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/9e72ae74/streams-contrib/streams-provider-rss/src/test/java/org/apache/streams/rss/test/SyndEntryActivitySerizlizerTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-rss/src/test/java/org/apache/streams/rss/test/SyndEntryActivitySerizlizerTest.java
b/streams-contrib/streams-provider-rss/src/test/java/org/apache/streams/rss/test/SyndEntryActivitySerizlizerTest.java
index 776f4ed..fd9a996 100644
--- a/streams-contrib/streams-provider-rss/src/test/java/org/apache/streams/rss/test/SyndEntryActivitySerizlizerTest.java
+++ b/streams-contrib/streams-provider-rss/src/test/java/org/apache/streams/rss/test/SyndEntryActivitySerizlizerTest.java
@@ -31,10 +31,13 @@ import org.joda.time.DateTime;
 import org.joda.time.DateTimeZone;
 import org.junit.Test;
 
+import java.net.URL;
 import java.util.List;
 import java.util.Scanner;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 public class SyndEntryActivitySerizlizerTest {
 
@@ -57,7 +60,7 @@ public class SyndEntryActivitySerizlizerTest {
             activities.add(serializer.deserialize(node));
         }
 
-        assertEquals(10, activities.size());
+        assertEquals(11, activities.size());
 
         for(int x = 0; x < activities.size(); x ++) {
             ObjectNode n = objects.get(x);
@@ -66,9 +69,10 @@ public class SyndEntryActivitySerizlizerTest {
             testActor(n.get("author").asText(), a.getActor());
             testAuthor(n.get("author").asText(), a.getObject().getAuthor());
             testProvider("id:providers:rss", "RSS", a.getProvider());
+            testProviderUrl(a.getProvider());
             testVerb("post", a.getVerb());
             testPublished(n.get("publishedDate").asText(), a.getPublished());
-            testUrl(n.get("uri").asText(), a);
+            testUrl(n.get("uri").asText(), n.get("link").asText(), a);
         }
     }
 
@@ -95,8 +99,21 @@ public class SyndEntryActivitySerizlizerTest {
         assertEquals(expectedDisplay, provider.getDisplayName());
     }
 
-    public void testUrl(String expected, Activity activity) {
-        assertEquals(expected, activity.getUrl());
-        assertEquals(expected, activity.getObject().getUrl());
+    public void testProviderUrl(Provider provider) {
+        URL url = null;
+
+        try {
+            url = new URL(provider.getUrl());
+            url.toURI();
+        } catch(Exception e) {
+            System.out.println("Threw an exception while trying to validate URL: " + provider.getUrl());
+        }
+
+        assertNotNull(url);
+    }
+
+    public void testUrl(String expectedURI, String expectedLink, Activity activity) {
+        assertTrue((expectedURI == activity.getUrl() || expectedLink == activity.getUrl()));
+        assertTrue((expectedURI == activity.getObject().getUrl() || expectedLink == activity.getObject().getUrl()));
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/9e72ae74/streams-contrib/streams-provider-rss/src/test/resources/TestSyndEntryJson.txt
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-rss/src/test/resources/TestSyndEntryJson.txt
b/streams-contrib/streams-provider-rss/src/test/resources/TestSyndEntryJson.txt
index e559b3b..6fef187 100644
--- a/streams-contrib/streams-provider-rss/src/test/resources/TestSyndEntryJson.txt
+++ b/streams-contrib/streams-provider-rss/src/test/resources/TestSyndEntryJson.txt
@@ -8,3 +8,4 @@
 {"author":"Greg Bates","categories":[],"contents":[{}],"description":{"value":"<a href=\"http://www.programmableweb.com/api/change.org\"><img
class=\"imgRight\" src=\"http://www.programmableweb.com/images/apis/at8881.png\" alt=\"Change.org\"
/></a>HackSummit features a partnership with The Evolve Organisation focused on two
problems for democracy. Kings of Code Hack Battle's brilliant hacks. Plus: Yodlee links incubators
for fintech innovation, LinkedIn launches Sponsored Updates API, and 10 new APIs.","type":"text/html"},"link":"http://feedproxy.google.com/~r/ProgrammableWeb/~3/12JNO5FUkCE/","modules":["http://purl.org/dc/elements/1.1/"],"publishedDate":"2014-04-28T16:01:00.000-05:00","title":"Today
in APIs: HackSummit Partners with Evolve, and 10 New APIs","uri":"http://blog.programmableweb.com/?p=83441"}
 {"author":"Guest Author","categories":[],"contents":[{}],"description":{"value":"<img
src=\"http://blog.programmableweb.com/wp-content/Screen-Shot-2014-03-07-at-4.51.06-PM5-150x58.png\"
alt=\"\" width=\"150\" height=\"58\" align=\"right\" />So you’ve built a stellar API.
Now what? How do you get the word out? First, throw everything you know about marketing out
the window. Indeed, the old style of marketing doesn’t apply when it comes to APIs. The
notion of building a marketing campaign replete with ads and PR fluff is virtually non-existent
in the world of API marketing. Why? When you create an API, you are creating a community.
This community of users will drive your marketing in a highly decentralized way.","type":"text/html"},"link":"http://feedproxy.google.com/~r/ProgrammableWeb/~3/O2Ol3kBFpqk/","modules":["http://purl.org/dc/elements/1.1/"],"publishedDate":"2014-04-28T15:00:07.000-05:00","title":"10
Ways To Market Your API (And Why Old-School Marketing Won’t Work)","uri"
 :"http://blog.programmableweb.com/?p=83440"}
 {"author":"Michael Vizard","categories":[],"contents":[{}],"description":{"value":"<img
src=\"http://blog.programmableweb.com/wp-content/Screen-Shot-2014-04-28-at-2.25.35-PM-150x61.png\"
alt=\"\" width=\"150\" height=\"61\" align=\"right\" />As a first step toward enabling
new economic models for software consumption, <a href=\"http://www-03.ibm.com/press/us/en/pressrelease/43723.wss\">today
IBM opened an IBM Cloud marketplace</a>, through which it and its partners will make
software available to enterprise IT customers. In addition, IBM also announced that it is
launching BlueMix Garages.","type":"text/html"},"link":"http://feedproxy.google.com/~r/ProgrammableWeb/~3/-Fot4vkTNi0/","modules":["http://purl.org/dc/elements/1.1/"],"publishedDate":"2014-04-28T13:26:34.000-05:00","title":"IBM
Opens Marketplace to Help Drive Emerging API Economy","uri":"http://blog.programmableweb.com/?p=83495"}
+{"author":"Michael Vizard","categories":[],"contents":[{}],"description":{"value":"<img
src=\"http://blog.programmableweb.com/wp-content/Screen-Shot-2014-04-28-at-2.25.35-PM-150x61.png\"
alt=\"\" width=\"150\" height=\"61\" align=\"right\" />As a first step toward enabling
new economic models for software consumption, <a href=\"http://www-03.ibm.com/press/us/en/pressrelease/43723.wss\">today
IBM opened an IBM Cloud marketplace</a>, through which it and its partners will make
software available to enterprise IT customers. In addition, IBM also announced that it is
launching BlueMix Garages.","type":"text/html"},"link":"http://www.whitehouse.gov/blog/2014/08/05/john-podesta-cost-inaction","modules":["http://purl.org/dc/elements/1.1/"],"publishedDate":"2014-04-28T13:26:34.000-05:00","title":"IBM
Opens Marketplace to Help Drive Emerging API Economy","uri":"292776 at http://www.whitehouse.gov"}
\ No newline at end of file


Mime
View raw message