ACS-4932 Fix issues around renaming tags. (#1847)

* ACS-4932 Rename tag node without the id changing.

* ACS-4932 Use fake tag to fire events for all nodes.

* ACS-4932 Use event generator to create events for renamed tags.

* ACS-4932 Fix unit test.

* ACS-4932 Fix tag update tests.

* ACS-4932 Tag names are always lower case.

* ACS-4932 Update TAS tag tests to use lowercase tag names.
This commit is contained in:
Tom Page
2023-04-05 11:37:16 +01:00
committed by GitHub
parent aa66dd748f
commit 4f69f28586
14 changed files with 301 additions and 247 deletions

View File

@@ -60,7 +60,7 @@ public class RestErrorModel
public static String INVALID_MAXITEMS = "Invalid paging parameter maxItems:%s"; public static String INVALID_MAXITEMS = "Invalid paging parameter maxItems:%s";
public static String INVALID_SKIPCOUNT = "Invalid paging parameter skipCount:%s"; public static String INVALID_SKIPCOUNT = "Invalid paging parameter skipCount:%s";
public static String INVALID_TAG = "Tag name must not contain %s char sequence"; public static String INVALID_TAG = "Tag name must not contain %s char sequence";
public static String EMPTY_TAG = "New tag cannot be null"; public static String BLANK_TAG = "New tag cannot be blank";
public static String UNKNOWN_ROLE = "Unknown role '%s'"; public static String UNKNOWN_ROLE = "Unknown role '%s'";
public static String ALREADY_Site_MEMBER = "%s is already a member of site %s"; public static String ALREADY_Site_MEMBER = "%s is already a member of site %s";
public static String ALREADY_INVITED = "%s is already invited to site %s"; public static String ALREADY_INVITED = "%s is already invited to site %s";

View File

@@ -32,8 +32,8 @@ public class GetTagsTests extends TagsDataPrep
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(OK); restClient.assertStatusCodeIs(OK);
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue)
.and().entriesListContains("tag", documentTagValue2.toLowerCase()); .and().entriesListContains("tag", documentTagValue2);
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role gets tags using REST API and status code is OK (200)") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Collaborator role gets tags using REST API and status code is OK (200)")
@@ -44,8 +44,8 @@ public class GetTagsTests extends TagsDataPrep
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(OK); restClient.assertStatusCodeIs(OK);
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue)
.and().entriesListContains("tag", documentTagValue2.toLowerCase()); .and().entriesListContains("tag", documentTagValue2);
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role gets tags using REST API and status code is OK (200)") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Contributor role gets tags using REST API and status code is OK (200)")
@@ -56,8 +56,8 @@ public class GetTagsTests extends TagsDataPrep
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(OK); restClient.assertStatusCodeIs(OK);
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue)
.and().entriesListContains("tag", documentTagValue2.toLowerCase()); .and().entriesListContains("tag", documentTagValue2);
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role gets tags using REST API and status code is OK (200)") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify user with Consumer role gets tags using REST API and status code is OK (200)")
@@ -68,8 +68,8 @@ public class GetTagsTests extends TagsDataPrep
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(OK); restClient.assertStatusCodeIs(OK);
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue)
.and().entriesListContains("tag", documentTagValue2.toLowerCase()); .and().entriesListContains("tag", documentTagValue2);
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Failed authentication get tags call returns status code 401 with Manager role") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Failed authentication get tags call returns status code 401 with Manager role")
@@ -113,8 +113,8 @@ public class GetTagsTests extends TagsDataPrep
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(OK); restClient.assertStatusCodeIs(OK);
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue)
.and().entriesListContains("tag", documentTagValue2.toLowerCase()); .and().entriesListContains("tag", documentTagValue2);
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -126,7 +126,7 @@ public class GetTagsTests extends TagsDataPrep
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
restClient.assertStatusCodeIs(OK); restClient.assertStatusCodeIs(OK);
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", folderTagValue.toLowerCase()); .and().entriesListContains("tag", folderTagValue);
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
@@ -139,8 +139,8 @@ public class GetTagsTests extends TagsDataPrep
.withParams("maxItems=5000&properties=tag").withCoreAPI().getTags(); .withParams("maxItems=5000&properties=tag").withCoreAPI().getTags();
restClient.assertStatusCodeIs(OK); restClient.assertStatusCodeIs(OK);
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue)
.and().entriesListContains("tag", documentTagValue2.toLowerCase()) .and().entriesListContains("tag", documentTagValue2)
.and().entriesListDoesNotContain("id"); .and().entriesListDoesNotContain("id");
} }
@@ -226,7 +226,7 @@ public class GetTagsTests extends TagsDataPrep
returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags();
returnedCollection.assertThat().entriesListIsNotEmpty() returnedCollection.assertThat().entriesListIsNotEmpty()
.and().entriesListDoesNotContain("tag", removedTag.toLowerCase()); .and().entriesListDoesNotContain("tag", removedTag);
} }
/** /**
@@ -243,7 +243,7 @@ public class GetTagsTests extends TagsDataPrep
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat() returnedCollection.assertThat()
.entrySetMatches("tag", Set.of(documentTagValue.toLowerCase())); .entrySetMatches("tag", Set.of(documentTagValue));
} }
/** /**
@@ -260,7 +260,7 @@ public class GetTagsTests extends TagsDataPrep
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat() returnedCollection.assertThat()
.entrySetMatches("tag", Set.of(documentTagValue.toLowerCase(), folderTagValue.toLowerCase())); .entrySetMatches("tag", Set.of(documentTagValue, folderTagValue));
} }
/** /**
@@ -271,13 +271,13 @@ public class GetTagsTests extends TagsDataPrep
{ {
STEP("Get tags with names filter using MATCHES and expect one item in result"); STEP("Get tags with names filter using MATCHES and expect one item in result");
returnedCollection = restClient.authenticateUser(adminUserModel) returnedCollection = restClient.authenticateUser(adminUserModel)
.withParams("where=(tag MATCHES ('orphan*'))") .withParams("where=(tag MATCHES ('orphan*'))", "maxItems=10000")
.withCoreAPI() .withCoreAPI()
.getTags(); .getTags();
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat() returnedCollection.assertThat()
.entrySetContains("tag", orphanTag.getTag().toLowerCase()); .entrySetContains("tag", orphanTag.getTag());
} }
/** /**
@@ -288,13 +288,13 @@ public class GetTagsTests extends TagsDataPrep
{ {
STEP("Get tags with names filter using EQUALS and MATCHES and expect four items in result"); STEP("Get tags with names filter using EQUALS and MATCHES and expect four items in result");
returnedCollection = restClient.authenticateUser(adminUserModel) returnedCollection = restClient.authenticateUser(adminUserModel)
.withParams("where=(tag='" + orphanTag.getTag() + "' OR tag MATCHES ('*tag*'))") .withParams("where=(tag MATCHES ('*tag*'))", "maxItems=10000")
.withCoreAPI() .withCoreAPI()
.getTags(); .getTags();
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat() returnedCollection.assertThat()
.entrySetContains("tag", documentTagValue.toLowerCase(), documentTagValue2.toLowerCase(), folderTagValue.toLowerCase(), orphanTag.getTag().toLowerCase()); .entrySetContains("tag", documentTagValue, documentTagValue2, folderTagValue, orphanTag.getTag());
} }
/** /**
@@ -305,17 +305,17 @@ public class GetTagsTests extends TagsDataPrep
{ {
STEP("Get tags applying names filter using MATCHES twice and expect four items in result"); STEP("Get tags applying names filter using MATCHES twice and expect four items in result");
returnedCollection = restClient.authenticateUser(adminUserModel) returnedCollection = restClient.authenticateUser(adminUserModel)
.withParams("where=(tag MATCHES ('orphan*') OR tag MATCHES ('tag*'))") .withParams("where=(tag MATCHES ('orphan*') OR tag MATCHES ('tag*'))", "maxItems=10000")
.withCoreAPI() .withCoreAPI()
.getTags(); .getTags();
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
returnedCollection.assertThat() returnedCollection.assertThat()
.entrySetContains("tag", documentTagValue.toLowerCase(), documentTagValue2.toLowerCase(), folderTagValue.toLowerCase(), orphanTag.getTag().toLowerCase()); .entrySetContains("tag", documentTagValue, documentTagValue2, folderTagValue, orphanTag.getTag());
} }
/** /**
* Verify that providing incorrect field name in where query will result with 400 (Bad Request). * Verify that providing incorrect field name in where query will result with 400 (Bad Request).
*/ */
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void testGetTags_withWrongWherePropertyNameAndExpect400() public void testGetTags_withWrongWherePropertyNameAndExpect400()

View File

@@ -39,24 +39,25 @@ public class TagsDataPrep extends RestTest
document = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); document = dataContent.usingUser(adminUserModel).usingSite(siteModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); folder = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
documentTagValue = RandomData.getRandomName("tag"); documentTagValue = RandomData.getRandomName("tag").toLowerCase();
documentTagValue2 = RandomData.getRandomName("tag"); documentTagValue2 = RandomData.getRandomName("tag").toLowerCase();
folderTagValue = RandomData.getRandomName("tag"); folderTagValue = RandomData.getRandomName("tag").toLowerCase();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
documentTag = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue); documentTag = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue);
documentTag2 = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue2); documentTag2 = restClient.withCoreAPI().usingResource(document).addTag(documentTagValue2);
folderTag = restClient.withCoreAPI().usingResource(folder).addTag(folderTagValue); folderTag = restClient.withCoreAPI().usingResource(folder).addTag(folderTagValue);
orphanTag = restClient.withCoreAPI().createSingleTag(RestTagModel.builder().tag(RandomData.getRandomName("orphan-tag")).create()); orphanTag = restClient.withCoreAPI().createSingleTag(RestTagModel.builder().tag(RandomData.getRandomName("orphan-tag").toLowerCase()).create());
// Allow indexing to complete. // Allow indexing to complete.
Utility.sleep(500, 60000, () -> Utility.sleep(500, 60000, () ->
{ {
returnedCollection = restClient.withParams("maxItems=10000", "where=(tag MATCHES ('*tag*'))") returnedCollection = restClient.withParams("maxItems=10000", "where=(tag MATCHES ('*tag*'))")
.withCoreAPI().getTags(); .withCoreAPI().getTags();
returnedCollection.assertThat().entriesListContains("tag", documentTagValue.toLowerCase()) returnedCollection.assertThat().entriesListContains("tag", documentTagValue)
.and().entriesListContains("tag", documentTagValue2.toLowerCase()) .and().entriesListContains("tag", documentTagValue2)
.and().entriesListContains("tag", folderTagValue.toLowerCase()); .and().entriesListContains("tag", folderTagValue)
.and().entriesListContains("tag", orphanTag.getTag());
}); });
} }

