You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2012/05/30 16:57:54 UTC
svn commit: r1344292 - in /incubator/wookie/trunk:
src-tests/org/apache/wookie/tests/functional/ParticipantsControllerTest.java
src/org/apache/wookie/controller/ParticipantsController.java
src/org/apache/wookie/helpers/ParticipantHelper.java
Author: scottbw
Date: Wed May 30 14:57:53 2012
New Revision: 1344292
URL: http://svn.apache.org/viewvc?rev=1344292&view=rev
Log:
Added support for participant role information to REST API - see WOOKIE-66
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ParticipantsControllerTest.java
incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java
incubator/wookie/trunk/src/org/apache/wookie/helpers/ParticipantHelper.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ParticipantsControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ParticipantsControllerTest.java?rev=1344292&r1=1344291&r2=1344292&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ParticipantsControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/ParticipantsControllerTest.java Wed May 30 14:57:53 2012
@@ -23,6 +23,7 @@ import org.apache.commons.httpclient.Htt
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -50,6 +51,19 @@ public class ParticipantsControllerTest
response.indexOf("</identifier>"));
post.releaseConnection();
}
+
+ @AfterClass
+ public static void tearDown() throws HttpException, IOException{
+ HttpClient client = new HttpClient();
+ DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+ post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+ + WIDGET_ID_VALID
+ + "&userid=test&shareddatakey=participantstest&participant_id=80");
+ client.executeMethod(post);
+ int code = post.getStatusCode();
+ assertEquals(200, code);
+ post.releaseConnection();
+ }
/**
* Tests adding and then getting a participant
@@ -294,5 +308,46 @@ public class ParticipantsControllerTest
assertEquals(400, code);
post.releaseConnection();
}
+
+ /**
+ * Tests adding and then getting a participant who is also the Host
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ @Test
+ public void addHost() throws HttpException, IOException {
+
+ //
+ // Create a new participant
+ //
+ HttpClient client = new HttpClient();
+ PostMethod post = new PostMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+ post.setQueryString("api_key="
+ + API_KEY_VALID
+ + "&widgetid="
+ + WIDGET_ID_VALID
+ + "&userid=test&shareddatakey=participantstest&participant_id=80&participant_display_name=bob&participant_role=host&participant_thumbnail_url=http://www.test.org");
+ client.executeMethod(post);
+ int code = post.getStatusCode();
+ assertEquals(201, code);
+ post.releaseConnection();
+
+ //
+ // Now lets GET it to make sure it was added OK
+ //
+ client = new HttpClient();
+ GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
+ get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid="
+ + WIDGET_ID_VALID + "&userid=test&shareddatakey=participantstest");
+ client.executeMethod(get);
+ code = get.getStatusCode();
+ assertEquals(200, code);
+ String response = get.getResponseBodyAsString();
+ assertTrue(response
+ .contains("<participant id=\"80\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" role=\"host\" />"));
+ get.releaseConnection();
+
+ }
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java?rev=1344292&r1=1344291&r2=1344292&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java Wed May 30 14:57:53 2012
@@ -105,6 +105,7 @@ public class ParticipantsController exte
String participantId = request.getParameter("participant_id"); //$NON-NLS-1$
String participantDisplayName = request.getParameter("participant_display_name"); //$NON-NLS-1$
String participantThumbnailUrl = request.getParameter("participant_thumbnail_url"); //$NON-NLS-1$
+ String participantRole = request.getParameter("participant_role");
// Check required params
if (participantId == null || participantId.trim().equals("")) {
@@ -112,7 +113,7 @@ public class ParticipantsController exte
throw new InvalidParametersException();
}
- if (new SharedContext(instance).addParticipant(participantId, participantDisplayName, participantThumbnailUrl)){
+ if (new SharedContext(instance).addParticipant(participantId, participantDisplayName, participantThumbnailUrl, participantRole)){
Notifier.notifyWidgets(session, instance, Notifier.PARTICIPANTS_UPDATED);
_logger.debug("added user to widget instance: " + participantId);
return true;
Modified: incubator/wookie/trunk/src/org/apache/wookie/helpers/ParticipantHelper.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/helpers/ParticipantHelper.java?rev=1344292&r1=1344291&r2=1344292&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/helpers/ParticipantHelper.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/helpers/ParticipantHelper.java Wed May 30 14:57:53 2012
@@ -102,6 +102,7 @@ public class ParticipantHelper {
element.setAttribute("id", participant.getParticipantId());
element.setAttribute("display_name", participant.getParticipantDisplayName());
element.setAttribute("thumbnail_url", participant.getParticipantThumbnailUrl());
+ if (participant.getRole() != null) element.setAttribute("role", participant.getRole());
return element;
}
@@ -116,6 +117,7 @@ public class ParticipantHelper {
obj.put("participant_id", participant.getParticipantId());
obj.put("participant_display_name", participant.getParticipantDisplayName());
obj.put("participant_thumbnail_url", participant.getParticipantThumbnailUrl());
+ if (participant.getRole() != null) obj.put("participant_role", participant.getRole());
return obj;
}