use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class ReplicationRestApiTest method testReplicationDefinitionsNastyNames.
/**
* Test that when creating and working with replication
* definitions with a name that includes "nasty"
* characters, things still work.
* Related to ALF-4610.
*/
public void testReplicationDefinitionsNastyNames() throws Exception {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
Response response;
String jsonStr;
String nastyName = "~!@#$%^&()_+-={}[];";
String nastyNameURL = URLEncoder.encodeUriComponent(nastyName);
// Create
JSONObject json = new JSONObject();
json.put("name", nastyName);
json.put("description", "Nasty Characters");
response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_OK);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals(nastyName, json.get("name"));
assertEquals("Nasty Characters", 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());
// Check it turned up
assertEquals(1, replicationService.loadReplicationDefinitions().size());
assertEquals(nastyName, replicationService.loadReplicationDefinitions().get(0).getReplicationName());
// Fetch the details
response = sendRequest(new GetRequest(URL_DEFINITION + nastyNameURL), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString();
json = new JSONObject(jsonStr).getJSONObject("data");
assertNotNull(json);
assertEquals(nastyName, json.get("name"));
assertEquals("Nasty Characters", json.get("description"));
assertEquals("New", json.get("status"));
// Delete
// Because some of the delete operations happen post-commit, and
// because we don't have real transactions, fake it
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
// Call the delete webscript
response = sendRequest(new DeleteRequest(URL_DEFINITION + nastyNameURL), Status.STATUS_NO_CONTENT);
assertEquals(Status.STATUS_NO_CONTENT, response.getStatus());
// Let the node service do its work
txn.commit();
Thread.sleep(50);
// Check the details webscript to ensure it went
response = sendRequest(new GetRequest(URL_DEFINITION + nastyNameURL), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
// And check the service too
assertEquals(0, replicationService.loadReplicationDefinitions().size());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class ReplicationRestApiTest method testReplicationDefinitionDelete.
public void testReplicationDefinitionDelete() throws Exception {
Response response;
// Not allowed if you're not an admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), 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 DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
// Create one, and then delete it
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test", "Testing");
replicationService.saveReplicationDefinition(rd);
assertEquals(1, replicationService.loadReplicationDefinitions().size());
// Because some of the delete operations happen post-commit, and
// because we don't have real transactions, fake it
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
// Call the delete webscript
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test"), Status.STATUS_NO_CONTENT);
assertEquals(Status.STATUS_NO_CONTENT, response.getStatus());
// Let the node service do its work
txn.commit();
Thread.sleep(50);
// Check the details webscript to ensure it went
response = sendRequest(new GetRequest(URL_DEFINITION + "Test"), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
// Check the replication service to ensure it went
assertNull(replicationService.loadReplicationDefinition("Test"));
assertEquals(0, replicationService.loadReplicationDefinitions().size());
// If there are several, make sure the right one goes
rd = replicationService.createReplicationDefinition("Test", "Testing");
replicationService.saveReplicationDefinition(rd);
rd = replicationService.createReplicationDefinition("Test 2", "Testing");
replicationService.saveReplicationDefinition(rd);
rd = replicationService.createReplicationDefinition("Test 3", "Testing");
replicationService.saveReplicationDefinition(rd);
// Delete one of three, correct one goes
assertEquals(3, replicationService.loadReplicationDefinitions().size());
txn = transactionService.getUserTransaction();
txn.begin();
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test"), Status.STATUS_NO_CONTENT);
assertEquals(Status.STATUS_NO_CONTENT, response.getStatus());
txn.commit();
Thread.sleep(50);
assertEquals(2, replicationService.loadReplicationDefinitions().size());
assertNull(replicationService.loadReplicationDefinition("Test"));
assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
assertNotNull(replicationService.loadReplicationDefinition("Test 3"));
// Delete the next one, correct one goes
txn = transactionService.getUserTransaction();
txn.begin();
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test 3"), Status.STATUS_NO_CONTENT);
assertEquals(Status.STATUS_NO_CONTENT, response.getStatus());
txn.commit();
Thread.sleep(50);
assertEquals(1, replicationService.loadReplicationDefinitions().size());
assertNull(replicationService.loadReplicationDefinition("Test"));
assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
assertNull(replicationService.loadReplicationDefinition("Test 3"));
// Ensure you can't delete for a 2nd time
txn = transactionService.getUserTransaction();
txn.begin();
response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test 3"), Status.STATUS_NOT_FOUND);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
txn.commit();
Thread.sleep(50);
assertEquals(1, replicationService.loadReplicationDefinitions().size());
assertNull(replicationService.loadReplicationDefinition("Test"));
assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
assertNull(replicationService.loadReplicationDefinition("Test 3"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class RuleServiceTest method testDeleteRule.
public void testDeleteRule() throws Exception {
JSONObject jsonRule = createRule(testNodeRef);
assertEquals(1, ruleService.getRules(testNodeRef).size());
String ruleId = jsonRule.getJSONObject("data").getString("id");
Response response = sendRequest(new DeleteRequest(formateRuleUrl(testNodeRef, ruleId)), 200);
JSONObject result = new JSONObject(response.getContentAsString());
assertNotNull(result);
assertTrue(result.has("success"));
boolean success = result.getBoolean("success");
assertTrue(success);
// no more rules present
assertEquals(0, ruleService.getRules(testNodeRef).size());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testGetInvitation.
/**
* Detailed Test of Get Invitation Web Script
* @throws Exception
*/
public void testGetInvitation() throws Exception {
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
/*
* Create a new moderated invitation
*/
String inviteeComments = "Please sir, let $* me in";
String userName = USER_TWO;
String roleName = SiteModel.SITE_CONSUMER;
String inviteId = createModeratedInvitation(shortName, inviteeComments, userName, roleName);
/*
* Negative test - site does not exist
*/
sendRequest(new GetRequest(URL_SITES + "/rubbish/invitations/" + inviteId), 404);
/*
* Negative test - site does exist but invitation doesn't
*/
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/activiti$8787487"), 404);
/*
* Negative test - site does exist but invitation engine is wrong
*/
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/trash$123"), 404);
/*
* Negative test - site does exist but invitation doesn't no $ in inviteId
*/
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/trash123"), 404);
/*
* Positive test - get the invitation and validate that it is correct
*/
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
JSONObject top = new JSONObject(response.getContentAsString());
// System.out.println(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertNotNull("data is null", data);
assertEquals("inviteId is not set", data.getString("inviteId"), inviteId);
assertEquals("invitationType", "MODERATED", data.getString("invitationType"));
assertEquals("inviteeUserName is not set", userName, data.getString("inviteeUserName"));
assertEquals("resourceName is not correct", shortName, data.getString("resourceName"));
assertEquals("resourceType is not correct", "WEB_SITE", data.getString("resourceType"));
// Moderated specific properties
assertEquals("inviteeComments", inviteeComments, data.getString("inviteeComments"));
assertEquals("roleName is not set", roleName, data.getString("roleName"));
}
/*
* Cancel the invitation
*/
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
/*
* Verify that the invitation is no longer open
*/
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 404);
/**
* Create a nominated invitation
*/
String inviteeFirstName = "Buffy";
String inviteeLastName = "Summers";
String inviteeEmail = "FirstName123.LastName123@email.com";
String inviteeUserName = null;
String serverPath = "http://localhost:8081/share/";
String acceptURL = "page/accept-invite";
String rejectURL = "page/reject-invite";
inviteId = createNominatedInvitation(shortName, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL, 201);
/*
* Positive test - get the invitation and validate that it is correct
* inviteId and inviteeUserName will be generated.
*/
{
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
JSONObject top = new JSONObject(response.getContentAsString());
// System.out.println(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertNotNull("data is null", data);
assertEquals("inviteId is not set", data.getString("inviteId"), inviteId);
assertEquals("invitationType", "NOMINATED", data.getString("invitationType"));
assertEquals("resourceName is not correct", shortName, data.getString("resourceName"));
assertEquals("resourceType is not correct", "WEB_SITE", data.getString("resourceType"));
// Nominated specific attributes
assertEquals("roleName is not set", roleName, data.getString("roleName"));
// Generated user name
assertNotNull("inviteeUserName is not set", data.getString("inviteeUserName"));
}
/*
* Cancel the nominated invitation
*/
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testDeleteSiteAsSiteAdmin.
public void testDeleteSiteAsSiteAdmin() throws Exception {
// Create a site
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// Get the site
sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
// try to delete the site
this.authenticationComponent.setCurrentUser(USER_THREE);
// Delete the site
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 500);
// Get the site
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
JSONObject jsonObj = new JSONObject(response.getContentAsString());
assertEquals(shortName, jsonObj.get("shortName"));
// set the current user as site-admin
this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
// Delete the site
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200);
sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404);
}
Aggregations