use of org.alfresco.rest.api.tests.client.data.Activity in project alfresco-remote-api by Alfresco.
the class ActivitiesPostingTest method testNonSite.
/**
* Tests non-site file activites. So no events.
*/
@Test
public void testNonSite() throws Exception {
setRequestContext(user1);
List<Activity> activities = getMyActivities();
String folder1 = "nonSitefolder" + System.currentTimeMillis() + "_1";
// Create a folder outside a site
Folder createdFolder = createFolder(Nodes.PATH_MY, folder1, null);
assertNotNull(createdFolder);
String f1Id = createdFolder.getId();
String docName = "nonsite_d1.txt";
Document documentResp = createEmptyTextFile(f1Id, docName);
assertNotNull(documentResp);
// Update the file
Document dUpdate = new Document();
dUpdate.setName("nonsite_d2.txt");
put(URL_NODES, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
List<Activity> activitiesAgain = getMyActivities();
assertEquals("No activites should be created for non-site nodes", activities, activitiesAgain);
}
use of org.alfresco.rest.api.tests.client.data.Activity in project alfresco-remote-api by Alfresco.
the class ActivitiesPostingTest method testNonFileActivities.
/**
* Tests non-file activites. So no events.
*/
@Test
public void testNonFileActivities() throws Exception {
setRequestContext(user1);
String folder1 = "InSitefolder" + System.currentTimeMillis() + "_1";
Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
assertNotNull(createdFolder);
List<Activity> activities = getMyActivities();
Node aNode = createNode(createdFolder.getId(), "mynode", "cm:failedThumbnail", null);
assertNotNull(aNode);
deleteNode(aNode.getId());
List<Activity> activitiesAgain = getMyActivities();
assertEquals("No activites should be created for non-file activities", activities, activitiesAgain);
}
use of org.alfresco.rest.api.tests.client.data.Activity in project alfresco-remote-api by Alfresco.
the class RepoService method getActivities.
public List<Activity> getActivities(String personId, String siteId, boolean excludeUser, boolean excludeOthers) {
List<ActivityFeedEntity> feedEntities = activityService.getUserFeedEntries(personId, siteId, excludeUser, excludeOthers, 0);
List<Activity> activities = new ArrayList<Activity>(feedEntities.size());
for (ActivityFeedEntity entity : feedEntities) {
String siteNetwork = entity.getSiteNetwork();
Pair<String, String> pair = splitSiteNetwork(siteNetwork);
siteId = pair.getFirst();
String networkId = pair.getSecond();
String postDateStr = PublicApiDateFormat.getDateFormat().format(entity.getPostDate());
Activity activity = new Activity(entity.getId(), networkId, siteId, entity.getFeedUserId(), entity.getPostUserId(), postDateStr, entity.getActivityType(), parseActivitySummary(entity));
activities.add(activity);
}
return activities;
}
use of org.alfresco.rest.api.tests.client.data.Activity 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.data.Activity 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