From 1e1f4c3c818505791260cc2c65f621cce5f77914 Mon Sep 17 00:00:00 2001 From: mionescu Date: Tue, 7 Feb 2017 09:46:52 +0200 Subject: [PATCH] added new test cases: FULL suite - TAS-2904 updated tests: check error model (Core and Sanity) --- .../AddProcessVariableCoreTests.java | 216 ++++++++++-------- .../AddProcessVariableFullTests.java | 201 ++++++++++++++++ .../AddProcessVariableSanityTests.java | 9 +- 3 files changed, 334 insertions(+), 92 deletions(-) create mode 100644 e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableFullTests.java diff --git a/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableCoreTests.java b/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableCoreTests.java index 889b850a8..9d3748599 100644 --- a/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableCoreTests.java +++ b/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableCoreTests.java @@ -49,8 +49,9 @@ public class AddProcessVariableCoreTests extends RestTest processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); restClient.assertStatusCodeIs(HttpStatus.OK); - processVariable.assertThat().field("name").is(processVariable.getName()).and().field("type").is(processVariable.getType()).and().field("value") - .is(processVariable.getValue()); + processVariable.assertThat().field("name").is(processVariable.getName()) + .and().field("type").is(processVariable.getType()) + .and().field("value").is(processVariable.getValue()); } @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, @@ -63,10 +64,127 @@ public class AddProcessVariableCoreTests extends RestTest processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); restClient.assertStatusCodeIs(HttpStatus.OK); - processVariable.assertThat().field("name").is(processVariable.getName()).and().field("type").is(processVariable.getType()).and().field("value") - .is(processVariable.getValue()); + processVariable.assertThat().field("name").is(processVariable.getName()) + .and().field("type").is(processVariable.getType()) + .and().field("value").is(processVariable.getValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid type is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) + public void failedAddingProcessVariableIfInvalidTypeIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:textarea"); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:textarea")) + .containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:textarea")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @Bug(id = "REPO-1938") + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid type prefix is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) + public void failedAddingProcessVariableIfInvalidTypePrefixIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("ddt:text"); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.INVALID_NAMEPACE_PREFIX, "ddt")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); } + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) + public void failedAddingProcessVariableIfInvalidValueIsProvided() throws Exception + { + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel.setValue("invalidValue"); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.FOR_INPUT_STRING, "invalidValue")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case missing required variable body (name) is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) + public void failedAddingProcessVariableIfMissingRequiredVariableNameBodyIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"value\": \"missingVariableName\",\"type\": \"d:text\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); + restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case invalid variableBody (adding extra parameter in body) is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) + public void failedAddingProcessVariableIfInvalidBodyIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"value\": \"testing\",\"type\": \"d:text\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); + restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \"scope\"")) + .containsSummary(String.format(RestErrorModel.NO_CONTENT, "Unrecognized field \"scope\"")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case empty name is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) + public void failedAddingProcessVariableIfEmptyNameIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); + RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + variableModel.setName(""); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED) + .assertLastError() + .containsErrorKey(RestErrorModel.PUT_EMPTY_ARGUMENT) + .containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + @TestRail(section = { TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, description = "Add process variable using by admin in other network.") @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE, TestGroup.NETWORKS }) @@ -84,93 +202,9 @@ public class AddProcessVariableCoreTests extends RestTest restClient.authenticateUser(adminTenantUser2); variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); - restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN).assertLastError().containsSummary(RestErrorModel.PROCESS_RUNNING_IN_ANOTHER_TENANT); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, - description = "Adding process variable is falling in case invalid type is provided") - @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) - public void failedAddingProcessVariableIfInvalidTypeIsProvided() throws Exception - { - variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:textarea"); - - processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); - restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); - - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary( - String.format(RestErrorModel.UNSUPPORTED_TYPE, "d:textarea")); - } - - @Bug(id = "REPO-1938") - @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, - description = "Adding process variable is falling in case invalid type prefix is provided") - @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) - public void failedAddingProcessVariableIfInvalidTypePrefixIsProvided() throws Exception - { - variableModel = RestProcessVariableModel.getRandomProcessVariableModel("ddt:text"); - - processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); - restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); - - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Namespace prefix ddt is not mapped to a namespace URI"); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, - description = "Adding process variable is falling in case invalid value is provided") - @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) - public void failedAddingProcessVariableIfInvalidValueIsProvided() throws Exception - { - RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); - variableModel.setValue("invalidValue"); - - processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); - restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); - - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("For input string: \"invalidValue\""); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, - description = "Adding process variable is falling in case missing required variable body (name) is provided") - @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) - public void failedAddingProcessVariableIfMissingRequiredVariableBodyIsProvided() throws Exception - { - processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); - - RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"value\": \"missingVariableName\",\"type\": \"d:text\"}", - "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); - restClient.processModel(RestProcessVariableModel.class, request); - - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary("Variable name is required."); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, - description = "Adding process variable is falling in case invalid variableBody (adding extra parameter in body) is provided") - @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) - public void failedAddingProcessVariableIfInvalidBodyIsProvided() throws Exception - { - processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); - - RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"scope\": \"local\",\"value\": \"testing\",\"type\": \"d:text\"}", - "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); - restClient.processModel(RestProcessVariableModel.class, request); - - restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError() - .containsSummary("Could not read content from HTTP request body: Unrecognized field \"scope\""); - } - - @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, - description = "Adding process variable is falling in case empty name is provided") - @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.CORE }) - public void failedAddingProcessVariableIfEmptyNameIsProvided() throws Exception - { - processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().addProcess("activitiAdhoc", assignee, false, Priority.Normal); - RestProcessVariableModel variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); - variableModel.setName(""); - - processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); - restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); - - restClient.assertStatusCodeIs(HttpStatus.METHOD_NOT_ALLOWED).assertLastError().containsSummary(RestErrorModel.PUT_EMPTY_ARGUMENT); + restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN) + .assertLastError() + .containsSummary(RestErrorModel.PROCESS_RUNNING_IN_ANOTHER_TENANT); } } diff --git a/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableFullTests.java b/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableFullTests.java new file mode 100644 index 000000000..219f4ba1d --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableFullTests.java @@ -0,0 +1,201 @@ +package org.alfresco.rest.workflow.processes; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.alfresco.rest.model.RestErrorModel; +import org.alfresco.rest.model.RestProcessModel; +import org.alfresco.rest.model.RestProcessVariableModel; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.SiteModel; +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.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AddProcessVariableFullTests extends RestTest +{ + private FileModel document; + private SiteModel siteModel; + private UserModel userWhoStartsProcess, assignee, adminUser; + private RestProcessModel processModel; + private RestProcessVariableModel variableModel, processVariable, updatedProcessVariable; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + userWhoStartsProcess = dataUser.createRandomTestUser(); + assignee = dataUser.createRandomTestUser(); + siteModel = dataSite.usingUser(userWhoStartsProcess).createPublicRandomSite(); + document = dataContent.usingSite(siteModel).createContent(DocumentType.TEXT_PLAIN); + dataWorkflow.usingUser(userWhoStartsProcess).usingSite(siteModel).usingResource(document).createNewTaskAndAssignTo(assignee); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify addProcessVariable by any user for invalid processID with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void addProcessVariableWithInvalidProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId("invalidProcessID"); + + processVariable = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "invalidProcessID")); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Verify addProcessVariable by any user for empty processID with REST API and status code is NOT_FOUND (404)") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void addProcessVariableWithEmptyProcessId() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processModel.setId(""); + + processVariable = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND) + .assertLastError().containsSummary(String.format(RestErrorModel.ENTITY_NOT_FOUND, "")); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is falling in case of empty value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void failedAddingProcessVariableIfEmptyValueIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:int"); + variableModel.setValue(""); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.API_DEFAULT_ERRORKEY) + .containsSummary(String.format(RestErrorModel.FOR_INPUT_STRING, "")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of having only 'name' field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void addingProcessVariableWithOnlyNameProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"name\": \"variableName\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), "variableName"); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is("variableName") + .and().field("type").is("d:any") + .and().field("value").isNull(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of missing type field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void addingProcessVariableIfMissingValueIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"name\": \"variableName\", \"type\": \"d:text\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), "variableName"); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is("variableName") + .and().field("type").is("d:text") + .and().field("value").isNull(); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of missing type field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void addingProcessVariableIfMissingTypeIsProvided() throws Exception + { + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{\"value\": \"variableValue\", \"name\": \"variableName\"}", + "processes/{processId}/variables/{variableName}", processModel.getId(), "variableValue"); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is("variableName") + .and().field("type").is("d:text") + .and().field("value").is("variableValue"); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable is case of empty type value is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void addingProcessVariableIfEmptyTypeIsProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel(""); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); + + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(processVariable.getName()) + .and().field("type").is("d:text") + .and().field("value").is(processVariable.getValue()); + } + + @TestRail(section = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Adding process variable in case of empty body field is provided") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void addingProcessVariableWithEmptyBodyProvided() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel(""); + + processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, "{ }", + "processes/{processId}/variables/{variableName}", processModel.getId(), variableModel.getName()); + processVariable = restClient.processModel(RestProcessVariableModel.class, request); + + restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) + .assertLastError() + .containsErrorKey(RestErrorModel.VARIABLE_NAME_REQUIRED) + .containsSummary(RestErrorModel.VARIABLE_NAME_REQUIRED) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); + } + + @TestRail(section = {TestGroup.REST_API, TestGroup.PROCESSES }, executionType = ExecutionType.REGRESSION, + description = "Update twice in a row the same variable.") + @Test(groups = { TestGroup.REST_API, TestGroup.WORKFLOW, TestGroup.PROCESSES, TestGroup.FULL }) + public void updateTwiceInARowSameProcessVariable() throws Exception + { + variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); + processModel = restClient.authenticateUser(userWhoStartsProcess).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + + processVariable = restClient.withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + processVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListContains("name", processVariable.getName()); + + updatedProcessVariable = restClient.withWorkflowAPI().usingProcess(processModel) + .updateProcessVariable(variableModel); + restClient.assertStatusCodeIs(HttpStatus.OK); + updatedProcessVariable.assertThat().field("name").is(variableModel.getName()) + .and().field("type").is(variableModel.getType()) + .and().field("value").is(variableModel.getValue()); + + restClient.withWorkflowAPI().usingProcess(processModel).getProcessVariables() + .assertThat().entriesListContains("name", variableModel.getName()); + } + +} diff --git a/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableSanityTests.java b/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableSanityTests.java index 0910f99aa..89c7dbdd9 100644 --- a/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableSanityTests.java +++ b/e2e-test/java/org/alfresco/rest/workflow/processes/AddProcessVariableSanityTests.java @@ -3,6 +3,7 @@ package org.alfresco.rest.workflow.processes; import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.dataprep.CMISUtil.Priority; import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestErrorModel; import org.alfresco.rest.model.RestProcessModel; import org.alfresco.rest.model.RestProcessVariableModel; import org.alfresco.utility.data.RandomData; @@ -89,6 +90,7 @@ public class AddProcessVariableSanityTests extends RestTest restClient.authenticateUser(tenantUser).withWorkflowAPI().addProcess("activitiAdhoc", tenantUserAssignee, false, Priority.Normal); variableModel = RestProcessVariableModel.getRandomProcessVariableModel("d:text"); processModel = restClient.authenticateUser(adminTenantUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + processVariable = restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); restClient.assertStatusCodeIs(HttpStatus.OK); processVariable.assertThat().field("name").is(variableModel.getName()) @@ -103,8 +105,13 @@ public class AddProcessVariableSanityTests extends RestTest { variableModel = RestProcessVariableModel.getRandomProcessVariableModel("incorrect type"); processModel = restClient.authenticateUser(adminUser).withWorkflowAPI().getProcesses().getOneRandomEntry().onModel(); + restClient.withWorkflowAPI().usingProcess(processModel).updateProcessVariable(variableModel); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST) - .assertLastError().containsSummary("Unsupported type of variable: 'incorrect type'."); + .assertLastError() + .containsErrorKey(String.format(RestErrorModel.UNSUPPORTED_TYPE, "incorrect type")) + .containsSummary(String.format(RestErrorModel.UNSUPPORTED_TYPE, "incorrect type")) + .descriptionURLIs(RestErrorModel.RESTAPIEXPLORER) + .stackTraceIs(RestErrorModel.STACKTRACE); } }