use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestFavourites method testInvalidRequests.
@Test
public void testInvalidRequests() throws Exception {
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite favourite = makeSiteFavourite(person1PublicSites.get(0));
Favourite ret = favouritesProxy.createFavourite(person11Id, favourite);
favourite.expected(ret);
fail();
} catch (PublicApiException e) {
// Note: un-authorized comes back as 404
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
log("cloud-2468");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
final NodeRef document = personDocs.get(0);
final NodeRef comment = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
NodeRef comment = repoService.createComment(document, new Comment("Title", "Content"));
return comment;
}
}, person10Id, network1.getId());
final String guid = comment.getId();
JSONAble commentJSON = new JSONAble() {
@SuppressWarnings("unchecked")
@Override
public JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("guid", guid);
return json;
}
};
FavouritesTarget target = new InvalidFavouriteTarget("comment", commentJSON, guid);
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
try {
log("cloud-2468");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Site site = person1PublicSites.get(0);
FavouritesTarget target = new InvalidFavouriteTarget(GUID.generate(), site, site.getGuid());
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// type = file, target is a site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
String siteGuid = person1PublicSites.get(0).getGuid();
FavouriteDocument document = new FavouriteDocument(siteGuid);
Favourite favourite = makeFileFavourite(document.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// type = folder, target is a site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
String siteGuid = person1PublicSites.get(0).getGuid();
FavouriteFolder folder = new FavouriteFolder(siteGuid);
Favourite favourite = makeFolderFavourite(folder.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// type = folder, target is a file
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteFolder folder = new FavouriteFolder(person1PublicDocs.get(0).getId());
Favourite favourite = makeFolderFavourite(folder.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// type = file, target is a folder
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteDocument document = new FavouriteDocument(person1PublicFolders.get(0).getId());
Favourite favourite = makeFileFavourite(document.getGuid());
Favourite ret = favouritesProxy.createFavourite(person10Id, favourite);
favourite.expected(ret);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// make sure that a user can't favourite on behalf of another user
// 2471
{
log("cloud-2471");
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId());
Favourite favourite = makeFileFavourite(document.getGuid());
favouritesProxy.createFavourite(person11Id, favourite);
fail();
} catch (PublicApiException e) {
// Note: un-authorized comes back as 404
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// person1 should have no favourites
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
ListResponse<Favourite> response = favouritesProxy.getFavourites(person11Id, createParams(null, null));
assertEquals(0, response.getList().size());
}
// 2469
try {
log("cloud-2469");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite favourite = makeSiteFavourite(personSites.get(0));
Favourite ret = favouritesProxy.createFavourite(GUID.generate(), favourite);
favourite.expected(ret);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// 2465
try {
log("cloud-2465");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
favouritesProxy.getFavourites(person11Id, null);
fail();
} catch (PublicApiException e) {
// Note: un-authorized comes back as 404
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// 2464, unknown user
try {
log("cloud-2464");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
favouritesProxy.getFavourites(GUID.generate(), null);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// non-existent entity for a given type
// 2480
{
log("cloud-2480");
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
SiteImpl site = new SiteImpl();
site.setGuid(GUID.generate());
Favourite favourite = makeSiteFavourite((Site) site);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null));
assertEquals(0, response.getList().size());
}
{
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteDocument document = new FavouriteDocument(GUID.generate());
Favourite favourite = makeFileFavourite(document.getGuid());
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null));
assertEquals(0, response.getList().size());
}
{
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouriteFolder folder = new FavouriteFolder(GUID.generate());
Favourite favourite = makeFolderFavourite(folder.getGuid());
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null));
assertEquals(0, response.getList().size());
}
// 2470
// incorrect type for a given favourite target
{
log("cloud-2470");
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Site site = person1PublicSites.get(0);
FavouritesTarget target = new InvalidFavouriteTarget("folder", site, site.getGuid());
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Site site = person1PublicSites.get(0);
FavouritesTarget target = new InvalidFavouriteTarget("file", site, site.getGuid());
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId());
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouritesTarget target = new InvalidFavouriteTarget("site", document, document.getGuid());
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouritesTarget target = new InvalidFavouriteTarget("folder", document, document.getGuid());
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
FavouriteFolder folder = new FavouriteFolder(person1PublicFolders.get(0).getId());
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouritesTarget target = new InvalidFavouriteTarget("site", folder, folder.getGuid());
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
FavouritesTarget target = new InvalidFavouriteTarget("file", folder, folder.getGuid());
Favourite favourite = new Favourite(target);
favouritesProxy.createFavourite(person10Id, favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
// none of these POSTs should have resulted in favourites being created...
ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null));
assertEquals(0, response.getList().size());
}
// invalid methods
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
try {
Favourite favourite = new Favourite(null);
favouritesProxy.update("people", "-me-", "favorites", null, favourite.toJSON().toString(), "Unable to PUT favourites");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
// invalid orderBy param
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
try {
Map<String, String> params = new HashMap<>();
params.put("orderBy", "invalid ASC");
favouritesProxy.getFavourites(person10Id, createParams(null, params));
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestFavourites method testValidRequests.
@Test
public void testValidRequests() throws Exception {
List<Favourite> expectedFavourites = new ArrayList<Favourite>();
{
// add some favourites
// 2467
log("cloud-2467");
Favourite siteFavourite1 = makeSiteFavourite(person1PublicSites.get(0));
FavouriteDocument document = repoService.getDocument(network1.getId(), person1PublicDocs.get(0));
Favourite fileFavourite1 = makeFileFavourite(document.getGuid());
FavouriteFolder folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(0));
Favourite folderFavourite1 = makeFolderFavourite(folder.getGuid());
Favourite siteFavourite2 = makeSiteFavourite(person1PublicSites.get(1));
document = repoService.getDocument(network1.getId(), person1PublicDocs.get(1));
Favourite fileFavourite2 = makeFileFavourite(document.getGuid());
folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(1));
Favourite folderFavourite2 = makeFolderFavourite(folder.getGuid());
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1);
expectedFavourites.add(ret);
siteFavourite1.expected(ret);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1);
expectedFavourites.add(ret);
fileFavourite1.expected(ret);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1);
expectedFavourites.add(ret);
folderFavourite1.expected(ret);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite2);
expectedFavourites.add(ret);
siteFavourite2.expected(ret);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite2);
expectedFavourites.add(ret);
fileFavourite2.expected(ret);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite2);
expectedFavourites.add(ret);
folderFavourite2.expected(ret);
}
// already a favourite - 201
{
log("cloud-2472");
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1);
siteFavourite1.expected(ret);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1);
folderFavourite1.expected(ret);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1);
fileFavourite1.expected(ret);
}
}
{
// cloud-2498
// cloud-2499
// create and list favourites across networks
List<Favourite> person21ExpectedFavourites = new ArrayList<Favourite>();
log("cloud-2498");
log("cloud-2499");
{
// favourite a site in another network
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
Favourite favourite = makeSiteFavourite(person1PrivateSites.get(0));
try {
favouritesProxy.createFavourite("-me-", favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
int skipCount = 0;
int maxItems = 10;
Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size());
try {
favouritesProxy.getFavourites("-me-", createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
}
// favourite a document in another network
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
FavouriteDocument document1 = new FavouriteDocument(person1PrivateDocs.get(0).getId());
Favourite favourite = makeFileFavourite(document1.getGuid());
try {
favouritesProxy.createFavourite("-me-", favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = 10;
Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size());
try {
favouritesProxy.getFavourites("-me-", createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
}
// favourite a folder in another network
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
FavouriteFolder folder1 = new FavouriteFolder(person1PrivateFolders.get(0).getId());
Favourite favourite = makeFolderFavourite(folder1.getGuid());
try {
favouritesProxy.createFavourite("-me-", favourite);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = 10;
Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size());
try {
favouritesProxy.getFavourites("-me-", createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
}
}
}
// GET favourites
// test paging and sorting
{
// cloud-2458
// cloud-2462
// cloud-2461
{
log("cloud-2458");
log("cloud-2461");
log("cloud-2462");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
List<Favourite> expected = new ArrayList<Favourite>(expectedFavourites);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
List<Favourite> expected = new ArrayList<Favourite>(expectedFavourites);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 2;
int maxItems = 4;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// 2466
// GET favourites for "-me-"
{
log("cloud-2466");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
List<Favourite> expected = new ArrayList<Favourite>(expectedFavourites);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
ListResponse<Favourite> resp = favouritesProxy.getFavourites("-me-", createParams(paging, null));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
// 2459
{
log("cloud-2459");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, 0, 0);
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person11Id, createParams(paging, null));
List<Favourite> empty = Collections.emptyList();
checkList(empty, paging.getExpectedPaging(), resp);
}
// cloud-2460: filtering by target type
{
log("cloud-2460");
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FILE));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FOLDER));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/folder))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// target/file
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FILE));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// target/folder
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FOLDER));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/folder))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// target/site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.SITE));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/site))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// target/folder OR target/file.
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FOLDER, Type.FILE));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/folder))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// target/site OR target/file.
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.SITE, Type.FILE));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/site))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// target/site OR target/folder.
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Set<Type> types = new HashSet<Type>(Arrays.asList(Type.SITE, Type.FOLDER));
List<Favourite> expected = filter(expectedFavourites, types);
sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/site) OR EXISTS(target/folder))");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
// GET a favourite
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
favouritesProxy.getFavourite(person10Id, GUID.generate());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite favourite = expectedFavourites.get(0);
favouritesProxy.getFavourite(GUID.generate(), favourite.getTargetGuid());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
Favourite favourite = expectedFavourites.get(0);
Favourite resp = favouritesProxy.getFavourite(person10Id, favourite.getTargetGuid());
favourite.expected(resp);
}
// cloud-2479, PUT case
{
log("cloud-2479.1");
updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site);
log("cloud-2479.2");
updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file);
log("cloud-2479.3");
updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder);
}
try {
// cloud-2474
// non-existent personId
log("cloud-2474");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
favouritesProxy.removeFavourite(GUID.generate(), GUID.generate());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// cloud-2475
// try delete a non-existent favourite for a node that exists
{
log("cloud-2475");
NodeRef doc = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {
@Override
public NodeRef doWork() throws Exception {
NodeRef containerNodeRef = person1PublicSites.get(0).getContainerNodeRef("documentLibrary");
NodeRef doc = repoService.createDocument(containerNodeRef, GUID.generate(), "");
return doc;
}
}, person11Id, network1.getId());
String favouriteId = doc.getId();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
ListResponse<Favourite> before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
List<Favourite> beforeList = before.getList();
assertTrue(beforeList.size() > 0);
try {
favouritesProxy.removeFavourite(person10Id, favouriteId);
fail("Should be a 404");
} catch (PublicApiException e) {
// expected
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// check no favourites have been removed
ListResponse<Favourite> after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
assertEquals(beforeList.size(), after.getList().size());
}
// cloud-2473, DELETE case
{
log("cloud-2473.1");
deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site);
log("cloud-2473.2");
deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file);
log("cloud-2473.3");
Favourite favourite = deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder);
// try to delete non-existent favourite
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
}
// cloud-2476
// try delete another user's favourite
{
log("cloud-2476");
// make sure there are favourites to delete
// publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
// SiteFavouriteTarget target = new SiteFavouriteTarget(person1Sites.get(0));
// Favourite favourite = new Favourite(target);
// favouritesProxy.createFavourite(personId, favourite);
ListResponse<Favourite> before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
assertTrue(before.getList().size() > 0);
Favourite favourite = before.getList().get(0);
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid());
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
ListResponse<Favourite> after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
assertEquals(before.getList().size(), after.getList().size());
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestSiteContainers method testSiteContainers.
@Test
public void testSiteContainers() throws Exception {
Sites sitesProxy = publicApiClient.sites();
List<SiteContainer> expectedSiteContainers = network1.getSiteContainers(site1.getSiteId(), person11);
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
skipCount = 2;
maxItems = expectedSiteContainers.size();
paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
skipCount = 2;
maxItems = expectedSiteContainers.size() + 2;
paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
SiteContainer expectedSiteContainer = new SiteContainer(site1.getSiteId(), "test2", null);
SiteContainer sc = sitesProxy.getSingleSiteContainer(site1.getSiteId(), "test2");
check(expectedSiteContainer, sc);
}
// site does not exist
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getSingleSiteContainer("gfyuosfgsf8y7s", "documentLibrary");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// container does not exist
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
sitesProxy.getSingleSiteContainer(site1.getSiteId(), "container1");
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// site containers - site does not exist
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
sitesProxy.getSiteContainers(GUID.generate(), createParams(paging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// a user in the same network, not invited to the site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> ret = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), ret);
}
// a user in a different network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// TODO a user in the same network, invited to the site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> ret = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), ret);
}
// person invited to site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13.getId()));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteContainers.size(), expectedSiteContainers.size());
ListResponse<SiteContainer> resp = sitesProxy.getSiteContainers(site1.getSiteId(), createParams(paging, null));
checkList(expectedSiteContainers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// invalid methods
try {
sitesProxy.create("sites", site1.getSiteId(), "containers", null, null, "Unable to POST to site containers");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.create("sites", site1.getSiteId(), "containers", "documentLibrary", null, "Unable to POST to a site container");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.update("sites", site1.getSiteId(), "containers", null, null, "Unable to PUT site containers");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.update("sites", site1.getSiteId(), "containers", "documentLibrary", null, "Unable to PUT a site container");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.remove("sites", site1.getSiteId(), "containers", null, "Unable to DELETE site containers");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
sitesProxy.remove("sites", site1.getSiteId(), "containers", "documentLibrary", "Unable to DELETE a site container");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// 1481
// user in external network, list site containers
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestSiteMembers method testSiteMembers.
// TODO set create member for a user who is a member of the site (not the creator)
// TODO split into more manageable test methods
@Test
public void testSiteMembers() throws Exception {
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
final TestNetwork testNetwork = networksIt.next();
final List<String> networkPeople = testNetwork.getPersonIds();
String personId = networkPeople.get(0);
Sites sitesProxy = publicApiClient.sites();
{
final List<SiteMember> expectedSiteMembers = new ArrayList<SiteMember>();
// Create a private site and invite some users
// TODO create site members using public api rather than directly using the services
TestSite testSite = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite testSite = testNetwork.createSite(SiteVisibility.PRIVATE);
for (int i = 1; i <= 5; i++) {
String inviteeId = networkPeople.get(i);
testSite.inviteToSite(inviteeId, SiteRole.SiteConsumer);
SiteMember sm = new SiteMember(inviteeId, repoService.getPerson(inviteeId), testSite.getSiteId(), SiteRole.SiteConsumer.toString());
expectedSiteMembers.add(sm);
}
return testSite;
}
}, personId, testNetwork.getId());
{
SiteMember sm = new SiteMember(personId, repoService.getPerson(personId), testSite.getSiteId(), SiteRole.SiteManager.toString());
expectedSiteMembers.add(sm);
Collections.sort(expectedSiteMembers);
}
// Test Case cloud-1482
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), 6);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(testSite.getSiteId(), createParams(paging, null));
checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
}
{
int skipCount = 2;
int maxItems = 10;
Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), 6);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(testSite.getSiteId(), createParams(paging, null));
checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
HttpResponse response = sitesProxy.getAll("sites", testSite.getSiteId(), "members", null, createParams(paging, Collections.singletonMap("includeSource", "true")), "Failed to get all site members");
checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), SiteMember.parseSiteMembers(testSite.getSiteId(), response.getJsonResponse()));
JSONObject source = sitesProxy.parseListSource(response.getJsonResponse());
Site sourceSite = SiteImpl.parseSite(source);
assertNotNull(sourceSite);
testSite.expected(sourceSite);
}
// invalid site id
try {
int skipCount = 2;
int maxItems = 10;
Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), 6);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
sitesProxy.getSiteMembers(GUID.generate(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid methods
try {
SiteMember siteMember = expectedSiteMembers.get(0);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
sitesProxy.update("sites", testSite.getSiteId(), "members", null, siteMember.toJSON().toString(), "Unable to PUT site members");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1965
try {
SiteMember siteMember1 = expectedSiteMembers.get(0);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
sitesProxy.create("sites", testSite.getSiteId(), "members", siteMember1.getMemberId(), siteMember1.toJSON().toString(), "Unable to POST to a site member");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
SiteMember siteMember1 = expectedSiteMembers.get(0);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
sitesProxy.update("sites", testSite.getSiteId(), "members", null, siteMember1.toJSON().toString(), "Unable to PUT site members");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
sitesProxy.remove("sites", testSite.getSiteId(), "members", null, "Unable to DELETE site members");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// update site member
{
SiteMember siteMember1 = expectedSiteMembers.get(0);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
SiteMember ret = sitesProxy.updateSiteMember(testSite.getSiteId(), siteMember1);
assertEquals(siteMember1.getRole(), ret.getRole());
Person expectedSiteMember = repoService.getPerson(siteMember1.getMemberId());
expectedSiteMember.expected(ret.getMember());
}
// GET single site member
{
SiteMember siteMember1 = expectedSiteMembers.get(0);
publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), personId));
SiteMember ret = sitesProxy.getSingleSiteMember(testSite.getSiteId(), siteMember1.getMemberId());
siteMember1.expected(ret);
}
}
// test: user is member of different tenant, but has site membership(s) in common with the http request user
{
Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
assertTrue(accountsIt.hasNext());
final TestNetwork network1 = accountsIt.next();
assertTrue(accountsIt.hasNext());
final TestNetwork network2 = accountsIt.next();
final List<TestPerson> people = new ArrayList<TestPerson>();
// Create users
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());
final TestPerson person1 = people.get(0);
final TestPerson person2 = people.get(1);
final TestPerson person3 = people.get(2);
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network2.createUser();
people.add(person);
return null;
}
}, network2.getId());
final TestPerson person4 = people.get(3);
// Create site
final TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = network1.createSite(SiteVisibility.PUBLIC);
return site;
}
}, person2.getId(), network1.getId());
// invalid role - 400
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), "dodgyRole"));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// user in network but not site member, try to create site member
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person3.getId(), SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// unknown invitee - 404
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember("dodgyUser", SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown site - 404
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.createSiteMember("dodgySite", new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// inviter is not a member of the site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(e.getMessage(), HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// inviter is not a member of the site nor a member of the tenant
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
// TODO check that 404 is correct here - external user of network can't see public site??
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
SiteMember sm = new SiteMember(person1.getId(), SiteRole.SiteConsumer.toString());
SiteMember siteMember = sitesProxy.createSiteMember(site.getSiteId(), sm);
assertEquals(person1.getId(), siteMember.getMemberId());
assertEquals(SiteRole.SiteConsumer.toString(), siteMember.getRole());
}
// already invited
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
}
// inviter is consumer member of the site, should not be able to add site member
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person4.getId(), SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(e.getMessage(), HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invitee from another network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person4.getId(), SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(e.getMessage(), HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// missing person id
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(null, SiteRole.SiteContributor.toString()));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// missing role
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// check site membership in GET
List<SiteMember> expectedSiteMembers = site.getMembers();
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), 2);
ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
}
}
// test: create site membership, remove it, get list of site memberships
{
Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
assertTrue(accountsIt.hasNext());
final TestNetwork network1 = accountsIt.next();
assertTrue(accountsIt.hasNext());
final List<TestPerson> people = new ArrayList<TestPerson>();
// Create user
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());
TestPerson person1 = people.get(0);
TestPerson person2 = people.get(1);
TestPerson person3 = people.get(2);
// Create site
TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = network1.createSite(SiteVisibility.PRIVATE);
return site;
}
}, person2.getId(), network1.getId());
// remove site membership
// for -me- user (PUBLICAPI-90)
{
// create a site member
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
SiteMember siteMember = sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
assertEquals(person1.getId(), siteMember.getMemberId());
assertEquals(SiteRole.SiteContributor.toString(), siteMember.getRole());
SiteMember toRemove = new SiteMember("-me-");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.removeSiteMember(site.getSiteId(), toRemove);
}
{
// create a site member
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
SiteMember siteMember = sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
assertEquals(person1.getId(), siteMember.getMemberId());
assertEquals(SiteRole.SiteContributor.toString(), siteMember.getRole());
// note: needed for contains check below, ugh
siteMember.setSiteId(site.getSiteId());
// create another site member
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
SiteMember siteMemberAno = sitesProxy.createSiteMember(site.getSiteId(), new SiteMember(person3.getId(), SiteRole.SiteCollaborator.toString()));
assertEquals(person3.getId(), siteMemberAno.getMemberId());
assertEquals(SiteRole.SiteCollaborator.toString(), siteMemberAno.getRole());
// note: needed for contains check below, ugh
siteMemberAno.setSiteId(site.getSiteId());
// unknown site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.removeSiteMember(GUID.generate(), siteMember);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown user
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.removeSiteMember(site.getSiteId(), new SiteMember(GUID.generate()));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// cannot update site member (without appropriate site "permission" - see SiteService)
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteCollaborator.toString()));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getHttpResponse().getStatusCode());
}
// cannot remove another site member (without appropriate site "permission" - see SiteService)
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.removeSiteMember(site.getSiteId(), new SiteMember(person3.getId()));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getHttpResponse().getStatusCode());
}
// remove site member
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.removeSiteMember(site.getSiteId(), siteMember);
}
// check site membership in GET
List<SiteMember> expectedSiteMembers = site.getMembers();
assertFalse(expectedSiteMembers.contains(siteMember));
assertTrue(expectedSiteMembers.contains(siteMemberAno));
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), 2);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
}
// unknown site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.updateSiteMember(GUID.generate(), siteMember);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown user
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(GUID.generate()));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// invalid role
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person1.getId(), "invalidRole"));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// user is not a member of the site - 400
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person1.getId(), SiteRole.SiteContributor.toString()));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// cannot update last member of site to be a non-manager
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.updateSiteMember(site.getSiteId(), new SiteMember(person2.getId(), SiteRole.SiteContributor.toString()));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getHttpResponse().getStatusCode());
}
// successful update
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
SiteMember sm = new SiteMember(person1.getId(), SiteRole.SiteContributor.toString());
SiteMember ret = sitesProxy.createSiteMember(site.getSiteId(), sm);
assertEquals(SiteRole.SiteContributor.toString(), ret.getRole());
person1.expected(ret.getMember());
sm = new SiteMember(person1.getId(), SiteRole.SiteCollaborator.toString());
ret = sitesProxy.updateSiteMember(site.getSiteId(), sm);
assertEquals(SiteRole.SiteCollaborator.toString(), ret.getRole());
person1.expected(ret.getMember());
// check site membership in GET
SiteMember smToCheck = sitesProxy.getSingleSiteMember(site.getSiteId(), person1.getId());
// check that the update site membership is present
assertNotNull(smToCheck);
// check that the role is correct
assertEquals(sm.getRole(), smToCheck.getRole());
expectedSiteMembers = new ArrayList<>();
SiteMember sm1 = new SiteMember(person1.getId(), person1, site.getSiteId(), SiteRole.SiteCollaborator.toString());
expectedSiteMembers.add(sm1);
SiteMember sm2 = new SiteMember(person2.getId(), person2, site.getSiteId(), SiteRole.SiteManager.toString());
expectedSiteMembers.add(sm2);
SiteMember sm3 = new SiteMember(person3.getId(), person3, site.getSiteId(), SiteRole.SiteCollaborator.toString());
expectedSiteMembers.add(sm3);
Collections.sort(expectedSiteMembers);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedSiteMembers.size(), 3);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
ListResponse<SiteMember> siteMembers = sitesProxy.getSiteMembers(site.getSiteId(), createParams(paging, null));
checkList(expectedSiteMembers.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), siteMembers);
}
}
}
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse in project alfresco-remote-api by Alfresco.
the class TestTags method testTags.
@Test
@Category({ LuceneTests.class, RedundantTests.class })
public void testTags() 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<NodeRef> nodes = new ArrayList<NodeRef>();
final List<TestSite> sites = new ArrayList<TestSite>();
// Create site
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestSite site = network1.createSite(SiteVisibility.PRIVATE);
sites.add(site);
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content");
nodes.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc 1", "Test Content 1");
nodes.add(nodeRef);
return null;
}
}, person1.getId(), network1.getId());
final NodeRef nodeRef1 = nodes.get(0);
final NodeRef nodeRef2 = nodes.get(1);
Nodes nodesProxy = publicApiClient.nodes();
Comments commentsProxy = publicApiClient.comments();
Tags tagsProxy = publicApiClient.tags();
final List<Tag> tags = new ArrayList<Tag>();
tags.add(new Tag("tag 1"));
tags.add(new Tag("tag 9"));
tags.add(new Tag("other tag 3"));
tags.add(new Tag("my tag 1"));
tags.add(new Tag("tag 5"));
// try to add a tag to a comment
try {
Comment comment = new Comment("Test Comment", "Test Comment");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Comment newComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
Tag tag = new Tag("testTag");
nodesProxy.createNodeTag(newComment.getId(), tag);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// try to add a tag to a tag
try {
Tag tag = new Tag("testTag");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Tag newTag = nodesProxy.createNodeTag(nodeRef1.getId(), tag);
nodesProxy.createNodeTag(newTag.getId(), tag);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-2221
// Test Case cloud-2222
// multi-byte characters, special characters, create and update tags
{
Tag[] multiByteTags = new Tag[] { new Tag("\u67e5\u770b\u5168\u90e8"), new Tag("\u67e5\u770b\u5168\u91e8"), new Tag("%^&%&$^£@") };
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
// first, create tags
Map<String, Tag> createdTags = new HashMap<String, Tag>();
for (Tag tag : multiByteTags) {
Tag ret = nodesProxy.createNodeTag(nodeRef2.getId(), tag);
createdTags.put(ret.getId(), ret);
}
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems);
ListResponse<Tag> resp = nodesProxy.getNodeTags(nodeRef2.getId(), createParams(paging, null));
List<Tag> retTags = resp.getList();
assertEquals(createdTags.size(), retTags.size());
for (Tag tag : retTags) {
String tagId = tag.getId();
Tag expectedTag = createdTags.get(tagId);
expectedTag.expected(tag);
}
try {
// update with an empty tag i.e. "" -> bad request
Tag tag = new Tag("");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.createNodeTag(nodeRef2.getId(), tag);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
List<Tag> tagUpdates = new ArrayList<Tag>(createdTags.values());
tagUpdates.get(0).setTag("\u4e00\u4e01\u4e02\u4e10");
tagUpdates.get(1).setTag("\u4e00\u4e01\u4e12\u4e11");
tagUpdates.get(2).setTag("\u4e00\u4e01\u4e12\u4e12");
Map<String, Tag> updatedTags = new HashMap<String, Tag>();
for (Tag tag : tagUpdates) {
Tag ret = tagsProxy.update(tag);
assertNotNull(ret.getId());
assertNotNull(ret.getTag());
// tag.expected(ret); disabled because tag id changes
updatedTags.put(ret.getId(), ret);
}
// get updated tags
List<Tag> expectedNodeTags = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Tag>>() {
@Override
public List<Tag> doWork() throws Exception {
List<Tag> tags = repoService.getTags(nodeRef2);
return tags;
}
}, person1.getId(), network1.getId());
skipCount = 0;
maxItems = tagUpdates.size();
paging = getPaging(skipCount, maxItems, tagUpdates.size(), tagUpdates.size());
resp = nodesProxy.getNodeTags(nodeRef2.getId(), createParams(paging, null));
checkList(expectedNodeTags.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
List<Tag> createdTags = new ArrayList<Tag>();
// Test Case cloud-1975
for (Tag tag : tags) {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Tag ret = nodesProxy.createNodeTag(nodeRef1.getId(), tag);
assertEquals(tag.getTag(), ret.getTag());
assertNotNull(ret.getId());
createdTags.add(ret);
}
// update tag, empty string
try {
Tag tag = new Tag(createdTags.get(0).getId(), "");
tagsProxy.update(tag);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// invalid node id
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.createNodeTag(GUID.generate(), tags.get(0));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1973
// Test Case cloud-2208
// Test Case cloud-2219
// check that the tags are there in the node tags, test paging
List<Tag> expectedNodeTags = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Tag>>() {
@Override
public List<Tag> doWork() throws Exception {
List<Tag> tags = repoService.getTags(nodeRef1);
return tags;
}
}, person1.getId(), network1.getId());
{
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedNodeTags.size(), expectedNodeTags.size());
ListResponse<Tag> resp = nodesProxy.getNodeTags(nodeRef1.getId(), createParams(paging, null));
checkList(expectedNodeTags.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 2;
int maxItems = Integer.MAX_VALUE;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedNodeTags.size(), expectedNodeTags.size());
ListResponse<Tag> resp = nodesProxy.getNodeTags(nodeRef1.getId(), createParams(paging, null));
checkList(expectedNodeTags.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
// invalid node
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedNodeTags.size(), expectedNodeTags.size());
ListResponse<Tag> allTags = nodesProxy.getNodeTags("invalidNode", createParams(paging, null));
checkList(expectedNodeTags.subList(skipCount, paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), allTags);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// user from another account - 403
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
Paging expectedPaging = getPaging(skipCount, maxItems, expectedNodeTags.size(), expectedNodeTags.size());
nodesProxy.getNodeTags(nodeRef1.getId(), createParams(expectedPaging, null));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// another user from the same account
try {
int skipCount = 0;
int maxItems = 2;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedNodeTags.size(), expectedNodeTags.size());
ListResponse<Tag> resp = nodesProxy.getNodeTags(nodeRef1.getId(), createParams(paging, null));
checkList(expectedNodeTags.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1519
// Test Case cloud-2206
// Test Case cloud-2218
// check that the tags are there in the network tags, test paging
// TODO for user from another network who is invited to this network
List<Tag> expectedNetworkTags = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Tag>>() {
@Override
public List<Tag> doWork() throws Exception {
List<Tag> tags = repoService.getTags();
return tags;
}
}, person1.getId(), network1.getId());
{
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedNetworkTags.size(), null);
ListResponse<Tag> allTags = tagsProxy.getTags(createParams(paging, null));
checkList(expectedNetworkTags.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), allTags);
}
{
int skipCount = 2;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedNetworkTags.size(), null);
ListResponse<Tag> allTags = tagsProxy.getTags(createParams(paging, null));
checkList(expectedNetworkTags.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), allTags);
}
}
{
// Try a create with the same tag value
Tag tag = tags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.createNodeTag(nodeRef1.getId(), tag);
}
try {
// Invalid node id
Tag tag = tags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.createNodeTag(GUID.generate(), tag);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-2183
// update tags
{
// get a network tag
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<Tag> allTags = tagsProxy.getTags(createParams(paging, null));
assertTrue(allTags.getList().size() > 0);
// and update it
Tag tag = allTags.getList().get(0);
String newTagValue = GUID.generate();
Tag newTag = new Tag(tag.getId(), newTagValue);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Tag ret = tagsProxy.update(newTag);
assertEquals(newTagValue, ret.getTag());
// assertNotEquals(tag.getId, ret.getId()); // disabled due to CLOUD-628
}
// update invalid/unknown tag id
try {
Tag unknownTag = new Tag(GUID.generate(), GUID.generate());
tagsProxy.update(unknownTag);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-1972
// Test Case cloud-1974
// not allowed methods
{
List<Tag> networkTags = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Tag>>() {
@Override
public List<Tag> doWork() throws Exception {
List<Tag> tags = repoService.getTags();
return tags;
}
}, person1.getId(), network1.getId());
assertTrue(networkTags.size() > 0);
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.update("nodes", nodeRef1.getId(), "tags", null, null, "Unable to PUT node tags");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.remove("nodes", nodeRef1.getId(), "tags", null, "Unable to DELETE node tags");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Tag tag = networkTags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.update("nodes", nodeRef1.getId(), "tags", tag.getId(), null, "Unable to PUT node tag");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Tag tag = networkTags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.create("tags", null, null, null, tag.toJSON().toString(), "Unable to POST to tags");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Tag tag = networkTags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.update("tags", null, null, null, tag.toJSON().toString(), "Unable to PUT tags");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.remove("tags", null, null, null, "Unable to DELETE tags");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Tag tag = networkTags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.create("tags", tag.getId(), null, null, tag.toJSON().toString(), "Unable to POST to a tag");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
Tag tag = networkTags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.remove("tags", tag.getId(), null, null, "Unable to DELETE a tag");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// delete node tag
{
Tag tag = networkTags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.removeNodeTag(nodeRef1.getId(), tag.getId());
// check that the tag is gone
ListResponse<Tag> resp = nodesProxy.getNodeTags(nodeRef1.getId(), createParams(getPaging(0, Integer.MAX_VALUE), null));
List<Tag> nodeTags = resp.getList();
assertTrue(!nodeTags.contains(tag));
}
try {
Tag tag = networkTags.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
nodesProxy.getSingle("nodes", nodeRef1.getId(), "tags", tag.getId(), "Unable to GET node tag");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
}
Aggregations