From 432105ae933be0f6e3703aa460ff3cc095e91b3a Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Tue, 31 Mar 2009 21:39:21 +0000 Subject: [PATCH] ALFCOM-2687 Implementing the list invitations web script and unit tests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13790 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../site/invitation/invitations.get.desc.xml | 2 + .../site/invitation/invitations.get.json.ftl | 14 ++-- .../web/scripts/site/SiteServiceTest.java | 79 +++++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.desc.xml index ef685ae199..653a7006cb 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.desc.xml @@ -11,6 +11,8 @@
+ Returns a JSON element +
]]> diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.json.ftl index b5a0a68050..7f94a663f4 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.json.ftl @@ -1,9 +1,11 @@ <#-- list / search / invitations --> <#import "../../invitation/invitation.lib.ftl" as invitationLib/> -"data": [ - <#list invitations as invitation> - <@invitationLib.invitationJSON invitation=invitation /> - <#if invitation_has_next>, - - ] +{ + "data": [ + <#list invitations as invitation> + <@invitationLib.invitationJSON invitation=invitation /> + <#if invitation_has_next>, + + ] +} diff --git a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java index 294a7103b2..240899eb04 100644 --- a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java @@ -683,6 +683,85 @@ public class SiteServiceTest extends BaseWebScriptTest String shortName = GUID.generate(); createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200); + String inviteeComments = "Please sir, let $* me in"; + String userName = USER_TWO; + String roleName = SiteModel.SITE_CONSUMER; + String moderatedIdA = createModeratedInvitation(shortName, inviteeComments, userName, roleName); + + String inviteeCommentsB = "Please sir, let $* me in"; + String userNameB = USER_THREE; + String roleNameB = SiteModel.SITE_CONSUMER; + String moderatedIdB = createModeratedInvitation(shortName, inviteeCommentsB, userNameB, roleNameB); + + String inviteeFirstName = "Buffy"; + String inviteeLastName = "Summers"; + String inviteeEmail = "buffy@sunnydale"; + String inviteeUserName = userName; + String serverPath = "http://localhost:8081/share/"; + String acceptURL = "page/accept-invite"; + String rejectURL = "page/reject-invite"; + + // Create a nominated invitation + String nominatedId = createNominatedInvitation(shortName, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL); + /** + * search by user - wombat does not have an invitation + */ + { + Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=wombat"), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("user wombat", data.length(), 0); + + } + /** + * search by user - find USER_TWO's two invitations + */ + { + Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=" + USER_TWO), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("user two invitation not found", data.length(), 2); + + } + + /** + * search by type + */ + + { + Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?invitationType=MODERATED"), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + } + + { + Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?invitationType=NOMINATED"), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + } + // negative test - unknown invitationType + { + + Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?invitationType=Crap"), 500); + JSONObject top = new JSONObject(response.getContentAsString()); + } + + /** + * search by user and type + */ + { + Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=" + USER_TWO + "&invitationType=MODERATED"), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("user two invitation not found", data.length(), 1); + + } + + }