You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by wo...@apache.org on 2011/03/10 23:41:40 UTC
svn commit: r1080381 [2/2] - in /shindig/trunk: config/ content/sampledata/
java/social-api/src/main/java/org/apache/shindig/social/core/model/
java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/
java/social-api/src/main/java/org/ap...
Modified: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityEntryTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityEntryTest.java?rev=1080381&r1=1080380&r2=1080381&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityEntryTest.java (original)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityEntryTest.java Thu Mar 10 22:41:38 2011
@@ -1,457 +1,31 @@
-/*
- * 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.shindig.social.dataservice.integration;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.shindig.social.core.model.ActionLinkImpl;
-import org.apache.shindig.social.core.model.ActivityEntryImpl;
-import org.apache.shindig.social.core.model.ActivityObjectImpl;
-import org.apache.shindig.social.core.model.MediaLinkImpl;
-import org.apache.shindig.social.core.model.StandardLinkImpl;
-import org.apache.shindig.social.opensocial.model.ActionLink;
-import org.apache.shindig.social.opensocial.model.ActivityEntry;
-import org.apache.shindig.social.opensocial.model.ActivityObject;
-import org.apache.shindig.social.opensocial.model.MediaLink;
-import org.apache.shindig.social.opensocial.model.StandardLink;
-import org.junit.Before;
+import org.apache.shindig.protocol.ContentTypes;
import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-
-public class RestfulXmlActivityEntryTest extends AbstractLargeRestfulTests {
-
- private static XPath xpath = XPathFactory.newInstance().newXPath();
-
- private ActivityEntry johnsEntry1;
- private ActivityEntry johnsEntry2;
-
- @Before
- public void restfulXmlActivityEntryTestBefore() throws Exception {
- johnsEntry1 = generateEntry1();
- johnsEntry2 = generateEntry2();
- }
+/**
+ * Tests the XML serialization of ActivityStreams.
+ */
+public class RestfulXmlActivityEntryTest extends AbstractLargeRestfulTests{
- protected static ActivityEntry generateEntry1() {
- ActivityObject actor = new ActivityObjectImpl();
- actor.setId("john.doe");
- actor.setDisplayName("John Doe");
-
- MediaLink image = new MediaLinkImpl();
- image.setUrl("http://www.example.com/johnsalbum/cover.jpg");
- image.setType("http://activitystrea.ms/schema/1.0/picture");
- image.setWidth(400);
- image.setHeight(300);
- image.setDuration(93);
-
- ActionLink actionLink1 = new ActionLinkImpl();
- actionLink1.setCaption("Frozen at the top of the German Alps");
- actionLink1.setTarget("http://example.com/johnsalbum/frozen.jpg");
- ActionLink actionLink2 = new ActionLinkImpl();
- actionLink2.setCaption("Sign of Garmisch-Partenkirchen");
- actionLink2.setTarget("http://example.com/johnsalbum/sign.jpg");
- List<ActionLink> actionLinks = new ArrayList<ActionLink>();
- actionLinks.add(actionLink1);
- actionLinks.add(actionLink2);
-
- StandardLink standardLink1 = new StandardLinkImpl();
- standardLink1.setHref("http://www.example.com/johnsalbum/1.jpg");
- standardLink1.setType("image/jpg");
- StandardLink standardLink2 = new StandardLinkImpl();
- standardLink2.setHref("http://www.example.com/johnsalbum/2.jpg");
- standardLink2.setType("image/jpg");
- StandardLink standardLink3 = new StandardLinkImpl();
- standardLink3.setHref("http://www.example.com/johnsalbum/3.jpg");
- standardLink3.setType("image/jpg");
- StandardLink standardLink4 = new StandardLinkImpl();
- standardLink4.setHref("http://www.example.com/johnsalbum/4.jpg");
- standardLink4.setType("image/jpg");
- List<StandardLink> standardLinksList1 = new ArrayList<StandardLink>();
- standardLinksList1.add(standardLink1);
- standardLinksList1.add(standardLink2);
- List<StandardLink> standardLinksList2 = new ArrayList<StandardLink>();
- standardLinksList2.add(standardLink3);
- standardLinksList2.add(standardLink4);
- Map<String, List<StandardLink>> standardLinks = new HashMap<String, List<StandardLink>>();
- standardLinks.put("myRel1", standardLinksList1);
- standardLinks.put("myRel2", standardLinksList2);
-
- ActivityObject johnsObject = new ActivityObjectImpl();
- johnsObject.setId("object1");
- johnsObject.setDisplayName("Frozen Eric");
- johnsObject.setLink("http://www.example.com/johnsalbum");
- johnsObject.setObjectType("picture");
- johnsObject.setImage(image);
- johnsObject.setActionLinks(actionLinks);
-
- List<String> to = new ArrayList<String>();
- to.add("jane.doe");
- to.add("canonical");
- List<String> cc = new ArrayList<String>();
- cc.add("george.doe");
-
- ActivityEntry entry = new ActivityEntryImpl();
- entry.setTitle("John posted a photo");
- entry.setBody("John Doe posted a photo to the album Germany 2009");
- entry.setPostedTime("2010-04-27T06:02:36+0000");
- entry.setActor(actor);
- entry.setVerb("post");
- entry.setObject(johnsObject);
- entry.setLinks(standardLinks);
- entry.setTo(to);
- entry.setCc(cc);
- return entry;
- }
+ private static final String FIXTURE_LOC = "src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/";
- protected static ActivityEntry generateEntry2() {
- ActivityObject actor = new ActivityObjectImpl();
- actor.setId("john.doe");
- actor.setDisplayName("John Doe");
-
- ActivityObject johnsObject = new ActivityObjectImpl();
- johnsObject.setId("object2");
- johnsObject.setDisplayName("Super simple ActivityObject");
- johnsObject.setObjectType("article");
-
- ActivityEntry entry = new ActivityEntryImpl();
- entry.setTitle("Super simple ActivityEntry");
- entry.setPostedTime("2010-04-27T06:02:36+0000");
- entry.setActor(actor);
- entry.setVerb("post");
- entry.setObject(johnsObject);
- return entry;
- }
-
- /**
- * Tests GET for a single ActivityEntry.
- *
- * @throws Exception if test encounters an error
- */
@Test
- public void testGetActivityEntryXml() throws Exception {
- String resp = getResponse("/activitystreams/john.doe/@self/@app/object1", "GET", "xml", "application/xml");
-
- // TODO: Uncomment this if ActivityEntry added to opensocial.xsd
- //XSDValidator.validateOpenSocial(resp);
-
- // Build XML Document
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(new InputSource(new StringReader(resp)));
-
- // Test ActivityEntry
- Node entryNode = (Node)xpath.evaluate("/response/activityEntry", doc, XPathConstants.NODE);
- assertNotNull("ActivityEntry should not be null", entryNode);
- assertActivityEntriesEqual(johnsEntry1, entryNode);
+ public void testGetActivityEntryXmlById() throws Exception {
+ String resp = getResponse("/activitystreams/john.doe/@self/1/object1", "GET", null, ContentTypes.OUTPUT_XML_CONTENT_TYPE);
+ String expected = TestUtils.loadTestFixture(FIXTURE_LOC + "ActivityEntryXmlId.xml");
+ assertTrue(TestUtils.xmlsEqual(expected, resp));
}
-
- /**
- * Tests GET for a list of ActivityEntries.
- *
- * @throws Exception if test encounters an error
- */
+
@Test
- public void testGetActivityEntriesXml() throws Exception {
- String resp = getResponse("/activitystreams/john.doe/@self", "GET", "xml", "application/xml");
-
- // TODO: Uncomment this if ActivityEntry added to opensocial.xsd
- //XSDValidator.validateOpenSocial(resp);
-
- // Build XML Document
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(new InputSource(new StringReader(resp)));
-
- // Test ActivityEntries
- NodeList entries = (NodeList)xpath.evaluate("/response/entry/activityEntry", doc, XPathConstants.NODESET);
- assertEquals(2, entries.getLength());
- if (johnsEntry1.getObject().getId().equals(xpath.evaluate("object/id", entries.item(0)))) {
- assertActivityEntriesEqual(johnsEntry1, entries.item(0));
- assertActivityEntriesEqual(johnsEntry2, entries.item(1));
- } else {
- assertActivityEntriesEqual(johnsEntry2, entries.item(0));
- assertActivityEntriesEqual(johnsEntry1, entries.item(1));
- }
+ public void testGetActivityEntryXmlByIds() throws Exception {
+ String resp = getResponse("/activitystreams/john.doe/@self/1/object1,object2", "GET", null, ContentTypes.OUTPUT_XML_CONTENT_TYPE);
+ String expected = TestUtils.loadTestFixture(FIXTURE_LOC + "ActivityEntryXmlIds.xml");
+ assertTrue(TestUtils.xmlsEqual(expected, resp));
}
@Test
public void testCreateActivityEntryXml() throws Exception {
- // TODO: REST POST with format = XML or ATOM doens't work; mapping with List or Map doesn't work
- }
-
- // ------------------------ ACTIVITYENTRY EQUALITY TESTS --------------------------
- /**
- * Utility to determine if two ActivityEntries are equal. Tests the
- * structure of the XML.
- *
- * @param entry is an ActivityEntry to compare
- * @param entryNode is an XML node containing the other ActivityEntry
- *
- * @throws XPathExpressionException if something goes wrong
- */
- protected static void assertActivityEntriesEqual(ActivityEntry entry, Node entryNode) throws XPathExpressionException {
- if (entry != null) {
- // Test single level items
- assertEqualsOrNull(entry.getTitle(), xpath.evaluate("title", entryNode));
- assertEqualsOrNull(entry.getBody(), xpath.evaluate("body", entryNode));
- assertEqualsOrNull(entry.getPostedTime(), xpath.evaluate("postedTime", entryNode));
- assertEqualsOrNull(entry.getVerb(), xpath.evaluate("verb", entryNode));
-
- // Test ActivityEntry's ActivityObjects
- assertActivityObjectsEqual(entry.getActor(), (Node)xpath.evaluate("actor", entryNode, XPathConstants.NODE));
- assertActivityObjectsEqual(entry.getObject(), (Node)xpath.evaluate("object", entryNode, XPathConstants.NODE));
- assertActivityObjectsEqual(entry.getTarget(), (Node)xpath.evaluate("target", entryNode, XPathConstants.NODE));
- assertActivityObjectsEqual(entry.getGenerator(), (Node)xpath.evaluate("generator", entryNode, XPathConstants.NODE));
- assertActivityObjectsEqual(entry.getProvider(), (Node)xpath.evaluate("provider", entryNode, XPathConstants.NODE));
-
- // Test ActivityEntry's List<String>
- assertListsStringEqual(entry.getTo(), (NodeList)xpath.evaluate("to", entryNode, XPathConstants.NODESET));
- assertListsStringEqual(entry.getCc(), (NodeList)xpath.evaluate("cc", entryNode, XPathConstants.NODESET));
- assertListsStringEqual(entry.getBcc(), (NodeList)xpath.evaluate("bcc", entryNode, XPathConstants.NODESET));
-
- // Test ActivityEntry's Map<String, List<StandardLink>>
- assertStandardLinkMapsEqual(entry.getLinks(), (Node)xpath.evaluate("links", entryNode, XPathConstants.NODE));
- } else {
- assertNull("EntryNode should be null", entryNode);
- }
- }
-
- /**
- * Asserts that two ActivityObjects are equal.
- *
- * @param object is an ActivityObject to compare with an XML node
- * @param objectNode is the XML node to compare with the ActivityObject
- * @throws XPathExpressionException
- */
- private static void assertActivityObjectsEqual(ActivityObject object, Node objectNode) throws XPathExpressionException {
- if (object != null) {
- // Test single level items
- assertEqualsOrNull(object.getId(), xpath.evaluate("id", objectNode));
- assertEqualsOrNull(object.getDisplayName(), xpath.evaluate("displayName", objectNode));
- assertEqualsOrNull(object.getLink(), xpath.evaluate("link", objectNode));
- assertEqualsOrNull(object.getObjectType(), xpath.evaluate("objectType", objectNode));
-
- // Test ActivityObject's image
- assertMediaLinksEqual(object.getImage(), (Node)xpath.evaluate("image", objectNode, XPathConstants.NODE));
-
- // Test ActivityObject's inReplyTo
- assertActivityObjectsEqual(object.getInReplyTo(), (Node)xpath.evaluate("inReplyTo", objectNode, XPathConstants.NODE));
-
- // Test ActivityObject's Map<String, List<StandardLink>> standardLinks
- assertStandardLinkMapsEqual(object.getLinks(), (Node)xpath.evaluate("links", objectNode, XPathConstants.NODE));
-
- // Test ActivityObject's List<ActivityObject> elements
- assertListsActivityObjectEqual(object.getAttachedObjects(), (NodeList)xpath.evaluate("attachedObjects", objectNode, XPathConstants.NODESET));
- assertListsActivityObjectEqual(object.getReplies(), (NodeList)xpath.evaluate("repies", objectNode, XPathConstants.NODESET));
- assertListsActivityObjectEqual(object.getReactions(), (NodeList)xpath.evaluate("reactions", objectNode, XPathConstants.NODESET));
-
- // Test ActivityObject's actionLinks
- assertListsActionLinkEqual(object.getActionLinks(), (NodeList)xpath.evaluate("actionLinks/actionLink", objectNode, XPathConstants.NODESET));
- } else {
- assertNull("ActivityObject should be null", objectNode);
- }
- }
-
- /**
- * Asserts that a Map<String, List<StandardLink>> is equal its XML NodeList equivalent.
- *
- * @param map is the map object to compare to the XML node
- * @param mapNode is the XML node to compare to the map object
- *
- * @throws XPathExpressionException if something goes wrong :)
- */
- private static void assertStandardLinkMapsEqual(Map<String, List<StandardLink>> map, Node mapNode) throws XPathExpressionException {
- if (map != null) {
- NodeList entries = (NodeList)xpath.evaluate("entry", mapNode, XPathConstants.NODESET);
- assertEquals(map.size(), entries.getLength());
- for (String rel : map.keySet()) {
- Node relNode = findNode("key", rel, entries);
- assertNotNull("'" + rel + "' rel not found", relNode);
- NodeList standardLinkNodes = (NodeList)xpath.evaluate("value/link", relNode, XPathConstants.NODESET);
- List<StandardLink> standardLinks = map.get(rel);
- assertListsStandardLinkEqual(standardLinks, standardLinkNodes);
- }
- } else {
- assertNull("mapNode should be null", mapNode);
- }
- }
-
- /**
- * Asserts that a List<String> is equal to its XML node equivalent.
- *
- * @param list is the list to compare to an XML node
- * @param nodeList is the XML node to compare to the list
- *
- * @throws XPathExpressionException if something goes wrong :)
- */
- private static void assertListsStringEqual(List<String> list, NodeList nodeList) throws XPathExpressionException {
- if (list != null) {
- assertEquals(list.size(), nodeList.getLength());
- for (String value : list) {
- assertNotNull("'" + value + "' was not found in nodeList", findNode(".", value, nodeList));
- }
- } else {
- assertEquals(0, nodeList.getLength());
- }
- }
-
- /**
- * Asserts that a List<ActivityObject> is equal to its XML node equivalent.
- *
- * @param list is the list to compare to an XML node
- * @param nodeList is the XML node to compare to the list
- *
- * @throws XPathExpressionException if something goes wrong :)
- */
- private static void assertListsActivityObjectEqual(List<ActivityObject> list, NodeList nodeList) throws XPathExpressionException {
- if (list != null) {
- assertEquals(list.size(), nodeList.getLength());
- for (ActivityObject object : list) {
- Node objectNode = findNode("id", object.getId(), nodeList);
- assertNotNull("node with id '" + object.getId() + "' not found", objectNode);
- assertActivityObjectsEqual(object, objectNode);
- }
- } else {
- assertEquals(0, nodeList.getLength());
- }
- }
-
- /**
- * Asserts that a List<ActionLink> is equal to its XML node equivalent.
- *
- * @param list is the list to compare to an XML node
- * @param nodeList is the XML node to compare to the list
- *
- * @throws XPathExpressionException if something goes wrong :)
- */
- private static void assertListsActionLinkEqual(List<ActionLink> list, NodeList nodeList) throws XPathExpressionException {
- if (list != null) {
- assertEquals(list.size(), nodeList.getLength());
- for (ActionLink actionLink : list) {
- Node actionLinkNode = findNode("target", actionLink.getTarget(), nodeList);
- assertNotNull("node with target '" + actionLink.getTarget() + "' not found", actionLinkNode);
- assertActionLinksEqual(actionLink, actionLinkNode);
- }
- } else {
- assertEquals(0, nodeList.getLength());
- }
- }
-
- /**
- * Asserts that a List<StandardLink> is equal to its XML node equivalent.
- *
- * @param list is the list to compare to an XML node
- * @param nodeList is the XML node to compare to the list
- *
- * @throws XPathExpressionException if something goes wrong :)
- */
- private static void assertListsStandardLinkEqual(List<StandardLink> list, NodeList nodeList) throws XPathExpressionException {
- if (list != null) {
- assertEquals(list.size(), nodeList.getLength());
- for (StandardLink standardLink : list) {
- Node standardLinkNode = findNode("href", standardLink.getHref(), nodeList);
- assertNotNull("node with href '" + standardLink.getHref() + "' not found", standardLinkNode);
- assertStandardLinksEqual(standardLink, standardLinkNode);
- }
- } else {
- assertEquals(0, nodeList.getLength());
- }
- }
-
- /**
- * Asserts that two MediaLinks are equal.
- *
- * @param media is the MediaLink object to compare with the XML node
- * @param mediaNode mediaNode is the XML node to compare with the MediaLink object
- * @throws XPathExpressionException
- */
- private static void assertMediaLinksEqual(MediaLink media, Node mediaNode) throws XPathExpressionException {
- if (media != null) {
- assertEqualsOrNull(media.getDuration().toString(), xpath.evaluate("duration", mediaNode));
- assertEqualsOrNull(media.getHeight().toString(), xpath.evaluate("height", mediaNode));
- assertEqualsOrNull(media.getWidth().toString(), xpath.evaluate("width", mediaNode));
- assertEqualsOrNull(media.getType(), xpath.evaluate("type", mediaNode));
- assertEqualsOrNull(media.getUrl(), xpath.evaluate("url", mediaNode));
- } else {
- assertNull("Image should be null", mediaNode);
- }
- }
-
- /**
- * Asserts an ActionLink to its XML node equivalent
- *
- * @param actionLink is the ActionLink to compare to the XML node
- * @param actionLinkNode is the XML node to compare to the ActionLink
- * @throws XPathExpressionException
- */
- private static void assertActionLinksEqual(ActionLink actionLink, Node actionLinkNode) throws XPathExpressionException {
- assertEqualsOrNull(actionLink.getTarget(), xpath.evaluate("target", actionLinkNode));
- assertEqualsOrNull(actionLink.getCaption(), xpath.evaluate("caption", actionLinkNode));
- }
-
- /**
- * Asserts that two StandardLinks are equal.
- *
- * @throws XPathExpressionException if something goes wrong :)
- */
- private static void assertStandardLinksEqual(StandardLink standardLink, Node standardLinkNode) throws XPathExpressionException {
- assertEqualsOrNull(standardLink.getHref(), xpath.evaluate("href", standardLinkNode));
- assertEqualsOrNull(standardLink.getType(), xpath.evaluate("type", standardLinkNode));
- assertEqualsOrNull(standardLink.getInline(), xpath.evaluate("inline", standardLinkNode));
- }
-
- /**
- * Finds a Node within a NodeList with the given key at the given path.
- *
- * @param path is the path to the key
- * @param key is the key that identifies the node to find
- * @param nodeList is the list of nodes to search through
- *
- * @return Node is the found node if located, null otherwise
- */
- private static Node findNode(String path, String key, NodeList nodeList) throws XPathExpressionException {
- for (int i = 0; i < nodeList.getLength(); i++) {
- if (key.equals(xpath.evaluate(path, nodeList.item(i))))
- return nodeList.item(i);
- }
- return null;
- }
-
- /**
- * Asserts that two objects are equal. Null and "" are considered equal.
- */
- protected static void assertEqualsOrNull(Object obj1, Object obj2) {
- if (obj1 == null) obj1 = "";
- if (obj2 == null) obj2 = "";
- assertEquals(obj1, obj2);
+ // TODO: Creating activity from XML not fully supported
}
}
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/TestUtils.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/TestUtils.java?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/TestUtils.java (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/TestUtils.java Thu Mar 10 22:41:38 2011
@@ -0,0 +1,143 @@
+package org.apache.shindig.social.dataservice.integration;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+
+/**
+ * Collection of utilities to assist in testing.
+ *
+ * @author Eric Woods
+ */
+public class TestUtils {
+
+ /**
+ * Loads the contents of the test fixture specified at the given path.
+ *
+ * @param path specifies the file to load the contents of
+ * @return String is the file contents
+ * @throws IOException
+ */
+ public static String loadTestFixture(String path) throws IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Tests two JSON strings for equality by performing a deep comparison.
+ *
+ * @param json1 represents a JSON object to compare with json2
+ * @param json2 represents a JSON object to compare with json1
+ * @return true if the JSON objects are equal, false otherwise
+ */
+ public static boolean jsonsEqual(String json1, String json2) throws Exception {
+ Object obj1Converted = convertJsonElement(new JSONObject(json1));
+ Object obj2Converted = convertJsonElement(new JSONObject(json2));
+ return obj1Converted.equals(obj2Converted);
+ }
+
+
+ /**
+ * Tests the DOMs represented by two XML strings for equality by performing
+ * a deep comparison. The two DOMs are considered equal if the paths to all
+ * leaf nodes are equal and the values at such paths are equal.
+ *
+ * @param xml1 represents the XML DOM to compare with xml2
+ * @param xml2 represents the XML DOM to compare with xml1
+ * return true if the represented DOMs are equal, false otherwise
+ */
+ public static boolean xmlsEqual(String xml1, String xml2) throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ Document doc1 = db.parse(new InputSource(new StringReader(xml1)));
+ Document doc2 = db.parse(new InputSource(new StringReader(xml2)));
+
+ Map<String, String> paths1 = getLeafPaths(doc1.getDocumentElement(), "");
+ Map<String, String> paths2 = getLeafPaths(doc2.getDocumentElement(), "");
+
+ return paths1.equals(paths2);
+ }
+
+ // ---------------------------- PRIVATE HELPERS -----------------------------
+
+ /*
+ * Recursive utility to convert a JSONObject to an Object composed of Sets,
+ * Maps, and the target types (e.g. Integer, String, Double). Used to do a
+ * deep comparison of two JSON objects.
+ *
+ * @param Object is the JSON element to convert (JSONObject, JSONArray, or target type)
+ *
+ * @return an Object representing the appropriate JSON element
+ */
+ @SuppressWarnings("unchecked")
+ private static Object convertJsonElement(Object elem) throws JSONException {
+ if (elem instanceof JSONObject) {
+ JSONObject obj = (JSONObject) elem;
+ Iterator<String> keys = obj.keys();
+ Map<String, Object> jsonMap = new HashMap<String, Object>();
+ while (keys.hasNext()) {
+ String key = keys.next();
+ jsonMap.put(key, convertJsonElement(obj.get(key)));
+ }
+ return jsonMap;
+ } else if (elem instanceof JSONArray) {
+ JSONArray arr = (JSONArray) elem;
+ Set<Object> jsonSet = new HashSet<Object>();
+ for (int i = 0; i < arr.length(); i++) {
+ jsonSet.add(convertJsonElement(arr.get(i)));
+ }
+ return jsonSet;
+ } else {
+ return elem;
+ }
+ }
+
+ /*
+ * Recursive utility to map all leaf node paths to the values at each path
+ * within an XML node.
+ *
+ * @param node is the root node to find all leaf paths & values for
+ * @param basePath is the path to the root node
+ * @return Map<String, String> is a Map of leaf paths & values for each path
+ */
+ private static Map<String, String> getLeafPaths(Node node, String basePath) {
+ Map<String, String> paths = new HashMap<String, String>();
+ if (!node.hasChildNodes()) {
+ if (!node.getTextContent().trim().equals("")) {
+ paths.put(basePath, node.getTextContent());
+ }
+ } else {
+ NodeList children = node.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ paths.putAll(getLeafPaths(children.item(i), basePath + "/" + node.getNodeName()));
+ }
+ }
+ return paths;
+ }
+}
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomId.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomId.xml?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomId.xml (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomId.xml Thu Mar 10 22:41:38 2011
@@ -0,0 +1,73 @@
+<feed xmlns="http://www.w3.org/2005/Atom" xmlns:osearch="http://a9.com/-/spec/opensearch/1.1">
+ <entry>
+ <id>object1</id>
+ <title>John Doe posted a new video to his album.</title>
+ <summary><body>My activity summary.</body></summary>
+ <author>
+ <uri>john.doe</uri>
+ <name xmlns="http://ns.opensocial.org/2008/opensocial">John Doe</name>
+ </author>
+ <content type="application/xml">
+ <activityEntry xmlns="http://ns.opensocial.org/2008/opensocial">
+ <actor>
+ <displayName>John Doe</displayName>
+ <id>john.doe</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/john/image</url>
+ <width>250</width>
+ </image>
+ <objectType>person</objectType>
+ <url>http://example.org/john</url>
+ </actor>
+ <generator>
+ <url>http://example.org/activities-app</url>
+ </generator>
+ <object>
+ <attachedObjects>
+ <object>
+ <id>attached1</id>
+ <url>http://example.org/attached1</url>
+ </object>
+ <object>
+ <id>attached2</id>
+ <url>http://example.org/attached2</url>
+ </object>
+ </attachedObjects>
+ <id>object1</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/my_fluffy_cat_thumb.jpg</url>
+ <width>250</width>
+ </image>
+ <objectType>http://activitystrea.ms/schema/1.0/photo</objectType>
+ <summary><body>My activity summary.</body></summary>
+ <upstreamDuplicates>upstreamId1</upstreamDuplicates>
+ <upstreamDuplicates>upstreamId2</upstreamDuplicates>
+ <url>http://example.org/album/my_fluffy_cat.jpg</url>
+ </object>
+ <postedTime>2011-02-10T15:04:55Z</postedTime>
+ <provider>
+ <url>http://example.org/activity-stream</url>
+ </provider>
+ <target>
+ <displayName>John's Photo Album</displayName>
+ <id>tag:example.org,2011:abc123</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/thumbnail.jpg</url>
+ <width>250</width>
+ </image>
+ <objectType>http://activitystrea.ms/schema/1.0/photo-album</objectType>
+ <url>http://example.org/album/</url>
+ </target>
+ <title>John Doe posted a new video to his album.</title>
+ <verb>post</verb>
+ </activityEntry>
+ </content>
+ </entry>
+ <osearch:startIndex>0</osearch:startIndex>
+ <osearch:totalResults>1</osearch:totalResults>
+ <osearch:itemsPerPage>1</osearch:itemsPerPage>
+
+</feed>
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomIds.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomIds.xml?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomIds.xml (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryAtomIds.xml Thu Mar 10 22:41:38 2011
@@ -0,0 +1,99 @@
+<feed xmlns="http://www.w3.org/2005/Atom" xmlns:osearch="http://a9.com/-/spec/opensearch/1.1">
+ <entry>
+ <id>object1</id>
+ <title>John Doe posted a new video to his album.</title>
+ <summary><body>My activity summary.</body></summary>
+ <author>
+ <uri>john.doe</uri>
+ <name xmlns="http://ns.opensocial.org/2008/opensocial">John Doe</name>
+ </author>
+ <content type="application/xml">
+ <activityEntry xmlns="http://ns.opensocial.org/2008/opensocial">
+ <actor>
+ <displayName>John Doe</displayName>
+ <id>john.doe</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/john/image</url>
+ <width>250</width>
+ </image>
+ <objectType>person</objectType>
+ <url>http://example.org/john</url>
+ </actor>
+ <generator>
+ <url>http://example.org/activities-app</url>
+ </generator>
+ <object>
+ <attachedObjects>
+ <object>
+ <id>attached1</id>
+ <url>http://example.org/attached1</url>
+ </object>
+ <object>
+ <id>attached2</id>
+ <url>http://example.org/attached2</url>
+ </object>
+ </attachedObjects>
+ <id>object1</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/my_fluffy_cat_thumb.jpg</url>
+ <width>250</width>
+ </image>
+ <objectType>http://activitystrea.ms/schema/1.0/photo</objectType>
+ <summary><body>My activity summary.</body></summary>
+ <upstreamDuplicates>upstreamId1</upstreamDuplicates>
+ <upstreamDuplicates>upstreamId2</upstreamDuplicates>
+ <url>http://example.org/album/my_fluffy_cat.jpg</url>
+ </object>
+ <postedTime>2011-02-10T15:04:55Z</postedTime>
+ <provider>
+ <url>http://example.org/activity-stream</url>
+ </provider>
+ <target>
+ <displayName>John's Photo Album</displayName>
+ <id>tag:example.org,2011:abc123</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/thumbnail.jpg</url>
+ <width>250</width>
+ </image>
+ <objectType>http://activitystrea.ms/schema/1.0/photo-album</objectType>
+ <url>http://example.org/album/</url>
+ </target>
+ <title>John Doe posted a new video to his album.</title>
+ <verb>post</verb>
+ </activityEntry>
+ </content>
+ </entry>
+ <entry>
+ <id>object2</id>
+ <title>Super simple ActivityEntry</title>
+ <author>
+ <uri>john.doe</uri>
+ <name xmlns="http://ns.opensocial.org/2008/opensocial">John Doe</name>
+ </author>
+ <content type="application/xml">
+ <activityEntry xmlns="http://ns.opensocial.org/2008/opensocial">
+ <actor>
+ <displayName>John Doe</displayName>
+ <id>john.doe</id>
+ </actor>
+ <object>
+ <displayName>Super simple ActivityObject</displayName>
+ <id>object2</id>
+ <objectType>article</objectType>
+ </object>
+ <postedTime>2010-04-27T06:02:36+0000</postedTime>
+ <title>Super simple ActivityEntry</title>
+ <verb>post</verb>
+ </activityEntry>
+ </content>
+ </entry>
+ <osearch:startIndex>0</osearch:startIndex>
+ <osearch:totalResults>2</osearch:totalResults>
+ <osearch:itemsPerPage>2</osearch:itemsPerPage>
+ <author>?</author>
+ <link rel="rel">???</link>
+
+</feed>
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonCreated.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonCreated.json?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonCreated.json (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonCreated.json Thu Mar 10 22:41:38 2011
@@ -0,0 +1,11 @@
+{
+ "entry": {
+ "title":"Super Created Activity",
+ "actor":{
+ "id":"john.doe",
+ },
+ "object":{
+ "id":"objectCreated",
+ }
+ }
+}
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json Thu Mar 10 22:41:38 2011
@@ -0,0 +1,21 @@
+{
+ "startIndex":0,
+ "totalResults":1,
+ "entry":[
+ {
+ "title":"Super simple ActivityEntry",
+ "verb":"post",
+ "postedTime":"2010-04-27T06:02:36+0000",
+ "actor":{
+ "id":"john.doe",
+ "displayName":"John Doe"
+ },
+ "object":{
+ "id":"object2",
+ "displayName":"Super simple ActivityObject",
+ "objectType":"article"
+ }
+ }
+ ],
+ "itemsPerPage":1
+}
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json Thu Mar 10 22:41:38 2011
@@ -0,0 +1,79 @@
+{
+ "startIndex":0,
+ "totalResults":2,
+ "entry":[
+ {
+ "title":"John Doe posted a new video to his album.",
+ "verb":"post",
+ "target":{
+ "id":"tag:example.org,2011:abc123",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/album/thumbnail.jpg"
+ },
+ "displayName":"John's Photo Album",
+ "objectType":"http://activitystrea.ms/schema/1.0/photo-album",
+ "url":"http://example.org/album/"
+ },
+ "generator":{
+ "url":"http://example.org/activities-app"
+ },
+ "postedTime":"2011-02-10T15:04:55Z",
+ "provider":{
+ "url":"http://example.org/activity-stream"
+ },
+ "actor":{
+ "id":"john.doe",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/john/image"
+ },
+ "displayName":"John Doe",
+ "objectType":"person",
+ "url":"http://example.org/john"
+ },
+ "object":{
+ "summary": "<body>My activity summary.</body>",
+ "upstreamDuplicates":[
+ "upstreamId1",
+ "upstreamId2"
+ ],
+ "id":"object1",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/album/my_fluffy_cat_thumb.jpg"
+ },
+ "objectType":"http://activitystrea.ms/schema/1.0/photo",
+ "url":"http://example.org/album/my_fluffy_cat.jpg",
+ "attachedObjects":[
+ {
+ "id":"attached1",
+ "url":"http://example.org/attached1"
+ },
+ {
+ "id":"attached2",
+ "url":"http://example.org/attached2"
+ }
+ ]
+ }
+ },
+ {
+ "title":"Super simple ActivityEntry",
+ "verb":"post",
+ "postedTime":"2010-04-27T06:02:36+0000",
+ "actor":{
+ "id":"john.doe",
+ "displayName":"John Doe"
+ },
+ "object":{
+ "id":"object2",
+ "displayName":"Super simple ActivityObject",
+ "objectType":"article"
+ }
+ }
+ ],
+ "itemsPerPage":2
+}
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonId.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonId.json?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonId.json (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonId.json Thu Mar 10 22:41:38 2011
@@ -0,0 +1,60 @@
+{
+ "entry":{
+ "verb":"post",
+ "postedTime":"2011-02-10T15:04:55Z",
+ "generator":{
+ "url":"http://example.org/activities-app"
+ },
+ "provider":{
+ "url":"http://example.org/activity-stream"
+ },
+ "title":"John Doe posted a new video to his album.",
+ "target":{
+ "url":"http://example.org/album/",
+ "objectType":"http://activitystrea.ms/schema/1.0/photo-album",
+ "id":"tag:example.org,2011:abc123",
+ "displayName":"John's Photo Album",
+ "image":{
+ "url":"http://example.org/album/thumbnail.jpg",
+ "width":250,
+ "height":250
+ }
+ },
+ "object":{
+ "url":"http://example.org/album/my_fluffy_cat.jpg",
+ "objectType":"http://activitystrea.ms/schema/1.0/photo",
+ "id":"object1",
+ "summary": "<body>My activity summary.</body>",
+ "image":{
+ "url":"http://example.org/album/my_fluffy_cat_thumb.jpg",
+ "width":250,
+ "height":250
+ },
+ "upstreamDuplicates":[
+ "upstreamId1",
+ "upstreamId2"
+ ],
+ "attachedObjects":[
+ {
+ "url":"http://example.org/attached1",
+ "id":"attached1"
+ },
+ {
+ "url":"http://example.org/attached2",
+ "id":"attached2"
+ }
+ ]
+ },
+ "actor":{
+ "url":"http://example.org/john",
+ "objectType":"person",
+ "id":"john.doe",
+ "image":{
+ "url":"http://example.org/john/image",
+ "width":250,
+ "height":250
+ },
+ "displayName":"John Doe"
+ }
+ }
+}
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json Thu Mar 10 22:41:38 2011
@@ -0,0 +1,79 @@
+{
+ "startIndex":0,
+ "totalResults":2,
+ "entry":[
+ {
+ "title":"John Doe posted a new video to his album.",
+ "verb":"post",
+ "target":{
+ "id":"tag:example.org,2011:abc123",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/album/thumbnail.jpg"
+ },
+ "displayName":"John's Photo Album",
+ "objectType":"http://activitystrea.ms/schema/1.0/photo-album",
+ "url":"http://example.org/album/"
+ },
+ "generator":{
+ "url":"http://example.org/activities-app"
+ },
+ "postedTime":"2011-02-10T15:04:55Z",
+ "provider":{
+ "url":"http://example.org/activity-stream"
+ },
+ "actor":{
+ "id":"john.doe",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/john/image"
+ },
+ "displayName":"John Doe",
+ "objectType":"person",
+ "url":"http://example.org/john"
+ },
+ "object":{
+ "upstreamDuplicates":[
+ "upstreamId1",
+ "upstreamId2"
+ ],
+ "id":"object1",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/album/my_fluffy_cat_thumb.jpg"
+ },
+ "summary": "<body>My activity summary.</body>",
+ "objectType":"http://activitystrea.ms/schema/1.0/photo",
+ "url":"http://example.org/album/my_fluffy_cat.jpg",
+ "attachedObjects":[
+ {
+ "id":"attached1",
+ "url":"http://example.org/attached1"
+ },
+ {
+ "id":"attached2",
+ "url":"http://example.org/attached2"
+ }
+ ]
+ }
+ },
+ {
+ "title":"Super simple ActivityEntry",
+ "verb":"post",
+ "postedTime":"2010-04-27T06:02:36+0000",
+ "actor":{
+ "id":"john.doe",
+ "displayName":"John Doe"
+ },
+ "object":{
+ "id":"object2",
+ "displayName":"Super simple ActivityObject",
+ "objectType":"article"
+ }
+ }
+ ],
+ "itemsPerPage":2
+}
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonUpdated.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonUpdated.json?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonUpdated.json (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonUpdated.json Thu Mar 10 22:41:38 2011
@@ -0,0 +1,74 @@
+{
+ "startIndex":0,
+ "totalResults":2,
+ "entry":[
+ {
+ "title":"John Doe posted a new video to his album.",
+ "verb":"post",
+ "target":{
+ "id":"tag:example.org,2011:abc123",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/album/thumbnail.jpg"
+ },
+ "displayName":"John's Photo Album",
+ "objectType":"http://activitystrea.ms/schema/1.0/photo-album",
+ "url":"http://example.org/album/"
+ },
+ "generator":{
+ "url":"http://example.org/activities-app"
+ },
+ "postedTime":"2011-02-10T15:04:55Z",
+ "provider":{
+ "url":"http://example.org/activity-stream"
+ },
+ "actor":{
+ "id":"john.doe",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/john/image"
+ },
+ "displayName":"John Doe",
+ "objectType":"person",
+ "url":"http://example.org/john"
+ },
+ "object":{
+ "summary": "<body>My activity summary.</body>",
+ "upstreamDuplicates":[
+ "upstreamId1",
+ "upstreamId2"
+ ],
+ "id":"object1",
+ "image":{
+ "height":250,
+ "width":250,
+ "url":"http://example.org/album/my_fluffy_cat_thumb.jpg"
+ },
+ "objectType":"http://activitystrea.ms/schema/1.0/photo",
+ "url":"http://example.org/album/my_fluffy_cat.jpg",
+ "attachedObjects":[
+ {
+ "id":"attached1",
+ "url":"http://example.org/attached1"
+ },
+ {
+ "id":"attached2",
+ "url":"http://example.org/attached2"
+ }
+ ]
+ }
+ },
+ {
+ "title":"Super Updated Activity",
+ "actor":{
+ "id":"john.doe",
+ },
+ "object":{
+ "id":"object2",
+ }
+ }
+ ],
+ "itemsPerPage":2
+}
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlId.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlId.xml?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlId.xml (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlId.xml Thu Mar 10 22:41:38 2011
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response xmlns="http://ns.opensocial.org/2008/opensocial">
+<activityEntry xmlns="http://ns.opensocial.org/2008/opensocial">
+ <actor>
+ <displayName>John Doe</displayName>
+ <id>john.doe</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/john/image</url>
+ <width>250</width>
+ </image>
+ <objectType>person</objectType>
+ <url>http://example.org/john</url>
+ </actor>
+ <generator>
+ <url>http://example.org/activities-app</url>
+ </generator>
+ <object>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/my_fluffy_cat_thumb.jpg</url>
+ <width>250</width>
+ </image>
+ <summary><body>My activity summary.</body></summary>
+ <attachedObjects>
+ <object>
+ <id>attached1</id>
+ <url>http://example.org/attached1</url>
+ </object>
+ <object>
+ <id>attached2</id>
+ <url>http://example.org/attached2</url>
+ </object>
+ </attachedObjects>
+ <id>object1</id>
+ <objectType>http://activitystrea.ms/schema/1.0/photo</objectType>
+ <upstreamDuplicates>upstreamId1</upstreamDuplicates>
+ <upstreamDuplicates>upstreamId2</upstreamDuplicates>
+ <url>http://example.org/album/my_fluffy_cat.jpg</url>
+ </object>
+ <postedTime>2011-02-10T15:04:55Z</postedTime>
+ <provider>
+ <url>http://example.org/activity-stream</url>
+ </provider>
+ <target>
+ <displayName>John's Photo Album</displayName>
+ <id>tag:example.org,2011:abc123</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/thumbnail.jpg</url>
+ <width>250</width>
+ </image>
+ <objectType>http://activitystrea.ms/schema/1.0/photo-album</objectType>
+ <url>http://example.org/album/</url>
+ </target>
+ <title>John Doe posted a new video to his album.</title>
+ <verb>post</verb>
+</activityEntry></response>
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlIds.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlIds.xml?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlIds.xml (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryXmlIds.xml Thu Mar 10 22:41:38 2011
@@ -0,0 +1,91 @@
+<response xmlns="http://ns.opensocial.org/2008/opensocial">
+ <itemsPerPage>2</itemsPerPage>
+ <startIndex>0</startIndex>
+ <totalResults>2</totalResults>
+ <filtered>true</filtered>
+ <sorted>true</sorted>
+ <updatedSince>true</updatedSince>
+
+ <entry>
+ <activityEntry>
+ <actor>
+ <displayName>John Doe</displayName>
+ <id>john.doe</id>
+ <image>
+ <height>250</height>
+
+ <url>http://example.org/john/image</url>
+ <width>250</width>
+ </image>
+ <objectType>person</objectType>
+ <url>http://example.org/john</url>
+ </actor>
+ <generator>
+
+ <url>http://example.org/activities-app</url>
+ </generator>
+ <object>
+ <attachedObjects>
+ <object>
+ <id>attached1</id>
+ <url>http://example.org/attached1</url>
+ </object>
+ <object>
+ <id>attached2</id>
+ <url>http://example.org/attached2</url>
+ </object>
+ </attachedObjects>
+ <id>object1</id>
+ <summary><body>My activity summary.</body></summary>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/my_fluffy_cat_thumb.jpg</url>
+ <width>250</width>
+ </image>
+ <objectType>http://activitystrea.ms/schema/1.0/photo</objectType>
+ <upstreamDuplicates>upstreamId1</upstreamDuplicates>
+
+ <upstreamDuplicates>upstreamId2</upstreamDuplicates>
+ <url>http://example.org/album/my_fluffy_cat.jpg</url>
+ </object>
+ <postedTime>2011-02-10T15:04:55Z</postedTime>
+ <provider>
+ <url>http://example.org/activity-stream</url>
+ </provider>
+
+ <target>
+ <displayName>John's Photo Album</displayName>
+ <id>tag:example.org,2011:abc123</id>
+ <image>
+ <height>250</height>
+ <url>http://example.org/album/thumbnail.jpg</url>
+
+ <width>250</width>
+ </image>
+ <objectType>http://activitystrea.ms/schema/1.0/photo-album</objectType>
+ <url>http://example.org/album/</url>
+ </target>
+ <title>John Doe posted a new video to his album.</title>
+ <verb>post</verb>
+
+ </activityEntry>
+ </entry>
+ <entry>
+ <activityEntry>
+ <actor>
+ <displayName>John Doe</displayName>
+ <id>john.doe</id>
+ </actor>
+
+ <object>
+ <displayName>Super simple ActivityObject</displayName>
+ <id>object2</id>
+ <objectType>article</objectType>
+ </object>
+ <postedTime>2010-04-27T06:02:36+0000</postedTime>
+ <title>Super simple ActivityEntry</title>
+
+ <verb>post</verb>
+ </activityEntry>
+ </entry>
+</response>
\ No newline at end of file
Added: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityStreamsSupportedFields.json
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityStreamsSupportedFields.json?rev=1080381&view=auto
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityStreamsSupportedFields.json (added)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityStreamsSupportedFields.json Thu Mar 10 22:41:38 2011
@@ -0,0 +1,15 @@
+{
+ "entry":[
+ "actor",
+ "body",
+ "generator",
+ "icon",
+ "object",
+ "postedTime",
+ "provider",
+ "target",
+ "title",
+ "updatedTime",
+ "verb"
+ ]
+}
\ No newline at end of file
Modified: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ActivityStreamHandlerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ActivityStreamHandlerTest.java?rev=1080381&r1=1080380&r2=1080381&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ActivityStreamHandlerTest.java (original)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ActivityStreamHandlerTest.java Thu Mar 10 22:41:38 2011
@@ -62,7 +62,7 @@ public class ActivityStreamHandlerTest e
private ActivityStreamService service;
- private ActivityStreamHandler handler; // TODO: Rename to ActivityStreamHandler
+ private ActivityStreamHandler handler;
private FakeGadgetToken token;
@@ -168,7 +168,7 @@ public class ActivityStreamHandlerTest e
/* Helper for testing PUT and POST */
private Future<?> setupBodyRequest(String method) throws ProtocolException {
- String jsonActivityEntry = "{title: hi mom!, etc etc}";
+ String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}";
String path = "/activitystreams/john.doe/@self/@app";
RestHandler operation = registry.getRestHandler(path, method);
@@ -188,7 +188,22 @@ public class ActivityStreamHandlerTest e
@Test
public void testHandlePost() throws Exception {
- Future<?> future = setupBodyRequest("POST");
+ String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}";
+
+ String path = "/activitystreams/john.doe/@self/@app";
+ RestHandler operation = registry.getRestHandler(path, "POST");
+
+ ActivityEntry entry = new ActivityEntryImpl();
+ org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class)))
+ .andReturn(entry);
+
+ org.easymock.EasyMock.expect(service.createActivityEntry(eq(JOHN_DOE.iterator().next()),
+ eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()),
+ eq(entry), eq(token))).andReturn(ImmediateFuture.newInstance((Void) null));
+ replay();
+
+ Future<?> future = operation.execute(Maps.<String, String[]>newHashMap(),
+ new StringReader(jsonActivityEntry), token, converter);
assertNull(future.get());
verify();
reset();
@@ -196,7 +211,22 @@ public class ActivityStreamHandlerTest e
@Test
public void testHandlePut() throws Exception {
- Future<?> future = setupBodyRequest("PUT");
+ String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}";
+
+ String path = "/activitystreams/john.doe/@self/@app/testObject";
+ RestHandler operation = registry.getRestHandler(path, "PUT");
+
+ ActivityEntry entry = new ActivityEntryImpl();
+ org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class)))
+ .andReturn(entry);
+
+ org.easymock.EasyMock.expect(service.updateActivityEntry(eq(JOHN_DOE.iterator().next()),
+ eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()),
+ eq(entry), eq("testObject"), eq(token))).andReturn(ImmediateFuture.newInstance((Void) null));
+ replay();
+
+ Future<?> future = operation.execute(Maps.<String, String[]>newHashMap(),
+ new StringReader(jsonActivityEntry), token, converter);
assertNull(future.get());
verify();
reset();
Modified: shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java?rev=1080381&r1=1080380&r2=1080381&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java (original)
+++ shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java Thu Mar 10 22:41:38 2011
@@ -295,10 +295,10 @@ public class JsonDbOpensocialServiceTest
@Test
public void testGetExpectedActivityEntry() throws Exception {
ActivityEntry entry = db.getActivityEntry(JOHN_DOE, SELF_GROUP, APP_ID,
- ImmutableSet.of("body"), "object1", new FakeGadgetToken()).get();
+ ImmutableSet.of("title"), "object1", new FakeGadgetToken()).get();
assertNotNull(entry);
// Check that some fields are fetched and others are not
- assertNotNull(entry.getBody());
+ assertNotNull(entry.getTitle());
assertNull(entry.getPostedTime());
}