use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testDeleteNonCurrentVersion.
/**
* Test delete version on versions other than latest (most recent) version (MNT-17228)
*/
@Test
public void testDeleteNonCurrentVersion() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person = network1.createUser(personInfo);
String personId = person.getId();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
Folder homeFolder = (Folder) cmisSession.getObjectByPath("/User Homes/" + personId);
assertNotNull(homeFolder.getId());
// Create a document
String name = String.format(TEST_DOCUMENT_NAME_PATTERN, GUID.generate());
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, name);
ContentStreamImpl fileContent = new ContentStreamImpl();
ByteArrayInputStream stream = new ByteArrayInputStream(GUID.generate().getBytes());
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(stream);
Document doc = homeFolder.createDocument(properties, fileContent, VersioningState.MAJOR);
String versionLabel = doc.getVersionLabel();
assertEquals("1.0", versionLabel);
Document docVersionToDelete = null;
Document latestDoc = doc;
int cnt = 4;
for (int i = 1; i <= cnt; i++) {
// Update content to create new versions (1.1, 1.2, 1.3, 1.4)
fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("Ipsum and so on and so on " + i);
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
latestDoc.setContentStream(fileContent, true);
latestDoc = latestDoc.getObjectOfLatestVersion(false);
versionLabel = latestDoc.getVersionLabel();
assertEquals("1." + i, versionLabel);
assertEquals(1 + i, cmisSession.getAllVersions(latestDoc.getId()).size());
if (i == 2) {
// ie. 1.2
docVersionToDelete = latestDoc;
}
}
// Test delete with a user without permissions
String username2 = "user" + System.currentTimeMillis();
PersonInfo person2Info = new PersonInfo(username2, username2, username2, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person2 = network1.createUser(person2Info);
String person2Id = person2.getId();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String nodeId = stripCMISSuffix(doc.getId());
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
// Give user person2 READ permissions to access the node
permissionService.setPermission(nodeRef, person2Id, PermissionService.READ, true);
return null;
}
}, network1.getId());
// Connect with person2
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2Id));
CmisSession cmisSession2 = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
CmisObject docVersionToDeleteBy2 = cmisSession2.getObject(docVersionToDelete.getId());
try {
// (-) Delete v 1.2 (without DELETE permission)
docVersionToDeleteBy2.delete(false);
fail("Node version was deleted without permissions.");
} catch (CmisPermissionDeniedException ex) {
// expected
}
// (+) Delete v 1.2 (with permission)
docVersionToDelete.delete(false);
// eg. 1.0, 1.2, 1.3, 1.4 (not 1.1)
assertEquals(cnt, cmisSession.getAllVersions(doc.getId()).size());
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMNT10430.
@Test
public void testMNT10430() throws Exception {
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
ObjectType objectType = cmisSession.getTypeDefinition("D:testcmis:maDoc");
// try and get the mandatory aspects
List<String> mandatoryAspects = ((AlfrescoType) objectType).getMandatoryAspects();
System.out.println("Mandatory Aspects");
for (String mandatoryAspect : mandatoryAspects) {
System.out.println(mandatoryAspect);
}
assertTrue("The aspects should have P:cm:generalclassifiable", mandatoryAspects.contains("P:cm:generalclassifiable"));
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestCMIS method testCreationDate.
/**
* MNT-12680
* The creation date of version should be the same as creation date of the original node
* @throws Exception
*/
@Test
public void testCreationDate() throws Exception {
// create a site
final TestNetwork network1 = getTestFixture().getRandomNetwork();
String username = "user" + System.currentTimeMillis();
PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null);
TestPerson person1 = network1.createUser(personInfo);
String person1Id = person1.getId();
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
final TestSite site = network1.createSite(siteInfo);
final NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "testdoc.txt", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
return resNode;
}
}, person1Id, network1.getId());
// create a document
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
AlfrescoFolder docLibrary = (AlfrescoFolder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
Map<String, String> properties = new HashMap<String, String>();
{
properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
properties.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent("some content");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
Document autoVersionedDoc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
String objectId = autoVersionedDoc.getId();
String bareObjectId = stripCMISSuffix(objectId);
// create versions
for (int i = 0; i < 3; i++) {
Document doc1 = (Document) cmisSession.getObject(bareObjectId);
ObjectId pwcId = doc1.checkOut();
Document pwc = (Document) cmisSession.getObject(pwcId.getId());
ContentStreamImpl contentStream = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
writer.putContent(GUID.generate());
ContentReader reader = writer.getReader();
contentStream.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentStream.setStream(reader.getContentInputStream());
}
pwc.checkIn(true, Collections.EMPTY_MAP, contentStream, "checkin " + i);
}
GregorianCalendar cDateFirst = cmisSession.getAllVersions(bareObjectId).get(0).getCreationDate();
GregorianCalendar cDateSecond = cmisSession.getAllVersions(bareObjectId).get(2).getCreationDate();
if (cDateFirst.before(cDateSecond) || cDateFirst.after(cDateSecond)) {
fail("The creation date of version should be the same as creation date of the original node");
}
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson 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.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestNetworks method setup.
@Before
public void setup() {
// create some networks
for (int i = 0; i < 2; i++) {
final TestNetwork network = repoService.createNetworkWithAlias("network" + i, true);
network.create();
networks.add(network);
}
final TestNetwork network = repoService.createNetworkWithAlias("cmisnew.test", true);
network.create();
networks.add(network);
// do we have all the networks created?
assertEquals(3, networks.size());
this.network1 = networks.get(0);
this.network2 = networks.get(1);
this.network3 = networks.get(2);
// create a couple of users in one of the networks
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());
// create a user in another network
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network2.createUser();
people.add(person);
return null;
}
}, network2.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network3.createUser();
people.add(person);
return null;
}
}, network3.getId());
Iterator<TestPerson> peopleIt = people.iterator();
this.person11 = peopleIt.next();
this.person12 = peopleIt.next();
this.person21 = peopleIt.next();
this.person31 = peopleIt.next();
}
Aggregations