use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class ReadOnlyTransactionInGetRestApiTest method testGetSiteLinks.
public void testGetSiteLinks() throws Exception {
Response response = sendRequest(new GetRequest(URL_GET_SITE_LINKS), 200);
logResponse(response);
assertEquals(Status.STATUS_OK, response.getStatus());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class RunningActionRestApiTest method testRunningActionGet.
public void testRunningActionGet() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
// If not found, you get a 404
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
// Create one
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionExecuting(rd);
String id = rd.getId();
String instance = Integer.toString(((ActionImpl) rd).getExecutionInstance());
String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
String key1 = "replicationActionExecutor=" + id + "=" + instance;
// Fetch the details of it
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key1), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt, jsonRD.get("startedAt"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key1, jsonRD.get("details"));
// Ensure we didn't get any unexpected data back,
// only the keys we should have done
JSONArray keys = jsonRD.names();
for (int i = 0; i < keys.length(); i++) {
String key = keys.getString(0);
if (key.equals("actionId") || key.equals("actionType") || key.equals("actionInstance") || key.equals("actionNodeRef") || key.equals("startedAt") || key.equals("cancelRequested") || key.equals("details")) {
// All good
} else {
fail("Unexpected key '" + key + "' found in json, raw json is\n" + jsonStr);
}
}
// Add another which is cancelled, check that
// we get the correct, different details for it
rd = replicationService.createReplicationDefinition("Test2", "Testing");
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionExecuting(rd);
actionTrackingService.requestActionCancellation(rd);
String id2 = rd.getId();
String instance2 = Integer.toString(((ActionImpl) rd).getExecutionInstance());
String startedAt2 = ISO8601DateFormat.format(rd.getExecutionStartDate());
String key2 = "replicationActionExecutor=" + id2 + "=" + instance2;
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key2), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id2, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance2, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt2, jsonRD.get("startedAt"));
assertEquals(true, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key2, jsonRD.get("details"));
// Check that the original is unchanged
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key1), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
rd = replicationService.loadReplicationDefinition("Test1");
jsonStr = response.getContentAsString();
jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt, jsonRD.get("startedAt"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key1, jsonRD.get("details"));
// Add one that is pending - has everything except start date
rd = replicationService.createReplicationDefinition("Test3", "Testing");
replicationService.saveReplicationDefinition(rd);
actionTrackingService.recordActionPending(rd);
String id3 = rd.getId();
String instance3 = Integer.toString(((ActionImpl) rd).getExecutionInstance());
String key3 = "replicationActionExecutor=" + id3 + "=" + instance3;
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key3), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
jsonRD = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(jsonRD);
assertEquals(id3, jsonRD.get("actionId"));
assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance3, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(JSONObject.NULL, jsonRD.get("startedAt"));
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
assertEquals("/" + URL_RUNNING_ACTION + key3, jsonRD.get("details"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class NodeArchiveServiceRestApiTest method getArchivedNodes.
/**
* This method makes a REST call to get all the nodes currently in the archive store.
*/
private JSONObject getArchivedNodes() throws IOException, JSONException, UnsupportedEncodingException {
String url = this.getArchiveUrl(nodesOriginalStoreRef);
Response rsp = sendRequest(new GetRequest(url), 200);
JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
return jsonRsp;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class BlogServiceTest method testBlogIntegration.
/**
* You can attach information to the blog container relating
* to integration with external blogs.
* This tests that feature
*/
public void testBlogIntegration() throws Exception {
// Try to fetch the details on a new site
Response response = sendRequest(new GetRequest(URL_BLOG_CORE), 200);
String json = response.getContentAsString();
JSONObject result = new JSONObject(json);
assertEquals("No item in:\n" + json, true, result.has("item"));
JSONObject item = result.getJSONObject("item");
assertEquals("Missing key in: " + item, true, item.has("qnamePath"));
assertEquals("Missing key in: " + item, true, item.has("detailsUrl"));
assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl"));
// Blog properties are empty to start
assertEquals("", item.getString("type"));
assertEquals("", item.getString("name"));
assertEquals("", item.getString("description"));
assertEquals("", item.getString("url"));
assertEquals("", item.getString("username"));
assertEquals("", item.getString("password"));
// Have it updated
JSONObject blog = new JSONObject();
blog.put("blogType", "wordpress");
blog.put("blogName", "A Blog!");
blog.put("username", "guest");
sendRequest(new PutRequest(URL_BLOG_CORE, blog.toString(), "application/json"), Status.STATUS_OK);
// Check again now
response = sendRequest(new GetRequest(URL_BLOG_CORE), 200);
json = response.getContentAsString();
result = new JSONObject(json);
assertEquals("No item in:\n" + json, true, result.has("item"));
item = result.getJSONObject("item");
assertEquals("Missing key in: " + item, true, item.has("qnamePath"));
assertEquals("Missing key in: " + item, true, item.has("detailsUrl"));
assertEquals("Missing key in: " + item, true, item.has("blogPostsUrl"));
// Blog properties should now be set
assertEquals("wordpress", item.getString("type"));
assertEquals("A Blog!", item.getString("name"));
assertEquals("", item.getString("description"));
assertEquals("", item.getString("url"));
assertEquals("guest", item.getString("username"));
assertEquals("", item.getString("password"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class SubscriptionServiceRestApiTest method getFollowingCount.
protected int getFollowingCount(String user) throws Exception {
String url = getUrl(URL_FOLLOWING_COUNT, user);
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
JSONObject resultObject = new JSONObject(response.getContentAsString());
assertTrue(resultObject.has("count"));
return resultObject.getInt("count");
}
Aggregations