Search in sources :

Example 71 with Response

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

the class RuleServiceTest method testQueueAction.

public void testQueueAction() throws Exception {
    String url = formateQueueActionUrl(false);
    JSONObject copyAction = buildCopyAction(testWorkNodeRef);
    copyAction.put("actionedUponNode", testNodeRef);
    // execute before response (should be successful)
    Response successResponse = sendRequest(new PostRequest(url, copyAction.toString(), "application/json"), 200);
    JSONObject successResult = new JSONObject(successResponse.getContentAsString());
    assertNotNull(successResult);
    assertTrue(successResult.has("data"));
    JSONObject successData = successResult.getJSONObject("data");
    assertTrue(successData.has("status"));
    assertEquals("success", successData.getString("status"));
    assertTrue(successData.has("actionedUponNode"));
    assertFalse(successData.has("exception"));
    assertTrue(successData.has("action"));
    // execute before response (should fail)
    sendRequest(new PostRequest(url, copyAction.toString(), "application/json"), 500);
    // execute after response (should fail but error should not present in response)
    String asyncUrl = formateQueueActionUrl(true);
    Response response = sendRequest(new PostRequest(asyncUrl, copyAction.toString(), "application/json"), 200);
    // wait while action executed
    Thread.sleep(1000);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertNotNull(result);
    assertTrue(result.has("data"));
    JSONObject data = result.getJSONObject("data");
    assertTrue(data.has("status"));
    assertEquals("queued", data.getString("status"));
    assertTrue(data.has("actionedUponNode"));
    assertFalse(data.has("exception"));
    assertTrue(data.has("action"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 72 with Response

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

the class AbstractSiteServiceTest method createSite.

protected JSONObject createSite(String sitePreset, String shortName, String title, String description, SiteVisibility visibility, int expectedStatus) throws Exception {
    JSONObject site = new JSONObject();
    site.put("sitePreset", sitePreset);
    site.put("shortName", shortName);
    site.put("title", title);
    site.put("description", description);
    site.put("visibility", visibility.toString());
    Response response = sendRequest(new PostRequest(URL_SITES, site.toString(), "application/json"), expectedStatus);
    this.createdSites.add(shortName);
    return new JSONObject(response.getContentAsString());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 73 with Response

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

the class SiteExportServiceTest method testExportSiteWithMutipleUsers.

public void testExportSiteWithMutipleUsers() throws Exception {
    // Create a site
    String shortName = GUID.generate();
    createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    // add a user and a person as members
    addSiteMember(USER_FROM_LDAP, shortName);
    addSiteMember(USER_ONE, shortName);
    // Export site
    Response response = sendRequest(new GetRequest(getExportUrl(shortName)), 200);
    // check exported files
    List<String> entries = getEntries(new ZipInputStream(new ByteArrayInputStream(response.getContentAsByteArray())));
    assertFalse(entries.contains("No_Users_In_Site.txt"));
    assertFalse(entries.contains("No_Persons_In_Site.txt"));
    assertTrue(entries.contains("People.acp"));
    assertTrue(entries.contains(shortName + "-people.xml"));
    assertTrue(entries.contains("Users.acp"));
    assertTrue(entries.contains(shortName + "-users.xml"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 74 with Response

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

the class SiteServiceTest method testListInvitation.

/**
 * Detailed Test of List Invitation Web Script.
 * @throws Exception
 */
public void testListInvitation() throws Exception {
    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, 201);
    /**
     * search by user - negative test 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 invitation
     */
    {
        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", 1, data.length());
        JSONObject first = data.getJSONObject(0);
        assertEquals("userid is wrong", first.getString("inviteeUserName"), USER_TWO);
    }
    /**
     * search by type - should find two moderated invitations
     */
    {
        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");
        assertEquals("two moderated invitations not found", data.length(), 2);
    }
    // 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);
        JSONObject first = data.getJSONObject(0);
        assertEquals("first userid is wrong", first.getString("inviteeUserName"), USER_TWO);
        assertEquals("type is wrong", first.getString("invitationType"), "MODERATED");
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 75 with Response

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

the class SiteServiceTest method testChangeMembershipRoleAsSiteAdmin.

public void testChangeMembershipRoleAsSiteAdmin() throws Exception {
    // 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 person = new JSONObject();
    person.put("userName", USER_TWO);
    membership.put("person", person);
    // Post the membership
    Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
    JSONObject jsonObj = new JSONObject(response.getContentAsString());
    // Check the result
    assertEquals(SiteModel.SITE_CONSUMER, jsonObj.get("role"));
    assertEquals(USER_TWO, jsonObj.getJSONObject("authority").get("userName"));
    // try to change the user role as user3
    this.authenticationComponent.setCurrentUser(USER_THREE);
    membership.put("role", SiteModel.SITE_COLLABORATOR);
    sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 500);
    assertEquals("User's role should not have been changed.", SiteModel.SITE_CONSUMER.toString(), siteService.getMembersRole(shortName, USER_TWO));
    // set the current user as site-admin
    this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
    response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
    jsonObj = new JSONObject(response.getContentAsString());
    // Check the result
    assertEquals(SiteModel.SITE_COLLABORATOR, jsonObj.get("role"));
    assertEquals(USER_TWO, jsonObj.getJSONObject("authority").get("userName"));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Aggregations

Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)281 JSONObject (org.json.JSONObject)228 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)171 JSONArray (org.json.JSONArray)116 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)84 JSONTokener (org.json.JSONTokener)39 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)37 NodeRef (org.alfresco.service.cmr.repository.NodeRef)34 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)32 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)16 TestWebScriptServer (org.springframework.extensions.webscripts.TestWebScriptServer)16 Serializable (java.io.Serializable)14 QName (org.alfresco.service.namespace.QName)14 Date (java.util.Date)13 JSONStringer (org.json.JSONStringer)13 UserTransaction (javax.transaction.UserTransaction)12 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)12 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)11 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)11