use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testWorkflowInstanceDeleteAsRecreatedUser.
public void testWorkflowInstanceDeleteAsRecreatedUser() throws Exception {
// Create task as USER1 and assign it to another user
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
Date dueDate = new Date();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
// Check the workflow was created
assertNotNull(workflowService.getWorkflowById(adhocPath.getInstance().getId()));
// Delete USER1
personManager.deletePerson(USER1);
// Recreate USER1
personManager.createPerson(USER1);
// Delete workflow
personManager.setUser(USER1);
sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocPath.getInstance().getId()), Status.STATUS_OK);
// Check the workflow was deleted
assertNull(workflowService.getWorkflowById(adhocPath.getInstance().getId()));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class GroupsTest method testUpdateGroup.
/**
* Detailed test of update group
* @throws Exception
*/
public void testUpdateGroup() throws Exception {
String myGroupName = "GT_UG";
String myDisplayName = "GT_UGDisplay";
String myNewDisplayName = "GT_UGDisplayNew";
this.authenticationComponent.setSystemUserAsCurrentUser();
try {
/**
* Create a root group
*/
{
JSONObject newGroupJSON = new JSONObject();
newGroupJSON.put("displayName", myDisplayName);
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
}
/**
* Now change its display name
*/
{
JSONObject newGroupJSON = new JSONObject();
newGroupJSON.put("displayName", myNewDisplayName);
Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertTrue(data.length() > 0);
assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName"));
}
/**
* Now get it and verify that the name has changed
*/
{
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myGroupName), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertTrue(data.length() > 0);
assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName"));
}
/**
* Negative test
*/
{
JSONObject newGroupJSON = new JSONObject();
newGroupJSON.put("displayName", myNewDisplayName);
sendRequest(new PutRequest(URL_GROUPS + "/" + "rubbish", newGroupJSON.toString(), "application/json"), Status.STATUS_NOT_FOUND);
}
} finally {
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class GroupsTest method testLinkChild.
/**
* Detailed test of link group
*/
public void testLinkChild() throws Exception {
String myRootGroup = "GT_LGROOT";
try {
this.authenticationComponent.setSystemUserAsCurrentUser();
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0);
String groupLinkFullName = "";
{
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_LINK), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertTrue(data.length() > 0);
groupLinkFullName = data.getString("fullName");
}
/**
* Create a root group
*/
{
JSONObject newGroupJSON = new JSONObject();
newGroupJSON.put("displayName", myRootGroup);
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myRootGroup, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
}
/**
* Link an existing group (GROUPB) to my root group.
*/
/**
* Negative test Link Group B without administrator access.
*/
this.authenticationComponent.setCurrentUser(USER_ONE);
{
JSONObject newGroupJSON = new JSONObject();
sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup + "/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR);
}
this.authenticationComponent.setSystemUserAsCurrentUser();
/**
* Link Group B
*/
{
JSONObject newGroupJSON = new JSONObject();
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup + "/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
}
/**
* Link the group again - this fails
* - duplicate groups (children with the same name) are not allowed
*/
{
JSONObject newGroupJSON = new JSONObject();
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup + "/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR);
}
/**
* Get All Children of myGroup which are GROUPS - should find GROUP B
*/
{
logger.debug("Get child GROUPS of myRootGroup");
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertTrue("no child groups of myGroup", data.length() == 1);
JSONObject subGroup = data.getJSONObject(0);
assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName"));
assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType"));
}
/**
* Now link in an existing user
*/
{
JSONObject newGroupJSON = new JSONObject();
String userOneFullName = USER_ONE;
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup + "/children/" + userOneFullName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
}
/**
* Get All Children of myGroup which are USERS - should find USER ONE
*/
{
logger.debug("Get child USERS of myRootGroup");
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=USER"), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertTrue("no child groups of myGroup", data.length() == 1);
JSONObject subGroup = data.getJSONObject(0);
assertEquals("shortName wrong", USER_ONE, subGroup.getString("shortName"));
assertEquals("authorityType wrong", "USER", subGroup.getString("authorityType"));
}
/**
* Unlink Group B
*/
{
logger.debug("Unlink Test Link");
Response response = sendRequest(new DeleteRequest(URL_GROUPS + "/" + myRootGroup + "/children/" + groupLinkFullName), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
}
/**
* Get All Children of myGroup which are GROUPS - should no longer find GROUP B
*/
{
logger.debug("Get child GROUPS of myRootGroup");
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
// TODO TEST failing
// assertTrue("group B not removed", data.length() == 0);
}
/**
* Create a new group (BUFFY)
*/
String myNewGroup = "GROUP_BUFFY";
{
// Delete incase it already exists from a previous test run
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/BUFFY"), 0);
JSONObject newGroupJSON = new JSONObject();
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup + "/children/" + myNewGroup, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertEquals("shortName wrong", "BUFFY", data.getString("shortName"));
assertEquals("fullName wrong", myNewGroup, data.getString("fullName"));
assertEquals("authorityType wrong", "GROUP", data.getString("authorityType"));
}
/**
* Get All Children of myGroup which are GROUPS - should find GROUP(BUFFY)
*/
{
logger.debug("Get child GROUPS of myRootGroup");
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
for (int i = 0; i < data.length(); i++) {
JSONObject rootGroup = data.getJSONObject(i);
if (rootGroup.getString("fullName").equals(myNewGroup)) {
}
}
}
/**
* Negative tests
*/
} finally {
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class InvitationWebScriptTest method deleteInvitation.
void deleteInvitation(String invitationID, String siteShortName, int expectedStatus) throws Exception {
assertNotNull(invitationID);
assertNotNull(siteShortName);
assertFalse(invitationID.isEmpty());
assertFalse(siteShortName.isEmpty());
Response response = sendRequest(new DeleteRequest(URL_SITES + "/" + siteShortName + "/invitations/" + invitationID), expectedStatus);
assertNotNull(new JSONObject(response.getContentAsString()));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class InvitationWebScriptTest method tearDown.
@Override
protected void tearDown() throws Exception {
super.tearDown();
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
RetryingTransactionCallback<Void> deleteCallback = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
personService.deletePerson(userOne);
personService.deletePerson(userTwo);
personService.deletePerson(userThree);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(deleteCallback);
// Tidy-up any sites created during the execution of the test
for (String shortName : this.createdSites) {
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 0);
}
// Clear the list
this.createdSites.clear();
// Clear the list
this.createdInvitations.clear();
}
Aggregations