use of org.alfresco.rest.api.tests.client.data.Action 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);
}
}
Aggregations