use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class InviteServiceTest method testGetInvitationStatus.
public void testGetInvitationStatus() throws Exception {
for (String invitationStatus : new String[] { InviteInfo.INVITATION_STATUS_REJECTED, InviteInfo.INVITATION_STATUS_ACCEPTED }) {
// inviter starts invite (sends out invitation)
JSONObject result = startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1, Status.STATUS_CREATED);
JSONObject data = result.getJSONObject("data");
String inviteId = data.getString("inviteId");
String inviteTicket = data.getString("inviteTicket");
String inviteeUserName = data.getString("inviteeUserName");
// get inviteInfo about invitation
result = getInviteInfo(inviteId, inviteTicket, inviteeUserName);
// get status of current invitation
String status = result.getJSONObject("invite").getString("invitationStatus");
// it should be peding
assertEquals(status, InviteInfo.INVITATION_STATUS_PENDING);
// accept/reject invitation
if (invitationStatus.equals(InviteInfo.INVITATION_STATUS_REJECTED)) {
rejectInvite(inviteId, inviteTicket, Status.STATUS_OK);
} else if (invitationStatus.equals(InviteInfo.INVITATION_STATUS_ACCEPTED)) {
// Invitee accepts invitation to a Site from Inviter
String acceptInviteUrl = URL_INVITE + "/" + inviteId + "/" + inviteTicket + "/accept";
sendRequest(new PutRequest(acceptInviteUrl, (byte[]) null, null), Status.STATUS_OK);
} else {
fail();
}
// get inviteInfo about invitation
result = getInviteInfo(inviteId, inviteTicket, inviteeUserName);
status = result.getJSONObject("invite").getString("invitationStatus");
// invitation status should be accepted/rejected
assertEquals(status, invitationStatus);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class ReplicationRestApiTest method testReplicationDefinitionPut.
public void testReplicationDefinitionPut() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new PutRequest(URL_DEFINITION + "MadeUp", "", JSON), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new PutRequest(URL_DEFINITION + "MadeUp", "", JSON), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
// Ensure there aren't any to start with
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
assertEquals(0, replicationService.loadReplicationDefinitions().size());
// You need to specify a real definition
response = sendRequest(new PutRequest(URL_DEFINITION + "MadeUp", "", JSON), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
// Create one, and change it
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test", "Testing");
replicationService.saveReplicationDefinition(rd);
response = sendRequest(new PutRequest(URL_DEFINITION + "Test", "{}", JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
// Check we got the right information back on it
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Test", json.get("name"));
assertEquals("Testing", json.get("description"));
assertEquals("New", json.get("status"));
assertEquals(JSONObject.NULL, json.get("startedAt"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals(JSONObject.NULL, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// Ensure we didn't get any unexpected data back
JSONArray keys = json.names();
for (int i = 0; i < keys.length(); i++) {
String key = keys.getString(0);
if (key.equals("name") || key.equals("description") || key.equals("status") || key.equals("startedAt") || key.equals("endedAt") || key.equals("failureMessage") || key.equals("executionDetails") || key.equals("payload") || key.equals("transferLocalReport") || key.equals("transferRemoteReport") || key.equals("enabled") || key.equals("targetName") || key.equals("schedule")) {
// All good
} else {
fail("Unexpected key '" + key + "' found in json, raw json is\n" + jsonStr);
}
}
// Change some details, and see them updated in both
// the JSON and on the object in the repo
json = new JSONObject();
json.put("description", "Updated Description");
json.put("enabled", false);
response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Test", json.get("name"));
assertEquals("Updated Description", json.get("description"));
assertEquals("New", json.get("status"));
assertEquals(JSONObject.NULL, json.get("startedAt"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals(JSONObject.NULL, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(false, json.get("enabled"));
assertEquals(JSONObject.NULL, json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
rd = replicationService.loadReplicationDefinition("Test");
assertEquals("Test", rd.getReplicationName());
assertEquals("Updated Description", rd.getDescription());
assertEquals(ActionStatus.New, rd.getExecutionStatus());
assertEquals(null, rd.getExecutionStartDate());
assertEquals(null, rd.getExecutionEndDate());
assertEquals(null, rd.getExecutionFailureMessage());
assertEquals(null, rd.getLocalTransferReport());
assertEquals(null, rd.getRemoteTransferReport());
assertEquals(null, rd.getTargetName());
assertEquals(0, rd.getPayload().size());
assertEquals(false, rd.isEnabled());
// Create a 2nd definition, and check that the correct
// one gets updated
rd = replicationService.createReplicationDefinition("Test2", "Testing2");
rd.setTargetName("Target");
replicationService.saveReplicationDefinition(rd);
json = new JSONObject();
json.put("description", "Updated Description 2");
json.put("enabled", false);
response = sendRequest(new PutRequest(URL_DEFINITION + "Test2", json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
// Check the response we got
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Test2", json.get("name"));
assertEquals("Updated Description 2", json.get("description"));
assertEquals("New", json.get("status"));
assertEquals(JSONObject.NULL, json.get("startedAt"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals(JSONObject.NULL, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(false, json.get("enabled"));
assertEquals("Target", json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// Check the 1st definition
rd = replicationService.loadReplicationDefinition("Test");
assertEquals("Test", rd.getReplicationName());
assertEquals("Updated Description", rd.getDescription());
assertEquals(ActionStatus.New, rd.getExecutionStatus());
assertEquals(null, rd.getExecutionStartDate());
assertEquals(null, rd.getExecutionEndDate());
assertEquals(null, rd.getExecutionFailureMessage());
assertEquals(null, rd.getLocalTransferReport());
assertEquals(null, rd.getRemoteTransferReport());
assertEquals(null, rd.getTargetName());
assertEquals(0, rd.getPayload().size());
assertEquals(false, rd.isEnabled());
// Check the 2nd definition
rd = replicationService.loadReplicationDefinition("Test2");
assertEquals("Test2", rd.getReplicationName());
assertEquals("Updated Description 2", rd.getDescription());
assertEquals(ActionStatus.New, rd.getExecutionStatus());
assertEquals(null, rd.getExecutionStartDate());
assertEquals(null, rd.getExecutionEndDate());
assertEquals(null, rd.getExecutionFailureMessage());
assertEquals(null, rd.getLocalTransferReport());
assertEquals(null, rd.getRemoteTransferReport());
assertEquals("Target", rd.getTargetName());
assertEquals(0, rd.getPayload().size());
assertEquals(false, rd.isEnabled());
// Mark it as running, then change some details and
// see it change as expected
rd = replicationService.loadReplicationDefinition("Test");
actionTrackingService.recordActionExecuting(rd);
replicationService.saveReplicationDefinition(rd);
String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
String actionId = rd.getId();
int instanceId = ((ActionImpl) rd).getExecutionInstance();
json = new JSONObject();
json.put("enabled", true);
json.put("targetName", "Another Target");
response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Test", json.get("name"));
assertEquals("Updated Description", json.get("description"));
assertEquals("Running", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals("Another Target", json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// Change the payload, and see the right information in
// the response JSON for it
JSONArray payloadRefs = new JSONArray();
payloadRefs.put(repositoryHelper.getCompanyHome().toString());
payloadRefs.put(dataDictionary.toString());
json = new JSONObject();
json.put("payload", payloadRefs);
response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Test", json.get("name"));
assertEquals("Updated Description", json.get("description"));
assertEquals("Running", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals("Another Target", json.get("targetName"));
assertEquals(2, json.getJSONArray("payload").length());
JSONObject payload = json.getJSONArray("payload").getJSONObject(0);
assertEquals(repositoryHelper.getCompanyHome().toString(), payload.get("nodeRef"));
assertEquals(true, payload.get("isFolder"));
assertEquals("Company Home", payload.get("name"));
assertEquals("/Company Home", payload.get("path"));
payload = json.getJSONArray("payload").getJSONObject(1);
assertEquals(dataDictionary.toString(), payload.get("nodeRef"));
assertEquals(true, payload.get("isFolder"));
assertEquals("Data Dictionary", payload.get("name"));
assertEquals("/Company Home/Data Dictionary", payload.get("path"));
// Remove the payload again
json = new JSONObject();
payloadRefs = new JSONArray();
json.put("payload", payloadRefs);
response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Test", json.get("name"));
assertEquals("Updated Description", json.get("description"));
assertEquals("Running", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals("Another Target", json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// Rename to a taken name, won't be allowed
json = new JSONObject();
json.put("name", "Test2");
response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_BAD_REQUEST);
assertEquals(Status.STATUS_BAD_REQUEST, response.getStatus());
// Rename to a spare name, will be updated
json = new JSONObject();
json.put("name", "Renamed");
response = sendRequest(new PutRequest(URL_DEFINITION + "Test", json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Renamed", json.get("name"));
assertEquals("Updated Description", json.get("description"));
assertEquals("Running", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals("Another Target", json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
// Check the repo too
assertEquals(null, replicationService.loadReplicationDefinition("Test"));
assertNotNull(replicationService.loadReplicationDefinition("Renamed"));
// Rename can both rename + change details
json = new JSONObject();
json.put("name", "Renamed Again");
json.put("description", "Was Renamed");
json.put("targetName", "New Target");
response = sendRequest(new PutRequest(URL_DEFINITION + "Renamed", json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals("Renamed Again", json.get("name"));
assertEquals("Was Renamed", json.get("description"));
assertEquals("Running", json.get("status"));
assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601"));
assertEquals(JSONObject.NULL, json.get("endedAt"));
assertEquals(JSONObject.NULL, json.get("failureMessage"));
assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor=" + actionId + "=" + instanceId, json.get("executionDetails"));
assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
assertEquals(true, json.get("enabled"));
assertEquals("New Target", json.get("targetName"));
assertEquals(0, json.getJSONArray("payload").length());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest in project alfresco-remote-api by Alfresco.
the class RuleServiceTest method testUpdateRule.
public void testUpdateRule() throws Exception {
JSONObject jsonRule = createRule(testNodeRef);
String ruleId = jsonRule.getJSONObject("data").getString("id");
Response getResponse = sendRequest(new GetRequest(formateRuleUrl(testNodeRef, ruleId)), 200);
JSONObject before = new JSONObject(getResponse.getContentAsString());
// do some changes
before.put("description", "this is modified description for test_rule");
// do some changes for action object
JSONObject beforeAction = before.getJSONObject("action");
// no changes for actions list
beforeAction.remove("actions");
// clear conditions
beforeAction.put("conditions", new JSONArray());
Response putResponse = sendRequest(new PutRequest(formateRuleUrl(testNodeRef, ruleId), before.toString(), "application/json"), 200);
JSONObject after = new JSONObject(putResponse.getContentAsString());
// sent and retrieved objects should be the same (except ids and urls)
// this means that all changes was saved
checkUpdatedRule(before, after);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest 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"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest 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"));
}
Aggregations