use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testUpdateTaskInvalidProperty.
@Test
public void testUpdateTaskInvalidProperty() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
TasksClient tasksClient = publicApiClient.tasksClient();
// Try updating an unexisting property
try {
JSONObject taskBody = new JSONObject();
List<String> selectedFields = new ArrayList<String>();
selectedFields.add("unexisting");
tasksClient.updateTask(task.getId(), taskBody, selectedFields);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The property selected for update does not exist for this resource: unexisting", expected.getHttpResponse());
}
// Try updating a readonly-property
try {
JSONObject taskBody = new JSONObject();
List<String> selectedFields = new ArrayList<String>();
selectedFields.add("id");
tasksClient.updateTask(task.getId(), taskBody, selectedFields);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.BAD_REQUEST.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The property selected for update is read-only: id", expected.getHttpResponse());
}
} finally {
cleanupProcessInstance(processInstance);
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class TestCMIS method testInvalidMethods.
// @Test
public void testInvalidMethods() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
Iterator<String> personIt = network1.getPersonIds().iterator();
final String person = personIt.next();
assertNotNull(person);
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
publicApiClient.post(Binding.atom, CMIS_VERSION_10, null, null);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
publicApiClient.head(Binding.atom, CMIS_VERSION_10, null, null);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
publicApiClient.options(Binding.atom, CMIS_VERSION_10, null, null);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
publicApiClient.trace(Binding.atom, CMIS_VERSION_10, null, null);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
publicApiClient.patch(Binding.atom, CMIS_VERSION_10, null, null);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class TestFavouriteSites method testFavouriteSites.
@Test
public void testFavouriteSites() throws Exception {
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
assertTrue(networksIt.hasNext());
final TestNetwork network1 = networksIt.next();
assertTrue(networksIt.hasNext());
final TestNetwork network2 = networksIt.next();
// Create some users and sites
final List<TestPerson> people = new ArrayList<TestPerson>();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
return null;
}
}, network1.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network2.createUser();
people.add(person);
person = network2.createUser();
people.add(person);
return null;
}
}, network2.getId());
final TestPerson person1 = people.get(0);
final TestPerson person2 = people.get(1);
final TestPerson person3 = people.get(2);
final TestPerson person4 = people.get(3);
final TestPerson person5 = people.get(3);
TestSite testSite = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person1.getId(), network1.getId());
}
}, false, true);
TestSite testSite1 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person1.getId(), network1.getId());
}
}, false, true);
TestSite testSite3 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person1.getId(), network1.getId());
}
}, false, true);
TestSite testSite4 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person5.getId(), network2.getId());
}
}, false, true);
Sites sitesProxy = publicApiClient.sites();
// invalid methods
try {
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.create("people", person1.getId(), "favorite-sites", testSite.getSiteId(), fs.toJSON().toString(), "Unable to POST to a favorite-site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.update("people", person1.getId(), "favorite-sites", null, fs.toJSON().toString(), "Unable to PUT favorite-sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.update("people", person1.getId(), "favorite-sites", testSite.getSiteId(), fs.toJSON().toString(), "Unable to PUT a favorite-site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.remove("people", person1.getId(), "favorite-sites", null, "Unable to DELETE favorite-sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// unknown user - 404
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
sitesProxy.createFavouriteSite("invalid.user", fs);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// user from another network - 401 (not able to auth against tenant)
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
sitesProxy.createFavouriteSite(person1.getId(), fs);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// another user from the same network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
sitesProxy.createFavouriteSite(person2.getId(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// a member of this site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
FavouriteSite resp = sitesProxy.createFavouriteSite(person1.getId(), fs);
fs.expected(resp);
}
// add same favourite site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.createFavouriteSite(person1.getId(), new FavouriteSite(testSite.getSiteId()));
fail();
} catch (PublicApiException e) {
assertEquals(409, e.getHttpResponse().getStatusCode());
}
// "-me" user
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
FavouriteSite resp = sitesProxy.createFavouriteSite(org.alfresco.rest.api.People.DEFAULT_USER, fs);
fs.expected(resp);
final List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person2);
}
}, person2.getId(), network1.getId());
// check it's there
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.getFavouriteSites(person2.getId(), createParams(paging, null));
}
// not a member of this site
{
FavouriteSite fs = new FavouriteSite(testSite1.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite ret = sitesProxy.createFavouriteSite(person1.getId(), fs);
fs.expected(ret);
}
// GET favourite sites
{
final List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person1);
}
}, person1.getId(), network1.getId());
// unknown user
try {
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.getFavouriteSites(GUID.generate(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// authentication: unknown user
try {
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), GUID.generate(), "password"));
sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// another user from the same network - 403
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// another user from another network - 401
try {
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// successful GET
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
}
// skipCount is greater than the number of favourite sites
{
int skipCount = expectedFavouriteSites.size() + 100;
Paging paging = getPaging(skipCount, null, expectedFavouriteSites.size(), expectedFavouriteSites.size());
List<FavouriteSite> expected = Collections.emptyList();
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
checkList(expected, paging.getExpectedPaging(), response);
}
// "-me-" user
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
}
}
// user is a member of the site which he has favourited
{
publicApiClient.setRequestContext(new RequestContext(network2.getId(), person5.getId()));
List<FavouriteSite> expectedFavouriteSites = new ArrayList<FavouriteSite>(1);
FavouriteSite fs = new FavouriteSite(testSite4.getSiteId());
expectedFavouriteSites.add(fs);
FavouriteSite ret = sitesProxy.createFavouriteSite(person5.getId(), fs);
fs.expected(ret);
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person5.getId(), createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
}
// remove
{
// create some favourite sites
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
FavouriteSite fs = new FavouriteSite(testSite);
sitesProxy.createFavouriteSite(person3.getId(), fs);
fs = new FavouriteSite(testSite1);
sitesProxy.createFavouriteSite(person3.getId(), fs);
}
// known user
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite);
sitesProxy.removeFavouriteSite(person1.getId(), fs);
List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person1);
}
}, person1.getId(), network1.getId());
// check removed
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
assertFalse(response.getList().contains(fs));
}
// unknown user
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite);
sitesProxy.removeFavouriteSite(GUID.generate(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(GUID.generate());
sitesProxy.removeFavouriteSite(person1.getId(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// try to remove a favourite site that is not a favourite site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite3);
sitesProxy.removeFavouriteSite(person1.getId(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// "-me-" user
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
FavouriteSite fs = new FavouriteSite(testSite1);
sitesProxy.removeFavouriteSite(org.alfresco.rest.api.People.DEFAULT_USER, fs);
List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person3);
}
}, person3.getId(), network1.getId());
// check removed
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person3.getId(), createParams(paging, null));
assertFalse(response.getList().contains(fs));
}
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException 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.PublicApiException in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeploymentById.
@Test
public void testGetDeploymentById() throws Exception {
// Use admin-user for tenant
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
// Fetch the actual deployment from activiti
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentName("adhoc.bpmn20.xml").processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
assertNotNull(activitiDeployment);
// Do the actual API-call
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
Deployment deployment = deploymentsClient.findDeploymentById(activitiDeployment.getId());
assertNotNull(deployment);
assertEquals(activitiDeployment.getId(), deployment.getId());
assertEquals(activitiDeployment.getCategory(), deployment.getCategory());
assertEquals(activitiDeployment.getName(), deployment.getName());
assertEquals(activitiDeployment.getDeploymentTime(), deployment.getDeployedAt());
try {
deploymentsClient.findDeploymentById("fakeid");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// get deployment with default user
try {
publicApiClient.setRequestContext(requestContext);
deploymentsClient.findDeploymentById(activitiDeployment.getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
}
Aggregations