use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestFavourites method testPUBLICAPI156.
@Test
public void testPUBLICAPI156() throws Exception {
// person1's public site
final TestSite publicSite = person1PublicSites.get(0);
// person1's public site
final TestSite publicSite1 = person1PublicSites.get(1);
// person1's folder
final NodeRef folderNodeRef = person1PublicFolders.get(0);
// a file in the folder
final NodeRef nodeRef = person1PublicDocs.get(1);
final List<Favourite> expectedFavourites = new ArrayList<Favourite>();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14Id));
// invite to another user's public site
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(publicSite.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person14Id, siteMembershipRequest);
// favourite other users site, folder and file
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
favouritesProxy.createFavourite(person14Id, folderFavourite);
expectedFavourites.add(folderFavourite);
Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
favouritesProxy.createFavourite(person14Id, fileFavourite);
expectedFavourites.add(fileFavourite);
final Favourite siteFavourite = makeSiteFavourite(publicSite);
favouritesProxy.createFavourite(person14Id, siteFavourite);
expectedFavourites.add(siteFavourite);
final Favourite siteFavourite1 = makeSiteFavourite(publicSite1);
favouritesProxy.createFavourite(person14Id, siteFavourite1);
expectedFavourites.add(siteFavourite1);
sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
// remove the folder and file
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
repoService.deleteNode(nodeRef);
repoService.deleteNode(folderNodeRef);
return null;
}
}, person11Id, network1.getId());
expectedFavourites.remove(folderFavourite);
expectedFavourites.remove(fileFavourite);
sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
// GETs should not return the favourites nor error
{
try {
favouritesProxy.getFavourite(person14Id, folderFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
favouritesProxy.getFavourite(person14Id, fileFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person14Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestFavourites method testPUBLICAPI141.
@Test
public void testPUBLICAPI141() throws Exception {
// person1's public site
final TestSite publicSite = person1PublicSites.get(0);
// person1's public site
final TestSite publicSite1 = person1PublicSites.get(1);
// person1's private site
final TestSite privateSite = person1PrivateSites.get(0);
// person1's folder
final NodeRef folderNodeRef = person1PublicFolders.get(0);
// a file in the folder
final NodeRef nodeRef = person1PublicDocs.get(1);
final List<Favourite> expectedFavourites = new ArrayList<Favourite>();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12Id));
// invite to another user's public site
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(publicSite.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
siteMembershipRequestsProxy.createSiteMembershipRequest(person12Id, siteMembershipRequest);
// favourite other users site, folder and file
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
favouritesProxy.createFavourite(person12Id, folderFavourite);
Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
favouritesProxy.createFavourite(person12Id, fileFavourite);
final Favourite siteFavourite = makeSiteFavourite(publicSite);
favouritesProxy.createFavourite(person12Id, siteFavourite);
expectedFavourites.add(siteFavourite);
final Favourite siteFavourite1 = makeSiteFavourite(publicSite1);
favouritesProxy.createFavourite(person12Id, siteFavourite1);
expectedFavourites.add(siteFavourite1);
sort(expectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
// move the folder and file to person1's private site
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
NodeRef documentLibraryNodeRef = privateSite.getContainerNodeRef("documentLibrary");
repoService.moveNode(folderNodeRef, documentLibraryNodeRef);
return null;
}
}, person11Id, network1.getId());
try {
favouritesProxy.getFavourite(person12Id, folderFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
favouritesProxy.getFavourite(person12Id, fileFavourite.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// make the public sites private
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
publicSite.setSiteVisibility(SiteVisibility.PRIVATE);
publicSite1.setSiteVisibility(SiteVisibility.PRIVATE);
return null;
}
}, person11Id, network1.getId());
expectedFavourites.remove(siteFavourite1);
// Given that person2Id is still a member of 'publicSite', they should still have access and therefore
// it should show up in their favourites. But person2Id is not a member of 'publicSite1', they should
// not have access and therefore it should not show up in their favourites.
{
Favourite actual = favouritesProxy.getFavourite(person12Id, siteFavourite.getTargetGuid());
siteFavourite.expected(actual);
try {
favouritesProxy.getFavourite(person12Id, siteFavourite1.getTargetGuid());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
checkList(sublist(expectedFavourites, skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestNodeComments method test_MNT_16446.
@Test
public void test_MNT_16446() throws Exception {
Comments commentsProxy = publicApiClient.comments();
// in a site
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13.getId()));
Comment comment = new Comment("Test Comment 1", "Test Comment 1");
Comment resp = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
String commentId = resp.getId();
// MNT-16446: another site collaborator should not be able to edit
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14.getId()));
Comment update = new Comment("Test Comment 4", "Test Comment 4");
commentsProxy.updateNodeComment(nodeRef1.getId(), commentId, update);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13.getId()));
Comment update = new Comment("Updated comment", "Updated comment");
commentsProxy.updateNodeComment(nodeRef1.getId(), commentId, update);
commentsProxy.removeNodeComment(nodeRef1.getId(), commentId);
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class TestNodeComments method testNodeCommentsAndLockingIncludingChildren.
// lock recursively (MNT-14945, MNT-16446, REPO-1150)
@Test
public void testNodeCommentsAndLockingIncludingChildren() throws Exception {
Comments commentsProxy = publicApiClient.comments();
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment comment = new Comment();
comment.setContent("my comment");
Comment createdComment = commentsProxy.createNodeComment(nodeRef5.getId(), comment);
// recursive lock (folderRef1, nodeRef5)
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
repoService.lockNode(folderNodeRef1, LockType.WRITE_LOCK, 0, true);
return null;
}
}, person11.getId(), network1.getId());
} finally {
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
repoService.unlockNode(folderNodeRef1, true);
return null;
}
}, network1.getId());
}
}
use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.
the class DeploymentWorkflowApiTest method testGetDeployments.
@Test
public void testGetDeployments() throws Exception {
// testGetDeployments#1: Getting deployments with admin-user
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
Map<String, Deployment> deploymentMap = new HashMap<String, Deployment>();
for (Deployment deployment : deploymentResponse.getList()) {
deploymentMap.put(deployment.getName(), deployment);
}
assertEquals(5, deploymentResponse.getList().size());
assertTrue(deploymentMap.containsKey("review-pooled.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("review.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("parallel-review-group.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("parallel-review.bpmn20.xml"));
assertTrue(deploymentMap.containsKey("adhoc.bpmn20.xml"));
// testGetDeployments#2: Check all deployment fields in resulting deployment
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentName("adhoc.bpmn20.xml").processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
assertNotNull(activitiDeployment);
Deployment adhocDeployment = deploymentMap.get("adhoc.bpmn20.xml");
assertEquals(activitiDeployment.getId(), adhocDeployment.getId());
assertEquals(activitiDeployment.getCategory(), adhocDeployment.getCategory());
assertEquals(activitiDeployment.getName(), adhocDeployment.getName());
assertEquals(activitiDeployment.getDeploymentTime(), adhocDeployment.getDeployedAt());
Map<String, String> params = new HashMap<String, String>();
params.put("maxItems", "2");
JSONObject deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
JSONObject paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "2");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "5");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "0");
params.put("maxItems", "7");
deploymentsListObject = deploymentsClient.getDeploymentsWithRawResponse(params);
assertNotNull(deploymentsListObject);
paginationJSON = (JSONObject) deploymentsListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
}
Aggregations