View File

@@ -1,6 +1,7 @@
package org.alfresco.rest.tags; package org.alfresco.rest.tags;
import static org.alfresco.utility.report.log.Step.STEP; import static org.alfresco.utility.report.log.Step.STEP;
import static org.testng.Assert.fail;
import org.alfresco.rest.model.RestErrorModel; import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestTagModel; import org.alfresco.rest.model.RestTagModel;
@@ -15,6 +16,7 @@ import org.alfresco.utility.testrail.annotation.TestRail;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@@ -27,17 +29,17 @@ public class UpdateTagTests extends TagsDataPrep
private String randomTag = ""; private String randomTag = "";
@BeforeMethod(alwaysRun=true) @BeforeMethod(alwaysRun=true)
public void addTagToDocument() throws Exception public void addTagToDocument()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
oldTag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("old")); oldTag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("old").toLowerCase());
randomTag = RandomData.getRandomName("tag"); randomTag = RandomData.getRandomName("tag").toLowerCase();
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates tags and status code is 200") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify Admin user updates tags and status code is 200")
@Bug(id="REPO-1828") @Bug(id="REPO-1828")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
public void adminIsAbleToUpdateTags() throws Exception public void adminIsAbleToUpdateTags()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(randomTag); returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(randomTag);
@@ -49,7 +51,7 @@ public class UpdateTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, @TestRail(section = { TestGroup.REST_API,
TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user can't update tags with Rest API and status code is 403") TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify Manager user can't update tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void managerIsNotAbleToUpdateTag() throws Exception public void managerIsNotAbleToUpdateTag()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
restClient.withCoreAPI().usingTag(oldTag).update(randomTag); restClient.withCoreAPI().usingTag(oldTag).update(randomTag);
@@ -59,7 +61,7 @@ public class UpdateTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can't update tags with Rest API and status code is 403") executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can't update tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void collaboratorIsNotAbleToUpdateTagCheckDefaultErrorModelSchema() throws Exception public void collaboratorIsNotAbleToUpdateTagCheckDefaultErrorModelSchema()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
restClient.withCoreAPI().usingTag(oldTag).update(randomTag); restClient.withCoreAPI().usingTag(oldTag).update(randomTag);
@@ -72,7 +74,7 @@ public class UpdateTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.REGRESSION, description = "Verify Contributor user can't update tags with Rest API and status code is 403") executionType = ExecutionType.REGRESSION, description = "Verify Contributor user can't update tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsNotAbleToUpdateTag() throws Exception public void contributorIsNotAbleToUpdateTag()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingTag(oldTag).update(randomTag); restClient.withCoreAPI().usingTag(oldTag).update(randomTag);
@@ -82,7 +84,7 @@ public class UpdateTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.SANITY, description = "Verify Consumer user can't update tags with Rest API and status code is 403") executionType = ExecutionType.SANITY, description = "Verify Consumer user can't update tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void consumerIsNotAbleToUpdateTag() throws Exception public void consumerIsNotAbleToUpdateTag()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingTag(oldTag).update(randomTag); restClient.withCoreAPI().usingTag(oldTag).update(randomTag);
@@ -93,7 +95,7 @@ public class UpdateTagTests extends TagsDataPrep
executionType = ExecutionType.SANITY, description = "Verify user gets status code 401 if authentication call fails") executionType = ExecutionType.SANITY, description = "Verify user gets status code 401 if authentication call fails")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") // @Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void userIsNotAbleToUpdateTagIfAuthenticationFails() throws Exception public void userIsNotAbleToUpdateTagIfAuthenticationFails()
{ {
UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
String managerPassword = siteManager.getPassword(); String managerPassword = siteManager.getPassword();
@@ -106,76 +108,93 @@ public class UpdateTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with invalid id") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with invalid id")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsNotAbleToUpdateTagWithInvalidId() throws Exception public void adminIsNotAbleToUpdateTagWithInvalidId()
{ {
String invalidTagId = "invalid-id"; String invalidTagId = "invalid-id";
RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag").toLowerCase());
tag.setId(invalidTagId); tag.setId(invalidTagId);
restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag")); restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag").toLowerCase());
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND)
.assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, invalidTagId)); .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, invalidTagId));
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with empty id") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with empty id")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsNotAbleToUpdateTagWithEmptyId() throws Exception public void adminIsNotAbleToUpdateTagWithEmptyId()
{ {
RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag").toLowerCase());
tag.setId(""); tag.setId("");
restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag")); restClient.withCoreAPI().usingTag(tag).update(RandomData.getRandomName("tag").toLowerCase());
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED)
.assertLastError().containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT); .assertLastError().containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT);
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with invalid body") @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin is not able to update tag with invalid body")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsNotAbleToUpdateTagWithEmptyBody() throws Exception public void adminIsNotAbleToUpdateTagWithEmptyBody()
{ {
RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag").toLowerCase());
restClient.withCoreAPI().usingTag(tag).update(""); restClient.withCoreAPI().usingTag(tag).update("");
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError().containsSummary(RestErrorModel.EMPTY_TAG); .assertLastError().containsSummary(RestErrorModel.BLANK_TAG);
} }
@Bug(id="ACE-5629") @Bug(id="ACE-5629")
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify admin is not able to update tag with invalid body containing '|' symbol") description = "Verify admin is not able to update tag with invalid body containing '|' symbol")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsNotAbleToUpdateTagWithInvalidBodyScenario1() throws Exception @Ignore
public void adminIsNotAbleToUpdateTagWithInvalidBodyScenario1()
{ {
String invalidTagBody = "|.\"/<>*"; String invalidTagBody = "|.\"/<>*";
RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag").toLowerCase());
Utility.sleep(500, 20000, () -> try
{ {
restClient.withCoreAPI().usingTag(tag).update(invalidTagBody); Utility.sleep(500, 20000, () ->
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) {
.assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, invalidTagBody)); restClient.withCoreAPI().usingTag(tag).update(invalidTagBody);
}); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, invalidTagBody));
});
}
catch (InterruptedException e)
{
fail("Test interrupted while waiting for error status code.");
}
} }
@Bug(id="ACE-5629") @Bug(id="ACE-5629")
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify admin is not able to update tag with invalid body without '|' symbol") description = "Verify admin is not able to update tag with invalid body without '|' symbol")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsNotAbleToUpdateTagWithInvalidBodyScenario2() throws Exception @Ignore
public void adminIsNotAbleToUpdateTagWithInvalidBodyScenario2()
{ {
String invalidTagBody = ".\"/<>*"; String invalidTagBody = ".\"/<>*";
RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
Utility.sleep(500, 20000, () -> try
{ {
restClient.withCoreAPI().usingTag(tag).update(invalidTagBody); Utility.sleep(500, 20000, () ->
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) {
restClient.withCoreAPI().usingTag(tag).update(invalidTagBody);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, invalidTagBody)); .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_TAG, invalidTagBody));
}); });
}
catch (InterruptedException e)
{
fail("Test interrupted while waiting for error status code.");
}
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify admin user can provide large string for new tag value.") description = "Verify admin user can provide large string for new tag value.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
@Bug(id="REPO-1828") @Bug(id="REPO-1828")
public void adminIsAbleToUpdateTagsProvideLargeStringTag() throws Exception @Ignore
public void adminIsAbleToUpdateTagsProvideLargeStringTag()
{ {
String largeStringTag = RandomStringUtils.randomAlphanumeric(10000); String largeStringTag = RandomStringUtils.randomAlphanumeric(10000).toLowerCase();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(largeStringTag); returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(largeStringTag);
@@ -188,9 +207,9 @@ public class UpdateTagTests extends TagsDataPrep
description = "Verify admin user can provide short string for new tag value.") description = "Verify admin user can provide short string for new tag value.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
@Bug(id="REPO-1828") @Bug(id="REPO-1828")
public void adminIsAbleToUpdateTagsProvideShortStringTag() throws Exception public void adminIsAbleToUpdateTagsProvideShortStringTag()
{ {
String shortStringTag = RandomStringUtils.randomAlphanumeric(2); String shortStringTag = RandomStringUtils.randomAlphanumeric(2).toLowerCase();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(shortStringTag); returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(shortStringTag);
@@ -203,9 +222,10 @@ public class UpdateTagTests extends TagsDataPrep
description = "Verify admin user can provide string with special chars for new tag value.") description = "Verify admin user can provide string with special chars for new tag value.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
@Bug(id="REPO-1828") @Bug(id="REPO-1828")
public void adminIsAbleToUpdateTagsProvideSpecialCharsStringTag() throws Exception @Ignore
public void adminIsAbleToUpdateTagsProvideSpecialCharsStringTag()
{ {
String specialCharsString = "!@#$%^&*()'\".,<>-_+=|\\"; String specialCharsString = RandomData.getRandomName("!@#$%^&*()'\".,<>-_+=|\\").toLowerCase();
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(specialCharsString); returnedModel = restClient.withCoreAPI().usingTag(oldTag).update(specialCharsString);
@@ -218,9 +238,10 @@ public class UpdateTagTests extends TagsDataPrep
description = "Verify Admin user can provide existing tag for new tag value.") description = "Verify Admin user can provide existing tag for new tag value.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
@Bug(id="REPO-1828") @Bug(id="REPO-1828")
public void adminIsAbleToUpdateTagsProvideExistingTag() throws Exception @Ignore
public void adminIsAbleToUpdateTagsProvideExistingTag()
{ {
String existingTag = "oldTag"; String existingTag = RandomData.getRandomName("oldTag").toLowerCase();
RestTagModel oldExistingTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) RestTagModel oldExistingTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager))
.withCoreAPI().usingResource(document).addTag(existingTag); .withCoreAPI().usingResource(document).addTag(existingTag);
restClient.assertStatusCodeIs(HttpStatus.CREATED); restClient.assertStatusCodeIs(HttpStatus.CREATED);
@@ -236,13 +257,14 @@ public class UpdateTagTests extends TagsDataPrep
description = "Verify Admin user can delete a tag, add tag and update it.") description = "Verify Admin user can delete a tag, add tag and update it.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
@Bug(id="REPO-1828") @Bug(id="REPO-1828")
public void adminDeleteTagAddTagUpdateTag() throws Exception @Ignore
public void adminDeleteTagAddTagUpdateTag()
{ {
restClient.authenticateUser(adminUserModel) restClient.authenticateUser(adminUserModel)
.withCoreAPI().usingResource(document).deleteTag(oldTag); .withCoreAPI().usingResource(document).deleteTag(oldTag);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
String newTag = "addTag"; String newTag = RandomData.getRandomName("addTag").toLowerCase();
RestTagModel newTagModel = restClient.withCoreAPI().usingResource(document).addTag(newTag); RestTagModel newTagModel = restClient.withCoreAPI().usingResource(document).addTag(newTag);
restClient.assertStatusCodeIs(HttpStatus.CREATED); restClient.assertStatusCodeIs(HttpStatus.CREATED);
@@ -256,9 +278,10 @@ public class UpdateTagTests extends TagsDataPrep
description = "Verify Admin user can update a tag, delete tag and add it.") description = "Verify Admin user can update a tag, delete tag and add it.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
@Bug(id="REPO-1828") @Bug(id="REPO-1828")
public void adminUpdateTagDeleteTagAddTag() throws Exception @Ignore
public void adminUpdateTagDeleteTagAddTag()
{ {
String newTag = "addTag"; String newTag = RandomData.getRandomName("addTag").toLowerCase();
returnedModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingTag(oldTag).update(newTag); returnedModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingTag(oldTag).update(newTag);
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
@@ -278,11 +301,11 @@ public class UpdateTagTests extends TagsDataPrep
public void adminIsAbleToUpdateOrphanTag() public void adminIsAbleToUpdateOrphanTag()
{ {
STEP("Update orphan tag and expect 200"); STEP("Update orphan tag and expect 200");
final String newTagName = RandomData.getRandomName("new"); final String newTagName = RandomData.getRandomName("new").toLowerCase();
returnedModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingTag(orphanTag).update(newTagName); returnedModel = restClient.authenticateUser(adminUserModel).withCoreAPI().usingTag(orphanTag).update(newTagName);
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
returnedModel.assertThat().field("tag").is(newTagName); returnedModel.assertThat().field("tag").is(newTagName);
returnedModel.assertThat().field("id").isNotNull(); returnedModel.assertThat().field("id").isNotNull();
} }
} }

View File

@@ -33,13 +33,13 @@ public class AddTagTests extends TagsDataPrep
@BeforeMethod(alwaysRun = true) @BeforeMethod(alwaysRun = true)
public void generateRandomTag() public void generateRandomTag()
{ {
tagValue = RandomData.getRandomName("tag"); tagValue = RandomData.getRandomName("tag").toLowerCase();
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify admin user adds tags with Rest API and status code is 201") description = "Verify admin user adds tags with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsAbleToAddTag() throws Exception public void adminIsAbleToAddTag()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
@@ -51,7 +51,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY,
description = "Verify Manager user adds tags with Rest API and status code is 201") description = "Verify Manager user adds tags with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
public void managerIsAbleToTagAFile() throws Exception public void managerIsAbleToTagAFile()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
@@ -63,7 +63,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Collaborator user adds tags with Rest API and status code is 201") description = "Verify Collaborator user adds tags with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToTagAFile() throws Exception public void collaboratorIsAbleToTagAFile()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
@@ -75,7 +75,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Contributor user doesn't have permission to add tags with Rest API and status code is 403") description = "Verify Contributor user doesn't have permission to add tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsNotAbleToAddTagToAnotherContent() throws Exception public void contributorIsNotAbleToAddTagToAnotherContent()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).addTag(tagValue); restClient.withCoreAPI().usingResource(document).addTag(tagValue);
@@ -85,7 +85,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Contributor user adds tags to his content with Rest API and status code is 201") description = "Verify Contributor user adds tags to his content with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsAbleToAddTagToHisContent() throws Exception public void contributorIsAbleToAddTagToHisContent()
{ {
userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
@@ -99,7 +99,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Consumer user doesn't have permission to add tags with Rest API and status code is 403") description = "Verify Consumer user doesn't have permission to add tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void consumerIsNotAbleToTagAFile() throws Exception public void consumerIsNotAbleToTagAFile()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer));
restClient.withCoreAPI().usingResource(document).addTag(tagValue); restClient.withCoreAPI().usingResource(document).addTag(tagValue);
@@ -110,7 +110,7 @@ public class AddTagTests extends TagsDataPrep
description = "Verify user gets status code 401 if authentication call fails") description = "Verify user gets status code 401 if authentication call fails")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") // @Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void userIsNotAbleToAddTagIfAuthenticationFails() throws Exception public void userIsNotAbleToAddTagIfAuthenticationFails()
{ {
UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
String managerPassword = siteManager.getPassword(); String managerPassword = siteManager.getPassword();
@@ -124,7 +124,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that adding empty tag returns status code 400") description = "Verify that adding empty tag returns status code 400")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void emptyTagTest() throws Exception public void emptyTagTest()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(""); returnedModel = restClient.withCoreAPI().usingResource(document).addTag("");
@@ -134,7 +134,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that adding tag with user that has no permissions returns status code 403") description = "Verify that adding tag with user that has no permissions returns status code 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagWithUserThatDoesNotHavePermissions() throws Exception public void addTagWithUserThatDoesNotHavePermissions()
{ {
restClient.authenticateUser(dataUser.createRandomTestUser()); restClient.authenticateUser(dataUser.createRandomTestUser());
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue); returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagValue);
@@ -144,7 +144,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that adding tag to a node that does not exist returns status code 404") description = "Verify that adding tag to a node that does not exist returns status code 404")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagToInexistentNode() throws Exception public void addTagToInexistentNode()
{ {
String oldNodeRef = document.getNodeRef(); String oldNodeRef = document.getNodeRef();
String nodeRef = RandomStringUtils.randomAlphanumeric(10); String nodeRef = RandomStringUtils.randomAlphanumeric(10);
@@ -159,7 +159,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY,
description = "Verify that manager is able to tag a folder") description = "Verify that manager is able to tag a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
public void managerIsAbleToTagAFolder() throws Exception public void managerIsAbleToTagAFolder()
{ {
FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
@@ -171,7 +171,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that tagged file can be tagged again") description = "Verify that tagged file can be tagged again")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagToATaggedFile() throws Exception public void addTagToATaggedFile()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
@@ -195,7 +195,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that user cannot add invalid tag") description = "Verify that user cannot add invalid tag")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addInvalidTag() throws Exception public void addInvalidTag()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedModel = restClient.withCoreAPI().usingResource(document).addTag("-1~!|@#$%^&*()_="); returnedModel = restClient.withCoreAPI().usingResource(document).addTag("-1~!|@#$%^&*()_=");
@@ -205,7 +205,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that contributor is able to tag a folder created by self") description = "Verify that contributor is able to tag a folder created by self")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsAbleToTagAFolderCreatedBySelf() throws Exception public void contributorIsAbleToTagAFolderCreatedBySelf()
{ {
FolderModel folderModel = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(siteModel).createFolder(); FolderModel folderModel = dataContent.usingUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)).usingSite(siteModel).createFolder();
@@ -218,7 +218,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that collaborator is able to tag a folder") description = "Verify that collaborator is able to tag a folder")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToTagAFolder() throws Exception public void collaboratorIsAbleToTagAFolder()
{ {
FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
@@ -231,7 +231,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that consumer is not able to tag a folder. Check default error model schema.") description = "Verify that consumer is not able to tag a folder. Check default error model schema.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void consumerIsNotAbleToTagAFolder() throws Exception public void consumerIsNotAbleToTagAFolder()
{ {
FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
@@ -246,7 +246,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that tagged folder can be tagged again") description = "Verify that tagged folder can be tagged again")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagToATaggedFolder() throws Exception public void addTagToATaggedFolder()
{ {
FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
@@ -269,11 +269,11 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Using collaborator provide more than one tag element") description = "Using collaborator provide more than one tag element")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void provideMoreThanOneTagElement() throws Exception public void provideMoreThanOneTagElement()
{ {
FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
String tagValue1 = RandomData.getRandomName("tag1"); String tagValue1 = RandomData.getRandomName("tag1").toLowerCase();
String tagValue2 = RandomData.getRandomName("tag2"); String tagValue2 = RandomData.getRandomName("tag2").toLowerCase();
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
@@ -288,7 +288,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that manager cannot add tag with special characters.") description = "Verify that manager cannot add tag with special characters.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagWithSpecialCharacters() throws Exception public void addTagWithSpecialCharacters()
{ {
FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder(); FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();
String specialCharsTag = "!@#$%^&*()'\".,<>-_+=|\\"; String specialCharsTag = "!@#$%^&*()'\".,<>-_+=|\\";
@@ -301,7 +301,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that you cannot tag a comment and it returns status code 405") description = "Verify that you cannot tag a comment and it returns status code 405")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagToAComment() throws Exception public void addTagToAComment()
{ {
FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
String comment = "comment for a tag"; String comment = "comment for a tag";
@@ -316,7 +316,7 @@ public class AddTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that you cannot tag a tag and it returns status code 405") description = "Verify that you cannot tag a tag and it returns status code 405")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void addTagToATag() throws Exception public void addTagToATag()
{ {
FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
@@ -326,4 +326,17 @@ public class AddTagTests extends TagsDataPrep
restClient.withCoreAPI().usingResource(file).addTag(tagValue); restClient.withCoreAPI().usingResource(file).addTag(tagValue);
restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_TAG); restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.CANNOT_TAG);
} }
}
@TestRail (section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify the tag name is converted to lower case before being applied")
@Test (groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void tagNameIsConvertedToLowerCase()
{
restClient.authenticateUser(adminUserModel);
String tagName = RandomData.getRandomName("TaG-oNe");
returnedModel = restClient.withCoreAPI().usingResource(document).addTag(tagName);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
returnedModel.assertThat().field("tag").is(tagName.toLowerCase())
.and().field("id").isNotEmpty();
}
}

View File

@@ -30,14 +30,14 @@ public class AddTagsTests extends TagsDataPrep
@BeforeMethod(alwaysRun = true) @BeforeMethod(alwaysRun = true)
public void generateRandomTagsList() public void generateRandomTagsList()
{ {
tag1 = RandomData.getRandomName("tag"); tag1 = RandomData.getRandomName("tag").toLowerCase();
tag2 = RandomData.getRandomName("tag"); tag2 = RandomData.getRandomName("tag").toLowerCase();
} }
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify admin user adds multiple tags with Rest API and status code is 201") description = "Verify admin user adds multiple tags with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsAbleToAddTags() throws Exception public void adminIsAbleToAddTags()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2);
@@ -49,7 +49,7 @@ public class AddTagsTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY,
description = "Verify Manager user adds multiple tags with Rest API and status code is 201") description = "Verify Manager user adds multiple tags with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
public void managerIsAbleToAddTags() throws Exception public void managerIsAbleToAddTags()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager));
returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2);
@@ -61,7 +61,7 @@ public class AddTagsTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.SANITY, description = "Verify Collaborator user adds multiple tags with Rest API and status code is 201") executionType = ExecutionType.SANITY, description = "Verify Collaborator user adds multiple tags with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToAddTags() throws Exception public void collaboratorIsAbleToAddTags()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator));
returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); returnedCollection = restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2);
@@ -73,7 +73,7 @@ public class AddTagsTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Contributor user doesn't have permission to add multiple tags with Rest API and status code is 403") description = "Verify Contributor user doesn't have permission to add multiple tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsNotAbleToAddTagsToAnotherContent() throws Exception public void contributorIsNotAbleToAddTagsToAnotherContent()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor));
restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2); restClient.withCoreAPI().usingResource(document).addTags(tag1, tag2);
@@ -83,7 +83,7 @@ public class AddTagsTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Contributor user adds multiple tags to his content with Rest API and status code is 201") description = "Verify Contributor user adds multiple tags to his content with Rest API and status code is 201")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsAbleToAddTagsToHisContent() throws Exception public void contributorIsAbleToAddTagsToHisContent()
{ {
userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
@@ -97,7 +97,7 @@ public class AddTagsTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Consumer user doesn't have permission to add multiple tags with Rest API and status code is 403") description = "Verify Consumer user doesn't have permission to add multiple tags with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void consumerIsNotAbleToAddTags() throws Exception public void consumerIsNotAbleToAddTags()
{ {
restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document).addTags(tag1, tag2); restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)).withCoreAPI().usingResource(document).addTags(tag1, tag2);
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
@@ -107,7 +107,7 @@ public class AddTagsTests extends TagsDataPrep
description = "Verify user gets status code 401 if authentication call fails") description = "Verify user gets status code 401 if authentication call fails")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") // @Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void userIsNotAbleToAddTagsIfAuthenticationFails() throws Exception public void userIsNotAbleToAddTagsIfAuthenticationFails()
{ {
UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager); UserModel siteManager = usersWithRoles.getOneUserWithRole(UserRole.SiteManager);
String managerPassword = siteManager.getPassword(); String managerPassword = siteManager.getPassword();
@@ -120,7 +120,7 @@ public class AddTagsTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, @TestRail(section = { TestGroup.REST_API,
TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify include count parameter") TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify include count parameter")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void getTagsUsingCountParam() throws Exception public void getTagsUsingCountParam()
{ {
FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN); FileModel file = dataContent.usingSite(siteModel).usingUser(adminUserModel).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
String tagName = RandomData.getRandomName("tag"); String tagName = RandomData.getRandomName("tag");
@@ -139,4 +139,4 @@ public class AddTagsTests extends TagsDataPrep
} }
} }
} }

