Search in sources :

Example 46 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project records-management by Alfresco.

the class DispositionRestApiTest method testPostDispositionAction.

public void testPostDispositionAction() throws Exception {
    // create a new recordCategory node in the recordSeries and then get
    // the disposition schedule
    NodeRef newRecordCategory = filePlanService.createRecordCategory(recordSeries, GUID.generate());
    dispositionService.createDispositionSchedule(newRecordCategory, null);
    String categoryNodeUrl = newRecordCategory.toString().replace("://", "/");
    String requestUrl = MessageFormat.format(POST_ACTIONDEF_URL_FORMAT, categoryNodeUrl);
    // Construct the JSON request.
    String name = "destroy";
    String desc = "Destroy this record after 5 years";
    String period = "year|5";
    String periodProperty = "rma:cutOffDate";
    boolean eligibleOnFirstCompleteEvent = true;
    JSONObject jsonPostData = new JSONObject();
    jsonPostData.put("name", name);
    jsonPostData.put("description", desc);
    jsonPostData.put("period", period);
    jsonPostData.put("location", "my location");
    jsonPostData.put("periodProperty", periodProperty);
    jsonPostData.put("eligibleOnFirstCompleteEvent", eligibleOnFirstCompleteEvent);
    JSONArray events = new JSONArray();
    events.put("superseded");
    events.put("no_longer_needed");
    jsonPostData.put("events", events);
    // Submit the JSON request.
    String jsonPostString = jsonPostData.toString();
    Response rsp = sendRequest(new PostRequest(requestUrl, jsonPostString, APPLICATION_JSON), 200);
    // check the returned data is what was expected
    JSONObject jsonResponse = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    JSONObject dataObj = jsonResponse.getJSONObject("data");
    JSONObject rootDataObject = (JSONObject) dataObj;
    assertNotNull(rootDataObject.getString("id"));
    assertNotNull(rootDataObject.getString("url"));
    assertEquals(0, rootDataObject.getInt("index"));
    assertEquals(name, rootDataObject.getString("name"));
    assertEquals("Destroy", rootDataObject.getString("label"));
    assertEquals(desc, rootDataObject.getString("description"));
    assertEquals(period, rootDataObject.getString("period"));
    assertEquals("my location", rootDataObject.getString("location"));
    assertEquals(periodProperty, rootDataObject.getString("periodProperty"));
    assertTrue(rootDataObject.getBoolean("eligibleOnFirstCompleteEvent"));
    events = rootDataObject.getJSONArray("events");
    assertNotNull(events);
    assertEquals(2, events.length());
    assertEquals("superseded", events.get(0));
    assertEquals("no_longer_needed", events.get(1));
    // test the minimum amount of data required to create an action definition
    jsonPostData = new JSONObject();
    jsonPostData.put("name", name);
    jsonPostString = jsonPostData.toString();
    rsp = sendRequest(new PostRequest(requestUrl, jsonPostString, APPLICATION_JSON), 200);
    // check the returned data is what was expected
    jsonResponse = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    dataObj = jsonResponse.getJSONObject("data");
    assertNotNull(rootDataObject.getString("id"));
    assertNotNull(rootDataObject.getString("url"));
    assertEquals(0, rootDataObject.getInt("index"));
    assertEquals(name, dataObj.getString("name"));
    assertEquals("none|0", dataObj.getString("period"));
    assertFalse(dataObj.has("description"));
    assertFalse(dataObj.has("periodProperty"));
    assertFalse(dataObj.has("events"));
    assertTrue(dataObj.getBoolean("eligibleOnFirstCompleteEvent"));
    // negative test to ensure not supplying mandatory data results in an error
    jsonPostData = new JSONObject();
    jsonPostData.put("description", desc);
    jsonPostData.put("period", period);
    jsonPostString = jsonPostData.toString();
    sendRequest(new PostRequest(requestUrl, jsonPostString, APPLICATION_JSON), 400);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 47 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project records-management by Alfresco.

the class EventRestApiTest method testPostEvents.

public void testPostEvents() throws Exception {
    String eventName = GUID.generate();
    JSONObject obj = new JSONObject();
    obj.put(KEY_EVENT_NAME, eventName);
    obj.put(KEY_EVENT_DISPLAY_LABEL, DISPLAY_LABEL);
    obj.put(KEY_EVENT_TYPE, EVENT_TYPE);
    Response rsp = sendRequest(new PostRequest(GET_EVENTS_URL, obj.toString(), APPLICATION_JSON), 200);
    try {
        String rspContent = rsp.getContentAsString();
        JSONObject resultObj = new JSONObject(rspContent);
        JSONObject eventObj = resultObj.getJSONObject("data");
        assertNotNull(eventObj);
        assertEquals(eventName, eventObj.get(KEY_EVENT_NAME));
        assertEquals(DISPLAY_LABEL, eventObj.get(KEY_EVENT_DISPLAY_LABEL));
        assertEquals(EVENT_TYPE, eventObj.get(KEY_EVENT_TYPE));
    } finally {
        eventService.removeEvent(eventName);
    }
    // Test with no event name set
    obj = new JSONObject();
    obj.put(KEY_EVENT_DISPLAY_LABEL, DISPLAY_LABEL);
    obj.put(KEY_EVENT_TYPE, EVENT_TYPE);
    rsp = sendRequest(new PostRequest(GET_EVENTS_URL, obj.toString(), APPLICATION_JSON), 200);
    try {
        String rspContent = rsp.getContentAsString();
        JSONObject resultObj = new JSONObject(rspContent);
        JSONObject eventObj = resultObj.getJSONObject("data");
        assertNotNull(eventObj);
        assertNotNull(eventObj.get(KEY_EVENT_NAME));
        assertEquals(DISPLAY_LABEL, eventObj.get(KEY_EVENT_DISPLAY_LABEL));
        assertEquals(EVENT_TYPE, eventObj.get(KEY_EVENT_TYPE));
        eventName = eventObj.getString(KEY_EVENT_NAME);
    } finally {
        eventService.removeEvent(eventName);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 48 with PostRequest

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

the class RemoteFileFolderLoaderTest method testLoad_default_default.

/**
 * Load with defaults
 */
@SuppressWarnings("unchecked")
public void testLoad_default_default() throws Exception {
    JSONObject body = new JSONObject();
    body.put(FileFolderLoaderPost.KEY_FOLDER_PATH, loadHomePath);
    Response response = sendRequest(new PostRequest(URL, body.toString(), "application/json"), Status.STATUS_OK, "bmarley");
    assertEquals("{\"count\":100}", response.getContentAsString());
    // Check file(s)
    assertEquals(100, nodeService.countChildAssocs(loadHomeNodeRef, true));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.simple.JSONObject)

Example 49 with PostRequest

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

the class FeedControlTest method createFeedControl.

protected void createFeedControl(String siteId, String appToolId) throws Exception {
    // Set (create) feed control
    JSONObject feedControl = new JSONObject();
    feedControl.put("siteId", siteId);
    feedControl.put("appToolId", appToolId);
    int expectedStatus = 200;
    Response response = sendRequest(new PostRequest(URL_CONTROL, feedControl.toString(), "application/json"), expectedStatus);
    if (logger.isDebugEnabled()) {
        logger.debug(response);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 50 with PostRequest

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

the class SubscriptionServiceRestApiTest method unfollow.

protected void unfollow(String user1, String user2) throws Exception {
    JSONArray jsonUsers = new JSONArray();
    jsonUsers.put(user2);
    String url = getUrl(URL_UNFOLLOW, user1);
    sendRequest(new PostRequest(url, jsonUsers.toString(), "application/json"), Status.STATUS_NO_CONTENT);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONArray(org.json.JSONArray)

Aggregations

PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)110 JSONObject (org.json.JSONObject)90 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)84 JSONArray (org.json.JSONArray)28 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)25 JSONTokener (org.json.JSONTokener)23 NodeRef (org.alfresco.service.cmr.repository.NodeRef)22 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)14 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)10 JSONStringer (org.json.JSONStringer)9 File (java.io.File)8 ZipFile (java.util.zip.ZipFile)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 JSONObject (org.json.simple.JSONObject)5 IOException (java.io.IOException)4 UserTransaction (javax.transaction.UserTransaction)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 JSONException (org.json.JSONException)4 Serializable (java.io.Serializable)3