From 803d570c8b719fefbe746dcc48f0e070895fa812 Mon Sep 17 00:00:00 2001 From: Cristina Jalba Date: Wed, 11 Jan 2017 15:39:22 +0200 Subject: [PATCH 1/2] Added GetFavorites full tests --- .../rest/favorites/GetFavoritesFullTests.java | 228 ++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java diff --git a/e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java b/e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java new file mode 100644 index 000000000..187bd0a30 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java @@ -0,0 +1,228 @@ +package org.alfresco.rest.favorites; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestPersonFavoritesModel; +import org.alfresco.rest.model.RestPersonFavoritesModelsCollection; +import org.alfresco.rest.model.RestSiteModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +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; + +public class GetFavoritesFullTests extends RestTest +{ + private UserModel adminUserModel; + private UserModel secondUserModel; + private SiteModel firstSiteModel, secondSiteModel, thirdSiteModel; + private RestPersonFavoritesModelsCollection userFavorites; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUserModel = dataUser.getAdminUser(); + secondUserModel = dataUser.createRandomTestUser(); + restClient.authenticateUser(adminUserModel); + firstSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + secondSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + thirdSiteModel = dataSite.usingUser(adminUserModel).createPublicRandomSite(); + + firstSiteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(firstSiteModel).getSite().getGuid()); + secondSiteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(secondSiteModel).getSite().getGuid()); + thirdSiteModel.setGuid(restClient.authenticateUser(adminUserModel).withCoreAPI().usingSite(thirdSiteModel).getSite().getGuid()); + + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingAuthUser().addSiteToFavorites(secondSiteModel); + + restClient.authenticateUser(secondUserModel); + restClient.withCoreAPI().usingUser(secondUserModel).addSiteToFavorites(firstSiteModel); + restClient.withCoreAPI().usingUser(secondUserModel).addSiteToFavorites(secondSiteModel); + restClient.withCoreAPI().usingUser(secondUserModel).addSiteToFavorites(thirdSiteModel); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites specifying -me- string in place of for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsAbleToGetFavoritesWhenUsingMeAsUsername() throws Exception + { + userFavorites = restClient.authenticateUser(secondUserModel).withCoreAPI().usingMe().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()).and().entriesListContains("targetGuid", secondSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites using empty for where parameter for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsAbleToGetFavoritesWhenUsingEmptyWhereParameter() throws Exception + { + userFavorites = restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().where().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that for invalid maxItems parameter status code returned is 400.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void checkInvalidMaxItemsStatusCode() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("maxItems=AB").withCoreAPI().usingUser(adminUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Invalid paging parameter"); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify that for invalid skipCount parameter status code returned is 400.") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void checkInvalidSkipCountStatusCode() throws Exception + { + restClient.authenticateUser(adminUserModel).withParams("skipCount=AB").withCoreAPI().usingUser(adminUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Invalid paging parameter"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites when using invalid network id") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void getFavoritesWhenNetworkIdIsInvalid() throws Exception + { + UserModel networkUserModel = dataUser.createRandomTestUser(); + networkUserModel.setDomain("invalidNetwork"); + restClient.authenticateUser(adminUserModel).withCoreAPI().usingUser(networkUserModel).where().targetSiteExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND).assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, networkUserModel.getUsername())); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites using special chars in where parameter for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsNotAbleToGetFavoritesWhenUsingSpecialCharsInWhereParameter() throws Exception + { + userFavorites = restClient.withCoreAPI().usingAuthUser().where().invalidWhereParameter("~!%40%23%24%25%5E%26*()_%2B%5B%5D%7B%7D%7C%5C%3B%27%3A%22%2C.%2F%3C%3E").getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")) + .containsErrorKey(RestErrorModel.INVALID_QUERY_ERRORKEY) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites using AND instead of OR in where parameter for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsNotAbleToGetFavoritesWhenUsingANDInWhereParameter() throws Exception + { + userFavorites = restClient.withCoreAPI().usingAuthUser().where().targetFolderExist().invalidWhereParameter("AND").targetFileExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites using wrong name instead of EXISTS in where parameter for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsNotAbleToGetFavoritesWhenUsingWrongWhereParameter() throws Exception + { + userFavorites = restClient.withCoreAPI().usingAuthUser().where().invalidWhereParameter("EXIST((target/site))").targetFileExist().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get favorites except the first one for request") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsAbleToGetFavoritesExceptTheFirstOne() throws Exception + { + userFavorites = restClient.authenticateUser(secondUserModel).withParams("skipCount=1").withCoreAPI().usingUser(secondUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", thirdSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get first two favorites sites") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsAbleToGetFirstTwoFavorites() throws Exception + { + userFavorites = restClient.authenticateUser(secondUserModel).withParams("maxItems=2").withCoreAPI().usingUser(secondUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + userFavorites.assertThat().entriesListContains("targetGuid", thirdSiteModel.getGuid()) + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", firstSiteModel.getGuid()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify get first two favorites sites") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsAbleToGetFavoritesWhenSkipCountAndMaxItemsAreEmpty() throws Exception + { + restClient.authenticateUser(secondUserModel).withParams("skipCount= ").withCoreAPI().usingUser(secondUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_SKIPCOUNT, " ")); + + restClient.authenticateUser(secondUserModel).withParams("maxItems= ").withCoreAPI().usingUser(secondUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(String.format(RestErrorModel.INVALID_MAXITEMS, " ")); + } + + @Bug(id = "MNT-16904") + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify the get favorites request when network id is invalid") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL, TestGroup.NETWORKS}) + public void getFavoriteSitesWhenNetworkIdIsInvalid() throws JsonToModelConversionException, Exception + { + UserModel adminTenantUser = UserModel.getAdminTenantUser(); + restClient.authenticateUser(adminUserModel); + restClient.usingTenant().createTenant(adminTenantUser); + UserModel tenantUser = dataUser.usingUser(adminTenantUser).createUserWithTenant("uTenant"); + restClient.authenticateUser(tenantUser).withCoreAPI().usingAuthUser().addSiteToFavorites(firstSiteModel); + + tenantUser.setDomain("invalidNetwork"); + restClient.authenticateUser(tenantUser).withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED) + .assertLastError() + .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify the get favorites request for a high value for skipCount parameter") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsAbleToGetFavoritesWithHighSkipCount() throws Exception + { + userFavorites = restClient.authenticateUser(secondUserModel).withParams("skipCount=999999999").withCoreAPI().usingUser(secondUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + userFavorites.assertThat().entriesListIsEmpty().assertThat().paginationField("skipCount").is("999999999"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, + description = "Verify the get favorites request with properties parameter applied") + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + public void userIsAbleToGetFavoritesWithPropertiesParamApplied() throws Exception + { + userFavorites = restClient.authenticateUser(secondUserModel).withParams("properties=targetGuid").withCoreAPI().usingUser(secondUserModel).getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + RestPersonFavoritesModel restPersonFavoritesModel = userFavorites.getEntries().get(0).onModel(); + restPersonFavoritesModel.assertThat().field("targetGuid").is(thirdSiteModel.getGuid()).and().field("createdAt").isNull(); + } + + @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) + @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify entry details for get favorites response with Rest API") + public void checkResponseSchemaForGetFavorites() throws Exception + { + userFavorites = restClient.authenticateUser(secondUserModel).withCoreAPI().usingAuthUser().getFavorites(); + restClient.assertStatusCodeIs(HttpStatus.OK); + + RestPersonFavoritesModel restPersonFavoritesModel = userFavorites.getEntries().get(0).onModel(); + restPersonFavoritesModel.assertThat().field("targetGuid").is(thirdSiteModel.getGuid()); + + RestSiteModel restSiteModel = restPersonFavoritesModel.getTarget().getSite(); + restSiteModel.assertThat().field("visibility").is(thirdSiteModel.getVisibility()).and() + .field("guid").is(thirdSiteModel.getGuid()).and() + .field("description").is(thirdSiteModel.getDescription()).and() + .field("id").is(thirdSiteModel.getId()).and() + .field("title").is(thirdSiteModel.getTitle()); + } +} From 3684c152d3b88e5657f456b0db761e22f59f8dc7 Mon Sep 17 00:00:00 2001 From: Valentin Popa Date: Wed, 11 Jan 2017 17:41:45 +0200 Subject: [PATCH 2/2] Fixes for get favorite sites --- .../rest/favorites/GetFavoritesFullTests.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java b/e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java index 187bd0a30..382cbed41 100644 --- a/e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java +++ b/e2e-test/java/org/alfresco/rest/favorites/GetFavoritesFullTests.java @@ -63,7 +63,7 @@ public class GetFavoritesFullTests extends RestTest { userFavorites = restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().where().getFavorites(); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) - .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); } @TestRail(section = { TestGroup.REST_API,TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, @@ -125,7 +125,7 @@ public class GetFavoritesFullTests extends RestTest { userFavorites = restClient.withCoreAPI().usingAuthUser().where().invalidWhereParameter("EXIST((target/site))").targetFileExist().getFavorites(); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) - .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); + .assertLastError().containsSummary(String.format(RestErrorModel.INVALID_ARGUMENT, "WHERE query")); } @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, @@ -137,8 +137,8 @@ public class GetFavoritesFullTests extends RestTest restClient.assertStatusCodeIs(HttpStatus.OK); userFavorites.assertThat().entriesListContains("targetGuid", firstSiteModel.getGuid()) - .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) - .and().entriesListDoesNotContain("targetGuid", thirdSiteModel.getGuid()); + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", thirdSiteModel.getGuid()); } @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, @@ -150,12 +150,15 @@ public class GetFavoritesFullTests extends RestTest restClient.assertStatusCodeIs(HttpStatus.OK); userFavorites.assertThat().entriesListContains("targetGuid", thirdSiteModel.getGuid()) - .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) - .and().entriesListDoesNotContain("targetGuid", firstSiteModel.getGuid()); + .and().entriesListContains("targetGuid", secondSiteModel.getGuid()) + .and().entriesListDoesNotContain("targetGuid", firstSiteModel.getGuid()) + .getPagination().assertThat().field("maxItems").is("2") + .and().field("hasMoreItems").is("true") + .and().field("count").is("2"); } @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, - description = "Verify get first two favorites sites") + description = "Verify get favorites sites when using empty values for skipCount and maxItems") @Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.FULL }) public void userIsAbleToGetFavoritesWhenSkipCountAndMaxItemsAreEmpty() throws Exception { @@ -181,8 +184,7 @@ public class GetFavoritesFullTests extends RestTest tenantUser.setDomain("invalidNetwork"); restClient.authenticateUser(tenantUser).withCoreAPI().usingAuthUser().getFavorites(); restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED) - .assertLastError() - .containsSummary(RestErrorModel.AUTHENTICATION_FAILED); + .assertLastError().containsSummary(RestErrorModel.AUTHENTICATION_FAILED); } @TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, @@ -225,4 +227,4 @@ public class GetFavoritesFullTests extends RestTest .field("id").is(thirdSiteModel.getId()).and() .field("title").is(thirdSiteModel.getTitle()); } -} +} \ No newline at end of file