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/20 17:13:32 UTC
svn commit: r658274 -
/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/
Author: doll
Date: Tue May 20 08:13:31 2008
New Revision: 658274
URL: http://svn.apache.org/viewvc?rev=658274&view=rev
Log:
Split the SocialApiProviderLargeTest into 6 test classes. Each subclass now focuses on a particular type of data with a particular format. Will be adding more to these classes shortly.
Added:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java
- copied, changed from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTests.java
- copied, changed from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTests.java
- copied, changed from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTests.java
- copied, changed from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTests.java
- copied, changed from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTests.java
- copied, changed from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTests.java
- copied, changed from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
Removed:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java
Modified:
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderTestFixture.java
Copied: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java (from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java?p2=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java&r1=658247&r2=658274&rev=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/AbstractLargeRestfulTests.java Tue May 20 08:13:31 2008
@@ -18,58 +18,43 @@
package org.apache.shindig.social.abdera;
import org.apache.shindig.social.JettyServer;
-import org.apache.shindig.social.ResponseItem;
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
-import junit.framework.Assert;
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Base;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
import org.apache.abdera.protocol.Response;
-import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.util.Constants;
import org.apache.abdera.util.MimeTypeHelper;
import org.apache.abdera.writer.Writer;
import org.apache.abdera.writer.WriterFactory;
-import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import java.util.logging.Logger;
-public class SocialApiProviderLargeTest extends Assert {
+public abstract class AbstractLargeRestfulTests {
private static Logger logger =
- Logger.getLogger(SocialApiProviderLargeTest.class.getName());
+ Logger.getLogger(RestfulJsonPeopleTests.class.getName());
private static JettyServer server;
private static Abdera abdera = Abdera.getInstance();
- private static AbderaClient client = new AbderaClient();
+ protected static AbderaClient client = new AbderaClient();
private static int JETTY_PORT = 9002;
private static String BASE = "/social/rest";
- private static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
+ protected static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
- private List<Person> people;
- private ClientResponse resp;
+ protected ClientResponse resp;
@BeforeClass
public static void setUpOnce() throws Exception {
@@ -88,213 +73,17 @@
@Before
public void setUp() throws Exception {
- people = new ArrayList<Person>();
- people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
- people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
-
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(
- new ResponseItem<ApiCollection<Person>>(
- new ApiCollection<Person>(people)));
-
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(
- new ResponseItem<Person>(SocialApiTestsGuiceModule
- .MockPeopleService.johnDoe));
}
@After
public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
resp.release();
}
-
- // Json tests
- // TODO: split into sub files
- // Note: most of these aren't annotated as tests because they don't pass yet
-
- /**
- * Expected response for john.doe's json:
- *
- * {
- * 'id' : 'john.doe',
- * 'name' : {'unstructured' : 'John Doe'},
- * 'phoneNumbers' : [
- * { 'number' : '+33H000000000', 'type' : 'home'},
- * { 'number' : '+33M000000000', 'type' : 'mobile'},
- * { 'number' : '+33W000000000', 'type' : 'work'}
- * ],
- * 'addresses' : [
- * {'unstructuredAddress' : 'My home address'}
- * ],
- * 'emails' : [
- * { 'address' : 'john.doe@work.bar', 'type' : 'work'},
- * { 'address' : 'john.doe@home.bar', 'type' : 'home'}
- * ]
- * }
- */
- @Test
- public void testGetPersonJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- Person johnDoe = SocialApiTestsGuiceModule.MockPeopleService.johnDoe;
- assertEquals(johnDoe.getId(), result.getString("id"));
-
- assertEquals(johnDoe.getName().getUnstructured(),
- result.getJSONObject("name").getString("unstructured"));
-
- assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
- result.getJSONArray("addresses").getJSONObject(0)
- .getString("unstructuredAddress"));
-
- JSONArray phoneArray = result.getJSONArray("phoneNumbers");
- assertEquals(3, phoneArray.length());
-
- for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
- Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
- JSONObject actualPhone = phoneArray.getJSONObject(i);
- assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
- assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
- }
-
- JSONArray emailArray = result.getJSONArray("emails");
- assertEquals(2, emailArray.length());
-
- for (int i = 0; i < johnDoe.getEmails().size(); i++) {
- Email expectedEmail = johnDoe.getEmails().get(i);
- JSONObject actualEmail = emailArray.getJSONObject(i);
- assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
- assertEquals(expectedEmail.getAddress(),
- actualEmail.getString("address"));
- }
- }
-
- /**
- * Expected response for a list of people in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 2,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<jane doe>}, // layed out like above
- * {<simple doe>},
- * ]
- * }
- */
- public void testGetPeopleJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@friends");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- assertEquals(2, result.getInt("totalResults"));
- assertEquals(0, result.getInt("startIndex"));
- assertEquals(10, result.getInt("itemsPerPage"));
-
- JSONArray people = result.getJSONArray("entry");
-
- JSONObject janeDoe = people.getJSONObject(0);
- assertEquals("jane.doe", janeDoe.getString("id"));
-
- JSONObject simpleDoe = people.getJSONObject(1);
- assertEquals("simple.doe", simpleDoe.getString("id"));
- }
-
- /**
- * Expected response for an activity in json:
- * {
- * 'id' : '1',
- * 'userId' : 'john.doe',
- * 'title' : 'yellow',
- * 'body' : 'what a color!'
- * }
- */
- public void testGetActivityJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self/1");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for a list of activities in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 1,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<activity>} // layed out like above
- * ]
- * }
- */
- public void testGetActivitiesJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for app data in json:
- *
- * {
- * "entry" : {
- * "jane.doe" : {"count" : 5},
- * "simple.doe" : {"count" : 7},
- * }
- * }
- */
- public void testGetAppDataJson() throws Exception {
- // app id is mocked out
- resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
-
- // Atom tests
-
- @Test
- public void testGetPeopleAtom() throws IOException {
- 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());
- }
-
- @Test
- public void testGetIndirectPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/jane.doe?format=atom");
- checkForGoodAtomResponse(resp);
-
- Document<Entry> doc = resp.getDocument();
- Entry entry = doc.getRoot();
- prettyPrint(entry);
-
- Person expectedJaneDoe = people.get(0);
- assertEquals(expectedJaneDoe.getName().getUnstructured(), entry.getTitle());
- }
-
- @Test
- public void testGetInvalidPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/nobody?format=atom");
- checkForBadResponse(resp);
- }
-
protected void checkForGoodResponse(ClientResponse response,
String mimeType) {
assertNotNull(response);
- assertEquals(ResponseType.SUCCESS, response.getType());
+ assertEquals(Response.ResponseType.SUCCESS, response.getType());
assertTrue(MimeTypeHelper.isMatch(response.getContentType().toString(),
mimeType));
}
@@ -309,10 +98,10 @@
protected void checkForBadResponse(ClientResponse response){
assertNotNull(response);
- assertEquals(ResponseType.CLIENT_ERROR, response.getType());
+ assertEquals(Response.ResponseType.CLIENT_ERROR, response.getType());
}
- private JSONObject getJson(ClientResponse resp) throws IOException,
+ protected JSONObject getJson(ClientResponse resp) throws IOException,
JSONException {
BufferedReader reader = new BufferedReader(resp.getReader());
Copied: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTests.java (from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTests.java?p2=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTests.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java&r1=658247&r2=658274&rev=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomActivityTests.java Tue May 20 08:13:31 2008
@@ -17,321 +17,27 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.JettyServer;
-import org.apache.shindig.social.ResponseItem;
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
-
-import junit.framework.Assert;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.model.Base;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.protocol.Response;
-import org.apache.abdera.protocol.Response.ResponseType;
-import org.apache.abdera.protocol.client.AbderaClient;
-import org.apache.abdera.protocol.client.ClientResponse;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.writer.Writer;
-import org.apache.abdera.writer.WriterFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Logger;
-
-
-public class SocialApiProviderLargeTest extends Assert {
- private static Logger logger =
- Logger.getLogger(SocialApiProviderLargeTest.class.getName());
-
- private static JettyServer server;
- private static Abdera abdera = Abdera.getInstance();
- private static AbderaClient client = new AbderaClient();
-
- private static int JETTY_PORT = 9002;
- private static String BASE = "/social/rest";
- private static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
-
- private List<Person> people;
- private ClientResponse resp;
-
- @BeforeClass
- public static void setUpOnce() throws Exception {
- try {
- server = new JettyServer();
- server.start(JETTY_PORT, BASE + "/*");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @AfterClass
- public static void tearDownOnce() throws Exception {
- server.stop();
- }
+public class RestfulAtomActivityTests extends AbstractLargeRestfulTests {
@Before
public void setUp() throws Exception {
- people = new ArrayList<Person>();
- people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
- people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
-
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(
- new ResponseItem<ApiCollection<Person>>(
- new ApiCollection<Person>(people)));
-
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(
- new ResponseItem<Person>(SocialApiTestsGuiceModule
- .MockPeopleService.johnDoe));
+ super.setUp();
}
@After
public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
- resp.release();
+ super.tearDown();
}
-
- // Json tests
- // TODO: split into sub files
- // Note: most of these aren't annotated as tests because they don't pass yet
-
- /**
- * Expected response for john.doe's json:
- *
- * {
- * 'id' : 'john.doe',
- * 'name' : {'unstructured' : 'John Doe'},
- * 'phoneNumbers' : [
- * { 'number' : '+33H000000000', 'type' : 'home'},
- * { 'number' : '+33M000000000', 'type' : 'mobile'},
- * { 'number' : '+33W000000000', 'type' : 'work'}
- * ],
- * 'addresses' : [
- * {'unstructuredAddress' : 'My home address'}
- * ],
- * 'emails' : [
- * { 'address' : 'john.doe@work.bar', 'type' : 'work'},
- * { 'address' : 'john.doe@home.bar', 'type' : 'home'}
- * ]
- * }
- */
@Test
- public void testGetPersonJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- Person johnDoe = SocialApiTestsGuiceModule.MockPeopleService.johnDoe;
- assertEquals(johnDoe.getId(), result.getString("id"));
-
- assertEquals(johnDoe.getName().getUnstructured(),
- result.getJSONObject("name").getString("unstructured"));
-
- assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
- result.getJSONArray("addresses").getJSONObject(0)
- .getString("unstructuredAddress"));
-
- JSONArray phoneArray = result.getJSONArray("phoneNumbers");
- assertEquals(3, phoneArray.length());
-
- for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
- Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
- JSONObject actualPhone = phoneArray.getJSONObject(i);
- assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
- assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
- }
-
- JSONArray emailArray = result.getJSONArray("emails");
- assertEquals(2, emailArray.length());
-
- for (int i = 0; i < johnDoe.getEmails().size(); i++) {
- Email expectedEmail = johnDoe.getEmails().get(i);
- JSONObject actualEmail = emailArray.getJSONObject(i);
- assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
- assertEquals(expectedEmail.getAddress(),
- actualEmail.getString("address"));
- }
- }
-
- /**
- * Expected response for a list of people in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 2,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<jane doe>}, // layed out like above
- * {<simple doe>},
- * ]
- * }
- */
- public void testGetPeopleJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@friends");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- assertEquals(2, result.getInt("totalResults"));
- assertEquals(0, result.getInt("startIndex"));
- assertEquals(10, result.getInt("itemsPerPage"));
-
- JSONArray people = result.getJSONArray("entry");
-
- JSONObject janeDoe = people.getJSONObject(0);
- assertEquals("jane.doe", janeDoe.getString("id"));
-
- JSONObject simpleDoe = people.getJSONObject(1);
- assertEquals("simple.doe", simpleDoe.getString("id"));
- }
-
- /**
- * Expected response for an activity in json:
- * {
- * 'id' : '1',
- * 'userId' : 'john.doe',
- * 'title' : 'yellow',
- * 'body' : 'what a color!'
- * }
- */
- public void testGetActivityJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self/1");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for a list of activities in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 1,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<activity>} // layed out like above
- * ]
- * }
- */
- public void testGetActivitiesJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for app data in json:
- *
- * {
- * "entry" : {
- * "jane.doe" : {"count" : 5},
- * "simple.doe" : {"count" : 7},
- * }
- * }
- */
- public void testGetAppDataJson() throws Exception {
- // app id is mocked out
- resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
-
- // Atom tests
-
- @Test
- public void testGetPeopleAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all?format=atom");
+ public void testGetActivityAtom() throws Exception {
+ resp = client.get(BASEURL + "/activities/john.doe/@all?format=atom");
checkForGoodAtomResponse(resp);
-
- Document<Feed> doc = resp.getDocument();
- prettyPrint(doc);
- Feed feed = doc.getRoot();
- assertEquals(2, feed.getEntries().size());
- }
-
- @Test
- public void testGetIndirectPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/jane.doe?format=atom");
- checkForGoodAtomResponse(resp);
-
- Document<Entry> doc = resp.getDocument();
- Entry entry = doc.getRoot();
- prettyPrint(entry);
-
- Person expectedJaneDoe = people.get(0);
- assertEquals(expectedJaneDoe.getName().getUnstructured(), entry.getTitle());
- }
-
- @Test
- public void testGetInvalidPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/nobody?format=atom");
- checkForBadResponse(resp);
- }
-
- protected void checkForGoodResponse(ClientResponse response,
- String mimeType) {
- assertNotNull(response);
- assertEquals(ResponseType.SUCCESS, response.getType());
- assertTrue(MimeTypeHelper.isMatch(response.getContentType().toString(),
- mimeType));
- }
-
- protected void checkForGoodJsonResponse(ClientResponse response){
- checkForGoodResponse(response, "application/json");
- }
-
- protected void checkForGoodAtomResponse(ClientResponse response){
- checkForGoodResponse(response, Constants.ATOM_MEDIA_TYPE);
- }
-
- protected void checkForBadResponse(ClientResponse response){
- assertNotNull(response);
- assertEquals(ResponseType.CLIENT_ERROR, response.getType());
- }
-
- private JSONObject getJson(ClientResponse resp) throws IOException,
- JSONException {
- BufferedReader reader = new BufferedReader(resp.getReader());
-
- StringBuffer json = new StringBuffer();
- String line = reader.readLine();
- while (line != null) {
- json.append(line);
- line = reader.readLine();
- }
-
- return new JSONObject(json.toString());
- }
-
- protected void prettyPrint(Base doc) throws IOException {
- WriterFactory writerFactory = abdera.getWriterFactory();
- Writer writer = writerFactory.getWriter("prettyxml");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- writer.writeTo(doc, os);
- logger.fine(os.toString("utf8"));
}
}
Copied: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTests.java (from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTests.java?p2=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTests.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java&r1=658247&r2=658274&rev=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomDataTests.java Tue May 20 08:13:31 2008
@@ -17,321 +17,26 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.JettyServer;
-import org.apache.shindig.social.ResponseItem;
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
-
-import junit.framework.Assert;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.model.Base;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.protocol.Response;
-import org.apache.abdera.protocol.Response.ResponseType;
-import org.apache.abdera.protocol.client.AbderaClient;
-import org.apache.abdera.protocol.client.ClientResponse;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.writer.Writer;
-import org.apache.abdera.writer.WriterFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Logger;
-
-
-public class SocialApiProviderLargeTest extends Assert {
- private static Logger logger =
- Logger.getLogger(SocialApiProviderLargeTest.class.getName());
-
- private static JettyServer server;
- private static Abdera abdera = Abdera.getInstance();
- private static AbderaClient client = new AbderaClient();
-
- private static int JETTY_PORT = 9002;
- private static String BASE = "/social/rest";
- private static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
-
- private List<Person> people;
- private ClientResponse resp;
-
- @BeforeClass
- public static void setUpOnce() throws Exception {
- try {
- server = new JettyServer();
- server.start(JETTY_PORT, BASE + "/*");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @AfterClass
- public static void tearDownOnce() throws Exception {
- server.stop();
- }
+public class RestfulAtomDataTests extends AbstractLargeRestfulTests {
@Before
public void setUp() throws Exception {
- people = new ArrayList<Person>();
- people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
- people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
-
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(
- new ResponseItem<ApiCollection<Person>>(
- new ApiCollection<Person>(people)));
-
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(
- new ResponseItem<Person>(SocialApiTestsGuiceModule
- .MockPeopleService.johnDoe));
+ super.setUp();
}
@After
public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
- resp.release();
- }
-
-
- // Json tests
- // TODO: split into sub files
- // Note: most of these aren't annotated as tests because they don't pass yet
-
- /**
- * Expected response for john.doe's json:
- *
- * {
- * 'id' : 'john.doe',
- * 'name' : {'unstructured' : 'John Doe'},
- * 'phoneNumbers' : [
- * { 'number' : '+33H000000000', 'type' : 'home'},
- * { 'number' : '+33M000000000', 'type' : 'mobile'},
- * { 'number' : '+33W000000000', 'type' : 'work'}
- * ],
- * 'addresses' : [
- * {'unstructuredAddress' : 'My home address'}
- * ],
- * 'emails' : [
- * { 'address' : 'john.doe@work.bar', 'type' : 'work'},
- * { 'address' : 'john.doe@home.bar', 'type' : 'home'}
- * ]
- * }
- */
- @Test
- public void testGetPersonJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- Person johnDoe = SocialApiTestsGuiceModule.MockPeopleService.johnDoe;
- assertEquals(johnDoe.getId(), result.getString("id"));
-
- assertEquals(johnDoe.getName().getUnstructured(),
- result.getJSONObject("name").getString("unstructured"));
-
- assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
- result.getJSONArray("addresses").getJSONObject(0)
- .getString("unstructuredAddress"));
-
- JSONArray phoneArray = result.getJSONArray("phoneNumbers");
- assertEquals(3, phoneArray.length());
-
- for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
- Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
- JSONObject actualPhone = phoneArray.getJSONObject(i);
- assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
- assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
- }
-
- JSONArray emailArray = result.getJSONArray("emails");
- assertEquals(2, emailArray.length());
-
- for (int i = 0; i < johnDoe.getEmails().size(); i++) {
- Email expectedEmail = johnDoe.getEmails().get(i);
- JSONObject actualEmail = emailArray.getJSONObject(i);
- assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
- assertEquals(expectedEmail.getAddress(),
- actualEmail.getString("address"));
- }
- }
-
- /**
- * Expected response for a list of people in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 2,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<jane doe>}, // layed out like above
- * {<simple doe>},
- * ]
- * }
- */
- public void testGetPeopleJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@friends");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- assertEquals(2, result.getInt("totalResults"));
- assertEquals(0, result.getInt("startIndex"));
- assertEquals(10, result.getInt("itemsPerPage"));
-
- JSONArray people = result.getJSONArray("entry");
-
- JSONObject janeDoe = people.getJSONObject(0);
- assertEquals("jane.doe", janeDoe.getString("id"));
-
- JSONObject simpleDoe = people.getJSONObject(1);
- assertEquals("simple.doe", simpleDoe.getString("id"));
- }
-
- /**
- * Expected response for an activity in json:
- * {
- * 'id' : '1',
- * 'userId' : 'john.doe',
- * 'title' : 'yellow',
- * 'body' : 'what a color!'
- * }
- */
- public void testGetActivityJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self/1");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for a list of activities in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 1,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<activity>} // layed out like above
- * ]
- * }
- */
- public void testGetActivitiesJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for app data in json:
- *
- * {
- * "entry" : {
- * "jane.doe" : {"count" : 5},
- * "simple.doe" : {"count" : 7},
- * }
- * }
- */
- public void testGetAppDataJson() throws Exception {
- // app id is mocked out
- resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
-
- // Atom tests
-
- @Test
- public void testGetPeopleAtom() throws IOException {
- 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());
+ super.tearDown();
}
@Test
- public void testGetIndirectPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/jane.doe?format=atom");
+ public void testGetActivityAtom() throws Exception {
+ resp = client.get(BASEURL + "/appdata/john.doe/@all?format=atom");
checkForGoodAtomResponse(resp);
-
- Document<Entry> doc = resp.getDocument();
- Entry entry = doc.getRoot();
- prettyPrint(entry);
-
- Person expectedJaneDoe = people.get(0);
- assertEquals(expectedJaneDoe.getName().getUnstructured(), entry.getTitle());
- }
-
- @Test
- public void testGetInvalidPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/nobody?format=atom");
- checkForBadResponse(resp);
}
-
- protected void checkForGoodResponse(ClientResponse response,
- String mimeType) {
- assertNotNull(response);
- assertEquals(ResponseType.SUCCESS, response.getType());
- assertTrue(MimeTypeHelper.isMatch(response.getContentType().toString(),
- mimeType));
- }
-
- protected void checkForGoodJsonResponse(ClientResponse response){
- checkForGoodResponse(response, "application/json");
- }
-
- protected void checkForGoodAtomResponse(ClientResponse response){
- checkForGoodResponse(response, Constants.ATOM_MEDIA_TYPE);
- }
-
- protected void checkForBadResponse(ClientResponse response){
- assertNotNull(response);
- assertEquals(ResponseType.CLIENT_ERROR, response.getType());
- }
-
- private JSONObject getJson(ClientResponse resp) throws IOException,
- JSONException {
- BufferedReader reader = new BufferedReader(resp.getReader());
-
- StringBuffer json = new StringBuffer();
- String line = reader.readLine();
- while (line != null) {
- json.append(line);
- line = reader.readLine();
- }
-
- return new JSONObject(json.toString());
- }
-
- protected void prettyPrint(Base doc) throws IOException {
- WriterFactory writerFactory = abdera.getWriterFactory();
- Writer writer = writerFactory.getWriter("prettyxml");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- writer.writeTo(doc, os);
- logger.fine(os.toString("utf8"));
- }
-
}
Copied: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTests.java (from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTests.java?p2=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTests.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java&r1=658247&r2=658274&rev=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulAtomPeopleTests.java Tue May 20 08:13:31 2008
@@ -17,77 +17,31 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.JettyServer;
import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.SocialApiTestsGuiceModule;
import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
-import junit.framework.Assert;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.model.Base;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
-import org.apache.abdera.protocol.Response;
-import org.apache.abdera.protocol.Response.ResponseType;
-import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.writer.Writer;
-import org.apache.abdera.writer.WriterFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.logging.Logger;
-public class SocialApiProviderLargeTest extends Assert {
- private static Logger logger =
- Logger.getLogger(SocialApiProviderLargeTest.class.getName());
-
- private static JettyServer server;
- private static Abdera abdera = Abdera.getInstance();
- private static AbderaClient client = new AbderaClient();
-
- private static int JETTY_PORT = 9002;
- private static String BASE = "/social/rest";
- private static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
-
+public class RestfulAtomPeopleTests extends AbstractLargeRestfulTests {
private List<Person> people;
private ClientResponse resp;
- @BeforeClass
- public static void setUpOnce() throws Exception {
- try {
- server = new JettyServer();
- server.start(JETTY_PORT, BASE + "/*");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDownOnce() throws Exception {
- server.stop();
- }
-
@Before
public void setUp() throws Exception {
+ super.setUp();
people = new ArrayList<Person>();
people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
@@ -108,159 +62,6 @@
resp.release();
}
-
- // Json tests
- // TODO: split into sub files
- // Note: most of these aren't annotated as tests because they don't pass yet
-
- /**
- * Expected response for john.doe's json:
- *
- * {
- * 'id' : 'john.doe',
- * 'name' : {'unstructured' : 'John Doe'},
- * 'phoneNumbers' : [
- * { 'number' : '+33H000000000', 'type' : 'home'},
- * { 'number' : '+33M000000000', 'type' : 'mobile'},
- * { 'number' : '+33W000000000', 'type' : 'work'}
- * ],
- * 'addresses' : [
- * {'unstructuredAddress' : 'My home address'}
- * ],
- * 'emails' : [
- * { 'address' : 'john.doe@work.bar', 'type' : 'work'},
- * { 'address' : 'john.doe@home.bar', 'type' : 'home'}
- * ]
- * }
- */
- @Test
- public void testGetPersonJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- Person johnDoe = SocialApiTestsGuiceModule.MockPeopleService.johnDoe;
- assertEquals(johnDoe.getId(), result.getString("id"));
-
- assertEquals(johnDoe.getName().getUnstructured(),
- result.getJSONObject("name").getString("unstructured"));
-
- assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
- result.getJSONArray("addresses").getJSONObject(0)
- .getString("unstructuredAddress"));
-
- JSONArray phoneArray = result.getJSONArray("phoneNumbers");
- assertEquals(3, phoneArray.length());
-
- for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
- Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
- JSONObject actualPhone = phoneArray.getJSONObject(i);
- assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
- assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
- }
-
- JSONArray emailArray = result.getJSONArray("emails");
- assertEquals(2, emailArray.length());
-
- for (int i = 0; i < johnDoe.getEmails().size(); i++) {
- Email expectedEmail = johnDoe.getEmails().get(i);
- JSONObject actualEmail = emailArray.getJSONObject(i);
- assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
- assertEquals(expectedEmail.getAddress(),
- actualEmail.getString("address"));
- }
- }
-
- /**
- * Expected response for a list of people in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 2,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<jane doe>}, // layed out like above
- * {<simple doe>},
- * ]
- * }
- */
- public void testGetPeopleJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@friends");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- assertEquals(2, result.getInt("totalResults"));
- assertEquals(0, result.getInt("startIndex"));
- assertEquals(10, result.getInt("itemsPerPage"));
-
- JSONArray people = result.getJSONArray("entry");
-
- JSONObject janeDoe = people.getJSONObject(0);
- assertEquals("jane.doe", janeDoe.getString("id"));
-
- JSONObject simpleDoe = people.getJSONObject(1);
- assertEquals("simple.doe", simpleDoe.getString("id"));
- }
-
- /**
- * Expected response for an activity in json:
- * {
- * 'id' : '1',
- * 'userId' : 'john.doe',
- * 'title' : 'yellow',
- * 'body' : 'what a color!'
- * }
- */
- public void testGetActivityJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self/1");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for a list of activities in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 1,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<activity>} // layed out like above
- * ]
- * }
- */
- public void testGetActivitiesJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for app data in json:
- *
- * {
- * "entry" : {
- * "jane.doe" : {"count" : 5},
- * "simple.doe" : {"count" : 7},
- * }
- * }
- */
- public void testGetAppDataJson() throws Exception {
- // app id is mocked out
- resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
-
- // Atom tests
-
@Test
public void testGetPeopleAtom() throws IOException {
resp = client.get(BASEURL + "/people/john.doe/@all?format=atom");
@@ -291,47 +92,4 @@
checkForBadResponse(resp);
}
- protected void checkForGoodResponse(ClientResponse response,
- String mimeType) {
- assertNotNull(response);
- assertEquals(ResponseType.SUCCESS, response.getType());
- assertTrue(MimeTypeHelper.isMatch(response.getContentType().toString(),
- mimeType));
- }
-
- protected void checkForGoodJsonResponse(ClientResponse response){
- checkForGoodResponse(response, "application/json");
- }
-
- protected void checkForGoodAtomResponse(ClientResponse response){
- checkForGoodResponse(response, Constants.ATOM_MEDIA_TYPE);
- }
-
- protected void checkForBadResponse(ClientResponse response){
- assertNotNull(response);
- assertEquals(ResponseType.CLIENT_ERROR, response.getType());
- }
-
- private JSONObject getJson(ClientResponse resp) throws IOException,
- JSONException {
- BufferedReader reader = new BufferedReader(resp.getReader());
-
- StringBuffer json = new StringBuffer();
- String line = reader.readLine();
- while (line != null) {
- json.append(line);
- line = reader.readLine();
- }
-
- return new JSONObject(json.toString());
- }
-
- protected void prettyPrint(Base doc) throws IOException {
- WriterFactory writerFactory = abdera.getWriterFactory();
- Writer writer = writerFactory.getWriter("prettyxml");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- writer.writeTo(doc, os);
- logger.fine(os.toString("utf8"));
- }
-
}
Copied: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTests.java (from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTests.java?p2=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTests.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java&r1=658247&r2=658274&rev=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTests.java Tue May 20 08:13:31 2008
@@ -17,192 +17,22 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.JettyServer;
-import org.apache.shindig.social.ResponseItem;
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
-
-import junit.framework.Assert;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.model.Base;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.protocol.Response;
-import org.apache.abdera.protocol.Response.ResponseType;
-import org.apache.abdera.protocol.client.AbderaClient;
-import org.apache.abdera.protocol.client.ClientResponse;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.writer.Writer;
-import org.apache.abdera.writer.WriterFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Logger;
-
-
-public class SocialApiProviderLargeTest extends Assert {
- private static Logger logger =
- Logger.getLogger(SocialApiProviderLargeTest.class.getName());
-
- private static JettyServer server;
- private static Abdera abdera = Abdera.getInstance();
- private static AbderaClient client = new AbderaClient();
-
- private static int JETTY_PORT = 9002;
- private static String BASE = "/social/rest";
- private static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
-
- private List<Person> people;
- private ClientResponse resp;
- @BeforeClass
- public static void setUpOnce() throws Exception {
- try {
- server = new JettyServer();
- server.start(JETTY_PORT, BASE + "/*");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDownOnce() throws Exception {
- server.stop();
- }
+public class RestfulJsonActivityTests extends AbstractLargeRestfulTests {
@Before
public void setUp() throws Exception {
- people = new ArrayList<Person>();
- people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
- people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
-
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(
- new ResponseItem<ApiCollection<Person>>(
- new ApiCollection<Person>(people)));
-
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(
- new ResponseItem<Person>(SocialApiTestsGuiceModule
- .MockPeopleService.johnDoe));
+ super.setUp();
}
@After
public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
- resp.release();
- }
-
-
- // Json tests
- // TODO: split into sub files
- // Note: most of these aren't annotated as tests because they don't pass yet
-
- /**
- * Expected response for john.doe's json:
- *
- * {
- * 'id' : 'john.doe',
- * 'name' : {'unstructured' : 'John Doe'},
- * 'phoneNumbers' : [
- * { 'number' : '+33H000000000', 'type' : 'home'},
- * { 'number' : '+33M000000000', 'type' : 'mobile'},
- * { 'number' : '+33W000000000', 'type' : 'work'}
- * ],
- * 'addresses' : [
- * {'unstructuredAddress' : 'My home address'}
- * ],
- * 'emails' : [
- * { 'address' : 'john.doe@work.bar', 'type' : 'work'},
- * { 'address' : 'john.doe@home.bar', 'type' : 'home'}
- * ]
- * }
- */
- @Test
- public void testGetPersonJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- Person johnDoe = SocialApiTestsGuiceModule.MockPeopleService.johnDoe;
- assertEquals(johnDoe.getId(), result.getString("id"));
-
- assertEquals(johnDoe.getName().getUnstructured(),
- result.getJSONObject("name").getString("unstructured"));
-
- assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
- result.getJSONArray("addresses").getJSONObject(0)
- .getString("unstructuredAddress"));
-
- JSONArray phoneArray = result.getJSONArray("phoneNumbers");
- assertEquals(3, phoneArray.length());
-
- for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
- Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
- JSONObject actualPhone = phoneArray.getJSONObject(i);
- assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
- assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
- }
-
- JSONArray emailArray = result.getJSONArray("emails");
- assertEquals(2, emailArray.length());
-
- for (int i = 0; i < johnDoe.getEmails().size(); i++) {
- Email expectedEmail = johnDoe.getEmails().get(i);
- JSONObject actualEmail = emailArray.getJSONObject(i);
- assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
- assertEquals(expectedEmail.getAddress(),
- actualEmail.getString("address"));
- }
- }
-
- /**
- * Expected response for a list of people in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 2,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<jane doe>}, // layed out like above
- * {<simple doe>},
- * ]
- * }
- */
- public void testGetPeopleJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@friends");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- assertEquals(2, result.getInt("totalResults"));
- assertEquals(0, result.getInt("startIndex"));
- assertEquals(10, result.getInt("itemsPerPage"));
-
- JSONArray people = result.getJSONArray("entry");
-
- JSONObject janeDoe = people.getJSONObject(0);
- assertEquals("jane.doe", janeDoe.getString("id"));
-
- JSONObject simpleDoe = people.getJSONObject(1);
- assertEquals("simple.doe", simpleDoe.getString("id"));
+ super.tearDown();
}
/**
@@ -213,7 +43,10 @@
* 'title' : 'yellow',
* 'body' : 'what a color!'
* }
+ *
+ * @throws Exception if test encounters an error
*/
+ @Test
public void testGetActivityJson() throws Exception {
resp = client.get(BASEURL + "/activities/john.doe/@self/1");
checkForGoodJsonResponse(resp);
@@ -234,104 +67,13 @@
* {<activity>} // layed out like above
* ]
* }
+ *
+ * @throws Exception if test encounters an error
*/
+ @Test
public void testGetActivitiesJson() throws Exception {
resp = client.get(BASEURL + "/activities/john.doe/@self");
checkForGoodJsonResponse(resp);
JSONObject result = getJson(resp);
}
-
- /**
- * Expected response for app data in json:
- *
- * {
- * "entry" : {
- * "jane.doe" : {"count" : 5},
- * "simple.doe" : {"count" : 7},
- * }
- * }
- */
- public void testGetAppDataJson() throws Exception {
- // app id is mocked out
- resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
-
- // Atom tests
-
- @Test
- public void testGetPeopleAtom() throws IOException {
- 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());
- }
-
- @Test
- public void testGetIndirectPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/jane.doe?format=atom");
- checkForGoodAtomResponse(resp);
-
- Document<Entry> doc = resp.getDocument();
- Entry entry = doc.getRoot();
- prettyPrint(entry);
-
- Person expectedJaneDoe = people.get(0);
- assertEquals(expectedJaneDoe.getName().getUnstructured(), entry.getTitle());
- }
-
- @Test
- public void testGetInvalidPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/nobody?format=atom");
- checkForBadResponse(resp);
- }
-
- protected void checkForGoodResponse(ClientResponse response,
- String mimeType) {
- assertNotNull(response);
- assertEquals(ResponseType.SUCCESS, response.getType());
- assertTrue(MimeTypeHelper.isMatch(response.getContentType().toString(),
- mimeType));
- }
-
- protected void checkForGoodJsonResponse(ClientResponse response){
- checkForGoodResponse(response, "application/json");
- }
-
- protected void checkForGoodAtomResponse(ClientResponse response){
- checkForGoodResponse(response, Constants.ATOM_MEDIA_TYPE);
- }
-
- protected void checkForBadResponse(ClientResponse response){
- assertNotNull(response);
- assertEquals(ResponseType.CLIENT_ERROR, response.getType());
- }
-
- private JSONObject getJson(ClientResponse resp) throws IOException,
- JSONException {
- BufferedReader reader = new BufferedReader(resp.getReader());
-
- StringBuffer json = new StringBuffer();
- String line = reader.readLine();
- while (line != null) {
- json.append(line);
- line = reader.readLine();
- }
-
- return new JSONObject(json.toString());
- }
-
- protected void prettyPrint(Base doc) throws IOException {
- WriterFactory writerFactory = abdera.getWriterFactory();
- Writer writer = writerFactory.getWriter("prettyxml");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- writer.writeTo(doc, os);
- logger.fine(os.toString("utf8"));
- }
-
}
Copied: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTests.java (from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTests.java?p2=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTests.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java&r1=658247&r2=658274&rev=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonDataTests.java Tue May 20 08:13:31 2008
@@ -17,228 +17,22 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.JettyServer;
-import org.apache.shindig.social.ResponseItem;
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.opensocial.model.ApiCollection;
-import org.apache.shindig.social.opensocial.model.Email;
-import org.apache.shindig.social.opensocial.model.Person;
-import org.apache.shindig.social.opensocial.model.Phone;
-
-import junit.framework.Assert;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.model.Base;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.protocol.Response;
-import org.apache.abdera.protocol.Response.ResponseType;
-import org.apache.abdera.protocol.client.AbderaClient;
-import org.apache.abdera.protocol.client.ClientResponse;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.writer.Writer;
-import org.apache.abdera.writer.WriterFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Logger;
-
-
-public class SocialApiProviderLargeTest extends Assert {
- private static Logger logger =
- Logger.getLogger(SocialApiProviderLargeTest.class.getName());
-
- private static JettyServer server;
- private static Abdera abdera = Abdera.getInstance();
- private static AbderaClient client = new AbderaClient();
-
- private static int JETTY_PORT = 9002;
- private static String BASE = "/social/rest";
- private static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
-
- private List<Person> people;
- private ClientResponse resp;
- @BeforeClass
- public static void setUpOnce() throws Exception {
- try {
- server = new JettyServer();
- server.start(JETTY_PORT, BASE + "/*");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDownOnce() throws Exception {
- server.stop();
- }
+public class RestfulJsonDataTests extends AbstractLargeRestfulTests {
@Before
public void setUp() throws Exception {
- people = new ArrayList<Person>();
- people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
- people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
-
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(
- new ResponseItem<ApiCollection<Person>>(
- new ApiCollection<Person>(people)));
-
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(
- new ResponseItem<Person>(SocialApiTestsGuiceModule
- .MockPeopleService.johnDoe));
+ super.setUp();
}
@After
public void tearDown() throws Exception {
- SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
- SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
- resp.release();
- }
-
-
- // Json tests
- // TODO: split into sub files
- // Note: most of these aren't annotated as tests because they don't pass yet
-
- /**
- * Expected response for john.doe's json:
- *
- * {
- * 'id' : 'john.doe',
- * 'name' : {'unstructured' : 'John Doe'},
- * 'phoneNumbers' : [
- * { 'number' : '+33H000000000', 'type' : 'home'},
- * { 'number' : '+33M000000000', 'type' : 'mobile'},
- * { 'number' : '+33W000000000', 'type' : 'work'}
- * ],
- * 'addresses' : [
- * {'unstructuredAddress' : 'My home address'}
- * ],
- * 'emails' : [
- * { 'address' : 'john.doe@work.bar', 'type' : 'work'},
- * { 'address' : 'john.doe@home.bar', 'type' : 'home'}
- * ]
- * }
- */
- @Test
- public void testGetPersonJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- Person johnDoe = SocialApiTestsGuiceModule.MockPeopleService.johnDoe;
- assertEquals(johnDoe.getId(), result.getString("id"));
-
- assertEquals(johnDoe.getName().getUnstructured(),
- result.getJSONObject("name").getString("unstructured"));
-
- assertEquals(johnDoe.getAddresses().get(0).getUnstructuredAddress(),
- result.getJSONArray("addresses").getJSONObject(0)
- .getString("unstructuredAddress"));
-
- JSONArray phoneArray = result.getJSONArray("phoneNumbers");
- assertEquals(3, phoneArray.length());
-
- for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
- Phone expectedPhone = johnDoe.getPhoneNumbers().get(i);
- JSONObject actualPhone = phoneArray.getJSONObject(i);
- assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
- assertEquals(expectedPhone.getNumber(), actualPhone.getString("number"));
- }
-
- JSONArray emailArray = result.getJSONArray("emails");
- assertEquals(2, emailArray.length());
-
- for (int i = 0; i < johnDoe.getEmails().size(); i++) {
- Email expectedEmail = johnDoe.getEmails().get(i);
- JSONObject actualEmail = emailArray.getJSONObject(i);
- assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
- assertEquals(expectedEmail.getAddress(),
- actualEmail.getString("address"));
- }
- }
-
- /**
- * Expected response for a list of people in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 2,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<jane doe>}, // layed out like above
- * {<simple doe>},
- * ]
- * }
- */
- public void testGetPeopleJson() throws Exception {
- resp = client.get(BASEURL + "/people/john.doe/@friends");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
-
- assertEquals(2, result.getInt("totalResults"));
- assertEquals(0, result.getInt("startIndex"));
- assertEquals(10, result.getInt("itemsPerPage"));
-
- JSONArray people = result.getJSONArray("entry");
-
- JSONObject janeDoe = people.getJSONObject(0);
- assertEquals("jane.doe", janeDoe.getString("id"));
-
- JSONObject simpleDoe = people.getJSONObject(1);
- assertEquals("simple.doe", simpleDoe.getString("id"));
- }
-
- /**
- * Expected response for an activity in json:
- * {
- * 'id' : '1',
- * 'userId' : 'john.doe',
- * 'title' : 'yellow',
- * 'body' : 'what a color!'
- * }
- */
- public void testGetActivityJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self/1");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for a list of activities in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 1,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<activity>} // layed out like above
- * ]
- * }
- */
- public void testGetActivitiesJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
+ super.tearDown();
}
/**
@@ -250,7 +44,10 @@
* "simple.doe" : {"count" : 7},
* }
* }
+ *
+ * @throws Exception if test encounters an error
*/
+ @Test
public void testGetAppDataJson() throws Exception {
// app id is mocked out
resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
@@ -258,80 +55,4 @@
JSONObject result = getJson(resp);
}
-
- // Atom tests
-
- @Test
- public void testGetPeopleAtom() throws IOException {
- 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());
- }
-
- @Test
- public void testGetIndirectPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/jane.doe?format=atom");
- checkForGoodAtomResponse(resp);
-
- Document<Entry> doc = resp.getDocument();
- Entry entry = doc.getRoot();
- prettyPrint(entry);
-
- Person expectedJaneDoe = people.get(0);
- assertEquals(expectedJaneDoe.getName().getUnstructured(), entry.getTitle());
- }
-
- @Test
- public void testGetInvalidPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/nobody?format=atom");
- checkForBadResponse(resp);
- }
-
- protected void checkForGoodResponse(ClientResponse response,
- String mimeType) {
- assertNotNull(response);
- assertEquals(ResponseType.SUCCESS, response.getType());
- assertTrue(MimeTypeHelper.isMatch(response.getContentType().toString(),
- mimeType));
- }
-
- protected void checkForGoodJsonResponse(ClientResponse response){
- checkForGoodResponse(response, "application/json");
- }
-
- protected void checkForGoodAtomResponse(ClientResponse response){
- checkForGoodResponse(response, Constants.ATOM_MEDIA_TYPE);
- }
-
- protected void checkForBadResponse(ClientResponse response){
- assertNotNull(response);
- assertEquals(ResponseType.CLIENT_ERROR, response.getType());
- }
-
- private JSONObject getJson(ClientResponse resp) throws IOException,
- JSONException {
- BufferedReader reader = new BufferedReader(resp.getReader());
-
- StringBuffer json = new StringBuffer();
- String line = reader.readLine();
- while (line != null) {
- json.append(line);
- line = reader.readLine();
- }
-
- return new JSONObject(json.toString());
- }
-
- protected void prettyPrint(Base doc) throws IOException {
- WriterFactory writerFactory = abdera.getWriterFactory();
- Writer writer = writerFactory.getWriter("prettyxml");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- writer.writeTo(doc, os);
- logger.fine(os.toString("utf8"));
- }
-
}
Copied: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTests.java (from r658247, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTests.java?p2=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTests.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java&r1=658247&r2=658274&rev=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderLargeTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonPeopleTests.java Tue May 20 08:13:31 2008
@@ -17,7 +17,6 @@
*/
package org.apache.shindig.social.abdera;
-import org.apache.shindig.social.JettyServer;
import org.apache.shindig.social.ResponseItem;
import org.apache.shindig.social.SocialApiTestsGuiceModule;
import org.apache.shindig.social.opensocial.model.ApiCollection;
@@ -25,70 +24,23 @@
import org.apache.shindig.social.opensocial.model.Person;
import org.apache.shindig.social.opensocial.model.Phone;
-import junit.framework.Assert;
-import org.apache.abdera.Abdera;
-import org.apache.abdera.model.Base;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.protocol.Response;
-import org.apache.abdera.protocol.Response.ResponseType;
-import org.apache.abdera.protocol.client.AbderaClient;
-import org.apache.abdera.protocol.client.ClientResponse;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.writer.Writer;
-import org.apache.abdera.writer.WriterFactory;
import org.json.JSONArray;
-import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.logging.Logger;
-public class SocialApiProviderLargeTest extends Assert {
- private static Logger logger =
- Logger.getLogger(SocialApiProviderLargeTest.class.getName());
-
- private static JettyServer server;
- private static Abdera abdera = Abdera.getInstance();
- private static AbderaClient client = new AbderaClient();
-
- private static int JETTY_PORT = 9002;
- private static String BASE = "/social/rest";
- private static String BASEURL = "http://localhost:" + JETTY_PORT + BASE;
-
- private List<Person> people;
- private ClientResponse resp;
-
- @BeforeClass
- public static void setUpOnce() throws Exception {
- try {
- server = new JettyServer();
- server.start(JETTY_PORT, BASE + "/*");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDownOnce() throws Exception {
- server.stop();
- }
+public class RestfulJsonPeopleTests extends AbstractLargeRestfulTests {
@Before
public void setUp() throws Exception {
- people = new ArrayList<Person>();
+ super.setUp();
+
+ List<Person> people = new ArrayList<Person>();
people.add(SocialApiTestsGuiceModule.MockPeopleService.janeDoe);
people.add(SocialApiTestsGuiceModule.MockPeopleService.simpleDoe);
@@ -105,13 +57,9 @@
public void tearDown() throws Exception {
SocialApiTestsGuiceModule.MockPeopleService.setPeople(null);
SocialApiTestsGuiceModule.MockPeopleService.setPerson(null);
- resp.release();
- }
-
- // Json tests
- // TODO: split into sub files
- // Note: most of these aren't annotated as tests because they don't pass yet
+ super.tearDown();
+ }
/**
* Expected response for john.doe's json:
@@ -132,6 +80,8 @@
* { 'address' : 'john.doe@home.bar', 'type' : 'home'}
* ]
* }
+ *
+ * @throws Exception if test encounters an error
*/
@Test
public void testGetPersonJson() throws Exception {
@@ -186,7 +136,10 @@
* {<simple doe>},
* ]
* }
+ *
+ * @throws Exception if test encounters an error
*/
+ @Test
public void testGetPeopleJson() throws Exception {
resp = client.get(BASEURL + "/people/john.doe/@friends");
checkForGoodJsonResponse(resp);
@@ -205,133 +158,4 @@
assertEquals("simple.doe", simpleDoe.getString("id"));
}
- /**
- * Expected response for an activity in json:
- * {
- * 'id' : '1',
- * 'userId' : 'john.doe',
- * 'title' : 'yellow',
- * 'body' : 'what a color!'
- * }
- */
- public void testGetActivityJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self/1");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for a list of activities in json:
- * TODO: Fix the question marks...
- *
- * {
- * "author" : "<???>",
- * "link" : {"rel" : "next", "href" : "<???>"},
- * "totalResults" : 1,
- * "startIndex" : 0
- * "itemsPerPage" : 10
- * "entry" : [
- * {<activity>} // layed out like above
- * ]
- * }
- */
- public void testGetActivitiesJson() throws Exception {
- resp = client.get(BASEURL + "/activities/john.doe/@self");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
- /**
- * Expected response for app data in json:
- *
- * {
- * "entry" : {
- * "jane.doe" : {"count" : 5},
- * "simple.doe" : {"count" : 7},
- * }
- * }
- */
- public void testGetAppDataJson() throws Exception {
- // app id is mocked out
- resp = client.get(BASEURL + "/appdata/john.doe/@friends/appId");
- checkForGoodJsonResponse(resp);
- JSONObject result = getJson(resp);
- }
-
-
- // Atom tests
-
- @Test
- public void testGetPeopleAtom() throws IOException {
- 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());
- }
-
- @Test
- public void testGetIndirectPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/jane.doe?format=atom");
- checkForGoodAtomResponse(resp);
-
- Document<Entry> doc = resp.getDocument();
- Entry entry = doc.getRoot();
- prettyPrint(entry);
-
- Person expectedJaneDoe = people.get(0);
- assertEquals(expectedJaneDoe.getName().getUnstructured(), entry.getTitle());
- }
-
- @Test
- public void testGetInvalidPersonAtom() throws IOException {
- resp = client.get(BASEURL + "/people/john.doe/@all/nobody?format=atom");
- checkForBadResponse(resp);
- }
-
- protected void checkForGoodResponse(ClientResponse response,
- String mimeType) {
- assertNotNull(response);
- assertEquals(ResponseType.SUCCESS, response.getType());
- assertTrue(MimeTypeHelper.isMatch(response.getContentType().toString(),
- mimeType));
- }
-
- protected void checkForGoodJsonResponse(ClientResponse response){
- checkForGoodResponse(response, "application/json");
- }
-
- protected void checkForGoodAtomResponse(ClientResponse response){
- checkForGoodResponse(response, Constants.ATOM_MEDIA_TYPE);
- }
-
- protected void checkForBadResponse(ClientResponse response){
- assertNotNull(response);
- assertEquals(ResponseType.CLIENT_ERROR, response.getType());
- }
-
- private JSONObject getJson(ClientResponse resp) throws IOException,
- JSONException {
- BufferedReader reader = new BufferedReader(resp.getReader());
-
- StringBuffer json = new StringBuffer();
- String line = reader.readLine();
- while (line != null) {
- json.append(line);
- line = reader.readLine();
- }
-
- return new JSONObject(json.toString());
- }
-
- protected void prettyPrint(Base doc) throws IOException {
- WriterFactory writerFactory = abdera.getWriterFactory();
- Writer writer = writerFactory.getWriter("prettyxml");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- writer.writeTo(doc, os);
- logger.fine(os.toString("utf8"));
- }
-
}
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderTestFixture.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderTestFixture.java?rev=658274&r1=658273&r2=658274&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderTestFixture.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/SocialApiProviderTestFixture.java Tue May 20 08:13:31 2008
@@ -19,8 +19,6 @@
import static org.easymock.EasyMock.expect;
-import com.google.inject.Provider;
-
import org.apache.shindig.social.EasyMockTestCase;
import org.apache.abdera.protocol.server.RequestContext;