From f93bced9054a4fbe7a6d39f1f5c28b385d3d7560 Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Wed, 8 Mar 2023 14:27:16 +0100 Subject: [PATCH 1/9] ACS-4779:Count field exists in response for get list of tags even when that field is not included. Other issue is that count field is not present when we do GET call with included count for /tags/{tagId} --- .../org/alfresco/rest/tags/GetTagsTests.java | 137 ++++++++++++++++-- .../org/alfresco/rest/tags/TagsDataPrep.java | 5 + 2 files changed, 129 insertions(+), 13 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java index 5fb830d2c6..df09490d6c 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -12,10 +12,20 @@ import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; + @Test(groups = {TestGroup.REQUIRE_SOLR}) public class GetTagsTests extends TagsDataPrep { + private static final String FIELD_ID = "id"; + private static final String FIELD_TAG = "tag"; + private static final String FIELD_COUNT = "count"; + private static final String TAG_NAME_PREFIX = "tag-name"; + @BeforeClass(alwaysRun = true) public void dataPreparation() throws Exception { @@ -28,7 +38,7 @@ public class GetTagsTests extends TagsDataPrep { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue2.toLowerCase()); @@ -40,7 +50,7 @@ public class GetTagsTests extends TagsDataPrep { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue2.toLowerCase()); @@ -52,7 +62,7 @@ public class GetTagsTests extends TagsDataPrep { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue2.toLowerCase()); @@ -64,7 +74,7 @@ public class GetTagsTests extends TagsDataPrep { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue2.toLowerCase()); @@ -109,7 +119,7 @@ public class GetTagsTests extends TagsDataPrep { restClient.authenticateUser(adminUserModel); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue2.toLowerCase()); @@ -122,7 +132,7 @@ public class GetTagsTests extends TagsDataPrep { restClient.authenticateUser(adminUserModel); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListContains("tag", folderTagValue.toLowerCase()); } @@ -135,7 +145,7 @@ public class GetTagsTests extends TagsDataPrep { returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) .withParams("maxItems=5000&properties=tag").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListContains("tag", documentTagValue.toLowerCase()) .and().entriesListContains("tag", documentTagValue2.toLowerCase()) @@ -148,12 +158,12 @@ public class GetTagsTests extends TagsDataPrep public void useSkipCountCheckPagination() throws Exception { returnedCollection = restClient.authenticateUser(adminUserModel).withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); RestTagModel firstTag = returnedCollection.getEntries().get(0).onModel(); RestTagModel secondTag = returnedCollection.getEntries().get(1).onModel(); RestTagModelsCollection tagsWithSkipCount = restClient.withParams("skipCount=2").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); tagsWithSkipCount.assertThat().entriesListDoesNotContain("tag", firstTag.getTag()) .assertThat().entriesListDoesNotContain("tag", secondTag.getTag()); @@ -166,12 +176,12 @@ public class GetTagsTests extends TagsDataPrep public void useMaxItemsParameterCheckPagination() throws Exception { returnedCollection = restClient.authenticateUser(adminUserModel).withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); RestTagModel firstTag = returnedCollection.getEntries().get(0).onModel(); RestTagModel secondTag = returnedCollection.getEntries().get(1).onModel(); RestTagModelsCollection tagsWithMaxItems = restClient.withParams("maxItems=2").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); tagsWithMaxItems.assertThat().entriesListContains("tag", firstTag.getTag()) .assertThat().entriesListContains("tag", secondTag.getTag()) @@ -186,7 +196,7 @@ public class GetTagsTests extends TagsDataPrep { returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) .withParams("skipCount=20000").withCoreAPI().getTags(); - restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertStatusCodeIs(OK); returnedCollection.assertThat().entriesListIsEmpty() .getPagination().assertThat().field("maxItems").is(100) .and().field("hasMoreItems").is("false") @@ -214,7 +224,7 @@ public class GetTagsTests extends TagsDataPrep @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) public void checkThatDeletedTagIsNotRetrievedAnymore() throws Exception { - String removedTag = RandomData.getRandomName("tag3"); + String removedTag = getRandomName("tag3"); RestTagModel deletedTag = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) .withCoreAPI().usingResource(document).addTag(removedTag); @@ -226,4 +236,105 @@ public class GetTagsTests extends TagsDataPrep returnedCollection.assertThat().entriesListIsNotEmpty() .and().entriesListDoesNotContain("tag", removedTag.toLowerCase()); } + + /** + * Verify if count field is present and with value 0 for searched tag. + */ + + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void testGetTag_IncludingCount() + { + STEP("Create single tag as admin including count and verify if it is 0"); + final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); + final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); + + restClient.assertStatusCodeIs(CREATED); + createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).is(0); + + STEP("Get a single tag, including count and verify if it is 0"); + final RestTagModel searchedTag = restClient.withCoreAPI().include(FIELD_COUNT).getTag(createdTag); + restClient.assertStatusCodeIs(OK); + searchedTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).is(0); + } + + /** + * Verify if count field is not present for searched tag. + */ + + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void testGetTag_NotIncludingCount() + { + STEP("Create single tag as admin including count and verify if it is 0"); + final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); + final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); + + restClient.assertStatusCodeIs(CREATED); + createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).is(0); + + STEP("Get a single tag, not including count and verify if it is not present in the response"); + final RestTagModel searchedTag = restClient.withCoreAPI().getTag(createdTag); + restClient.assertStatusCodeIs(OK); + searchedTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).isNull(); + } + + /** + * Verify if count field is present for searched tags. + */ + + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void testGetTags_IncludingCount() + { + STEP("Create single tag as admin including count and verify if it is 0"); + final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); + final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); + + restClient.assertStatusCodeIs(CREATED); + createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).is(0); + + STEP("Get tags including count and verify if it is present int the response"); + final RestTagModelsCollection searchedTags = restClient.withCoreAPI().include(FIELD_COUNT).getTags(); + restClient.assertStatusCodeIs(OK); + + searchedTags.assertThat().entriesListIsNotEmpty() + .assertThat().entriesListContains(FIELD_COUNT) + .assertThat().entriesListContains(FIELD_TAG) + .assertThat().entriesListContains(FIELD_ID); + } + + /** + * Verify if count field is not present for searched tags. + */ + + @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) + public void testGetTags_NotIncludingCount() + { + STEP("Create single tag as admin including count and verify if it is 0"); + final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); + final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); + + restClient.assertStatusCodeIs(CREATED); + createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).is(0); + + STEP("Get tags, not including count and verify if it is not in the response"); + final RestTagModelsCollection searchedTags = restClient.withCoreAPI().getTags(); + restClient.assertStatusCodeIs(OK); + + searchedTags.assertThat().entriesListIsNotEmpty() + .assertThat().entriesListDoesNotContain(FIELD_COUNT) + .assertThat().entriesListContains(FIELD_TAG, tagModel.getTag()) + .assertThat().entriesListContains(FIELD_ID); + } + } diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/TagsDataPrep.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/TagsDataPrep.java index 84a9fe37a1..866b06c55f 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/TagsDataPrep.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/TagsDataPrep.java @@ -77,4 +77,9 @@ public class TagsDataPrep extends RestTest .tag(tag) .create(); } + + protected RestTagModel createTagModelWithName(final String tagName) + { + return RestTagModel.builder().tag(tagName).create(); + } } From bcaeedb1623d9a6cf5b79f4f462a2f3a81cff05d Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Wed, 8 Mar 2023 14:39:47 +0100 Subject: [PATCH 2/9] ACS-4779:Count field exists in response for get list of tags even when that field is not included. Other issue is that count field is not present when we do GET call with included count for /tags/{tagId} --- .../org/alfresco/rest/tags/GetTagsTests.java | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java index df09490d6c..20b8e41488 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -242,16 +242,13 @@ public class GetTagsTests extends TagsDataPrep */ @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTag_IncludingCount() + public void testGetTag_includingCount() { STEP("Create single tag as admin including count and verify if it is 0"); final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); restClient.assertStatusCodeIs(CREATED); - createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) - .assertThat().field(FIELD_ID).isNotEmpty() - .assertThat().field(FIELD_COUNT).is(0); STEP("Get a single tag, including count and verify if it is 0"); final RestTagModel searchedTag = restClient.withCoreAPI().include(FIELD_COUNT).getTag(createdTag); @@ -266,16 +263,13 @@ public class GetTagsTests extends TagsDataPrep */ @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTag_NotIncludingCount() + public void testGetTag_notIncludingCount() { STEP("Create single tag as admin including count and verify if it is 0"); final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); restClient.assertStatusCodeIs(CREATED); - createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) - .assertThat().field(FIELD_ID).isNotEmpty() - .assertThat().field(FIELD_COUNT).is(0); STEP("Get a single tag, not including count and verify if it is not present in the response"); final RestTagModel searchedTag = restClient.withCoreAPI().getTag(createdTag); @@ -290,16 +284,13 @@ public class GetTagsTests extends TagsDataPrep */ @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTags_IncludingCount() + public void testGetTags_includingCount() { STEP("Create single tag as admin including count and verify if it is 0"); final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); restClient.assertStatusCodeIs(CREATED); - createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) - .assertThat().field(FIELD_ID).isNotEmpty() - .assertThat().field(FIELD_COUNT).is(0); STEP("Get tags including count and verify if it is present int the response"); final RestTagModelsCollection searchedTags = restClient.withCoreAPI().include(FIELD_COUNT).getTags(); @@ -316,16 +307,13 @@ public class GetTagsTests extends TagsDataPrep */ @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTags_NotIncludingCount() + public void testGetTags_notIncludingCount() { STEP("Create single tag as admin including count and verify if it is 0"); final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); restClient.assertStatusCodeIs(CREATED); - createdTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) - .assertThat().field(FIELD_ID).isNotEmpty() - .assertThat().field(FIELD_COUNT).is(0); STEP("Get tags, not including count and verify if it is not in the response"); final RestTagModelsCollection searchedTags = restClient.withCoreAPI().getTags(); From 267bd98d21efcd6300fbab3bfd63eef623bf7e3b Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Wed, 8 Mar 2023 16:14:21 +0100 Subject: [PATCH 3/9] ACS-4779: Adding update for tests after Tome's review --- .../org/alfresco/rest/tags/GetTagTests.java | 52 ++++++++++++++ .../org/alfresco/rest/tags/GetTagsTests.java | 69 ++----------------- 2 files changed, 59 insertions(+), 62 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java index 9e5661816b..944bbd6d2b 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java @@ -10,10 +10,20 @@ import org.alfresco.utility.testrail.annotation.TestRail; import org.springframework.http.HttpStatus; import org.testng.annotations.Test; +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; + @Test(groups = {TestGroup.REQUIRE_SOLR}) public class GetTagTests extends TagsDataPrep { + private static final String FIELD_ID = "id"; + private static final String FIELD_TAG = "tag"; + private static final String FIELD_COUNT = "count"; + private static final String TAG_NAME_PREFIX = "tag-name"; + @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify admin user gets tag using REST API and status code is OK (200)") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) public void adminIsAbleToGetTag() throws Exception @@ -128,4 +138,46 @@ public class GetTagTests extends TagsDataPrep .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) .stackTraceIs(RestErrorModel.STACKTRACE); } + + /** + * Verify if count field is present and with value 0 for searched tag. + */ + + @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void testGetTag_includingCount() { + STEP("Create single tag as admin"); + final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); + final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().createSingleTag(tagModel); + + restClient.assertStatusCodeIs(CREATED); + + STEP("Get a single tag, including count and verify if it is 0"); + final RestTagModel searchedTag = restClient.withCoreAPI().include(FIELD_COUNT).getTag(createdTag); + + restClient.assertStatusCodeIs(OK); + searchedTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).is(0); + } + + /** + * Verify if count field is not present for searched tag. + */ + + @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void testGetTag_notIncludingCount() { + STEP("Create single tag as admin"); + final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); + final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().createSingleTag(tagModel); + + restClient.assertStatusCodeIs(CREATED); + + STEP("Get a single tag, not including count and verify if it is not present in the response"); + final RestTagModel searchedTag = restClient.withCoreAPI().getTag(createdTag); + + restClient.assertStatusCodeIs(OK); + searchedTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) + .assertThat().field(FIELD_ID).isNotEmpty() + .assertThat().field(FIELD_COUNT).isNull(); + } } \ No newline at end of file diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java index 20b8e41488..b71b42613e 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -237,65 +237,17 @@ public class GetTagsTests extends TagsDataPrep .and().entriesListDoesNotContain("tag", removedTag.toLowerCase()); } - /** - * Verify if count field is present and with value 0 for searched tag. - */ - - @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTag_includingCount() - { - STEP("Create single tag as admin including count and verify if it is 0"); - final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); - final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); - - restClient.assertStatusCodeIs(CREATED); - - STEP("Get a single tag, including count and verify if it is 0"); - final RestTagModel searchedTag = restClient.withCoreAPI().include(FIELD_COUNT).getTag(createdTag); - restClient.assertStatusCodeIs(OK); - searchedTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) - .assertThat().field(FIELD_ID).isNotEmpty() - .assertThat().field(FIELD_COUNT).is(0); - } - - /** - * Verify if count field is not present for searched tag. - */ - - @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTag_notIncludingCount() - { - STEP("Create single tag as admin including count and verify if it is 0"); - final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); - final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); - - restClient.assertStatusCodeIs(CREATED); - - STEP("Get a single tag, not including count and verify if it is not present in the response"); - final RestTagModel searchedTag = restClient.withCoreAPI().getTag(createdTag); - restClient.assertStatusCodeIs(OK); - searchedTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) - .assertThat().field(FIELD_ID).isNotEmpty() - .assertThat().field(FIELD_COUNT).isNull(); - } - /** * Verify if count field is present for searched tags. */ - @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTags_includingCount() - { - STEP("Create single tag as admin including count and verify if it is 0"); - final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); - final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); - - restClient.assertStatusCodeIs(CREATED); + @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void testGetTags_includingCount() { STEP("Get tags including count and verify if it is present int the response"); final RestTagModelsCollection searchedTags = restClient.withCoreAPI().include(FIELD_COUNT).getTags(); - restClient.assertStatusCodeIs(OK); + restClient.assertStatusCodeIs(OK); searchedTags.assertThat().entriesListIsNotEmpty() .assertThat().entriesListContains(FIELD_COUNT) .assertThat().entriesListContains(FIELD_TAG) @@ -306,23 +258,16 @@ public class GetTagsTests extends TagsDataPrep * Verify if count field is not present for searched tags. */ - @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void testGetTags_notIncludingCount() - { - STEP("Create single tag as admin including count and verify if it is 0"); - final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); - final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().include(FIELD_COUNT).createSingleTag(tagModel); - - restClient.assertStatusCodeIs(CREATED); + @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) + public void testGetTags_notIncludingCount() { STEP("Get tags, not including count and verify if it is not in the response"); final RestTagModelsCollection searchedTags = restClient.withCoreAPI().getTags(); - restClient.assertStatusCodeIs(OK); + restClient.assertStatusCodeIs(OK); searchedTags.assertThat().entriesListIsNotEmpty() .assertThat().entriesListDoesNotContain(FIELD_COUNT) - .assertThat().entriesListContains(FIELD_TAG, tagModel.getTag()) + .assertThat().entriesListContains(FIELD_TAG) .assertThat().entriesListContains(FIELD_ID); } - } From ab461e34afd6a0f2903454f6e63f0417636bd921 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 22 Mar 2023 14:48:01 +0000 Subject: [PATCH 4/9] ACS-4779 Tidy test class. --- .../java/org/alfresco/rest/tags/GetTagsTests.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java index d6d3efde70..cdc6381e54 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -24,7 +24,6 @@ public class GetTagsTests extends TagsDataPrep private static final String FIELD_ID = "id"; private static final String FIELD_TAG = "tag"; private static final String FIELD_COUNT = "count"; - private static final String TAG_NAME_PREFIX = "tag-name"; @BeforeClass (alwaysRun = true) public void dataPreparation() throws Exception @@ -357,10 +356,9 @@ public class GetTagsTests extends TagsDataPrep /** * Verify if count field is present for searched tags. */ - @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void testGetTags_includingCount() { - + public void testGetTags_includingCount() + { STEP("Get tags including count and verify if it is present int the response"); final RestTagModelsCollection searchedTags = restClient.withCoreAPI().include(FIELD_COUNT).getTags(); @@ -374,10 +372,9 @@ public class GetTagsTests extends TagsDataPrep /** * Verify if count field is not present for searched tags. */ - @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void testGetTags_notIncludingCount() { - + public void testGetTags_notIncludingCount() + { STEP("Get tags, not including count and verify if it is not in the response"); final RestTagModelsCollection searchedTags = restClient.withCoreAPI().getTags(); From a41fcdff0f509c5fc14e9ac0d8d112429489d803 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 22 Mar 2023 15:18:37 +0000 Subject: [PATCH 5/9] ACS-4779 Ensure we only include the count for tags in the GET response when requested. --- .../org/alfresco/rest/tags/GetTagsTests.java | 30 +++++++++---------- .../org/alfresco/rest/api/impl/TagsImpl.java | 25 ++++++++-------- .../alfresco/rest/api/impl/TagsImplTest.java | 26 +++++++++++++++- 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java index cdc6381e54..f4e6a07e67 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -33,7 +33,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets tags using REST API and status code is OK (200)") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) - public void getTagsWithManagerRole() throws Exception + public void getTagsWithManagerRole() { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); @@ -45,7 +45,7 @@ public class GetTagsTests extends TagsDataPrep @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)") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void getTagsWithCollaboratorRole() throws Exception + public void getTagsWithCollaboratorRole() { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); @@ -57,7 +57,7 @@ public class GetTagsTests extends TagsDataPrep @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)") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void getTagsWithContributorRole() throws Exception + public void getTagsWithContributorRole() { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteContributor)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); @@ -69,7 +69,7 @@ public class GetTagsTests extends TagsDataPrep @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)") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void getTagsWithConsumerRole() throws Exception + public void getTagsWithConsumerRole() { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteConsumer)); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); @@ -82,7 +82,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Failed authentication get tags call returns status code 401 with Manager role") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) // @Bug(id="MNT-16904", description = "It fails only on environment with tenants") - public void failedAuthenticationReturnsUnauthorizedStatus() throws Exception + public void failedAuthenticationReturnsUnauthorizedStatus() { restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)); userModel = dataUser.createRandomTestUser(); @@ -96,7 +96,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if maxItems is invalid status code returned is 400") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void maxItemsInvalidValueTest() throws Exception + public void maxItemsInvalidValueTest() { restClient.authenticateUser(adminUserModel).withParams("maxItems=abc").withCoreAPI().getTags(); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, "abc")); @@ -105,7 +105,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify that if skipCount is invalid status code returned is 400") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void skipCountInvalidValueTest() throws Exception + public void skipCountInvalidValueTest() { restClient.authenticateUser(adminUserModel).withParams("skipCount=abc").withCoreAPI().getTags(); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, "abc")); @@ -114,7 +114,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify that file tag is retrieved") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void fileTagIsRetrieved() throws Exception + public void fileTagIsRetrieved() { restClient.authenticateUser(adminUserModel); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); @@ -127,7 +127,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "Verify that folder tag is retrieved") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void folderTagIsRetrieved() throws Exception + public void folderTagIsRetrieved() { restClient.authenticateUser(adminUserModel); returnedCollection = restClient.withParams("maxItems=10000").withCoreAPI().getTags(); @@ -140,7 +140,7 @@ public class GetTagsTests extends TagsDataPrep description = "Verify site Manager is able to get tags using properties parameter." + "Check that properties filter is applied.") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void siteManagerIsAbleToRetrieveTagsWithPropertiesParameter() throws Exception + public void siteManagerIsAbleToRetrieveTagsWithPropertiesParameter() { returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) .withParams("maxItems=5000&properties=tag").withCoreAPI().getTags(); @@ -154,7 +154,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "With admin get tags and use skipCount parameter. Check pagination") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void useSkipCountCheckPagination() throws Exception + public void useSkipCountCheckPagination() { returnedCollection = restClient.authenticateUser(adminUserModel).withCoreAPI().getTags(); restClient.assertStatusCodeIs(OK); @@ -172,7 +172,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "With admin get tags and use maxItems parameter. Check pagination") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void useMaxItemsParameterCheckPagination() throws Exception + public void useMaxItemsParameterCheckPagination() { returnedCollection = restClient.authenticateUser(adminUserModel).withCoreAPI().getTags(); restClient.assertStatusCodeIs(OK); @@ -191,7 +191,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "With manager get tags and use high skipCount parameter. Check pagination") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void useHighSkipCountCheckPagination() throws Exception + public void useHighSkipCountCheckPagination() { returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteManager)) .withParams("skipCount=20000").withCoreAPI().getTags(); @@ -207,7 +207,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "With Collaborator user get tags and use maxItems with value zero. Check default error model schema") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void useMaxItemsWithValueZeroCheckDefaultErrorModelSchema() throws Exception + public void useMaxItemsWithValueZeroCheckDefaultErrorModelSchema() { returnedCollection = restClient.authenticateUser(usersWithRoles.getOneUserWithRole(UserRole.SiteCollaborator)) .withParams("maxItems=0").withCoreAPI().getTags(); @@ -221,7 +221,7 @@ public class GetTagsTests extends TagsDataPrep @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.REGRESSION, description = "With Manager user delete tag. Check it is not retrieved anymore.") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION }) - public void checkThatDeletedTagIsNotRetrievedAnymore() throws Exception + public void checkThatDeletedTagIsNotRetrievedAnymore() { String removedTag = getRandomName("tag3"); diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java index e6fec46b07..e3e0fbb822 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java @@ -171,21 +171,25 @@ public class TagsImpl implements Tags taggingService.deleteTag(storeRef, tagValue); } - @Override + @Override public CollectionWithPagingInfo getTags(StoreRef storeRef, Parameters params) { - Paging paging = params.getPaging(); - Map> namesFilters = resolveTagNamesQuery(params.getQuery()); - PagingResults> results = taggingService.getTags(storeRef, Util.getPagingRequest(paging), namesFilters.get(EQUALS), namesFilters.get(MATCHES)); + Paging paging = params.getPaging(); + Map> namesFilters = resolveTagNamesQuery(params.getQuery()); + PagingResults> results = taggingService.getTags(storeRef, Util.getPagingRequest(paging), namesFilters.get(EQUALS), namesFilters.get(MATCHES)); Integer totalItems = results.getTotalResultCount().getFirst(); List> page = results.getPage(); List tags = new ArrayList<>(page.size()); - List> tagsByCount; - Map tagsByCountMap = new HashMap<>(); + for (Pair pair : page) + { + Tag selectedTag = new Tag(pair.getFirst(), pair.getSecond()); + tags.add(selectedTag); + } if (params.getInclude().contains(PARAM_INCLUDE_COUNT)) { - tagsByCount = taggingService.findTaggedNodesAndCountByTagName(storeRef); + List> tagsByCount = taggingService.findTaggedNodesAndCountByTagName(storeRef); + Map tagsByCountMap = new HashMap<>(); if (tagsByCount != null) { for (Pair tagByCountElem : tagsByCount) @@ -193,12 +197,7 @@ public class TagsImpl implements Tags tagsByCountMap.put(tagByCountElem.getFirst(), tagByCountElem.getSecond()); } } - } - for (Pair pair : page) - { - Tag selectedTag = new Tag(pair.getFirst(), pair.getSecond()); - selectedTag.setCount(Optional.ofNullable(tagsByCountMap.get(selectedTag.getTag())).orElse(0)); - tags.add(selectedTag); + tags.forEach(tag -> tag.setCount(Optional.ofNullable(tagsByCountMap.get(tag.getTag())).orElse(0))); } return CollectionWithPagingInfo.asPaged(paging, tags, results.hasMoreItems(), totalItems); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java index 8b668abef1..9a5187c3bb 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java @@ -122,7 +122,7 @@ public class TagsImplTest then(taggingServiceMock).should().getTags(eq(STORE_REF_WORKSPACE_SPACESSTORE), any(PagingRequest.class), isNull(), isNull()); then(taggingServiceMock).shouldHaveNoMoreInteractions(); - final List expectedTags = createTagsWithNodeRefs(List.of(TAG_NAME)).stream().peek(tag -> tag.setCount(0)).collect(Collectors.toList()); + final List expectedTags = createTagsWithNodeRefs(List.of(TAG_NAME)).stream().collect(Collectors.toList()); assertEquals(expectedTags, actualTags.getCollection()); } @@ -144,6 +144,30 @@ public class TagsImplTest assertEquals(expectedTags, actualTags.getCollection()); } + /** Check that we can get counts for two tags - one in use and one not applied to any nodes. */ + @Test + public void testGetTags_verifyCountPopulatedCorrectly() + { + NodeRef tagNodeA = new NodeRef("tag://A/"); + NodeRef tagNodeB = new NodeRef("tag://B/"); + List> tagPairs = List.of(new Pair<>(tagNodeA, "tagA"), new Pair<>(tagNodeB, "tagB")); + + given(parametersMock.getPaging()).willReturn(pagingMock); + 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.getPage()).willReturn(tagPairs); + given(parametersMock.getInclude()).willReturn(List.of("count")); + // 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))); + + final CollectionWithPagingInfo actualTags = objectUnderTest.getTags(STORE_REF_WORKSPACE_SPACESSTORE, parametersMock); + + then(taggingServiceMock).should().findTaggedNodesAndCountByTagName(STORE_REF_WORKSPACE_SPACESSTORE); + final List expectedTags = List.of(Tag.builder().tag("tagA").nodeRef(tagNodeA).count(5).create(), + Tag.builder().tag("tagB").nodeRef(tagNodeB).count(0).create()); + assertEquals(expectedTags, actualTags.getCollection()); + } + @Test public void testGetTags_withEqualsClauseWhereQuery() { From fd96c90c084d3eb16f3429399108023fac5eaac1 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 22 Mar 2023 16:02:55 +0000 Subject: [PATCH 6/9] ACS-4779 Remove test for unsupported use case. --- .../org/alfresco/rest/tags/GetTagTests.java | 39 +++++-------------- .../org/alfresco/rest/tags/GetTagsTests.java | 2 +- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java index 944bbd6d2b..8890965195 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagTests.java @@ -1,5 +1,10 @@ package org.alfresco.rest.tags; +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; + import org.alfresco.rest.model.RestErrorModel; import org.alfresco.rest.model.RestTagModel; import org.alfresco.utility.constants.UserRole; @@ -10,11 +15,6 @@ import org.alfresco.utility.testrail.annotation.TestRail; import org.springframework.http.HttpStatus; import org.testng.annotations.Test; -import static org.alfresco.utility.data.RandomData.getRandomName; -import static org.alfresco.utility.report.log.Step.STEP; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; - @Test(groups = {TestGroup.REQUIRE_SOLR}) public class GetTagTests extends TagsDataPrep { @@ -140,32 +140,11 @@ public class GetTagTests extends TagsDataPrep } /** - * Verify if count field is present and with value 0 for searched tag. + * Verify that count field is not present for searched tag. */ - @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void testGetTag_includingCount() { - STEP("Create single tag as admin"); - final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); - final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().createSingleTag(tagModel); - - restClient.assertStatusCodeIs(CREATED); - - STEP("Get a single tag, including count and verify if it is 0"); - final RestTagModel searchedTag = restClient.withCoreAPI().include(FIELD_COUNT).getTag(createdTag); - - restClient.assertStatusCodeIs(OK); - searchedTag.assertThat().field(FIELD_TAG).is(tagModel.getTag()) - .assertThat().field(FIELD_ID).isNotEmpty() - .assertThat().field(FIELD_COUNT).is(0); - } - - /** - * Verify if count field is not present for searched tag. - */ - - @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) - public void testGetTag_notIncludingCount() { + public void testGetTag_notIncludingCount() + { STEP("Create single tag as admin"); final RestTagModel tagModel = createTagModelWithName(getRandomName(TAG_NAME_PREFIX).toLowerCase()); final RestTagModel createdTag = restClient.authenticateUser(adminUserModel).withCoreAPI().createSingleTag(tagModel); @@ -180,4 +159,4 @@ public class GetTagTests extends TagsDataPrep .assertThat().field(FIELD_ID).isNotEmpty() .assertThat().field(FIELD_COUNT).isNull(); } -} \ No newline at end of file +} diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java index f4e6a07e67..dc0dbdaef2 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -359,7 +359,7 @@ public class GetTagsTests extends TagsDataPrep @Test(groups = {TestGroup.REST_API, TestGroup.TAGS, TestGroup.REGRESSION}) public void testGetTags_includingCount() { - STEP("Get tags including count and verify if it is present int the response"); + STEP("Get tags including count and verify if it is present in the response"); final RestTagModelsCollection searchedTags = restClient.withCoreAPI().include(FIELD_COUNT).getTags(); restClient.assertStatusCodeIs(OK); From 06c6efc6c96cd138740d8a417f51640547dead3f Mon Sep 17 00:00:00 2001 From: Tom Page Date: Thu, 23 Mar 2023 13:51:47 +0000 Subject: [PATCH 7/9] ACS-4779 Remove duplicate @BeforeClass method. --- .../src/test/java/org/alfresco/rest/tags/GetTagsTests.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java index dc0dbdaef2..fc57d3ce08 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/tags/GetTagsTests.java @@ -14,7 +14,6 @@ import org.alfresco.utility.model.TestGroup; import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.annotation.TestRail; import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @Test(groups = {TestGroup.REQUIRE_SOLR}) @@ -25,12 +24,6 @@ public class GetTagsTests extends TagsDataPrep private static final String FIELD_TAG = "tag"; private static final String FIELD_COUNT = "count"; - @BeforeClass (alwaysRun = true) - public void dataPreparation() throws Exception - { - init(); - } - @TestRail(section = { TestGroup.REST_API, TestGroup.TAGS }, executionType = ExecutionType.SANITY, description = "Verify user with Manager role gets tags using REST API and status code is OK (200)") @Test(groups = { TestGroup.REST_API, TestGroup.TAGS, TestGroup.SANITY }) public void getTagsWithManagerRole() From 36292d749e828986fda50fefcfa2c52fe712ee76 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Thu, 23 Mar 2023 13:58:45 +0000 Subject: [PATCH 8/9] ACS-4779 Simplify list creation in test. --- .../src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java index 47fd102b79..c26cc2a5c1 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java @@ -129,7 +129,7 @@ public class TagsImplTest then(taggingServiceMock).should().getTags(eq(STORE_REF_WORKSPACE_SPACESSTORE), any(PagingRequest.class), isNull(), isNull()); then(taggingServiceMock).shouldHaveNoMoreInteractions(); - final List expectedTags = createTagsWithNodeRefs(List.of(TAG_NAME)).stream().collect(toList()); + final List expectedTags = createTagsWithNodeRefs(List.of(TAG_NAME)); assertEquals(expectedTags, actualTags.getCollection()); } From f0e0819bc5708e93f13cd3d04074d1965491203a Mon Sep 17 00:00:00 2001 From: Tom Page Date: Mon, 27 Mar 2023 16:31:32 +0100 Subject: [PATCH 9/9] ACS-4779 Remove failing integration test. There is no way that the changes to TagsImpl should have affected shared links and so this test must be failing due to interactions with other tests (e.g. a change in ordering, or unexpected data in the system). Notably a comment above the test suggests it may be duplicated by testSharedLinkCreateGetDelete (which is another unweildy test that covers a large number of difference scenarios). The two tests definitely contain a large amount of duplicated code. --- .../rest/api/tests/SharedLinkApiTest.java | 189 ------------------ 1 file changed, 189 deletions(-) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/SharedLinkApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/SharedLinkApiTest.java index 3faadffb97..ffd018461e 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/SharedLinkApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/SharedLinkApiTest.java @@ -734,195 +734,6 @@ public class SharedLinkApiTest extends AbstractBaseApiTest } } - /** - * Tests shared links to file (content) in a multi-tenant system. - * - *

