use of org.alfresco.rest.api.tests.client.RequestContext 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);
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestActions method canGetActionDefinitionsForNode.
@Test
public void canGetActionDefinitionsForNode() throws Exception {
final String person1 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
// Get the actions available on the -my- node-ref alias
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode("-my-", emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
// Check defaults, given that no paging params were sent in the request
assertEquals(Paging.DEFAULT_MAX_ITEMS, actionDefs.getPaging().getMaxItems().intValue());
assertEquals(Paging.DEFAULT_SKIP_COUNT, actionDefs.getPaging().getSkipCount().intValue());
// Check ActionDefinition fields
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("add-features")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("add-features", action.getId());
assertEquals("add-features", action.getName());
assertEquals("Add aspect", action.getTitle());
assertEquals("This will add an aspect to the matched item.", action.getDescription());
// Applicable types
assertEquals(0, action.getApplicableTypes().size());
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(1, action.getParameterDefinitions().size());
ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
assertEquals(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, paramDefs.getName());
assertEquals("d:qname", paramDefs.getType());
assertEquals(true, paramDefs.isMandatory());
assertEquals("Aspect", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals("ac-aspects", paramDefs.getParameterConstraintName());
}
AuthenticationUtil.setFullyAuthenticatedUser(person1);
// Get the actions for a "checked out" node - there should be a "check-in" action present.
// Inspect the fields, to make sure that they're all there. Especially applicableTypes, as
// this isn't available on any of the actions that appear for the "-my-" alias in the test above.
{
NodeRef nodeForCheckout = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, getMyNodeId()), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node-checkedout"), ContentModel.TYPE_CONTENT).getChildRef();
CheckOutCheckInService coci = applicationContext.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
coci.checkout(nodeForCheckout);
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(nodeForCheckout.getId(), emptyParams, 200);
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("check-in")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("check-in", action.getId());
assertEquals("check-in", action.getName());
assertEquals("Check in", action.getTitle());
assertEquals("This will check in the matched content.", action.getDescription());
// Applicable types
assertEquals(1, action.getApplicableTypes().size());
assertEquals("cm:content", action.getApplicableTypes().get(0));
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(2, action.getParameterDefinitions().size());
// "description"
ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
assertEquals(CheckInActionExecuter.PARAM_DESCRIPTION, paramDefs.getName());
assertEquals("d:text", paramDefs.getType());
assertEquals(false, paramDefs.isMandatory());
assertEquals("Description", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals(null, paramDefs.getParameterConstraintName());
// "minorChange"
paramDefs = action.getParameterDefinitions().get(1);
assertEquals(CheckInActionExecuter.PARAM_MINOR_CHANGE, paramDefs.getName());
assertEquals("d:boolean", paramDefs.getType());
assertEquals(false, paramDefs.isMandatory());
assertEquals("Minor change", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals(null, paramDefs.getParameterConstraintName());
}
String myNode = getMyNodeId();
NodeRef validNode = nodeService.createNode(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myNode), ContentModel.ASSOC_CONTAINS, QName.createQName("test", "test-node"), ContentModel.TYPE_CONTENT).getChildRef();
// Get the actions available using a specific node ID
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
}
// Basic/default paging and sorting
checkBasicPagingAndSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName)).map(ParameterizedItemDefinition::getName).collect(Collectors.toList()), // Actual results
paging -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 200));
// Test explicit sorting by title
checkSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getTitle, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "title");
// Test explicit sorting by name
checkSorting(// Expected
() -> actionService.getActionDefinitions(validNode).stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, orderBy), 200), "name");
// Badly formed request -> 400
{
// -1 is not acceptable
PublicApiClient.Paging paging = getPaging(0, -1);
actions.getActionDefinitionsForNode(validNode.getId(), createParams(paging, null), 400);
}
// Non-existent node ID
{
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));
actions.getActionDefinitionsForNode(nodeRef.getId(), emptyParams, 404);
}
// Unauthorized -> 401
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
actions.getActionDefinitionsForNode(validNode.getId(), emptyParams, 401);
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestActions method canGetActionDefinition.
@Test
public void canGetActionDefinition() throws PublicApiException {
final String person1 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
ActionDefinition actionDef = actions.getActionDefinition("add-features", 200);
assertNotNull("Action definition should not be null", actionDef);
// Check ActionDefinition fields
assertEquals("add-features", actionDef.getId());
assertEquals("add-features", actionDef.getName());
assertEquals("Add aspect", actionDef.getTitle());
assertEquals("This will add an aspect to the matched item.", actionDef.getDescription());
// Applicable types
assertEquals(0, actionDef.getApplicableTypes().size());
assertEquals(false, actionDef.isTrackStatus());
// Parameter definitions
assertEquals(1, actionDef.getParameterDefinitions().size());
ActionDefinition.ParameterDefinition paramDefs = actionDef.getParameterDefinitions().get(0);
assertEquals(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, paramDefs.getName());
assertEquals("d:qname", paramDefs.getType());
assertEquals(true, paramDefs.isMandatory());
assertEquals("Aspect", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals("ac-aspects", paramDefs.getParameterConstraintName());
// Non-existing actionDefinitionId -> 404
{
actions.getActionDefinition("some-text", 404);
}
// Unauthorized -> 401
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
actions.getActionDefinition(null, 401);
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestActions method canGetActionDefinitions.
@Test
public void canGetActionDefinitions() throws PublicApiException {
final String person1 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
{
ListResponse<ActionDefinition> actionDefs = actions.getActionDefinitions(emptyParams, 200);
assertNotNull("Action definition list should not be null", actionDefs);
assertFalse("Action definition list should not be empty", actionDefs.getList().isEmpty());
// Check defaults, given that no paging params were sent in the request
assertEquals(Paging.DEFAULT_MAX_ITEMS, actionDefs.getPaging().getMaxItems().intValue());
assertEquals(Paging.DEFAULT_SKIP_COUNT, actionDefs.getPaging().getSkipCount().intValue());
// Check ActionDefinition fields
List<ActionDefinition> actionDefinitions = actionDefs.getList().stream().filter(ad -> ad.getName().equals("add-features")).collect(Collectors.toList());
assertEquals(1, actionDefinitions.size());
ActionDefinition action = actionDefinitions.get(0);
assertEquals("add-features", action.getId());
assertEquals("add-features", action.getName());
assertEquals("Add aspect", action.getTitle());
assertEquals("This will add an aspect to the matched item.", action.getDescription());
// Applicable types
assertEquals(0, action.getApplicableTypes().size());
assertEquals(false, action.isTrackStatus());
// Parameter definitions
assertEquals(1, action.getParameterDefinitions().size());
ActionDefinition.ParameterDefinition paramDefs = action.getParameterDefinitions().get(0);
assertEquals(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, paramDefs.getName());
assertEquals("d:qname", paramDefs.getType());
assertEquals(true, paramDefs.isMandatory());
assertEquals("Aspect", paramDefs.getDisplayLabel());
assertEquals(false, paramDefs.isMultiValued());
assertEquals("ac-aspects", paramDefs.getParameterConstraintName());
}
checkBasicPagingAndSorting(// Expected
() -> actionService.getActionDefinitions().stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName)).map(ParameterizedItemDefinition::getName).collect(Collectors.toList()), // Actual results
paging -> actions.getActionDefinitions(createParams(paging, null), 200));
// Explicit sorting by title
checkSorting(// Expected
() -> actionService.getActionDefinitions().stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getTitle, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitions(createParams(paging, orderBy), 200), "title");
// Explicit sorting by name
checkSorting(// Expected
() -> actionService.getActionDefinitions().stream().sorted(comparing(org.alfresco.service.cmr.action.ActionDefinition::getName, nullsFirst(naturalOrder()))).map(act -> new Pair<>(act.getName(), act.getTitle())).collect(Collectors.toList()), // Actual results
(paging, orderBy) -> actions.getActionDefinitions(createParams(paging, orderBy), 200), "name");
// Badly formed request -> 400
{
// -1 is not acceptable
PublicApiClient.Paging paging = getPaging(0, -1);
actions.getActionDefinitions(createParams(paging, null), 400);
}
// Unauthorized -> 401
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1, "invalid-password"));
actions.getActionDefinitions(emptyParams, 401);
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestActivities method testPUBLICAPI23.
/*
* Test that empty roles are not returned
*/
@Test
public void testPUBLICAPI23() throws Exception {
// Add and then remove personId as a member of the public site
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
testSite.updateMember(person2.getId(), SiteRole.SiteConsumer);
testSite.removeMember(person2.getId());
return null;
}
}, person1.getId(), network1.getId());
// make sure activities have been generated
repoService.generateFeed();
// check that (empty) role is not in the response
People peopleProxy = publicApiClient.people();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
int skipCount = 0;
int maxItems = 10;
Paging paging = getPaging(skipCount, maxItems);
ListResponse<Activity> activities = peopleProxy.getActivities(person2.getId(), createParams(paging, null));
for (Activity activity : activities.getList()) {
String activityType = activity.getActivityType();
if (activityType.equals("org.alfresco.site.user-left")) {
String role = (String) activity.getSummary().get("role");
String feedPersonId = activity.getFeedPersonId();
if (feedPersonId.equals(person2.getId())) {
assertTrue(role == null);
break;
}
}
}
}
}
Aggregations