Search in sources :

Example 21 with DeleteRequest

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()));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest) Date(java.util.Date)

Example 22 with DeleteRequest

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);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 23 with DeleteRequest

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);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 24 with DeleteRequest

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()));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 25 with DeleteRequest

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();
}
Also used : RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Aggregations

DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)43 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)32 JSONObject (org.json.JSONObject)29 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)21 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)14 JSONArray (org.json.JSONArray)9 JSONTokener (org.json.JSONTokener)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Serializable (java.io.Serializable)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 UserTransaction (javax.transaction.UserTransaction)3 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)3 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)3 QName (org.alfresco.service.namespace.QName)3 JSONStringer (org.json.JSONStringer)3 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)3 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)2