use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class TestSiteMembershipRequests method testInvalidRequests.
@Test
public void testInvalidRequests() throws Exception {
{
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id));
// unknown invitee
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(GUID.generate(), siteMembershipRequest);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id));
// unknown siteId
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(GUID.generate());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id));
// create site membership for another user
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person11Id, siteMembershipRequest);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// get requests for another user
try {
log("cloud-2506");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
// get site membership requests for another user
int skipCount = 0;
int maxItems = 4;
Paging paging = getPaging(skipCount, maxItems);
siteMembershipRequestsProxy.getSiteMembershipRequests(person12Id, createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// get site membership requests for unknown user
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
int skipCount = 0;
int maxItems = 4;
Paging paging = getPaging(skipCount, maxItems);
siteMembershipRequestsProxy.getSiteMembershipRequests(GUID.generate(), createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// get site membership request for unknown site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
siteMembershipRequestsProxy.getSiteMembershipRequest(person11Id, GUID.generate());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// DELETEs
{
{
// cloud-2524
// runAs user != target user
log("cloud-2524");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
// create moderated site invitation to delete
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(person1ModeratedSites.get(0).getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
SiteMembershipRequest request = getSiteMembershipRequest(network1.getId(), person14Id, person14Id);
// user from another network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person24Id));
siteMembershipRequestsProxy.cancelSiteMembershipRequest(person14Id, request.getId());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// unknown personId
try {
log("cloud-2525");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
siteMembershipRequestsProxy.cancelSiteMembershipRequest(GUID.generate(), request.getId());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
}
// unknown siteId
try {
log("cloud-2526");
log("cloud-2527");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
SiteMembershipRequest request = new SiteMembershipRequest();
request.setId(GUID.generate());
siteMembershipRequestsProxy.cancelSiteMembershipRequest(person14Id, request.getId());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown request id
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
siteMembershipRequestsProxy.cancelSiteMembershipRequest(person14Id, GUID.generate());
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
}
// cloud-2519 - PUT to site membership requests
try {
log("cloud-2519");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
SiteMembershipRequest request = new SiteMembershipRequest();
request.setId(GUID.generate());
request.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.update("people", person11Id, "favorites", null, request.toJSON().toString(), "Unable to PUT site membership requests");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// cloud-2520 - unknown request/site id
try {
log("cloud-2516");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
SiteMembershipRequest request = new SiteMembershipRequest();
request.setId(GUID.generate());
request.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.updateSiteMembershipRequest(person11Id, request);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class TestUserPreferences method testUserPreferences.
@Test
public void testUserPreferences() throws Exception {
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
assertTrue(networksIt.hasNext());
final TestNetwork network1 = networksIt.next();
assertTrue(networksIt.hasNext());
final TestNetwork network2 = networksIt.next();
final List<TestPerson> people = new ArrayList<TestPerson>(3);
// create users and some preferences
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson 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);
return null;
}
}, network2.getId());
final TestPerson person1 = people.get(0);
final TestPerson person2 = people.get(1);
final TestPerson person3 = people.get(2);
final List<Preference> expectedPreferences = new ArrayList<Preference>();
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference2", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference1", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.share.documentList.sortAscending", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference3", String.valueOf(true)));
// new preference name for issue REPO-855
expectedPreferences.add(new Preference("org.alfresco.ext.folders.favourites.workspace://SpacesStore/4e3d0779-388a-4b94-91e1-eab588a7da3d.createdAt", String.valueOf(true)));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
for (Preference pref : expectedPreferences) {
// TODO add preferences thru api
repoService.addPreference(person1.getId(), pref.getId(), pref.getValue());
}
return null;
}
}, person1.getId(), network1.getId());
Collections.sort(expectedPreferences);
People peopleProxy = publicApiClient.people();
// unknown user
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
peopleProxy.getPreferences(GUID.generate(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// test paging
{
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 2;
int maxItems = 10;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// "-me-" user
{
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
ListResponse<Preference> resp = peopleProxy.getPreferences(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// invalid user - 404
try {
int skipCount = 2;
int maxItems = 10;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
peopleProxy.getPreferences("invalid.user", createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// user from another account - 401
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
// ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
// checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(e.getHttpResponse().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
}
// another user from the same account - 403
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// get a single preference
// Test Case: cloud-1493
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Preference pref = expectedPreferences.get(0);
Preference ret = peopleProxy.getPreference(person1.getId(), pref.getId());
pref.expected(ret);
}
// unknown person id
try {
Preference pref = expectedPreferences.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
peopleProxy.getPreference(GUID.generate(), pref.getId());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown preference id
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getPreference(person1.getId(), GUID.generate());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// Test case: cloud-1968
try {
Preference pref = expectedPreferences.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.create("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to POST to a preference");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Preference pref = expectedPreferences.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.update("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to PUT a preference");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Preference pref = expectedPreferences.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.remove("people", person1.getId(), "preferences", pref.getId(), "Unable to DELETE a preference");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Preference pref = expectedPreferences.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.create("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to POST to preferences");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Preference pref = expectedPreferences.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.update("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to PUT preferences");
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(), "preferences", null, "Unable to DELETE preferences");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
{
// REPO-1061, REPO-890
try {
String skipCount = "a";
String maxItems = "hi";
HashMap<String, String> params = new HashMap<String, String>();
params.put("skipCount", skipCount);
params.put("maxItems", maxItems);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getPreferences(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
try {
String skipCount = "a";
String maxItems = "null";
HashMap<String, String> params = new HashMap<String, String>();
params.put("skipCount", skipCount);
params.put("maxItems", maxItems);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getPreferences(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
try {
String maxItems = "Red";
HashMap<String, String> params = new HashMap<String, String>();
params.put("maxItems", maxItems);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getPreferences(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
try {
String skipCount = "yuck";
HashMap<String, String> params = new HashMap<String, String>();
params.put("skipCount", skipCount);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getPreferences(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
try {
String skipCount = "-1";
HashMap<String, String> params = new HashMap<String, String>();
params.put("skipCount", skipCount);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getPreferences(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
try {
String maxItems = "0";
HashMap<String, String> params = new HashMap<String, String>();
params.put("maxItems", maxItems);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.getPreferences(person1.getId(), params);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeploymentsWithNonAdminUser.
@Test
public void testGetDeploymentsWithNonAdminUser() throws Exception {
// deployments-get#1
initApiClientWithTestUser();
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
try {
deploymentsClient.getDeployments();
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("Permission was denied", expected.getHttpResponse());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class EnterpriseWorkflowTestApi method startReviewPooledProcess.
/**
* Start a review pooled process through the public REST-API.
*/
@SuppressWarnings("unchecked")
protected ProcessInfo startReviewPooledProcess(final RequestContext requestContext) throws PublicApiException {
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiReviewPooled").singleResult();
ProcessesClient processesClient = publicApiClient.processesClient();
final JSONObject createProcessObject = new JSONObject();
createProcessObject.put("processDefinitionId", processDefinition.getId());
final JSONObject variablesObject = new JSONObject();
variablesObject.put("bpm_priority", 1);
variablesObject.put("bpm_workflowDueDate", ISO8601DateFormat.format(new Date()));
variablesObject.put("wf_notifyMe", Boolean.FALSE);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
List<MemberOfSite> memberships = getTestFixture().getNetwork(requestContext.getNetworkId()).getSiteMemberships(requestContext.getRunAsUser());
assertTrue(memberships.size() > 0);
MemberOfSite memberOfSite = memberships.get(0);
String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name();
variablesObject.put("bpm_groupAssignee", group);
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
createProcessObject.put("variables", variablesObject);
return processesClient.createProcess(createProcessObject.toJSONString());
}
use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionStartModelUnexisting.
@Test
public void testGetProcessDefinitionStartModelUnexisting() throws Exception {
initApiClientWithTestUser();
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
try {
processDefinitionsClient.findStartFormModel("unexisting");
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
}
}
Aggregations