You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/05/21 10:20:33 UTC
svn commit: r658591 - in
/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera:
AbstractLargeRestfulTests.java RestfulAtomPeopleTest.java
Author: doll
Date: Wed May 21 01:20:32 2008
New Revision: 658591
URL: http://svn.apache.org/viewvc?rev=658591&view=rev
Log:
SHINDIG-287
Patch from Vasu Nori. Added code to restful tests to look inside entries within a feed when checking data.
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java?rev=658591&r1=658590&r2=658591&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java Wed May 21 01:20:32 2008
@@ -32,13 +32,22 @@
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
-import static org.junit.Assert.*;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.logging.Logger;
@@ -124,4 +133,38 @@
logger.fine(os.toString("utf8"));
}
+ protected String getIdFromXmlContent(String str) throws XMLStreamException {
+ return parseXmlContent(str).get("id");
+ }
+
+ /**
+ * parse entry.content xml into a Map<> struct
+ * @param str input content string
+ * @return the map<> of <name, value> pairs from the content xml
+ * @throws XMLStreamException If the str is not valid xml
+ */
+ protected Map<String, String> parseXmlContent(String str)
+ throws XMLStreamException {
+ ByteArrayInputStream inStr = new ByteArrayInputStream(str.getBytes());
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLStreamReader parser = factory.createXMLStreamReader(inStr);
+ Map<String, String> columns = new HashMap<String, String>();
+
+ while (true) {
+ int event = parser.next();
+ if (event == XMLStreamConstants.END_DOCUMENT) {
+ parser.close();
+ break;
+ } else if (event == XMLStreamConstants.START_ELEMENT) {
+ String name = parser.getLocalName();
+ int eventType = parser.next();
+ if (eventType == XMLStreamConstants.CHARACTERS) {
+ String value = parser.getText();
+ columns.put(name, value);
+ }
+ }
+ }
+ return columns;
+ }
+
}
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java?rev=658591&r1=658590&r2=658591&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTest.java Wed May 21 01:20:32 2008
@@ -31,7 +31,6 @@
import org.junit.Test;
import static org.junit.Assert.*;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -64,18 +63,23 @@
}
@Test
- public void testGetPeopleAtom() throws IOException {
+ public void testGetPeople() throws Exception {
resp = client.get(BASEURL + "/people/john.doe/@all?format=atom");
checkForGoodAtomResponse(resp);
Document<Feed> doc = resp.getDocument();
prettyPrint(doc);
- Feed feed = doc.getRoot();
- assertEquals(2, feed.getEntries().size());
+
+ List<Entry> entries = doc.getRoot().getEntries();
+ assertEquals(2, entries.size());
+ assertEquals(people.get(1).getId(), getIdFromXmlContent(entries.get(0)
+ .getContentElement().getValue()));
+ assertEquals(people.get(0).getId(), getIdFromXmlContent(entries.get(1)
+ .getContentElement().getValue()));
}
@Test
- public void testGetIndirectPersonAtom() throws IOException {
+ public void testGetIndirectPerson() throws Exception {
resp = client.get(BASEURL + "/people/john.doe/@all/jane.doe?format=atom");
checkForGoodAtomResponse(resp);
@@ -84,11 +88,12 @@
prettyPrint(entry);
Person expectedJaneDoe = people.get(0);
- assertEquals(expectedJaneDoe.getName().getUnstructured(), entry.getTitle());
+ assertEquals(expectedJaneDoe.getId(),
+ getIdFromXmlContent(entry.getContentElement().getValue()));
}
@Test
- public void testGetInvalidPersonAtom() throws IOException {
+ public void testGetInvalidPerson() throws Exception {
resp = client.get(BASEURL + "/people/john.doe/@all/nobody?format=atom");
checkForBadResponse(resp);
}