mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ACS-4033: List linked categories for a particular node (#1672)
* ACS-4033: List linked categories for a particular node - GET /nodes/{nodeId}/category-links
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
import org.alfresco.utility.model.TestModel;
|
||||
@@ -36,5 +38,51 @@ public class RestCategoryLinkBodyModel extends TestModel implements IRestModel<R
|
||||
{
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
RestCategoryLinkBodyModel that = (RestCategoryLinkBodyModel) o;
|
||||
return Objects.equals(categoryId, that.categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "RestCategoryLinkBodyModel{" + "categoryId='" + categoryId + '\'' + '}';
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private String categoryId;
|
||||
|
||||
public Builder categoryId(String categoryId)
|
||||
{
|
||||
this.categoryId = categoryId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RestCategoryLinkBodyModel create()
|
||||
{
|
||||
final RestCategoryLinkBodyModel categoryLink = new RestCategoryLinkBodyModel();
|
||||
categoryLink.setCategoryId(categoryId);
|
||||
return categoryLink;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1112,6 +1112,17 @@ public class Node extends ModelRequest<Node>
|
||||
return restWrapper.processModel(RestRuleExecutionModel.class, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get linked categories performing GET cal on "/nodes/{nodeId}/category-links"
|
||||
*
|
||||
* @return categories which are linked from content
|
||||
*/
|
||||
public RestCategoryModelsCollection getLinkedCategories()
|
||||
{
|
||||
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "nodes/{nodeId}/category-links", repoModel.getNodeRef());
|
||||
return restWrapper.processModels(RestCategoryModelsCollection.class, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link content to category performing POST call on "/nodes/{nodeId}/category-links"
|
||||
*
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -30,8 +30,14 @@ import static org.alfresco.utility.data.RandomData.getRandomName;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.model.RestCategoryLinkBodyModel;
|
||||
import org.alfresco.rest.model.RestCategoryModel;
|
||||
import org.alfresco.utility.model.RepoTestModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
@@ -71,6 +77,30 @@ abstract class CategoriesRestTest extends RestTest
|
||||
return createdCategory;
|
||||
}
|
||||
|
||||
protected List<RestCategoryModel> prepareCategoriesUnderRoot(final int categoriesCount)
|
||||
{
|
||||
return prepareCategoriesUnder(ROOT_CATEGORY_ID, categoriesCount);
|
||||
}
|
||||
|
||||
protected List<RestCategoryModel> prepareCategoriesUnder(final String parentId, final int categoriesCount)
|
||||
{
|
||||
final RestCategoryModel parentCategory = createCategoryModelWithId(parentId);
|
||||
final List<RestCategoryModel> categoryModels = IntStream
|
||||
.range(0, categoriesCount)
|
||||
.mapToObj(i -> createCategoryModelWithName(getRandomName(CATEGORY_NAME_PREFIX)))
|
||||
.collect(Collectors.toList());
|
||||
final List<RestCategoryModel> createdCategories = restClient.authenticateUser(dataUser.getAdminUser())
|
||||
.withCoreAPI()
|
||||
.usingCategory(parentCategory)
|
||||
.createCategoriesList(categoryModels)
|
||||
.getEntries().stream()
|
||||
.map(RestCategoryModel::onModel)
|
||||
.collect(Collectors.toList());
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
|
||||
return createdCategories;
|
||||
}
|
||||
|
||||
protected RestCategoryModel createCategoryModelWithId(final String id)
|
||||
{
|
||||
return createCategoryModelWithIdAndName(id, null);
|
||||
@@ -88,4 +118,18 @@ abstract class CategoriesRestTest extends RestTest
|
||||
.name(name)
|
||||
.create();
|
||||
}
|
||||
|
||||
protected RestCategoryLinkBodyModel createCategoryLinkModelWithId(final String id)
|
||||
{
|
||||
return RestCategoryLinkBodyModel.builder()
|
||||
.categoryId(id)
|
||||
.create();
|
||||
}
|
||||
|
||||
protected RepoTestModel createNodeModelWithId(final String id)
|
||||
{
|
||||
final RepoTestModel nodeModel = new RepoTestModel() {};
|
||||
nodeModel.setNodeRef(id);
|
||||
return nodeModel;
|
||||
}
|
||||
}
|
||||
|
@@ -60,13 +60,13 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
private static final String ASPECTS_FIELD = "aspectNames";
|
||||
private static final String PROPERTIES_FIELD = "properties";
|
||||
|
||||
private UserModel user;
|
||||
private SiteModel site;
|
||||
private FolderModel folder;
|
||||
private FileModel file;
|
||||
private RestCategoryModel category;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
@Override
|
||||
public void dataPreparation()
|
||||
{
|
||||
STEP("Create user and a site");
|
||||
@@ -96,8 +96,8 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
fileNode.assertThat().field(PROPERTIES_FIELD).notContains("cm:categories");
|
||||
|
||||
STEP("Link content to created category and expect 201");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(category.getId());
|
||||
final RestCategoryModel linkedCategory = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
||||
final RestCategoryModel linkedCategory = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
linkedCategory.assertThat().isEqualTo(category);
|
||||
@@ -126,11 +126,11 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
final RestCategoryModel secondCategory = prepareCategoryUnderRoot();
|
||||
|
||||
STEP("Link content to created categories and expect 201");
|
||||
final List<RestCategoryLinkBodyModel> categoryLinks = List.of(
|
||||
createCategoryLinkWithId(category.getId()),
|
||||
createCategoryLinkWithId(secondCategory.getId())
|
||||
final List<RestCategoryLinkBodyModel> categoryLinkModels = List.of(
|
||||
createCategoryLinkModelWithId(category.getId()),
|
||||
createCategoryLinkModelWithId(secondCategory.getId())
|
||||
);
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategories(categoryLinks);
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategories(categoryLinkModels);
|
||||
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
linkedCategories.getEntries().get(0).onModel().assertThat().isEqualTo(category);
|
||||
@@ -152,18 +152,18 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
public void testLinkContentToCategory_usingContentWithAlreadyLinkedCategories()
|
||||
{
|
||||
STEP("Link content to created category");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(category.getId());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
|
||||
STEP("Create second and third category under root, link content to them and expect 201");
|
||||
final RestCategoryModel secondCategory = prepareCategoryUnderRoot();
|
||||
final RestCategoryModel thirdCategory = prepareCategoryUnderRoot();
|
||||
final List<RestCategoryLinkBodyModel> categoryLinks = List.of(
|
||||
createCategoryLinkWithId(secondCategory.getId()),
|
||||
createCategoryLinkWithId(thirdCategory.getId())
|
||||
final List<RestCategoryLinkBodyModel> categoryLinkModels = List.of(
|
||||
createCategoryLinkModelWithId(secondCategory.getId()),
|
||||
createCategoryLinkModelWithId(thirdCategory.getId())
|
||||
);
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategories(categoryLinks);
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategories(categoryLinkModels);
|
||||
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
linkedCategories.assertThat().entriesListCountIs(2);
|
||||
@@ -186,9 +186,9 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
public void testLinkContentToCategory_asUserWithoutReadPermissionAndExpect403()
|
||||
{
|
||||
STEP("Try to link content to a category using user without read permission and expect 403");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(category.getId());
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
||||
final UserModel userWithoutRights = dataUser.createRandomTestUser();
|
||||
restClient.authenticateUser(userWithoutRights).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
restClient.authenticateUser(userWithoutRights).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(FORBIDDEN);
|
||||
}
|
||||
@@ -201,11 +201,11 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
{
|
||||
STEP("Create another user as a consumer for file");
|
||||
final UserModel consumer = dataUser.createRandomTestUser();
|
||||
addPermissionsForUser(consumer.getUsername(), "Consumer", file);
|
||||
allowPermissionsForUser(consumer.getUsername(), "Consumer", file);
|
||||
|
||||
STEP("Try to link content to a category using user without change permission and expect 403");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(category.getId());
|
||||
restClient.authenticateUser(consumer).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
||||
restClient.authenticateUser(consumer).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(FORBIDDEN);
|
||||
}
|
||||
@@ -226,8 +226,8 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
dataUser.removeUserFromSite(user, privateSite);
|
||||
|
||||
STEP("Try to link content to a category as owner and expect 201");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(category.getId());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(privateFile).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(privateFile).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
}
|
||||
@@ -240,8 +240,8 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
{
|
||||
STEP("Try to link content to non-existing category and expect 404");
|
||||
final String nonExistingCategoryId = "non-existing-dummy-id";
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(nonExistingCategoryId);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(nonExistingCategoryId);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
@@ -266,8 +266,8 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
{
|
||||
STEP("Try to call link content API with empty category ID and expect 400");
|
||||
final String nonExistingCategoryId = StringUtils.EMPTY;
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(nonExistingCategoryId);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(nonExistingCategoryId);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(BAD_REQUEST);
|
||||
}
|
||||
@@ -279,8 +279,8 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
public void testLinkFolderToCategory()
|
||||
{
|
||||
STEP("Link folder node to category");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(category.getId());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(folder).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(folder).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(CREATED);
|
||||
}
|
||||
@@ -292,11 +292,10 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
public void testLinkContentToCategory_usingTagInsteadOfContentAndExpect405()
|
||||
{
|
||||
STEP("Try to link a tag to category and expect 405");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(category.getId());
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
||||
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
|
||||
final RepoTestModel tagNode = new RepoTestModel() {};
|
||||
tagNode.setNodeRef(tag.getId());
|
||||
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingNode(tagNode).linkToCategory(categoryLink);
|
||||
final RepoTestModel tagNode = createNodeModelWithId(tag.getId());
|
||||
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingNode(tagNode).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(METHOD_NOT_ALLOWED);
|
||||
}
|
||||
@@ -308,8 +307,8 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
public void testLinkContentToCategory_usingFolderInsteadOfCategoryAndExpect400()
|
||||
{
|
||||
STEP("Try to link content to non-category and expect 400");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(folder.getNodeRef());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(folder.getNodeRef());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(BAD_REQUEST);
|
||||
}
|
||||
@@ -321,30 +320,22 @@ public class LinkToCategoriesTests extends CategoriesRestTest
|
||||
public void testLinkContentToCategory_usingRootCategoryAndExpect400()
|
||||
{
|
||||
STEP("Try to link content to root category and expect 400");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkWithId(ROOT_CATEGORY_ID);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(ROOT_CATEGORY_ID);
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLinkModel);
|
||||
|
||||
restClient.assertStatusCodeIs(BAD_REQUEST);
|
||||
}
|
||||
|
||||
private RestCategoryLinkBodyModel createCategoryLinkWithId(final String id)
|
||||
{
|
||||
final RestCategoryLinkBodyModel categoryLink = new RestCategoryLinkBodyModel();
|
||||
categoryLink.setCategoryId(id);
|
||||
return categoryLink;
|
||||
}
|
||||
|
||||
private void addPermissionsForUser(final String username, final String role, final FileModel file)
|
||||
private void allowPermissionsForUser(final String username, final String role, final FileModel file)
|
||||
{
|
||||
final String putPermissionsBody = Json.createObjectBuilder().add("permissions",
|
||||
Json.createObjectBuilder()
|
||||
.add("isInheritanceEnabled", true)
|
||||
.add("locallySet", Json.createObjectBuilder()
|
||||
.add("authorityId", username)
|
||||
.add("name", role).add("accessStatus", "ALLOWED")))
|
||||
.build()
|
||||
.toString();
|
||||
|
||||
.add("name", role)
|
||||
.add("accessStatus", "ALLOWED")))
|
||||
.build().toString();
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).updateNode(putPermissionsBody);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.categories;
|
||||
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED;
|
||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import javax.json.Json;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.alfresco.dataprep.CMISUtil;
|
||||
import org.alfresco.rest.model.RestCategoryLinkBodyModel;
|
||||
import org.alfresco.rest.model.RestCategoryModel;
|
||||
import org.alfresco.rest.model.RestCategoryModelsCollection;
|
||||
import org.alfresco.rest.model.RestTagModel;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.RepoTestModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class ListCategoriesForNodeTests extends CategoriesRestTest
|
||||
{
|
||||
|
||||
private SiteModel site;
|
||||
private FolderModel folder;
|
||||
private FileModel file;
|
||||
private RestCategoryModel category;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
@Override
|
||||
public void dataPreparation()
|
||||
{
|
||||
STEP("Create user and a site");
|
||||
user = dataUser.createRandomTestUser();
|
||||
site = dataSite.usingUser(user).createPublicRandomSite();
|
||||
}
|
||||
|
||||
@BeforeMethod(alwaysRun = true)
|
||||
public void setUp()
|
||||
{
|
||||
STEP("Create a folder, file in it and a category under root");
|
||||
folder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
file = dataContent.usingUser(user).usingResource(folder).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
category = prepareCategoryUnderRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one linked category using file
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API})
|
||||
public void testListSingleCategoryForNode_usingFile()
|
||||
{
|
||||
STEP("Link file to category");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkModelWithId(category.getId());
|
||||
final RestCategoryModel linkedCategory = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
|
||||
STEP("Get linked category");
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(file).getLinkedCategories();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
linkedCategories.assertThat().entriesListCountIs(1);
|
||||
linkedCategories.getEntries().get(0).onModel().assertThat().isEqualTo(linkedCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one linked category using folder
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API})
|
||||
public void testListSingleCategoryForNode_usingFolder()
|
||||
{
|
||||
STEP("Link folder to category");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkModelWithId(category.getId());
|
||||
final RestCategoryModel linkedCategory = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).linkToCategory(categoryLink);
|
||||
|
||||
STEP("Get linked category");
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).getLinkedCategories();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
linkedCategories.assertThat().entriesListCountIs(1);
|
||||
linkedCategories.getEntries().get(0).onModel().assertThat().isEqualTo(linkedCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple linked categories using file
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API})
|
||||
public void testListMultipleCategoriesForNode_usingFile()
|
||||
{
|
||||
STEP("Create multiple categories under root");
|
||||
final List<RestCategoryModel> createdCategories = prepareCategoriesUnderRoot(10);
|
||||
|
||||
STEP("Link file to created categories");
|
||||
final List<RestCategoryLinkBodyModel> categoryLinkModels = createdCategories.stream()
|
||||
.map(RestCategoryModel::getId)
|
||||
.map(this::createCategoryLinkModelWithId)
|
||||
.collect(Collectors.toList());
|
||||
final List<RestCategoryModel> createdCategoryLinks = restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategories(
|
||||
categoryLinkModels
|
||||
).getEntries();
|
||||
|
||||
STEP("Get categories which are linked from file and compare them to created category links");
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(file).getLinkedCategories();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
linkedCategories.assertThat().entriesListCountIs(createdCategoryLinks.size());
|
||||
IntStream.range(0, createdCategoryLinks.size()).forEach(i ->
|
||||
linkedCategories.getEntries().get(i).onModel().assertThat().isEqualTo(createdCategoryLinks.get(i).onModel())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get linked categories for content which is not linked to any category
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API})
|
||||
public void testListCategoriesForNode_withoutLinkedCategories()
|
||||
{
|
||||
STEP("Try to get linked categories and expect empty list");
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(file).getLinkedCategories();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
linkedCategories.assertThat().entriesListIsEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get linked categories using non-existing node and expect 404 (Not Found)
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API})
|
||||
public void testListCategoriesForNode_usingNonExistingNodeAndExpect404()
|
||||
{
|
||||
STEP("Try to get linked categories for non-existing node and expect 404");
|
||||
final RepoTestModel nonExistingNode = createNodeModelWithId("non-existing-id");
|
||||
final RestCategoryModelsCollection linkedCategories = restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistingNode).getLinkedCategories();
|
||||
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
linkedCategories.assertThat().entriesListIsEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get multiple linked categories as user without read permission and expect 403 (Forbidden)
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API})
|
||||
public void testListCategoriesForNode_asUserWithoutReadPermissionAndExpect403()
|
||||
{
|
||||
STEP("Link content to category");
|
||||
final RestCategoryLinkBodyModel categoryLink = createCategoryLinkModelWithId(category.getId());
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).linkToCategory(categoryLink);
|
||||
|
||||
STEP("Create another user and deny consumer rights");
|
||||
final UserModel userWithoutRights = dataUser.createRandomTestUser();
|
||||
denyPermissionsForUser(userWithoutRights.getUsername(), "Consumer", file);
|
||||
|
||||
STEP("Try to get linked categories using user without read permission and expect 403");
|
||||
restClient.authenticateUser(userWithoutRights).withCoreAPI().usingNode(file).getLinkedCategories();
|
||||
|
||||
restClient.assertStatusCodeIs(FORBIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get linked categories using tag instead of a content and expect 405 (Method Not Allowed)
|
||||
*/
|
||||
@Test(groups = { TestGroup.REST_API})
|
||||
public void testListCategoriesForNode_usingTagInsteadOfContentAndExpect405()
|
||||
{
|
||||
STEP("Add tag to file");
|
||||
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
|
||||
final RepoTestModel tagNode = createNodeModelWithId(tag.getId());
|
||||
|
||||
STEP("Try to get linked categories for a tag and expect 405");
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(tagNode).getLinkedCategories();
|
||||
|
||||
restClient.assertStatusCodeIs(METHOD_NOT_ALLOWED);
|
||||
}
|
||||
|
||||
private void denyPermissionsForUser(final String username, final String role, final FileModel file)
|
||||
{
|
||||
final String putPermissionsBody = Json.createObjectBuilder().add("permissions",
|
||||
Json.createObjectBuilder()
|
||||
.add("isInheritanceEnabled", true)
|
||||
.add("locallySet", Json.createObjectBuilder()
|
||||
.add("authorityId", username)
|
||||
.add("name", role)
|
||||
.add("accessStatus", "DENIED")))
|
||||
.build().toString();
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(file).updateNode(putPermissionsBody);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user