use of org.alfresco.rest.api.tests.client.PublicApiClient.Sites in project alfresco-remote-api by Alfresco.
the class TestCMIS method testScenario1.
/**
* Tests CMIS and non-CMIS public api interactions
*/
@SuppressWarnings("deprecation")
@Test
public void testScenario1() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
Iterator<String> personIt = network1.getPersonIds().iterator();
final String person = personIt.next();
assertNotNull(person);
Sites sitesProxy = publicApiClient.sites();
Comments commentsProxy = publicApiClient.comments();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
ListResponse<MemberOfSite> sites = sitesProxy.getPersonSites(person, null);
assertTrue(sites.getList().size() > 0);
MemberOfSite siteMember = sites.getList().get(0);
String siteId = siteMember.getSite().getSiteId();
Folder documentLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteId + "/documentLibrary");
System.out.println("documentLibrary id = " + documentLibrary.getId());
Map<String, String> fileProps = new HashMap<String, String>();
{
fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document doc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
System.out.println("Document id = " + doc.getId());
Comment c = commentsProxy.createNodeComment(doc.getId(), new Comment("comment title 1", "comment 1"));
System.out.println("Comment = " + c);
// Now lock the document
String nodeRefStr = (String) doc.getPropertyValue("alfcmis:nodeRef");
final NodeRef nodeRef = new NodeRef(nodeRefStr);
final TenantRunAsWork<Void> runAsWork = new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
lockService.lock(nodeRef, LockType.WRITE_LOCK);
return null;
}
};
RetryingTransactionCallback<Void> txnWork = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
TenantUtil.runAsUserTenant(runAsWork, "bob", network1.getId());
return null;
}
};
transactionHelper.doInTransaction(txnWork);
// Now attempt to update the document's metadata
try {
doc.delete();
} catch (CmisUpdateConflictException e) {
// Expected: ACE-762 BM-0012: NodeLockedException not handled by CMIS
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.Sites in project alfresco-remote-api by Alfresco.
the class TestSiteGroups method shouldAddGroup.
@Test
public void shouldAddGroup() throws Exception {
Sites sitesProxy = publicApiClient.sites();
try {
groupName = createAuthorityContext(user1);
setRequestContext(networkOne.getId(), DEFAULT_ADMIN, DEFAULT_ADMIN_PWD);
TestSite site = TenantUtil.runAsUserTenant(() -> networkOne.createSite(SiteVisibility.PRIVATE), DEFAULT_ADMIN, networkOne.getId());
// Should throw 404 error
try {
sitesProxy.addGroup(site.getSiteId(), new SiteGroup(GUID.generate(), SiteRole.SiteCollaborator.name()));
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
SiteGroup response = sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
assertEquals(response.getGroup().getId(), groupName);
assertEquals(response.getRole(), SiteRole.SiteCollaborator.name());
// Should throw 409 error
try {
sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
}
siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
assertEquals(siteMembers.getList().size(), 3);
PublicApiClient.ListResponse<SiteGroup> groups = sitesProxy.getGroups(site.getSiteId(), createParams(paging, null));
assertEquals(groups.getList().size(), 1);
assertEquals(groups.getList().get(0).getRole(), SiteRole.SiteCollaborator.name());
} finally {
clearAuthorityContext(groupName);
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.Sites in project alfresco-remote-api by Alfresco.
the class TestSiteGroups method shouldUpdateGroup.
@Test
public void shouldUpdateGroup() throws Exception {
Sites sitesProxy = publicApiClient.sites();
try {
groupName = createAuthorityContext(user1);
setRequestContext(networkOne.getId(), DEFAULT_ADMIN, DEFAULT_ADMIN_PWD);
TestSite site = TenantUtil.runAsUserTenant(() -> networkOne.createSite(SiteVisibility.PRIVATE), DEFAULT_ADMIN, networkOne.getId());
// Should throw 400 error
try {
sitesProxy.updateGroup(site.getSiteId(), new SiteGroup(GUID.generate(), SiteRole.SiteCollaborator.name()));
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
SiteGroup response = sitesProxy.addGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteCollaborator.name()));
assertEquals(response.getGroup().getId(), groupName);
assertEquals(response.getRole(), SiteRole.SiteCollaborator.name());
response = sitesProxy.updateGroup(site.getSiteId(), new SiteGroup(groupName, SiteRole.SiteContributor.name()));
assertEquals(response.getGroup().getId(), groupName);
assertEquals(response.getRole(), SiteRole.SiteContributor.name());
siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
assertEquals(siteMembers.getList().size(), 3);
assertEquals(siteMembers.getList().get(1).getRole(), SiteRole.SiteContributor.name());
assertEquals(siteMembers.getList().get(2).getRole(), SiteRole.SiteContributor.name());
} finally {
clearAuthorityContext(groupName);
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.Sites in project alfresco-remote-api by Alfresco.
the class TestPersonSites method getSiteMembershipsForPerson32.
/**
* Retrieves the site memberships associated to a user
*
* @param sortColumn
* @param asc
* @return
* @throws Exception
*/
private ListResponse<MemberOfSite> getSiteMembershipsForPerson32(final Paging paging, String sortColumn, boolean asc) throws Exception {
final Sites sitesProxy = publicApiClient.sites();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person32.getId()));
// sort params
final Map<String, String> params = new HashMap<String, String>();
if (sortColumn != null) {
params.put("orderBy", sortColumn + " " + (asc ? "ASC" : "DESC"));
}
// get memberships
ListResponse<MemberOfSite> resp = TenantUtil.runAsUserTenant(new TenantRunAsWork<ListResponse<MemberOfSite>>() {
@Override
public ListResponse<MemberOfSite> doWork() throws Exception {
ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person32.getId(), createParams(paging, params));
return resp;
}
}, person32.getId(), network1.getId());
return resp;
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.Sites in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testPersonSites.
@Test
public void testPersonSites() throws Exception {
Set<MemberOfSite> personSites = new TreeSet<MemberOfSite>();
// Get last site for use with personRemoveSite
TestSite personRemoveSite = sites.get(sites.size() - 1);
sites.remove(sites.size() - 1);
personSites.addAll(network1.getSiteMemberships(person11.getId()));
// Create some sites
personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {
@Override
public List<MemberOfSite> doWork() throws Exception {
List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
TestSite site = network1.createSite(SiteVisibility.PRIVATE);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
site = network1.createSite(SiteVisibility.PUBLIC);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
site = network1.createSite(SiteVisibility.MODERATED);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
return expectedSites;
}
}, person11.getId(), network1.getId()));
personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {
@Override
public List<MemberOfSite> doWork() throws Exception {
List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
TestSite site = network1.createSite(SiteVisibility.PRIVATE);
site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
site = network1.createSite(SiteVisibility.PUBLIC);
site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
site = network1.createSite(SiteVisibility.MODERATED);
site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
return expectedSites;
}
}, person12.getId(), network1.getId()));
final List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>(personSites);
Sites sitesProxy = publicApiClient.sites();
// unknown user
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSites(GUID.generate(), null);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-2200
// Test Case cloud-2213
// user should be able to list their sites
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 2;
int maxItems = 8;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// "-me-" user
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// a user in another tenant should not be able to list a user's sites
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), null);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// Test case cloud-1488
{
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
MemberOfSite ret = sitesProxy.getPersonSite(person11.getId(), memberOfSite.getSiteId());
memberOfSite.expected(ret);
}
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(person11.getId(), GUID.generate());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown person id
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getPersonSite(person11.getId(), GUID.generate());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
{
// Tests removing a person from the site
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.remove("people", person11.getId(), "sites", personRemoveSite.getSiteId(), "Unable to DELETE a person site");
try {
sitesProxy.getPersonSite(person11.getId(), personRemoveSite.getSiteId());
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
}
// Not allowed methods
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.create("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to POST to a person site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.create("people", person11.getId(), "sites", null, null, "Unable to POST to person sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
MemberOfSite memberOfSite = expectedSites.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.update("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to PUT a person site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.update("people", person11.getId(), "sites", null, null, "Unable to PUT person sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.remove("people", person11.getId(), "sites", null, "Unable to DELETE person sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
Aggregations