Search in sources :

Example 46 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.

the class SiteServiceTest method testInvitationSanityCheck.

/**
 * End to end sanity check of web site invitation.
 *
 * Nominated and Moderated invitations.
 *
 * @throws Exception
 */
public void testInvitationSanityCheck() throws Exception {
    String shortName = GUID.generate();
    String secondShortName = GUID.generate();
    createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    createSite("myPreset", secondShortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    String inviteComments = "Please sir, let me in";
    String userName = USER_TWO;
    String roleName = SiteModel.SITE_CONSUMER;
    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 new moderated invitation
    String moderatedId = createModeratedInvitation(secondShortName, inviteComments, userName, roleName);
    // Get the moderated invitation
    sendRequest(new GetRequest(URL_SITES + "/" + secondShortName + "/invitations/" + moderatedId), 200);
    // search for the moderated invitation
    sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=" + userName), 200);
    // Create a nominated invitation
    String nominatedId = createNominatedInvitation(shortName, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL, 201);
    // Search for all invitations on this site
    sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations"), 200);
    // cancel the moderated invitation
    sendRequest(new DeleteRequest(URL_SITES + "/" + secondShortName + "/invitations/" + moderatedId), 200);
}
Also used : GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 47 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.

the class SiteServiceTest method testUpdateSite.

public void testUpdateSite() throws Exception {
    // Create a site
    String shortName = GUID.generate();
    JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    // Update the site
    result.put("title", "abs123abc");
    result.put("description", "123abc123");
    result.put("visibility", SiteVisibility.PRIVATE.toString());
    Response response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, result.toString(), "application/json"), 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals("abs123abc", result.get("title"));
    assertEquals("123abc123", result.get("description"));
    assertFalse(result.getBoolean("isPublic"));
    assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
    // Try and get the site and double check it's changed
    response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals("abs123abc", result.get("title"));
    assertEquals("123abc123", result.get("description"));
    assertFalse(result.getBoolean("isPublic"));
    assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 48 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.

the class SiteServiceTest method testGetMemberInfo.

public void testGetMemberInfo() throws Exception {
    String testGroup = "SiteServiceTestGroupA";
    String testGroupName = "GROUP_" + testGroup;
    if (!authorityService.authorityExists(testGroupName)) {
        this.authenticationComponent.setSystemUserAsCurrentUser();
        testGroupName = authorityService.createAuthority(AuthorityType.GROUP, testGroup, testGroup, authorityService.getDefaultZones());
    }
    if (!authorityService.getContainedAuthorities(AuthorityType.USER, testGroupName, true).contains(USER_TWO)) {
        this.authenticationComponent.setSystemUserAsCurrentUser();
        this.authorityService.addAuthority(testGroupName, USER_TWO);
    }
    this.authenticationComponent.setCurrentUser(USER_ONE);
    // CRUD a membership group for a web site
    // Create a site
    String shortName = GUID.generate();
    createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    // Build the JSON membership object
    JSONObject membership = new JSONObject();
    membership.put("role", SiteModel.SITE_CONSUMER);
    JSONObject group = new JSONObject();
    group.put("fullName", testGroupName);
    membership.put("group", group);
    // Create a new group membership
    {
        Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
        JSONObject newMember = new JSONObject(response.getContentAsString());
        // Validate the return value
        assertEquals("role not correct", SiteModel.SITE_CONSUMER, newMember.getString("role"));
        JSONObject newGroup = newMember.getJSONObject("authority");
        assertNotNull(newGroup);
        assertEquals("full name not correct", testGroupName, newGroup.getString("fullName"));
        assertEquals("authorityType not correct", "GROUP", newGroup.getString("authorityType"));
    }
    // Now List memberships
    {
        Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "?authorityType=USER"), 200);
        JSONArray listResult = new JSONArray(response.getContentAsString());
        assertNotNull(listResult);
        assertEquals(2, listResult.length());
        for (int i = 0; i < listResult.length(); i++) {
            JSONObject json = listResult.getJSONObject(i);
            if (USER_ONE.equals(json.getJSONObject("authority").get("fullName"))) {
                assertEquals("user one is Not member of any group", false, json.get("isMemberOfGroup"));
            } else {
                assertEquals("full name not correct", USER_TWO, json.getJSONObject("authority").get("fullName"));
                assertEquals("user two is member of a SiteServiceTestGroupA group", true, json.get("isMemberOfGroup"));
            }
        }
    }
    // cleanup
    if (authorityService.authorityExists(testGroupName)) {
        this.authenticationComponent.setSystemUserAsCurrentUser();
        this.authorityService.deleteAuthority(testGroupName);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 49 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.

the class SiteServiceTest method testDeleteSite.

public void testDeleteSite() throws Exception {
    // Delete non-existent site
    sendRequest(new DeleteRequest(URL_SITES + "/" + "somerandomshortname"), 404);
    // Create a site
    String shortName = GUID.generate();
    createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    // Get the site
    sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
    // Delete the site
    sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200);
    // Get the site
    sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404);
}
Also used : GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 50 with GetRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.

the class SiteServiceTest method testGetSite.

public void testGetSite() throws Exception {
    // Get a site that doesn't exist
    sendRequest(new GetRequest(URL_SITES + "/" + "somerandomshortname"), 404);
    // Create a site and get it
    String shortName = GUID.generate();
    createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
}
Also used : GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Aggregations

GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)182 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)171 JSONObject (org.json.JSONObject)141 JSONArray (org.json.JSONArray)89 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)25 HashMap (java.util.HashMap)23 JSONTokener (org.json.JSONTokener)23 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)21 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Serializable (java.io.Serializable)13 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)13 QName (org.alfresco.service.namespace.QName)13 ArrayList (java.util.ArrayList)12 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)12 Date (java.util.Date)11 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)11 JSONStringer (org.json.JSONStringer)7 Calendar (java.util.Calendar)6 UserTransaction (javax.transaction.UserTransaction)6