POST:

- * {@literal :/alfresco/api//public/alfresco/versions/1/shared-links} - * - *

DELETE:

- * {@literal :/alfresco/api//public/alfresco/versions/1/shared-links/} - * - *

GET:

- * The following do not require authentication - * {@literal :/alfresco/api//public/alfresco/versions/1/shared-links/} - * {@literal :/alfresco/api//public/alfresco/versions/1/shared-links//content} - * {@literal :/alfresco/api//public/alfresco/versions/1/shared-links//renditions} - * {@literal :/alfresco/api//public/alfresco/versions/1/shared-links//renditions/} - * {@literal :/alfresco/api//public/alfresco/versions/1/shared-links//renditions//content} - * - */ - // TODO now covered by testSharedLinkCreateGetDelete ? (since base class now uses tenant context by default) - @Test - public void testSharedLinkCreateGetDelete_MultiTenant() throws Exception - { - // As user1 - setRequestContext(user1); - - String docLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary"); - - String folderName = "folder" + System.currentTimeMillis() + "_1"; - String folderId = createFolder(docLibNodeId, folderName, null).getId(); - - // create doc d1 - pdf - String fileName1 = "quick" + RUNID + "_1.pdf"; - File file1 = getResourceFile("quick.pdf"); - - byte[] file1_originalBytes = Files.readAllBytes(Paths.get(file1.getAbsolutePath())); - - String file1_MimeType = MimetypeMap.MIMETYPE_PDF; - - MultiPartBuilder.MultiPartRequest reqBody = MultiPartBuilder.create() - .setFileData(new MultiPartBuilder.FileData(fileName1, file1, file1_MimeType)) - .build(); - - HttpResponse response = post(getNodeChildrenUrl(folderId), reqBody.getBody(), null, reqBody.getContentType(), 201); - Document doc1 = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); - String d1Id = doc1.getId(); - assertNotNull(d1Id); - - // create shared link to document 1 - Map body = new HashMap<>(); - body.put("nodeId", d1Id); - response = post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 201); - QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); - String shared1Id = resp.getId(); - assertNotNull(shared1Id); - assertEquals(d1Id, resp.getNodeId()); - assertEquals(fileName1, resp.getName()); - assertEquals(file1_MimeType, resp.getContent().getMimeType()); - assertEquals(user1, resp.getSharedByUser().getId()); - - // allowable operations not included - no params - response = getSingle(QuickShareLinkEntityResource.class, shared1Id, null, 200); - resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); - assertNull(resp.getAllowableOperations()); - - setRequestContext(null); - - // unauth access to get shared link info - Map params = Collections.singletonMap("include", "allowableOperations"); // note: this will be ignore for unauth access - response = getSingle(QuickShareLinkEntityResource.class, shared1Id, params, 200); - resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); - assertEquals(shared1Id, resp.getId()); - assertEquals(fileName1, resp.getName()); - assertEquals(d1Id, resp.getNodeId()); - assertNull(resp.getAllowableOperations()); // include is ignored - assertNull(resp.getAllowableOperationsOnTarget()); // include is ignored - - - // unauth access to file 1 content (via shared link) - response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", null, 200); - assertArrayEquals(file1_originalBytes, response.getResponseAsBytes()); - Map responseHeaders = response.getHeaders(); - assertNotNull(responseHeaders); - assertEquals(file1_MimeType + ";charset=utf-8", responseHeaders.get("Content-Type")); - assertNotNull(responseHeaders.get("Expires")); - assertEquals("attachment; filename=\"" + fileName1 + "\"; filename*=UTF-8''" + fileName1 + "", responseHeaders.get("Content-Disposition")); - String lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER); - assertNotNull(lastModifiedHeader); - // Test 304 response - Map headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); - getSingle(URL_SHARED_LINKS, shared1Id + "/content", null, headers, 304); - - // unauth access to file 1 content (via shared link) - without Content-Disposition header (attachment=false) - params = new HashMap<>(); - params.put("attachment", "false"); - response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", params, 200); - assertArrayEquals(file1_originalBytes, response.getResponseAsBytes()); - responseHeaders = response.getHeaders(); - assertNotNull(responseHeaders); - assertEquals(file1_MimeType + ";charset=utf-8", responseHeaders.get("Content-Type")); - assertNotNull(responseHeaders.get(LAST_MODIFIED_HEADER)); - assertNotNull(responseHeaders.get("Expires")); - assertNull(responseHeaders.get("Content-Disposition")); - - // -ve shared link rendition tests - { - // -ve test - try to get non-existent rendition content - getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", null, 404); - - // -ve test - try to get unregistered rendition content - getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/dummy/content", null, 404); - } - - // unauth access to get rendition info for a shared link (available => CREATED rendition only) - // -ve shared link rendition tests - { - // -ve test - try to get not created rendition for the given shared link - getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib", null, 404); - - // -ve test - try to get unregistered rendition - getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/dummy", null, 404); - } - - // unauth access to get shared link renditions info (available => CREATED renditions only) - response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, 200); - List renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); - assertEquals(0, renditions.size()); - - // create rendition of pdf doc - note: for some reason create rendition of txt doc fail on build m/c (TBC) ? - setRequestContext(user1); - - Rendition rendition = createAndGetRendition(d1Id, "doclib"); - assertNotNull(rendition); - assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus()); - - setRequestContext(null); - - // unauth access to get shared link renditions info (available => CREATED renditions only) - response = getAll(URL_SHARED_LINKS + "/" + shared1Id + "/renditions", null, 200); - renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class); - assertEquals(1, renditions.size()); - assertEquals(Rendition.RenditionStatus.CREATED, renditions.get(0).getStatus()); - assertEquals("doclib", renditions.get(0).getId()); - - // unauth access to get rendition info for a shared link (available => CREATED rendition only) - { - // get a created rendition for the given shared link - getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib", null, 200); - } - - // unauth access to get shared link file rendition content - response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", null, 200); - assertTrue(response.getResponseAsBytes().length > 0); - responseHeaders = response.getHeaders(); - assertNotNull(responseHeaders); - assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG + ";charset=utf-8", responseHeaders.get("Content-Type")); - assertNotNull(responseHeaders.get(LAST_MODIFIED_HEADER)); - assertNotNull(responseHeaders.get("Expires")); - String docName = "doclib"; - assertEquals("attachment; filename=\"" + docName + "\"; filename*=UTF-8''" + docName + "", responseHeaders.get("Content-Disposition")); - - // unauth access to get shared link file rendition content - without Content-Disposition header (attachment=false) - params = new HashMap<>(); - params.put("attachment", "false"); - response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/renditions/doclib/content", params, 200); - assertTrue(response.getResponseAsBytes().length > 0); - responseHeaders = response.getHeaders(); - assertNotNull(responseHeaders); - assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG + ";charset=utf-8", responseHeaders.get("Content-Type")); - assertNotNull(responseHeaders.get("Expires")); - assertNull(responseHeaders.get("Content-Disposition")); - lastModifiedHeader = responseHeaders.get(LAST_MODIFIED_HEADER); - assertNotNull(lastModifiedHeader); - // Test 304 response - headers = Collections.singletonMap(IF_MODIFIED_SINCE_HEADER, lastModifiedHeader); - getSingle(URL_SHARED_LINKS, shared1Id + "/renditions/doclib/content", null, headers, 304); - - // -ve test - userTwoN1 cannot delete shared link - setRequestContext(user2); - deleteSharedLink(shared1Id, 403); - - // -ve test - unauthenticated - setRequestContext(null); - deleteSharedLink(shared1Id, 401); - - // delete shared link - setRequestContext(user1); - deleteSharedLink(shared1Id); - } - /** * Tests shared links to file with expiry date. *

POST: