use of org.alfresco.rest.api.tests.client.data.InvalidFavouriteTarget 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());
}
}
}
Aggregations