Search in sources :

Example 51 with GetRequest

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

the class SiteServiceTest method testDeleteMembership.

public void testDeleteMembership() 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
    sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
    // Delete the membership
    sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
    // Check that the membership has been deleted
    sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 404);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 52 with GetRequest

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

the class SiteServiceTest method testGetAllSitesAsSiteAdmin.

public void testGetAllSitesAsSiteAdmin() throws Exception {
    String user1PublicSiteName = GUID.generate();
    String user1ModeratedSiteName = GUID.generate();
    String user1PrivateSiteName = GUID.generate();
    String user2PrivateSiteName = GUID.generate();
    // USER_ONE public site
    JSONObject result = createSite("myPreset", user1PublicSiteName, "u1PublicSite", "myDescription", SiteVisibility.PUBLIC, 200);
    assertEquals(SiteVisibility.PUBLIC.toString(), result.get("visibility"));
    // USER_ONE moderated site
    result = createSite("myPreset", user1ModeratedSiteName, "u1ModeratedSite", "myDescription", SiteVisibility.MODERATED, 200);
    assertEquals(SiteVisibility.MODERATED.toString(), result.get("visibility"));
    // USER_ONE private site
    result = createSite("myPreset", user1PrivateSiteName, "u1PrivateSite", "myDescription", SiteVisibility.PRIVATE, 200);
    assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
    this.authenticationComponent.setCurrentUser(USER_TWO);
    // USER_TWO private site
    result = createSite("myPreset", user2PrivateSiteName, "u2PrivateSite", "myDescription", SiteVisibility.PRIVATE, 200);
    assertEquals(SiteVisibility.PRIVATE.toString(), result.get("visibility"));
    this.authenticationComponent.setCurrentUser(USER_THREE);
    // Note: we'll get 404 rather than 403
    sendRequest(new GetRequest(URL_SITES_ADMIN), 404);
    this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
    Response response = sendRequest(new GetRequest(URL_SITES_ADMIN), 200);
    JSONObject jsonObject = new JSONObject(response.getContentAsString());
    JSONArray jsonArray = jsonObject.getJSONObject("list").getJSONArray("entries");
    int siteAdminGetSitesSize = jsonArray.length();
    // SiteAdmin can see the public, moderated and private sites
    assertTrue("result too small", siteAdminGetSitesSize >= 4);
    assertTrue("Site admin can access all the sites (PUBLIC | MODERATED | PRIVATE).", canSeePrivateSites(jsonArray));
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    response = sendRequest(new GetRequest(URL_SITES_ADMIN), 200);
    jsonObject = new JSONObject(response.getContentAsString());
    jsonArray = jsonObject.getJSONObject("list").getJSONArray("entries");
    ;
    assertEquals("SiteAdmin must have access to the same sites as the super Admin.", siteAdminGetSitesSize, jsonArray.length());
}
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 53 with GetRequest

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

the class DictionaryRestApiTest method testGetAssociationDef.

public void testGetAssociationDef() throws Exception {
    GetRequest req = new GetRequest(URL_SITES + "/cm_person/association/cm_avatar");
    Response response = sendRequest(req, 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertEquals(200, response.getStatus());
    validateAssociationDef(result);
    // wrong data
    response = sendRequest(new GetRequest(URL_SITES + "/cm_personalbe/association/cms_avatarsara"), 404);
    assertEquals(404, response.getStatus());
    // ask for an invalid association, which returns a null array
    response = sendRequest(new GetRequest(URL_SITES + "/cm_person/association/cm_atari"), 200);
    // change to return 404
    result = new JSONObject(response.getContentAsString());
    assertEquals(0, result.length());
    assertEquals(200, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 54 with GetRequest

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

the class DictionaryRestApiTest method validatePropertiesConformity.

private void validatePropertiesConformity(JSONArray classDefs) throws Exception {
    final int itemsToTest = 10;
    for (int i = 0; (i < itemsToTest) && (i < classDefs.length()); ++i) {
        JSONObject classDef1 = classDefs.getJSONObject(i);
        JSONArray propertyNames1 = classDef1.getJSONObject("properties").names();
        // properties of class obtained by api/classes
        List<String> propertyValues1 = Collections.emptyList();
        if (propertyNames1 != null) {
            propertyValues1 = new ArrayList<String>(propertyNames1.length());
            for (int j = 0; j < propertyNames1.length(); j++) {
                propertyValues1.add(propertyNames1.getString(j));
            }
        }
        String classUrl = classDef1.getString("url");
        assertTrue(classUrl.contains(URL_SITES));
        Response responseFromGetClassDef = sendRequest(new GetRequest(classUrl), 200);
        JSONObject classDef2 = new JSONObject(responseFromGetClassDef.getContentAsString());
        assertTrue(classDef2.length() > 0);
        assertEquals(200, responseFromGetClassDef.getStatus());
        assertEquals(classDef1.getString("name"), classDef2.getString("name"));
        JSONArray propertyNames2 = classDef2.getJSONObject("properties").names();
        // properties of class obtained by api/classes/class
        List<String> propertyValues2 = Collections.emptyList();
        if (propertyNames2 != null) {
            propertyValues2 = new ArrayList<String>(propertyNames2.length());
            for (int j = 0; j < propertyNames2.length(); j++) {
                propertyValues2.add(propertyNames2.getString(j));
            }
        }
        Response responseFromGetPropertiesDef = sendRequest(new GetRequest(classUrl + "/properties"), 200);
        JSONArray propertiesDefs = new JSONArray(responseFromGetPropertiesDef.getContentAsString());
        assertEquals(200, responseFromGetClassDef.getStatus());
        // properties of class obtained by api/classes/class/properties
        List<String> propertyValues3 = new ArrayList<String>(propertiesDefs.length());
        for (int j = 0; j < propertiesDefs.length(); j++) {
            propertyValues3.add(propertiesDefs.getJSONObject(j).getString("name"));
        }
        assertEquivalenceProperties(propertyValues1, propertyValues2);
        assertEquivalenceProperties(propertyValues2, propertyValues3);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList)

Example 55 with GetRequest

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

the class DictionaryRestApiTest method testGetClassDetail.

public void testGetClassDetail() throws Exception {
    GetRequest req = new GetRequest(URL_SITES + "/cm_thumbnailed");
    Response response = sendRequest(req, 200);
    JSONObject result = new JSONObject(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    assertEquals(200, response.getStatus());
    validateAspectClass(result);
    req = new GetRequest(URL_SITES + "/cm_cmobject");
    response = sendRequest(req, 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals(result.length() > 0, true);
    assertEquals(200, response.getStatus());
    validateTypeClass(result);
    response = sendRequest(new GetRequest("/api/classes/cm_hi"), 404);
    assertEquals(404, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) 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