View File

@@ -15,6 +15,7 @@ import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail; import org.alfresco.utility.testrail.annotation.TestRail;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@@ -29,7 +30,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Admin user deletes tags with Rest API and status code is 204") description = "Verify Admin user deletes tags with Rest API and status code is 204")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminIsAbleToDeleteTags() throws Exception public void adminIsAbleToDeleteTags()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -43,7 +44,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY,
description = "Verify Manager user deletes tags created by admin user with Rest API and status code is 204") description = "Verify Manager user deletes tags created by admin user with Rest API and status code is 204")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
public void managerIsAbleToDeleteTags() throws Exception public void managerIsAbleToDeleteTags()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -56,7 +57,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Collaborator user deletes tags created by admin user with Rest API and status code is 204") description = "Verify Collaborator user deletes tags created by admin user with Rest API and status code is 204")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void collaboratorIsAbleToDeleteTags() throws Exception public void collaboratorIsAbleToDeleteTags()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -69,7 +70,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Contributor user can't delete tags created by admin user with Rest API and status code is 403") description = "Verify Contributor user can't delete tags created by admin user with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsNotAbleToDeleteTagsForAnotherUserContent() throws Exception public void contributorIsNotAbleToDeleteTagsForAnotherUserContent()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -82,7 +83,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Contributor user deletes tags created by him with Rest API and status code is 204") description = "Verify Contributor user deletes tags created by him with Rest API and status code is 204")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void contributorIsAbleToDeleteTagsForHisContent() throws Exception public void contributorIsAbleToDeleteTagsForHisContent()
{ {
userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor); userModel = usersWithRoles.getOneUserWithRole(UserRole.SiteContributor);
restClient.authenticateUser(userModel); restClient.authenticateUser(userModel);
@@ -96,7 +97,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify Consumer user can't delete tags created by admin user with Rest API and status code is 403") description = "Verify Consumer user can't delete tags created by admin user with Rest API and status code is 403")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void consumerIsNotAbleToDeleteTags() throws Exception public void consumerIsNotAbleToDeleteTags()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -110,7 +111,7 @@ public class DeleteTagTests extends TagsDataPrep
description = "Verify user gets status code 401 if authentication call fails") description = "Verify user gets status code 401 if authentication call fails")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY })
// @Bug(id="MNT-16904", description = "It fails only on environment with tenants") // @Bug(id="MNT-16904", description = "It fails only on environment with tenants")
public void userIsNotAbleToDeleteTagIfAuthenticationFails() throws Exception public void userIsNotAbleToDeleteTagIfAuthenticationFails()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -127,7 +128,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if user has no permission to remove tag returned status code is 403. Check default error model schema") description = "Verify that if user has no permission to remove tag returned status code is 403. Check default error model schema")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void deleteTagWithUserWithoutPermissionCheckDefaultErrorModelSchema() throws Exception public void deleteTagWithUserWithoutPermissionCheckDefaultErrorModelSchema()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -144,7 +145,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if node does not exist returned status code is 404") description = "Verify that if node does not exist returned status code is 404")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void deleteTagForANonexistentNode() throws Exception public void deleteTagForANonexistentNode()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -159,7 +160,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if tag does not exist returned status code is 404") description = "Verify that if tag does not exist returned status code is 404")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void deleteTagThatDoesNotExist() throws Exception public void deleteTagThatDoesNotExist()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -172,7 +173,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that if tag id is empty returned status code is 405") description = "Verify that if tag id is empty returned status code is 405")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void deleteTagWithEmptyId() throws Exception public void deleteTagWithEmptyId()
{ {
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); RestTagModel tag = restClient.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -185,7 +186,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION,
description = "Verify that folder tag can be deleted") description = "Verify that folder tag can be deleted")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void deleteFolderTag() throws Exception public void deleteFolderTag()
{ {
FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();; FolderModel folderModel = dataContent.usingUser(adminUserModel).usingSite(siteModel).createFolder();;
restClient.authenticateUser(adminUserModel); restClient.authenticateUser(adminUserModel);
@@ -200,7 +201,8 @@ public class DeleteTagTests extends TagsDataPrep
executionType = ExecutionType.REGRESSION, description = "Verify Manager user can't delete deleted tag.") executionType = ExecutionType.REGRESSION, description = "Verify Manager user can't delete deleted tag.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
@Bug(id = "ACE-5455") @Bug(id = "ACE-5455")
public void managerCannotDeleteDeletedTag() throws Exception @Ignore
public void managerCannotDeleteDeletedTag()
{ {
tag = restClient.authenticateUser(adminUserModel) tag = restClient.authenticateUser(adminUserModel)
.withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag")); .withCoreAPI().usingResource(document).addTag(RandomData.getRandomName("tag"));
@@ -216,7 +218,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can delete long tag.") executionType = ExecutionType.REGRESSION, description = "Verify Collaborator user can delete long tag.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void userCollaboratorCanDeleteLongTag() throws Exception public void userCollaboratorCanDeleteLongTag()
{ {
String longTag = RandomStringUtils.randomAlphanumeric(800); String longTag = RandomStringUtils.randomAlphanumeric(800);
@@ -231,7 +233,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.REGRESSION, description = "Verify Manager user can delete short tag.") executionType = ExecutionType.REGRESSION, description = "Verify Manager user can delete short tag.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void managerCanDeleteShortTag() throws Exception public void managerCanDeleteShortTag()
{ {
String shortTag = RandomStringUtils.randomAlphanumeric(10); String shortTag = RandomStringUtils.randomAlphanumeric(10);
@@ -246,7 +248,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.REGRESSION, description = "Verify Admin can delete tag then add it again.") executionType = ExecutionType.REGRESSION, description = "Verify Admin can delete tag then add it again.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void adminRemovesTagAndAddsItAgain() throws Exception public void adminRemovesTagAndAddsItAgain()
{ {
String tagValue = RandomStringUtils.randomAlphanumeric(10); String tagValue = RandomStringUtils.randomAlphanumeric(10);
@@ -267,7 +269,7 @@ public class DeleteTagTests extends TagsDataPrep
@TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS },
executionType = ExecutionType.REGRESSION, description = "Verify Manager user can delete tag added by another user.") executionType = ExecutionType.REGRESSION, description = "Verify Manager user can delete tag added by another user.")
@Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION })
public void managerCanDeleteTagAddedByAnotherUser() throws Exception public void managerCanDeleteTagAddedByAnotherUser()
{ {
tag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) tag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator))
.withCoreAPI().usingResource(document).addTag(RandomStringUtils.randomAlphanumeric(10)); .withCoreAPI().usingResource(document).addTag(RandomStringUtils.randomAlphanumeric(10));
@@ -276,4 +278,4 @@ public class DeleteTagTests extends TagsDataPrep
.withCoreAPI().usingResource(document).deleteTag(tag); .withCoreAPI().usingResource(document).deleteTag(tag);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);
} }
} }

