use of org.alfresco.rest.api.tests.client.data.MemberOfSite 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.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSitesWithSameTitles.
// ACE-4823
@Test
public void testSitesWithSameTitles() throws Exception {
// Creates 3 sites
initializeSites();
final String site4_name = "d_" + GUID.generate();
// Same title as site3
final String site4_title = site3_title;
final SiteRole site4_role = SiteRole.SiteCollaborator;
TestSite site4 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(site4_name, site4_title, site4_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site4_role);
return site;
}
}, person31.getId(), network1.getId());
assertNotNull(site4);
// paging
int totalResults = 4;
Paging paging = getPaging(null, null, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(null, null, false);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site2, site2_role));
expectedList.add(new MemberOfSite(site3, site3_role));
expectedList.add(new MemberOfSite(site4, site4_role));
expectedList.add(new MemberOfSite(site1, site1_role));
try {
checkList(expectedList, paging.getExpectedPaging(), resp);
} catch (AssertionError error) {
// Site3 and Site4 have a same title, and as we are sorting on titles (default sorting),
// we can't guarantee the order in which the sites will
// return, hence swap the sites and compare again.
Collections.swap(expectedList, 1, 2);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSortingAndPagingByRoleDesc.
/**
* Tests the capability to sort and paginate the site memberships associated
* to a user orderBy = role DESC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByRoleDesc() throws Exception {
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(paging, "role", false);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site1, site1_role));
expectedList.add(new MemberOfSite(site3, site3_role));
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSortingAndPagingDefault.
/**
* Tests the capability to sort and paginate the site memberships associated
* default sorting (title asc), all results
*
* @throws Exception
*/
public void testSortingAndPagingDefault() throws Exception {
// paging
int totalResults = 3;
Paging paging = getPaging(null, null, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(null, null, false);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site2, site2_role));
expectedList.add(new MemberOfSite(site3, site3_role));
expectedList.add(new MemberOfSite(site1, site1_role));
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testGetSiteMembershipsWhereSiteVisibilityPublic.
public void testGetSiteMembershipsWhereSiteVisibilityPublic() throws Exception {
// paging
int totalResults = 2;
Paging paging = getPaging(null, null, totalResults, totalResults);
// list sites
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson41(null, SiteVisibility.PUBLIC.name());
// check results
List<MemberOfSite> expectedList = getPersonSites(person41, site42, site43);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
Aggregations