From d3c5b5026877ca63f72f21efdafe27e35b150608 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Fri, 1 Dec 2017 15:35:15 +0000 Subject: [PATCH 1/5] REPO-1308: added simple 'GET /action-definitions' sanity test Added an Actions API representation and an ActionsTests class containing a simple sanity test. --- .../alfresco/rest/actions/ActionsTests.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 e2e-test/java/org/alfresco/rest/actions/ActionsTests.java diff --git a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java new file mode 100644 index 000000000..577f30b2e --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java @@ -0,0 +1,31 @@ +package org.alfresco.rest.actions; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestActionDefinitionModelsCollection; +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.Test; + +import static org.testng.Assert.assertFalse; + +public class ActionsTests extends RestTest +{ + // TODO: TestGroup.ACTIONS not TestGroup.NODES + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify actions") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) + public void testActionDefinitions() throws Exception + { + restClient.authenticateUser(dataContent.getAdminUser()); + + RestActionDefinitionModelsCollection restActionDefinitions = restClient.withCoreAPI().usingActions().listActionDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); + assertFalse(restActionDefinitions.isEmpty()); + restActionDefinitions.assertThat().entriesListContains("name", "copy"); + restActionDefinitions.assertThat().entriesListContains("name", "move"); + restActionDefinitions.assertThat().entriesListContains("name", "check-out"); + restActionDefinitions.assertThat().entriesListContains("name", "check-in"); + } +} From d7efa10b654387facb2d630c0dbcb01de6045cb5 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Fri, 1 Dec 2017 16:47:02 +0000 Subject: [PATCH 2/5] REPO-1308: added 'GET /action-definitions' error status checks Added a couple of error code checks: 400 (bad request) and 401 (unauthorised) - the latter actually fails and raises the question of whether the actions API implmentation or the TAS test framework are wrong. Committing to capture the test code, but will sort it out one way or another. --- .../alfresco/rest/actions/ActionsTests.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java index 577f30b2e..a4523de61 100644 --- a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java +++ b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java @@ -3,6 +3,7 @@ package org.alfresco.rest.actions; import org.alfresco.rest.RestTest; import org.alfresco.rest.model.RestActionDefinitionModelsCollection; import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.annotation.TestRail; import org.springframework.http.HttpStatus; @@ -20,7 +21,11 @@ public class ActionsTests extends RestTest { restClient.authenticateUser(dataContent.getAdminUser()); - RestActionDefinitionModelsCollection restActionDefinitions = restClient.withCoreAPI().usingActions().listActionDefinitions(); + RestActionDefinitionModelsCollection restActionDefinitions = restClient. + withCoreAPI(). + usingActions(). + listActionDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.OK); assertFalse(restActionDefinitions.isEmpty()); restActionDefinitions.assertThat().entriesListContains("name", "copy"); @@ -28,4 +33,32 @@ public class ActionsTests extends RestTest restActionDefinitions.assertThat().entriesListContains("name", "check-out"); restActionDefinitions.assertThat().entriesListContains("name", "check-in"); } + + // TODO: TestGroup.ACTIONS not TestGroup.NODES + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify actions error conditions") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION}) + public void testActionDefinitionsNegative() throws Exception{ + // Badly formed request -> 400 + { + restClient.authenticateUser(dataContent.getAdminUser()). + // invalid skipCount + withParams("skipCount=-1"). + withCoreAPI(). + usingActions(). + listActionDefinitions(); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); + + } + + // Unauthorized -> 401 + { + + UserModel userUnauthorized = new UserModel("invalid-user", "invalid-pasword"); + restClient.authenticateUser(userUnauthorized).withCoreAPI().usingActions().listActionDefinitions(); + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + + } + } } From d80e953cf54afd1fe45cb7b7483f5c07d8dfacb2 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 4 Dec 2017 11:56:07 +0000 Subject: [PATCH 3/5] REPO-1308: fix 401 response test The listActions API wrapper was expecting JSON to be present, but for a 401 it is not. --- .../org/alfresco/rest/actions/ActionsTests.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java index a4523de61..8e69e9179 100644 --- a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java +++ b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java @@ -1,6 +1,7 @@ package org.alfresco.rest.actions; import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.EmptyJsonResponseException; import org.alfresco.rest.model.RestActionDefinitionModelsCollection; import org.alfresco.utility.model.TestGroup; import org.alfresco.utility.model.UserModel; @@ -9,6 +10,7 @@ import org.alfresco.utility.testrail.annotation.TestRail; import org.springframework.http.HttpStatus; import org.testng.annotations.Test; +import static junit.framework.TestCase.fail; import static org.testng.Assert.assertFalse; public class ActionsTests extends RestTest @@ -56,9 +58,17 @@ public class ActionsTests extends RestTest { UserModel userUnauthorized = new UserModel("invalid-user", "invalid-pasword"); - restClient.authenticateUser(userUnauthorized).withCoreAPI().usingActions().listActionDefinitions(); - restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); - + try + { + restClient.authenticateUser(userUnauthorized).withCoreAPI().usingActions().listActionDefinitions(); + fail("Expected an empty JSON response exception"); + } + catch (EmptyJsonResponseException e) + { + // Since there is no JSON for a 401, the processModels directive + // will throw the EmptyJsonResponseException + restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED); + } } } } From aca6d62548690d6192ce7ee7f15b498ae5c45976 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 4 Dec 2017 13:02:30 +0000 Subject: [PATCH 4/5] REPO-1308: use TestGroup.ACTIONS instead of TestGroup.NODES --- .../java/org/alfresco/rest/actions/ActionsTests.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java index 8e69e9179..0905f0eb5 100644 --- a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java +++ b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java @@ -15,10 +15,9 @@ import static org.testng.Assert.assertFalse; public class ActionsTests extends RestTest { - // TODO: TestGroup.ACTIONS not TestGroup.NODES - @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY, + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.SANITY, description = "Verify actions") - @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.SANITY}) public void testActionDefinitions() throws Exception { restClient.authenticateUser(dataContent.getAdminUser()); @@ -35,11 +34,10 @@ public class ActionsTests extends RestTest restActionDefinitions.assertThat().entriesListContains("name", "check-out"); restActionDefinitions.assertThat().entriesListContains("name", "check-in"); } - - // TODO: TestGroup.ACTIONS not TestGroup.NODES - @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + + @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.REGRESSION, description = "Verify actions error conditions") - @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.REGRESSION}) + @Test(groups = { TestGroup.REST_API, TestGroup.ACTIONS, TestGroup.REGRESSION}) public void testActionDefinitionsNegative() throws Exception{ // Badly formed request -> 400 { From b2e9149d64f3ecfd67369f6c86c38dac61a33248 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Tue, 5 Dec 2017 13:39:53 +0000 Subject: [PATCH 5/5] REPO-1308: use method chaining for assertions As per review feedback in: https://git.alfresco.com/tas/alfresco-tas-restapi-test/merge_requests/39#note_13621 --- .../java/org/alfresco/rest/actions/ActionsTests.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java index 0905f0eb5..a05ce82f3 100644 --- a/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java +++ b/e2e-test/java/org/alfresco/rest/actions/ActionsTests.java @@ -29,10 +29,11 @@ public class ActionsTests extends RestTest restClient.assertStatusCodeIs(HttpStatus.OK); assertFalse(restActionDefinitions.isEmpty()); - restActionDefinitions.assertThat().entriesListContains("name", "copy"); - restActionDefinitions.assertThat().entriesListContains("name", "move"); - restActionDefinitions.assertThat().entriesListContains("name", "check-out"); - restActionDefinitions.assertThat().entriesListContains("name", "check-in"); + restActionDefinitions.assertThat(). + entriesListContains("name", "copy"). + and().entriesListContains("name", "move"). + and().entriesListContains("name", "check-out"). + and().entriesListContains("name", "check-in"); } @TestRail(section = { TestGroup.REST_API,TestGroup.ACTIONS }, executionType = ExecutionType.REGRESSION,