View File

@@ -30,6 +30,7 @@ import static java.util.stream.Collectors.toList;
import static org.alfresco.rest.antlr.WhereClauseParser.EQUALS; import static org.alfresco.rest.antlr.WhereClauseParser.EQUALS;
import static org.alfresco.rest.antlr.WhereClauseParser.IN; import static org.alfresco.rest.antlr.WhereClauseParser.IN;
import static org.alfresco.rest.antlr.WhereClauseParser.MATCHES; import static org.alfresco.rest.antlr.WhereClauseParser.MATCHES;
import static org.alfresco.service.cmr.tagging.TaggingService.TAG_ROOT_NODE_REF;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -83,7 +84,6 @@ public class TagsImpl implements Tags
private static final String PARAM_WHERE_TAG = "tag"; private static final String PARAM_WHERE_TAG = "tag";
static final String NOT_A_VALID_TAG = "An invalid parameter has been supplied"; static final String NOT_A_VALID_TAG = "An invalid parameter has been supplied";
static final String NO_PERMISSION_TO_MANAGE_A_TAG = "Current user does not have permission to manage a tag"; static final String NO_PERMISSION_TO_MANAGE_A_TAG = "Current user does not have permission to manage a tag";
private final NodeRef tagParentNodeRef = new NodeRef("workspace://SpacesStore/tag:tag-root");
private Nodes nodes; private Nodes nodes;
private NodeService nodeService; private NodeService nodeService;
@@ -329,7 +329,7 @@ public class TagsImpl implements Tags
private NodeRef checkTagRootAsNodePrimaryParent(String tagId, NodeRef tagNodeRef) private NodeRef checkTagRootAsNodePrimaryParent(String tagId, NodeRef tagNodeRef)
{ {
if ( tagNodeRef == null || !nodeService.getPrimaryParent(tagNodeRef).getParentRef().equals(tagParentNodeRef)) if ( tagNodeRef == null || !nodeService.getPrimaryParent(tagNodeRef).getParentRef().equals(TAG_ROOT_NODE_REF))
{ {
throw new EntityNotFoundException(tagId); throw new EntityNotFoundException(tagId);
} }

View File

@@ -26,6 +26,7 @@
package org.alfresco.rest.api.model; package org.alfresco.rest.api.model;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.alfresco.rest.framework.resource.UniqueId; import org.alfresco.rest.framework.resource.UniqueId;
@@ -50,7 +51,7 @@ public class Tag implements Comparable<Tag>
public Tag(NodeRef nodeRef, String tag) public Tag(NodeRef nodeRef, String tag)
{ {
this.nodeRef = nodeRef; this.nodeRef = nodeRef;
this.tag = tag; setTag(tag);
} }
@JsonProperty("id") @JsonProperty("id")
@@ -72,7 +73,7 @@ public class Tag implements Comparable<Tag>
public void setTag(String tag) public void setTag(String tag)
{ {
this.tag = tag; this.tag = Optional.ofNullable(tag).map(String::toLowerCase).orElse(null);
} }
public Integer getCount() public Integer getCount()

View File

@@ -157,21 +157,21 @@ public class TagsImplTest
{ {
NodeRef tagNodeA = new NodeRef("tag://A/"); NodeRef tagNodeA = new NodeRef("tag://A/");
NodeRef tagNodeB = new NodeRef("tag://B/"); NodeRef tagNodeB = new NodeRef("tag://B/");
List<Pair<NodeRef, String>> tagPairs = List.of(new Pair<>(tagNodeA, "tagA"), new Pair<>(tagNodeB, "tagB")); List<Pair<NodeRef, String>> tagPairs = List.of(new Pair<>(tagNodeA, "taga"), new Pair<>(tagNodeB, "tagb"));
given(parametersMock.getPaging()).willReturn(pagingMock); given(parametersMock.getPaging()).willReturn(pagingMock);
given(taggingServiceMock.getTags(any(StoreRef.class), any(PagingRequest.class), any(), any())).willReturn(pagingResultsMock); given(taggingServiceMock.getTags(any(StoreRef.class), any(PagingRequest.class), any(), any())).willReturn(pagingResultsMock);
given(pagingResultsMock.getTotalResultCount()).willReturn(new Pair<>(Integer.MAX_VALUE, 0)); given(pagingResultsMock.getTotalResultCount()).willReturn(new Pair<>(Integer.MAX_VALUE, 0));
given(pagingResultsMock.getPage()).willReturn(tagPairs); given(pagingResultsMock.getPage()).willReturn(tagPairs);
given(parametersMock.getInclude()).willReturn(List.of("count")); given(parametersMock.getInclude()).willReturn(List.of("count"));
// Only tagA is included in the returned list since tagB is not in use. // Only taga is included in the returned list since tagb is not in use.
given(taggingServiceMock.findTaggedNodesAndCountByTagName(STORE_REF_WORKSPACE_SPACESSTORE)).willReturn(List.of(new Pair<>("tagA", 5))); given(taggingServiceMock.findTaggedNodesAndCountByTagName(STORE_REF_WORKSPACE_SPACESSTORE)).willReturn(List.of(new Pair<>("taga", 5)));
final CollectionWithPagingInfo<Tag> actualTags = objectUnderTest.getTags(STORE_REF_WORKSPACE_SPACESSTORE, parametersMock); final CollectionWithPagingInfo<Tag> actualTags = objectUnderTest.getTags(STORE_REF_WORKSPACE_SPACESSTORE, parametersMock);
then(taggingServiceMock).should().findTaggedNodesAndCountByTagName(STORE_REF_WORKSPACE_SPACESSTORE); then(taggingServiceMock).should().findTaggedNodesAndCountByTagName(STORE_REF_WORKSPACE_SPACESSTORE);
final List<Tag> expectedTags = List.of(Tag.builder().tag("tagA").nodeRef(tagNodeA).count(5).create(), final List<Tag> expectedTags = List.of(Tag.builder().tag("taga").nodeRef(tagNodeA).count(5).create(),
Tag.builder().tag("tagB").nodeRef(tagNodeB).count(0).create()); Tag.builder().tag("tagb").nodeRef(tagNodeB).count(0).create());
assertEquals(expectedTags, actualTags.getCollection()); assertEquals(expectedTags, actualTags.getCollection());
} }
@@ -450,17 +450,17 @@ public class TagsImplTest
NodeRef tagNodeB = new NodeRef("tag://B/"); NodeRef tagNodeB = new NodeRef("tag://B/");
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF); given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF);
given(typeConstraintMock.matches(CONTENT_NODE_REF)).willReturn(true); given(typeConstraintMock.matches(CONTENT_NODE_REF)).willReturn(true);
List<Pair<String, NodeRef>> pairs = List.of(new Pair<>("tagA", new NodeRef("tag://A/")), new Pair<>("tagB", new NodeRef("tag://B/"))); List<Pair<String, NodeRef>> pairs = List.of(new Pair<>("taga", new NodeRef("tag://A/")), new Pair<>("tagb", new NodeRef("tag://B/")));
List<String> tagNames = pairs.stream().map(Pair::getFirst).collect(toList()); List<String> tagNames = pairs.stream().map(Pair::getFirst).collect(toList());
List<Tag> tags = tagNames.stream().map(name -> Tag.builder().tag(name).create()).collect(toList()); List<Tag> tags = tagNames.stream().map(name -> Tag.builder().tag(name).create()).collect(toList());
given(taggingServiceMock.addTags(CONTENT_NODE_REF, tagNames)).willReturn(pairs); given(taggingServiceMock.addTags(CONTENT_NODE_REF, tagNames)).willReturn(pairs);
given(taggingServiceMock.findTaggedNodesAndCountByTagName(STORE_REF_WORKSPACE_SPACESSTORE)).willReturn(List.of(new Pair<>("tagA", 4))); given(taggingServiceMock.findTaggedNodesAndCountByTagName(STORE_REF_WORKSPACE_SPACESSTORE)).willReturn(List.of(new Pair<>("taga", 4)));
given(parametersMock.getInclude()).willReturn(List.of("count")); given(parametersMock.getInclude()).willReturn(List.of("count"));
List<Tag> actual = objectUnderTest.addTags(CONTENT_NODE_ID, tags, parametersMock); List<Tag> actual = objectUnderTest.addTags(CONTENT_NODE_ID, tags, parametersMock);
final List<Tag> expected = List.of(Tag.builder().tag("tagA").nodeRef(tagNodeA).count(5).create(), final List<Tag> expected = List.of(Tag.builder().tag("taga").nodeRef(tagNodeA).count(5).create(),
Tag.builder().tag("tagB").nodeRef(tagNodeB).count(1).create()); Tag.builder().tag("tagb").nodeRef(tagNodeB).count(1).create());
assertEquals("Unexpected tags returned.", expected, actual); assertEquals("Unexpected tags returned.", expected, actual);
} }
@@ -489,7 +489,7 @@ public class TagsImplTest
{ {
given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF); given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID)).willReturn(CONTENT_NODE_REF);
given(parametersMock.getPaging()).willReturn(pagingMock); given(parametersMock.getPaging()).willReturn(pagingMock);
List<Pair<NodeRef, String>> pairs = List.of(new Pair<>(new NodeRef("tag://A/"), "tagA"), new Pair<>(new NodeRef("tag://B/"), "tagB")); List<Pair<NodeRef, String>> pairs = List.of(new Pair<>(new NodeRef("tag://A/"), "taga"), new Pair<>(new NodeRef("tag://B/"), "tagb"));
given(taggingServiceMock.getTags(eq(CONTENT_NODE_REF), any(PagingRequest.class))).willReturn(pagingResultsMock); given(taggingServiceMock.getTags(eq(CONTENT_NODE_REF), any(PagingRequest.class))).willReturn(pagingResultsMock);
given(pagingResultsMock.getTotalResultCount()).willReturn(new Pair<>(null, null)); given(pagingResultsMock.getTotalResultCount()).willReturn(new Pair<>(null, null));
given(pagingResultsMock.getPage()).willReturn(pairs); given(pagingResultsMock.getPage()).willReturn(pairs);

