use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse 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.PublicApiClient.ListResponse 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.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestNodeComments method testNodeComments.
@Test
public // TODO test update comment and modifiedBy in result is a person object
void testNodeComments() throws Exception {
Comments commentsProxy = publicApiClient.comments();
Nodes nodesProxy = publicApiClient.nodes();
People peopleProxy = publicApiClient.people();
// invalid node id
try {
Comment comment = new Comment("Test Comment 4", "Test Comment 4");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.createNodeComment(GUID.generate(), comment);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// person from the same network - no permission
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
Comment comment = new Comment("Test Comment 4", "Test Comment 4");
commentsProxy.createNodeComment(nodeRef1.getId(), comment);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-2196
// multi-byte characters, create and update comments
{
Comment[] multiByteComments = new Comment[] { new Comment("ڠڡڢ", "ڠڡڢ"), new Comment("\u67e5\u770b\u5168\u90e8", "\u67e5\u770b\u5168\u90e8") };
Map<String, Comment> createdComments = new HashMap<String, Comment>();
for (Comment comment : multiByteComments) {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment ret = commentsProxy.createNodeComment(nodeRef2.getId(), comment);
createdComments.put(ret.getId(), ret);
}
// test that it is possible to add comment to custom type node
commentsProxy.createNodeComment(customTypeObject.getId(), new Comment("Custom type node comment", "The Comment"));
try {
// test that it is not possible to add comment to cm:object node
commentsProxy.createNodeComment(cmObjectNodeRef.getId(), new Comment("CM Object node comment", "The Comment"));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// get comments of the non-folder/non-document nodeRef
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
commentsProxy.getNodeComments(cmObjectNodeRef.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef2.getId(), createParams(paging, null));
List<Comment> retComments = resp.getList();
assertEquals(2, retComments.size());
for (Comment comment : retComments) {
String commentId = comment.getId();
Comment expectedComment = createdComments.get(commentId);
expectedComment.expected(comment);
}
Comment[] multiByteCommentUpdates = new Comment[] { new Comment("ӉӋӐӞ", "ӉӋӐӞ"), new Comment("\u4e00\u4e01\u4e02\u4e03", "\u4e00\u4e01\u4e02\u4e03") };
Map<String, Comment> updatedComments = new HashMap<String, Comment>();
for (Comment comment : multiByteCommentUpdates) {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment ret = commentsProxy.createNodeComment(nodeRef2.getId(), comment);
updatedComments.put(ret.getId(), ret);
}
skipCount = 0;
maxItems = 2;
paging = getPaging(skipCount, maxItems);
resp = commentsProxy.getNodeComments(nodeRef2.getId(), createParams(paging, null));
retComments = resp.getList();
assertEquals(2, retComments.size());
for (Comment comment : retComments) {
String commentId = comment.getId();
Comment expectedComment = updatedComments.get(commentId);
expectedComment.expected(comment);
}
}
{
// special characters
Comment comment = new Comment("", "?*^&*(,");
List<Comment> expectedComments = new ArrayList<Comment>(1);
expectedComments.add(comment);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.createNodeComment(nodeRef3.getId(), comment);
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef3.getId(), createParams(paging, null));
checkList(expectedComments.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
try {
Comment comment = new Comment("", "");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.createNodeComment(nodeRef2.getId(), comment);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
DateFormat format = PublicApiDateFormat.getDateFormat();
final List<Comment> expectedComments = new ArrayList<Comment>(10);
final List<Comment> comments = new ArrayList<Comment>(10);
comments.add(new Comment("Test Comment 4", "Test Comment 4"));
comments.add(new Comment("Test Comment 1", "Test Comment 1"));
comments.add(new Comment("Test Comment 3", "Test Comment 3"));
comments.add(new Comment("Test Comment 2", "Test Comment 2"));
{
Date time = new Date();
for (Comment comment : comments) {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment resp = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
// check response
assertEquals(comment.getContent(), resp.getContent());
assertFalse(StringUtils.isEmpty(resp.getCreatedBy().getDisplayName()));
assertEquals(resp.getCreatedBy().getDisplayName(), person11.getDisplayName());
assertTrue(format.parse(resp.getCreatedAt()).after(time));
person11.expected(resp.getCreatedBy());
assertNotNull(resp.getId());
expectedComments.add(resp);
}
// check activities have been raised
repoService.generateFeed();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Paging paging = getPaging(0, Integer.MAX_VALUE);
ListResponse<Activity> activities = peopleProxy.getActivities(person11.getId(), createParams(paging, null));
boolean found = false;
for (Activity activity : activities.getList()) {
String activityType = activity.getActivityType();
if (activityType.equals(ActivityType.COMMENT_CREATED)) {
Map<String, Object> summary = activity.getSummary();
assertNotNull(summary);
String objectId = (String) summary.get("objectId");
assertNotNull(objectId);
if (nodeRef1.getId().equals(objectId)) {
found = true;
break;
}
}
}
assertTrue(found);
}
}
// try to add a comment to a comment
try {
Comment comment = comments.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment newComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
expectedComments.add(newComment);
commentsProxy.createNodeComment(newComment.getId(), comment);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// try to add a comment to a tag
try {
Comment comment = comments.get(0);
Tag tag = new Tag("taggification");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Tag addedTag = nodesProxy.createNodeTag(nodeRef1.getId(), tag);
commentsProxy.createNodeComment(addedTag.getId(), comment);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// add a comment to a folder
{
Date time = new Date();
Comment comment = comments.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment resp = commentsProxy.createNodeComment(folderNodeRef1.getId(), comment);
// check response
assertEquals(comment.getContent(), resp.getContent());
assertTrue(format.parse(resp.getCreatedAt()).after(time));
person11.expected(resp.getCreatedBy());
assertNotNull(resp.getId());
}
Collections.sort(expectedComments);
// Test Case cloud-2205
// Test Case cloud-2217
// Test Case cloud-1517
// pagination
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null));
checkList(expectedComments.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 2;
int maxItems = 10;
Paging paging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null));
checkList(expectedComments.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// invalid node id - 404
try {
int skipCount = 0;
int maxItems = 2;
Paging expectedPaging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
commentsProxy.getNodeComments("invalid", createParams(expectedPaging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
commentsProxy.getNodeComments(nodeRef1.getId() + ";pwc", createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// suffix the node id with a version number
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef1.getId() + ";3.0", createParams(paging, null));
checkList(expectedComments.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// in which the comment resides
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
Paging expectedPaging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
commentsProxy.getNodeComments(nodeRef1.getId(), createParams(expectedPaging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// document owned by another person in another network, the user is not a member of that network
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
Paging expectedPaging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
commentsProxy.getNodeComments(nodeRef1.getId(), createParams(expectedPaging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1971
// invalid methods
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
int skipCount = 0;
int maxItems = 2;
Paging expectedPaging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef1.getId(), createParams(expectedPaging, null));
List<Comment> nodeComments = resp.getList();
assertTrue(nodeComments.size() > 0);
Comment comment = nodeComments.get(0);
try {
commentsProxy.create("nodes", nodeRef1.getId(), "comments", comment.getId(), null, "Unable to POST to a node comment");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
commentsProxy.update("nodes", nodeRef1.getId(), "comments", null, null, "Unable to PUT node comments");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
commentsProxy.getSingle("nodes", nodeRef1.getId(), "comments", comment.getId(), "Unable to GET a node comment");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
commentsProxy.remove("nodes", nodeRef1.getId(), "comments", null, "Unable to DELETE node comments");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
// Test Case cloud-2184
// update comments
{
Comment[] testComments = new Comment[] { new Comment("ӉӋӐӞ", "ӉӋӐӞ"), new Comment("\u4e00\u4e01\u4e02\u4e03", "\u4e00\u4e01\u4e02\u4e03") };
List<Comment> mlComments = new ArrayList<Comment>();
mlComments.add(new Comment("ӉӋӐӞ", "ӉӋӐӞ"));
mlComments.add(new Comment("\u4e00\u4e01\u4e02\u4e03", "\u4e00\u4e01\u4e02\u4e03"));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
// create some comments
Map<String, Comment> createdComments = new HashMap<String, Comment>();
for (Comment comment : testComments) {
Comment ret = commentsProxy.createNodeComment(nodeRef4.getId(), comment);
createdComments.put(ret.getId(), ret);
}
// update them with multi-byte content
int i = 0;
List<Comment> updatedComments = new ArrayList<Comment>();
for (Comment comment : createdComments.values()) {
Comment updateComment = mlComments.get(i);
Comment ret = commentsProxy.updateNodeComment(nodeRef4.getId(), comment.getId(), updateComment);
updatedComments.add(ret);
i++;
}
Collections.sort(updatedComments);
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, mlComments.size(), mlComments.size());
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef4.getId(), createParams(paging, null));
checkList(updatedComments, paging.getExpectedPaging(), resp);
}
// invalid node id
try {
Comment comment = expectedComments.get(1);
Comment update = new Comment("Test Comment 4", "Test Comment 4");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.updateNodeComment(GUID.generate(), comment.getId(), update);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid comment id
try {
Comment update = new Comment("Test Comment 4", "Test Comment 4");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.updateNodeComment(nodeRef1.getId(), GUID.generate(), update);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// person from the same network, not comment creator
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
Comment comment = expectedComments.get(1);
Comment update = new Comment("Test Comment 4", "Test Comment 4");
commentsProxy.updateNodeComment(nodeRef1.getId(), comment.getId(), update);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// person from a different network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person22.getId()));
Comment comment = expectedComments.get(1);
Comment update = new Comment("Test Comment 4", "Test Comment 4");
commentsProxy.updateNodeComment(nodeRef1.getId(), comment.getId(), update);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// successful update
{
Date time = new Date();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment comment = expectedComments.get(1);
Comment update = new Comment("Updated comment", "Updated comment");
Comment resp = commentsProxy.updateNodeComment(nodeRef1.getId(), comment.getId(), update);
// simulate a user edit to a comment
Thread.sleep(100);
Comment expected = new Comment(comment);
expected.setTitle("Updated comment");
expected.setEdited(true);
expected.setContent("Updated comment");
expected.setModifiedBy(repoService.getPerson(person11.getId()));
expected.setModifiedAt(PublicApiDateFormat.getDateFormat().format(time));
expected.expected(resp);
}
// invalid node ref
try {
Comment comment = expectedComments.get(1);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.removeNodeComment(GUID.generate(), comment.getId());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid comment id
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.removeNodeComment(nodeRef1.getId(), GUID.generate());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// successful delete
{
Comment toDelete = expectedComments.get(1);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
commentsProxy.removeNodeComment(nodeRef1.getId(), toDelete.getId());
// check it's been removed
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging expectedPaging = getPaging(skipCount, maxItems, expectedComments.size(), expectedComments.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<Comment> resp = commentsProxy.getNodeComments(nodeRef1.getId(), createParams(expectedPaging, null));
List<Comment> actualComments = resp.getList();
assertFalse(actualComments.contains(toDelete));
}
// PUT: test update with null/empty comment
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment comment = new Comment();
comment.setContent("my comment");
Comment createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
Comment updatedComment = new Comment();
updatedComment.setContent(null);
commentsProxy.updateNodeComment(nodeRef1.getId(), createdComment.getId(), updatedComment);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// ACE-5463
testSkipCountHighValue(expectedComments, commentsProxy);
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestSiteMembershipRequests method testGetSiteMembershipRequests.
@Test
public void testGetSiteMembershipRequests() throws Exception {
String networkId = network1.getId();
final TestNetwork systemNetwork = getRepoService().getSystemNetwork();
// note: username for site creator is of the form user@network
TestPerson siteManager = network1.createUser();
TestPerson person1 = network1.createUser();
TestPerson person2 = network1.createUser();
TestSite sitePublic = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = systemNetwork.createSite(SiteVisibility.PUBLIC);
return site;
}
}, siteManager.getId(), networkId);
TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
return site;
}
}, siteManager.getId(), networkId);
TestSite site2 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
return site;
}
}, siteManager.getId(), networkId);
// Public site.
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(sitePublic.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person1.getId(), siteMembershipRequest);
assertNotNull(ret);
// Moderated site.
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(site.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person1.getId(), siteMembershipRequest);
assertNotNull(ret);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems);
// Test that we have a moderated site request only.
{
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
List<SiteMembershipRequest> list = resp.getList();
assertEquals(1, list.size());
SiteMembershipRequest smr = list.get(0);
// Check if the person details is retrieved.
assertNotNull(smr.getPerson());
assertNotNull(smr.getPerson().getUserName());
}
// Test that the user has no site membership requests.
{
publicApiClient.setRequestContext(new RequestContext(networkId, person2.getId()));
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
List<SiteMembershipRequest> list = resp.getList();
assertEquals(0, list.size());
}
// Test retrieve site membership request using where clause.
{
// Prepare test data.
publicApiClient.setRequestContext(new RequestContext("-default-", person2.getId()));
ret = createSiteMembershipRequest(site.getSiteId(), person2.getId());
assertNotNull(ret);
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
ret = createSiteMembershipRequest(site2.getSiteId(), person1.getId());
assertNotNull(ret);
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
List<SiteMembershipRequest> list = resp.getList();
assertEquals(3, list.size());
// Test filter by site id.
Map<String, String> otherParams = new HashMap<>();
otherParams.put("where", "(siteId='" + site.getSiteId() + "')");
resp = getSiteMembershipRequests(paging, otherParams);
list = resp.getList();
assertEquals(2, list.size());
// Test filter by person id.
otherParams = new HashMap<>();
otherParams.put("where", "(personId='" + person2.getId() + "')");
resp = getSiteMembershipRequests(paging, otherParams);
list = resp.getList();
assertEquals(1, list.size());
// Test filter by site and personId
otherParams = new HashMap<>();
otherParams.put("where", "(siteId='" + site.getSiteId() + "' and personId='" + person2.getId() + "')");
resp = getSiteMembershipRequests(paging, otherParams);
list = resp.getList();
assertEquals(1, list.size());
}
{
TestPerson person3 = network1.createUser();
publicApiClient.setRequestContext(new RequestContext("-default-", person3.getId()));
ret = createSiteMembershipRequest(site.getSiteId(), person3.getId());
assertNotNull(ret);
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
approve(site.getSiteId(), person3.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_OK, null);
publicApiClient.setRequestContext(new RequestContext(networkId, person3.getId()));
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
List<SiteMembershipRequest> list = resp.getList();
assertEquals(0, list.size());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestSiteMembershipRequests method testRejectSiteMembershipRequests.
@Test
public void testRejectSiteMembershipRequests() throws Exception {
String networkId = network1.getId();
final TestNetwork systemNetwork = getRepoService().getSystemNetwork();
TestPerson siteManager = network1.createUser();
TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
return site;
}
}, siteManager.getId(), networkId);
TestPerson person1 = network1.createUser();
TestPerson person2 = network1.createUser();
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
SiteMembershipRequest ret = createSiteMembershipRequest(site.getSiteId(), person1.getId());
assertNotNull(ret);
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
// Site not found.
reject("siteId", person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
// Invitee not found.
reject(site.getSiteId(), null, new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
// Invitation not found.
reject(site.getSiteId(), person2.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
{
// Create moderated site.
TestSite tempSite = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
return site;
}
}, siteManager.getId(), networkId);
// Create site membership request
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
ret = createSiteMembershipRequest(tempSite.getSiteId(), person1.getId());
assertNotNull(ret);
// Change site visibility to private.
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
SiteInfo tempSiteInfo = tempSite.getSiteInfo();
assertEquals(SiteVisibility.MODERATED, tempSiteInfo.getVisibility());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
tempSite.setSiteVisibility(SiteVisibility.PRIVATE);
assertEquals(SiteVisibility.PRIVATE, tempSiteInfo.getVisibility());
return null;
}
}, siteManager.getId(), networkId);
// Site private so not found error.
reject(tempSite.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
}
// User tries to reject his own request.
{
publicApiClient.setRequestContext(new RequestContext(networkId, person1.getId()));
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_FORBIDDEN, null);
// null body (see REPO-3344 for details)
reject(site.getSiteId(), person1.getId(), null, HttpServletResponse.SC_FORBIDDEN, null);
}
// User tries to reject another user request without having permissions.
{
publicApiClient.setRequestContext(new RequestContext(networkId, person2.getId()));
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
}
// User from same site tries to reject another user request without having
// permissions.
{
TestPerson person3 = network1.createUser();
// Create site membership request
publicApiClient.setRequestContext(new RequestContext("-default-", person3.getId()));
ret = createSiteMembershipRequest(site.getSiteId(), person3.getId());
assertNotNull(ret);
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
approve(site.getSiteId(), person3.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_OK, null);
publicApiClient.setRequestContext(new RequestContext(networkId, person3.getId()));
MemberOfSite memberOfSite = publicApiClient.sites().getPersonSite(person3.getId(), site.getSiteId());
assertNotNull(memberOfSite);
assertEquals(SiteRole.SiteConsumer, memberOfSite.getRole());
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
}
// Valid request.
{
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_OK, null);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems);
Map<String, String> otherParams = new HashMap<>();
otherParams.put("where", "(siteId='" + site.getSiteId() + "')");
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, otherParams);
List<SiteMembershipRequest> list = resp.getList();
assertEquals(0, list.size());
}
// Reject again.
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
}
Aggregations