Search in sources :

Example 1 with RetryingCallbackHelper

use of org.alfresco.ibatis.RetryingCallbackHelper in project alfresco-remote-api by Alfresco.

the class TestActions method testExecuteAction.

@Test
public void testExecuteAction() throws Throwable {
    final String person1 = account1PersonIt.next();
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
    AuthenticationUtil.setFullyAuthenticatedUser(person1);
    String myNode = getMyNodeId();
    NodeRef validNode = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myNode), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-ea-node"), ContentModel.TYPE_CONTENT).getChildRef();
    // actionDefinitionId missing but required by the action.
    {
        actions.executeAction(new Action(), emptyParams, 400);
    }
    // Non-existent actionDefinitionId
    {
        Action action = new Action();
        action.setActionDefinitionId("nonExistentActionDefId");
        actions.executeAction(action, emptyParams, 404);
    }
    // Non-existent targetId
    {
        NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "750a2867-ecfa-478c-8343-fa0e39d27be3");
        assertFalse("Test pre-requisite: node must not exist", nodeService.exists(nodeRef));
        Action action = new Action();
        action.setActionDefinitionId(AddFeaturesActionExecuter.NAME);
        action.setTargetId(nodeRef.getId());
        actions.executeAction(action, emptyParams, 404);
    }
    // Missing mandatory params - action not executed.
    {
        Action action = new Action();
        action.setActionDefinitionId(AddFeaturesActionExecuter.NAME);
        action.setTargetId(validNode.getId());
        actions.executeAction(action, emptyParams, 202);
        Thread.sleep(1000);
        assertFalse("Aspect versionable wasn't expected !", nodeService.hasAspect(validNode, ContentModel.ASPECT_VERSIONABLE));
    }
    // Check add versionable aspect.
    {
        assertFalse(nodeService.hasAspect(validNode, ContentModel.ASPECT_VERSIONABLE));
        Map<String, String> params = new HashMap<>();
        params.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, "cm:versionable");
        Action action = new Action();
        action.setActionDefinitionId(AddFeaturesActionExecuter.NAME);
        action.setTargetId(validNode.getId());
        action.setParams(params);
        Action executedAction = actions.executeAction(action, emptyParams, 202);
        assertNotNull(executedAction);
        assertNotNull(executedAction.getId());
        RetryingCallbackHelper retryingCallbackHelper = new RetryingCallbackHelper();
        retryingCallbackHelper.setRetryWaitMs(500);
        RetryingCallbackHelper.RetryingCallback retryingCallback = new RetryingCallbackHelper.RetryingCallback() {

            @Override
            public Void execute() throws Throwable {
                assertTrue("Expected aspect versionable!", nodeService.hasAspect(validNode, ContentModel.ASPECT_VERSIONABLE));
                return null;
            }
        };
        retryingCallbackHelper.doWithRetry(retryingCallback);
    }
    // Unauthorized -> 401
    {
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
        actions.executeAction(new Action(), emptyParams, 401);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.rest.api.tests.client.data.Action) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map) RetryingCallbackHelper(org.alfresco.ibatis.RetryingCallbackHelper) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 RetryingCallbackHelper (org.alfresco.ibatis.RetryingCallbackHelper)1 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)1 Action (org.alfresco.rest.api.tests.client.data.Action)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 Test (org.junit.Test)1