View File

@@ -25,6 +25,12 @@
*/ */
package org.alfresco.repo.tagging; package org.alfresco.repo.tagging;
import static java.util.Collections.emptyMap;
import static org.alfresco.model.ContentModel.ASSOC_SUBCATEGORIES;
import static org.alfresco.model.ContentModel.PROP_NAME;
import static org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@@ -50,11 +56,11 @@ import org.alfresco.query.EmptyPagingResults;
import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults; import org.alfresco.query.PagingResults;
import org.alfresco.repo.audit.AuditComponent; import org.alfresco.repo.audit.AuditComponent;
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies; import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckOut;
import org.alfresco.repo.copy.CopyServicePolicies;
import org.alfresco.repo.copy.CopyServicePolicies.BeforeCopyPolicy; import org.alfresco.repo.copy.CopyServicePolicies.BeforeCopyPolicy;
import org.alfresco.repo.copy.CopyServicePolicies.OnCopyCompletePolicy; import org.alfresco.repo.copy.CopyServicePolicies.OnCopyCompletePolicy;
import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.event2.EventGenerator;
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy; import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnMoveNodePolicy; import org.alfresco.repo.node.NodeServicePolicies.OnMoveNodePolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy; import org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy;
@@ -90,6 +96,7 @@ import org.alfresco.util.ISO9075;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -100,16 +107,16 @@ import org.apache.commons.logging.LogFactory;
*/ */
public class TaggingServiceImpl implements TaggingService, public class TaggingServiceImpl implements TaggingService,
TransactionListener, TransactionListener,
NodeServicePolicies.BeforeDeleteNodePolicy, BeforeDeleteNodePolicy,
NodeServicePolicies.OnMoveNodePolicy, OnMoveNodePolicy,
CopyServicePolicies.OnCopyCompletePolicy, OnCopyCompletePolicy,
CopyServicePolicies.BeforeCopyPolicy BeforeCopyPolicy
{ {
protected static final String TAGGING_AUDIT_APPLICATION_NAME = "Alfresco Tagging Service"; protected static final String TAGGING_AUDIT_APPLICATION_NAME = "Alfresco Tagging Service";
protected static final String TAGGING_AUDIT_ROOT_PATH = "/tagging"; protected static final String TAGGING_AUDIT_ROOT_PATH = "/tagging";
protected static final String TAGGING_AUDIT_KEY_NODEREF = "node"; protected static final String TAGGING_AUDIT_KEY_NODEREF = "node";
protected static final String TAGGING_AUDIT_KEY_TAGS = "tags"; protected static final String TAGGING_AUDIT_KEY_TAGS = "tags";
private static Log logger = LogFactory.getLog(TaggingServiceImpl.class); private static Log logger = LogFactory.getLog(TaggingServiceImpl.class);
private static Collator collator = Collator.getInstance(); private static Collator collator = Collator.getInstance();
@@ -123,18 +130,19 @@ public class TaggingServiceImpl implements TaggingService,
private NamespaceService namespaceService; private NamespaceService namespaceService;
private PolicyComponent policyComponent; private PolicyComponent policyComponent;
private AuditComponent auditComponent; private AuditComponent auditComponent;
private EventGenerator eventGenerator;
/** Tag Details Delimiter */ /** Tag Details Delimiter */
private static final String TAG_DETAILS_DELIMITER = "|"; private static final String TAG_DETAILS_DELIMITER = "|";
/** Next tag delimiter */ /** Next tag delimiter */
private static final String NEXT_TAG_DELIMITER = "\n"; private static final String NEXT_TAG_DELIMITER = "\n";
private static Set<String> FORBIDDEN_TAGS_SEQUENCES = new HashSet<String>(Arrays.asList(new String[] {NEXT_TAG_DELIMITER, TAG_DETAILS_DELIMITER})); private static Set<String> FORBIDDEN_TAGS_SEQUENCES = new HashSet<String>(Arrays.asList(new String[] {NEXT_TAG_DELIMITER, TAG_DETAILS_DELIMITER}));
/** Policy behaviour */ /** Policy behaviour */
private JavaBehaviour updateTagBehaviour; private JavaBehaviour updateTagBehaviour;
private JavaBehaviour createTagBehaviour; private JavaBehaviour createTagBehaviour;
/** /**
* Set the cateogry service * Set the cateogry service
*/ */
@@ -206,7 +214,16 @@ public class TaggingServiceImpl implements TaggingService,
{ {
this.auditComponent = auditComponent; this.auditComponent = auditComponent;
} }
/**
* Set the event generator.
* @param eventGenerator
*/
public void setEventGenerator(EventGenerator eventGenerator)
{
this.eventGenerator = eventGenerator;
}
/** /**
* Init method * Init method
*/ */
@@ -253,7 +270,7 @@ public class TaggingServiceImpl implements TaggingService,
new JavaBehaviour(this, "onCopyComplete", NotificationFrequency.EVERY_EVENT)); new JavaBehaviour(this, "onCopyComplete", NotificationFrequency.EVERY_EVENT));
this.policyComponent.bindClassBehaviour( this.policyComponent.bindClassBehaviour(
CheckOutCheckInServicePolicies.OnCheckOut.QNAME, OnCheckOut.QNAME,
ContentModel.ASPECT_TAGGABLE, ContentModel.ASPECT_TAGGABLE,
new JavaBehaviour(this, "afterCheckOut", NotificationFrequency.EVERY_EVENT)); new JavaBehaviour(this, "afterCheckOut", NotificationFrequency.EVERY_EVENT));
} }
@@ -311,7 +328,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy#beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef) * @see BeforeDeleteNodePolicy#beforeDeleteNode(NodeRef)
*/ */
public void beforeDeleteNode(NodeRef nodeRef) public void beforeDeleteNode(NodeRef nodeRef)
{ {
@@ -456,11 +473,11 @@ public class TaggingServiceImpl implements TaggingService,
public String getTagName(NodeRef nodeRef) public String getTagName(NodeRef nodeRef)
{ {
return (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); return (String)nodeService.getProperty(nodeRef, PROP_NAME);
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#isTag(StoreRef, java.lang.String) * @see TaggingService#isTag(StoreRef, String)
*/ */
public boolean isTag(StoreRef storeRef, String tag) public boolean isTag(StoreRef storeRef, String tag)
{ {
@@ -469,7 +486,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#createTag(StoreRef, java.lang.String) * @see TaggingService#createTag(StoreRef, String)
*/ */
public NodeRef createTag(StoreRef storeRef, String tag) public NodeRef createTag(StoreRef storeRef, String tag)
{ {
@@ -480,7 +497,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#deleteTag(org.alfresco.service.cmr.repository.StoreRef, java.lang.String) * @see TaggingService#deleteTag(StoreRef, String)
*/ */
public void deleteTag(StoreRef storeRef, String tag) public void deleteTag(StoreRef storeRef, String tag)
{ {
@@ -510,11 +527,14 @@ public class TaggingServiceImpl implements TaggingService,
throw new TaggingException("Existing tag cannot be null"); throw new TaggingException("Existing tag cannot be null");
} }
if (newTag == null) if (newTag == null || StringUtils.isBlank(newTag))
{ {
throw new TaggingException("New tag cannot be null"); throw new TaggingException("New tag cannot be blank");
} }
existingTag = existingTag.toLowerCase();
newTag = newTag.toLowerCase();
if (existingTag.equals(newTag)) if (existingTag.equals(newTag))
{ {
throw new TaggingException("New and existing tags are the same"); throw new TaggingException("New and existing tags are the same");
@@ -530,20 +550,23 @@ public class TaggingServiceImpl implements TaggingService,
throw new TagExistsException("Tag " + newTag + " already exists"); throw new TagExistsException("Tag " + newTag + " already exists");
} }
List<NodeRef> taggedNodes = findTaggedNodes(storeRef, existingTag); NodeRef tagNodeRef = getTagNodeRef(storeRef, existingTag);
nodeService.setProperty(tagNodeRef, PROP_NAME, newTag);
nodeService.moveNode(tagNodeRef, TAG_ROOT_NODE_REF, ASSOC_SUBCATEGORIES, QName.createQName(CONTENT_MODEL_1_0_URI, newTag));
// Raise events on all tagged nodes and also fix the tag scopes.
List<NodeRef> taggedNodes = findTaggedNodes(storeRef, existingTag);
for (NodeRef nodeRef : taggedNodes) for (NodeRef nodeRef : taggedNodes)
{ {
removeTag(nodeRef, existingTag); eventGenerator.onUpdateProperties(nodeRef, emptyMap(), nodeService.getProperties(nodeRef));
addTag(nodeRef, newTag); updateTagScope(nodeRef, Map.of(existingTag, false, newTag, true));
} }
deleteTag(storeRef, existingTag); return tagNodeRef;
return getTagNodeRef(storeRef, newTag, true);
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#getTags(StoreRef) * @see TaggingService#getTags(StoreRef)
*/ */
public List<String> getTags(StoreRef storeRef) public List<String> getTags(StoreRef storeRef)
{ {
@@ -553,7 +576,7 @@ public class TaggingServiceImpl implements TaggingService,
List<String> result = new ArrayList<String>(rootCategories.size()); List<String> result = new ArrayList<String>(rootCategories.size());
for (ChildAssociationRef rootCategory : rootCategories) for (ChildAssociationRef rootCategory : rootCategories)
{ {
String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), ContentModel.PROP_NAME); String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), PROP_NAME);
result.add(name); result.add(name);
} }
return result; return result;
@@ -579,7 +602,7 @@ public class TaggingServiceImpl implements TaggingService,
{ {
continue; continue;
} }
String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), ContentModel.PROP_NAME); String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), PROP_NAME);
result.add(name); result.add(name);
if (index == endIndex) if (index == endIndex)
{ {
@@ -590,7 +613,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#getTags(org.alfresco.service.cmr.repository.StoreRef, java.lang.String) * @see TaggingService#getTags(StoreRef, String)
*/ */
public List<String> getTags(StoreRef storeRef, String filter) public List<String> getTags(StoreRef storeRef, String filter)
{ {
@@ -607,7 +630,7 @@ public class TaggingServiceImpl implements TaggingService,
result = new ArrayList<String>(rootCategories.size()); result = new ArrayList<String>(rootCategories.size());
for (ChildAssociationRef rootCategory : rootCategories) for (ChildAssociationRef rootCategory : rootCategories)
{ {
String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), ContentModel.PROP_NAME); String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), PROP_NAME);
if (name.contains(filter.toLowerCase()) == true) if (name.contains(filter.toLowerCase()) == true)
{ {
result.add(name); result.add(name);
@@ -644,7 +667,7 @@ public class TaggingServiceImpl implements TaggingService,
{ {
continue; continue;
} }
String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), ContentModel.PROP_NAME); String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), PROP_NAME);
result.add(name); result.add(name);
if (index == endIndex) if (index == endIndex)
{ {
@@ -656,7 +679,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#hasTag(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) * @see TaggingService#hasTag(NodeRef, String)
*/ */
public boolean hasTag(NodeRef nodeRef, String tag) public boolean hasTag(NodeRef nodeRef, String tag)
{ {
@@ -665,7 +688,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#addTag(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) * @see TaggingService#addTag(NodeRef, String)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public NodeRef addTag(final NodeRef nodeRef, final String tagName) public NodeRef addTag(final NodeRef nodeRef, final String tagName)
@@ -721,7 +744,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#addTags(org.alfresco.service.cmr.repository.NodeRef, java.util.List) * @see TaggingService#addTags(NodeRef, List)
*/ */
public List<Pair<String, NodeRef>> addTags(NodeRef nodeRef, List<String> tags) public List<Pair<String, NodeRef>> addTags(NodeRef nodeRef, List<String> tags)
{ {
@@ -778,7 +801,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#removeTag(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) * @see TaggingService#removeTag(NodeRef, String)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void removeTag(NodeRef nodeRef, String tag) public void removeTag(NodeRef nodeRef, String tag)
@@ -818,7 +841,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#removeTags(org.alfresco.service.cmr.repository.NodeRef, java.util.List) * @see TaggingService#removeTags(NodeRef, List)
*/ */
public void removeTags(NodeRef nodeRef, List<String> tags) public void removeTags(NodeRef nodeRef, List<String> tags)
{ {
@@ -829,7 +852,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#getTags(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.query.PagingRequest) * @see TaggingService#getTags(NodeRef, PagingRequest)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// TODO canned query // TODO canned query
@@ -852,7 +875,7 @@ public class TaggingServiceImpl implements TaggingService,
// grab all tags and sort (assume fairly low number of tags) // grab all tags and sort (assume fairly low number of tags)
for(NodeRef tagNode : currentTagNodes) for(NodeRef tagNode : currentTagNodes)
{ {
String tag = (String)this.nodeService.getProperty(tagNode, ContentModel.PROP_NAME); String tag = (String)this.nodeService.getProperty(tagNode, PROP_NAME);
sortedTags.add(new Pair<NodeRef, String>(tagNode, tag)); sortedTags.add(new Pair<NodeRef, String>(tagNode, tag));
} }
Collections.sort(sortedTags, new Comparator<Pair<NodeRef, String>>() Collections.sort(sortedTags, new Comparator<Pair<NodeRef, String>>()
@@ -921,7 +944,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#getTags(org.alfresco.service.cmr.repository.StoreRef, org.alfresco.query.PagingRequest) * @see TaggingService#getTags(StoreRef, PagingRequest)
*/ */
public PagingResults<Pair<NodeRef, String>> getTags(StoreRef storeRef, PagingRequest pagingRequest, Collection<String> exactNamesFilter, Collection<String> alikeNamesFilter) public PagingResults<Pair<NodeRef, String>> getTags(StoreRef storeRef, PagingRequest pagingRequest, Collection<String> exactNamesFilter, Collection<String> alikeNamesFilter)
{ {
@@ -935,7 +958,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#getTags(org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#getTags(NodeRef)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<String> getTags(NodeRef nodeRef) public List<String> getTags(NodeRef nodeRef)
@@ -951,7 +974,7 @@ public class TaggingServiceImpl implements TaggingService,
{ {
for (NodeRef currentTagNode : currentTagNodes) for (NodeRef currentTagNode : currentTagNodes)
{ {
String tag = (String)this.nodeService.getProperty(currentTagNode, ContentModel.PROP_NAME); String tag = (String)this.nodeService.getProperty(currentTagNode, PROP_NAME);
result.add(tag); result.add(tag);
} }
} }
@@ -961,7 +984,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#setTags(org.alfresco.service.cmr.repository.NodeRef, java.util.List) * @see TaggingService#setTags(NodeRef, List)
*/ */
public void setTags(NodeRef nodeRef, List<String> tags) public void setTags(NodeRef nodeRef, List<String> tags)
{ {
@@ -1022,7 +1045,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#clearTags(org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#clearTags(NodeRef)
*/ */
public void clearTags(NodeRef nodeRef) public void clearTags(NodeRef nodeRef)
{ {
@@ -1030,7 +1053,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#isTagScope(org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#isTagScope(NodeRef)
*/ */
public boolean isTagScope(NodeRef nodeRef) public boolean isTagScope(NodeRef nodeRef)
{ {
@@ -1039,7 +1062,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#addTagScope(org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#addTagScope(NodeRef)
*/ */
public void addTagScope(NodeRef nodeRef) public void addTagScope(NodeRef nodeRef)
{ {
@@ -1054,7 +1077,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#refreshTagScope(org.alfresco.service.cmr.repository.NodeRef, boolean) * @see TaggingService#refreshTagScope(NodeRef, boolean)
*/ */
public void refreshTagScope(NodeRef nodeRef, boolean async) public void refreshTagScope(NodeRef nodeRef, boolean async)
{ {
@@ -1067,7 +1090,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#removeTagScope(org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#removeTagScope(NodeRef)
*/ */
public void removeTagScope(NodeRef nodeRef) public void removeTagScope(NodeRef nodeRef)
{ {
@@ -1078,7 +1101,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#findTagScope(org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#findTagScope(NodeRef)
*/ */
public TagScope findTagScope(NodeRef nodeRef) public TagScope findTagScope(NodeRef nodeRef)
{ {
@@ -1115,7 +1138,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#findAllTagScopes(org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#findAllTagScopes(NodeRef)
*/ */
public List<TagScope> findAllTagScopes(NodeRef nodeRef) public List<TagScope> findAllTagScopes(NodeRef nodeRef)
{ {
@@ -1205,7 +1228,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodes(StoreRef, java.lang.String) * @see TaggingService#findTaggedNodes(StoreRef, String)
*/ */
public List<NodeRef> findTaggedNodes(StoreRef storeRef, String tag) public List<NodeRef> findTaggedNodes(StoreRef storeRef, String tag)
{ {
@@ -1230,7 +1253,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodes(StoreRef, java.lang.String, org.alfresco.service.cmr.repository.NodeRef) * @see TaggingService#findTaggedNodes(StoreRef, String, NodeRef)
*/ */
public List<NodeRef> findTaggedNodes(StoreRef storeRef, String tag, NodeRef nodeRef) public List<NodeRef> findTaggedNodes(StoreRef storeRef, String tag, NodeRef nodeRef)
{ {
@@ -1459,7 +1482,7 @@ public class TaggingServiceImpl implements TaggingService,
// ===== Transaction Listener Callback Methods ===== // // ===== Transaction Listener Callback Methods ===== //
/** /**
* @see org.alfresco.repo.transaction.TransactionListener#afterCommit() * @see TransactionListener#afterCommit()
*/ */
public void afterCommit() public void afterCommit()
{ {
@@ -1467,14 +1490,14 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.repo.transaction.TransactionListener#afterRollback() * @see TransactionListener#afterRollback()
*/ */
public void afterRollback() public void afterRollback()
{ {
} }
/** /**
* @see org.alfresco.repo.transaction.TransactionListener#beforeCommit(boolean) * @see TransactionListener#beforeCommit(boolean)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void beforeCommit(boolean readOnly) public void beforeCommit(boolean readOnly)
@@ -1499,14 +1522,14 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.repo.transaction.TransactionListener#beforeCompletion() * @see TransactionListener#beforeCompletion()
*/ */
public void beforeCompletion() public void beforeCompletion()
{ {
} }
/** /**
* @see org.alfresco.repo.transaction.TransactionListener#flush() * @see TransactionListener#flush()
*/ */
public void flush() public void flush()
{ {
@@ -1522,7 +1545,7 @@ public class TaggingServiceImpl implements TaggingService,
} }
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodesAndCountByTagName(StoreRef) * @see TaggingService#findTaggedNodesAndCountByTagName(StoreRef)
*/ */
@Override @Override
public List<Pair<String, Integer>> findTaggedNodesAndCountByTagName(StoreRef storeRef) public List<Pair<String, Integer>> findTaggedNodesAndCountByTagName(StoreRef storeRef)

View File

@@ -48,6 +48,8 @@ import org.alfresco.util.Pair;
@AlfrescoPublicApi @AlfrescoPublicApi
public interface TaggingService public interface TaggingService
{ {
NodeRef TAG_ROOT_NODE_REF = new NodeRef("workspace://SpacesStore/tag:tag-root");
/** /**
* Indicates whether the tag already exists * Indicates whether the tag already exists
* *

View File

@@ -37,13 +37,14 @@
<bean id="taggingService" class="org.alfresco.repo.tagging.TaggingServiceImpl" init-method="init"> <bean id="taggingService" class="org.alfresco.repo.tagging.TaggingServiceImpl" init-method="init">
<property name="nodeService" ref="NodeService"/> <property name="nodeService" ref="NodeService"/>
<property name="nodeServiceInternal" ref="nodeService"/> <property name="nodeServiceInternal" ref="nodeService"/>
<property name="categoryService" ref="CategoryService"/> <property name="categoryService" ref="CategoryService"/>
<property name="searchService" ref="SearchService"/> <property name="searchService" ref="SearchService"/>
<property name="actionService" ref="ActionService"/> <property name="actionService" ref="ActionService"/>
<property name="contentService" ref="ContentService"/> <property name="contentService" ref="ContentService"/>
<property name="namespaceService" ref="NamespaceService"/> <property name="namespaceService" ref="NamespaceService"/>
<property name="policyComponent" ref="policyComponent"/> <property name="policyComponent" ref="policyComponent"/>
<property name="auditComponent" ref="auditComponent"/> <property name="auditComponent" ref="auditComponent"/>
<property name="eventGenerator" ref="eventGeneratorV2"/>
</bean> </bean>
<bean id="update-tagscope" class="org.alfresco.repo.tagging.UpdateTagScopesActionExecuter" parent="action-executer"> <bean id="update-tagscope" class="org.alfresco.repo.tagging.UpdateTagScopesActionExecuter" parent="action-executer">

View File

@@ -25,10 +25,16 @@
*/ */
package org.alfresco.repo.tagging; package org.alfresco.repo.tagging;
import static java.util.Collections.emptyMap;
import static org.alfresco.model.ContentModel.ASPECT_TAGGABLE; import static org.alfresco.model.ContentModel.ASPECT_TAGGABLE;
import static org.alfresco.model.ContentModel.PROP_TAGS; import static org.alfresco.model.ContentModel.ASSOC_SUBCATEGORIES;
import static org.alfresco.model.ContentModel.PROP_NAME;
import static org.alfresco.repo.tagging.TaggingServiceImpl.TAG_UPDATES; import static org.alfresco.repo.tagging.TaggingServiceImpl.TAG_UPDATES;
import static org.alfresco.service.cmr.repository.StoreRef.STORE_REF_WORKSPACE_SPACESSTORE; import static org.alfresco.service.cmr.repository.StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
import static org.alfresco.service.cmr.tagging.TaggingService.TAG_ROOT_NODE_REF;
import static org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@@ -36,16 +42,15 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.event2.EventGenerator;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -56,6 +61,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.CategoryService; import org.alfresco.service.cmr.search.CategoryService;
import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -84,6 +90,8 @@ public class TaggingServiceImplUnitTest
private ResultSet resultSetMock; private ResultSet resultSetMock;
@Mock(extraInterfaces = List.class) @Mock(extraInterfaces = List.class)
private Serializable currentTagsMock; private Serializable currentTagsMock;
@Mock
private EventGenerator eventGenerator;
@InjectMocks @InjectMocks
private TaggingServiceImpl taggingService; private TaggingServiceImpl taggingService;
@@ -128,45 +136,25 @@ public class TaggingServiceImplUnitTest
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testChangeTag() public void testChangeTag()
{ {
final String newTagName = "new-tag-name"; final String newTagName = "new-tag-name";
final NodeRef newTagNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, newTagName);
given(searchServiceMock.query(any(), any(String.class), any(String.class))).willReturn(resultSetMock);
given(resultSetMock.getNodeRefs()).willReturn(List.of(CONTENT_NODE_REF), Collections.emptyList());
given(nodeServiceMock.hasAspect(CONTENT_NODE_REF, ASPECT_TAGGABLE)).willReturn(true);
given(categoryServiceMock.getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, TAG_NAME, false)).willReturn(childAssociationsOf(TAG_NODE_REF)); given(categoryServiceMock.getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, TAG_NAME, false)).willReturn(childAssociationsOf(TAG_NODE_REF));
given(nodeServiceMock.getProperty(CONTENT_NODE_REF, PROP_TAGS)).willReturn(currentTagsMock); given(searchServiceMock.query(STORE_REF_WORKSPACE_SPACESSTORE, LANGUAGE_LUCENE, "+PATH:\"/cm:taggable/cm:" + TAG_NAME + "/member\"")).willReturn(resultSetMock);
given(((List<NodeRef>) currentTagsMock).size()).willReturn(1); given(resultSetMock.getNodeRefs()).willReturn(List.of(CONTENT_NODE_REF));
given(((List<NodeRef>) currentTagsMock).contains(TAG_NODE_REF)).willReturn(true);
given(categoryServiceMock.getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, newTagName, true)).willReturn(childAssociationsOf(newTagNodeRef));
given(((List<NodeRef>) currentTagsMock).contains(newTagNodeRef)).willReturn(false);
//when //when
taggingService.changeTag(STORE_REF_WORKSPACE_SPACESSTORE, TAG_NAME, newTagName); taggingService.changeTag(STORE_REF_WORKSPACE_SPACESSTORE, TAG_NAME, newTagName);
then((List<NodeRef>) currentTagsMock).should().remove(TAG_NODE_REF); then(nodeServiceMock).should().setProperty(TAG_NODE_REF, PROP_NAME, newTagName);
then((List<NodeRef>) currentTagsMock).should().add(newTagNodeRef); then(nodeServiceMock).should().moveNode(TAG_NODE_REF, TAG_ROOT_NODE_REF, ASSOC_SUBCATEGORIES, QName.createQName(CONTENT_MODEL_1_0_URI, newTagName));
then(nodeServiceMock).should(times(2)).setProperty(CONTENT_NODE_REF, PROP_TAGS, currentTagsMock); then(nodeServiceMock).should().getProperties(CONTENT_NODE_REF);
then(categoryServiceMock).should().deleteCategory(TAG_NODE_REF); then(nodeServiceMock).should().hasAspect(CONTENT_NODE_REF, ContentModel.ASPECT_TAGSCOPE);
then(categoryServiceMock).should(times(2)).getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, newTagName, true); then(nodeServiceMock).should().getPrimaryParent(CONTENT_NODE_REF);
} then(nodeServiceMock).shouldHaveNoMoreInteractions();
@Test then(eventGenerator).should().onUpdateProperties(eq(CONTENT_NODE_REF), eq(emptyMap()), any());
public void testChangeOrphanTag() then(eventGenerator).shouldHaveNoMoreInteractions();
{
final String newTagName = "new-tag-name";
given(searchServiceMock.query(any(), any(String.class), any(String.class))).willReturn(resultSetMock);
given(resultSetMock.getNodeRefs()).willReturn(Collections.emptyList());
given(categoryServiceMock.getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, TAG_NAME, false)).willReturn(childAssociationsOf(TAG_NODE_REF));
//when
taggingService.changeTag(STORE_REF_WORKSPACE_SPACESSTORE, TAG_NAME, newTagName);
then(nodeServiceMock).should(never()).setProperty(any(), any(), any());
then(categoryServiceMock).should().deleteCategory(TAG_NODE_REF);
then(categoryServiceMock).should().getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, newTagName, true);
} }
private static List<ChildAssociationRef> childAssociationsOf(final NodeRef... childNodeRefs) private static List<ChildAssociationRef> childAssociationsOf(final NodeRef... childNodeRefs)
@@ -175,4 +163,4 @@ public class TaggingServiceImplUnitTest
.map(childNodeRef -> new ChildAssociationRef(null, null, null, childNodeRef)) .map(childNodeRef -> new ChildAssociationRef(null, null, null, childNodeRef))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }