use of org.alfresco.rest.api.tests.client.PublicApiClient.People in project alfresco-remote-api by Alfresco.
the class TestActivities method testPersonActivities.
@Test
public void testPersonActivities() throws Exception {
People peopleProxy = publicApiClient.people();
// Test with default tenant domain. see ALF-20448
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person5.getId(), null, false, true);
return activities;
}
}, person5.getId(), defaultNetwork.getId());
for (Activity activity : expectedActivities) {
if (activity.getSiteId() == null) {
fail("SiteId should present in user-joined activity.");
}
}
{
int skipCount = 0;
int maxItems = expectedActivities.size();
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(defaultNetwork.getId(), person5.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person5.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
}
// Test Case cloud-2204
// Test case cloud-1500
// Test Case cloud-2216
// paging
// Test Case cloud-1500
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
{
int skipCount = 2;
int maxItems = expectedActivities.size() - 2;
assertTrue(maxItems > 0);
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
// "-me-" user
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.me));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(org.alfresco.rest.api.People.DEFAULT_USER, params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
}
// unknown user - 404
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
peopleProxy.getActivities(GUID.generate(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown site - 404
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("siteId", GUID.generate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(GUID.generate(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// user from another network - 404
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
peopleProxy.getActivities(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// another user from the same network - 403
try {
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
peopleProxy.getActivities(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
try {
List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
return activities;
}
}, person1.getId(), network1.getId());
assertTrue(activities.size() > 0);
Activity activity = activities.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.remove("people", person1.getId(), "activities", String.valueOf(activity.getId()), "Unable to DELETE a person activity");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1500
// other user activities
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> expectedActivities = repoService.getActivities(person1.getId(), null, true, false);
return expectedActivities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("who", String.valueOf(ActivityWho.others));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
// all activities with siteId exclusion
{
List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> expectedActivities = repoService.getActivities(person1.getId(), testSite.getSiteId(), false, false);
return expectedActivities;
}
}, person1.getId(), network1.getId());
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null);
Map<String, String> params = createParams(paging, null);
params.put("siteId", testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params);
checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response);
}
// all activities with siteId exclusion, unknown site id
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
Map<String, String> params = createParams(paging, null);
params.put("siteId", GUID.generate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown person id
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
Map<String, String> params = createParams(paging, null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(GUID.generate(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid who parameter
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
Map<String, String> params = createParams(paging, null);
params.put("who", GUID.generate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getActivities(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1970
// Not allowed methods
// try
// {
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.create("people", person1.getId(), "activities", null, null, "Unable to POST to person activities");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.update("people", person1.getId(), "activities", null, null, "Unable to PUT person activities");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.remove("people", person1.getId(), "activities", null, "Unable to DELETE person activities");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>()
// {
// @Override
// public List<Activity> doWork() throws Exception
// {
// List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
// return activities;
// }
// }, person1.getId(), network1.getId());
// assertTrue(activities.size() > 0);
// Activity activity = activities.get(0);
//
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.create("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to POST to a person activity");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
//
// try
// {
// List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>()
// {
// @Override
// public List<Activity> doWork() throws Exception
// {
// List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true);
// return activities;
// }
// }, person1.getId(), network1.getId());
// assertTrue(activities.size() > 0);
// Activity activity = activities.get(0);
//
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// peopleProxy.update("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to PUT a person activity");
// fail("");
// }
// catch(PublicApiException e)
// {
// assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
// }
// Test Case cloud-1970
// not allowed methods
{
List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() {
@Override
public List<Activity> doWork() throws Exception {
List<Activity> activities = repoService.getActivities(person1.getId(), null, false, false);
return activities;
}
}, person1.getId(), network1.getId());
assertTrue(activities.size() > 0);
Activity activity = activities.get(0);
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.create("people", person1.getId(), "activities", null, null, "Unable to POST to activities");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.create("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to POST to an activity");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.update("people", person1.getId(), "activities", null, null, "Unable to PUT activities");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.update("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to PUT an activity");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.remove("people", person1.getId(), "activities", null, "Unable to DELETE activities");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.remove("people", person1.getId(), "activities", String.valueOf(activity.getId()), "Unable to DELETE an activity");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.People 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;
}
}
}
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.People 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.People in project alfresco-remote-api by Alfresco.
the class TestNetworks method testCLOUD1856.
/*
* CLOUD-1856: test that a network id of the form "cmis*" works
*/
@Test
public void testCLOUD1856() throws Exception {
People peopleProxy = publicApiClient.people();
publicApiClient.setRequestContext(new RequestContext(network3.getId(), person31.getId()));
Person ret = peopleProxy.getPerson(person31.getId());
person31.expected(ret);
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.People in project alfresco-remote-api by Alfresco.
the class TestNetworks method testPersonNetworks.
@Test
public void testPersonNetworks() throws Exception {
People peopleProxy = publicApiClient.people();
{
/**
* Test http://<host>:<port>/alfresco/a i.e. tenant servlet root - should return user's networks
*/
final TestNetwork testAccount = getTestFixture().getRandomNetwork();
Iterator<TestPerson> personIt = testAccount.getPeople().iterator();
final TestPerson person = personIt.next();
RequestContext rc = new RequestContext(null, person.getId());
publicApiClient.setRequestContext(rc);
HttpResponse response = publicApiClient.delete(null, null, null, null, null);
// url /null/alfresco/versions/1 does not map to a Web Script
assertEquals(404, response.getStatusCode());
PublicApiClient.ExpectedErrorResponse errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
assertNotNull(errorResponse);
assertNotNull(errorResponse.getErrorKey());
assertNotNull(errorResponse.getBriefSummary());
response = publicApiClient.put(null, null, null, null, null, null, null);
assertEquals(404, response.getStatusCode());
errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
assertNotNull(errorResponse);
assertNotNull(errorResponse.getErrorKey());
assertNotNull(errorResponse.getBriefSummary());
response = publicApiClient.post(null, null, null, null, null, null);
assertEquals(404, response.getStatusCode());
errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
assertNotNull(errorResponse);
assertNotNull(errorResponse.getErrorKey());
assertNotNull(errorResponse.getBriefSummary());
List<PersonNetwork> expectedNetworkMembers = person.getNetworkMemberships();
int expectedTotal = expectedNetworkMembers.size();
{
// GET / - users networks
Paging paging = getPaging(0, Integer.MAX_VALUE, expectedTotal, expectedTotal);
publicApiClient.setRequestContext(new RequestContext("-default-", person.getId()));
response = publicApiClient.index(createParams(paging, null));
ListResponse<PersonNetwork> resp = PersonNetwork.parseNetworkMembers(response.getJsonResponse());
assertEquals(200, response.getStatusCode());
checkList(new ArrayList<PersonNetwork>(expectedNetworkMembers), paging.getExpectedPaging(), resp);
}
}
// user from another network
{
publicApiClient.setRequestContext(new RequestContext("-default-", person21.getId()));
List<PersonNetwork> networksMemberships = Collections.emptyList();
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
}
// user from the same network
try {
List<PersonNetwork> networksMemberships = person12.getNetworkMemberships();
publicApiClient.setRequestContext(new RequestContext("-default-", person12.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
List<PersonNetwork> networksMemberships = person11.getNetworkMemberships();
// Test Case cloud-2203
// Test Case cloud-1498
// test paging
{
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
ListResponse<PersonNetwork> resp = peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
checkList(networksMemberships.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// "-me-" user
{
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
ListResponse<PersonNetwork> resp = peopleProxy.getNetworkMemberships(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
checkList(networksMemberships.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// unknown person id
try {
List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
int skipCount = 0;
int maxItems = 2;
Paging expectedPaging = getPaging(skipCount, maxItems, networkMemberships.size(), networkMemberships.size());
peopleProxy.getNetworkMemberships("invalidUser", createParams(expectedPaging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid caller authentication
try {
List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId(), GUID.generate()));
int skipCount = 0;
int maxItems = 2;
Paging expectedPaging = getPaging(skipCount, maxItems, networkMemberships.size(), networkMemberships.size());
peopleProxy.getNetworkMemberships(person11.getId(), createParams(expectedPaging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// unknown person id
try {
List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
assertTrue(networkMemberships.size() > 0);
PersonNetwork network = networkMemberships.get(0);
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.getNetworkMembership("invalidUser", network.getId());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid caller authentication
try {
List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
assertTrue(networkMemberships.size() > 0);
PersonNetwork network = networkMemberships.get(0);
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId(), GUID.generate()));
peopleProxy.getNetworkMembership(person11.getId(), network.getId());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// incorrect network id
try {
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.getNetworkMembership(person11.getId(), GUID.generate());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// POST, POST networkId, PUT, PUT networkId, DELETE, DELETE networkId
try {
PersonNetwork pn = new PersonNetwork(GUID.generate());
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.create("people", person11.getId(), "networks", null, pn.toJSON().toString(), "Unable to POST to person networks");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
PersonNetwork pn = networksMemberships.get(0);
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.create("people", person11.getId(), "networks", pn.getId(), pn.toJSON().toString(), "Unable to POST to a person network");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
PersonNetwork pn = new PersonNetwork(GUID.generate());
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.update("people", person11.getId(), "networks", null, pn.toJSON().toString(), "Unable to PUT person networks");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
PersonNetwork pn = networksMemberships.get(0);
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.update("people", person11.getId(), "networks", pn.getId(), pn.toJSON().toString(), "Unable to PUT a person network");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.remove("people", person11.getId(), "networks", null, "Unable to DELETE person networks");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
PersonNetwork pn = networksMemberships.get(0);
publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
peopleProxy.remove("people", person11.getId(), "networks", pn.getId(), "Unable to DELETE a person network");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// user not a member of the network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
int skipCount = 0;
int maxItems = 2;
Paging expectedPaging = getPaging(skipCount, maxItems);
peopleProxy.getNetworkMemberships(person11.getId(), createParams(expectedPaging, null));
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
}
Aggregations