From 819f0c992163a061ab1fc79871975c58aac9ad11 Mon Sep 17 00:00:00 2001 From: Maciej Pichura <41297682+mpichura@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:26:59 +0200 Subject: [PATCH] ACS-3510: Rule Action updates E2E tests. (#1431) * ACS-3510: Rule Action updates E2E tests. * ACS-3510: Rule Action updates E2E tests - fixes and enhancements. --- .../alfresco/rest/rules/UpdateRulesTests.java | 79 +++++++++++++++++-- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java index 0934ca0e3f..841c67328d 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java @@ -33,8 +33,10 @@ import static org.alfresco.rest.rules.RulesTestsUtils.RULE_ASYNC_DEFAULT; import static org.alfresco.rest.rules.RulesTestsUtils.RULE_CASCADE_DEFAULT; import static org.alfresco.rest.rules.RulesTestsUtils.RULE_ENABLED_DEFAULT; import static org.alfresco.rest.rules.RulesTestsUtils.createCompositeCondition; +import static org.alfresco.rest.rules.RulesTestsUtils.createCustomActionModel; import static org.alfresco.rest.rules.RulesTestsUtils.createDefaultActionModel; import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel; +import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModelWithDefaultValues; import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModelWithModifiedValues; import static org.alfresco.rest.rules.RulesTestsUtils.createSimpleCondition; import static org.alfresco.rest.rules.RulesTestsUtils.createVariousConditions; @@ -46,6 +48,8 @@ import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.OK; +import java.io.Serializable; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -235,7 +239,7 @@ public class UpdateRulesTests extends RestTest * Check we get error when attempt to update a rule to one with invalid action. */ @Test(groups = {TestGroup.REST_API, TestGroup.RULES}) - public void updateRuleWithInvalidActionsShouldFail() + public void updateRuleWithInvalidActionDefinitionShouldFail() { RestRuleModel rule = createAndSaveRule("Rule name"); @@ -388,7 +392,6 @@ public class UpdateRulesTests extends RestTest rule.setConditions(conditions); restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet() - .include(IS_SHARED) .updateRule(rule.getId(), rule); restClient.assertStatusCodeIs(BAD_REQUEST); @@ -409,7 +412,6 @@ public class UpdateRulesTests extends RestTest rule.setConditions(conditions); restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet() - .include(IS_SHARED) .updateRule(rule.getId(), rule); restClient.assertStatusCodeIs(BAD_REQUEST); @@ -430,7 +432,6 @@ public class UpdateRulesTests extends RestTest rule.setConditions(conditions); restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet() - .include(IS_SHARED) .updateRule(rule.getId(), rule); restClient.assertStatusCodeIs(BAD_REQUEST); @@ -451,13 +452,81 @@ public class UpdateRulesTests extends RestTest rule.setConditions(conditions); restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet() - .include(IS_SHARED) .updateRule(rule.getId(), rule); restClient.assertStatusCodeIs(BAD_REQUEST); restClient.assertLastError().containsSummary("Parameter in condition must not be blank"); } + /** + * Check we can update a rule by adding several actions. + */ + @Test(groups = {TestGroup.REST_API, TestGroup.RULES}) + public void updateRuleAddActions() + { + final RestRuleModel rule = createAndSaveRule(createRuleModelWithModifiedValues()); + + STEP("Try to update the rule by adding several actions"); + final Map copyParams = + Map.of("destination-folder", "dummy-folder-node", "deep-copy", true); + final RestActionBodyExecTemplateModel copyAction = createCustomActionModel("copy", copyParams); + final Map scriptParams = Map.of("script-ref", "dummy-script-node-id"); + final RestActionBodyExecTemplateModel scriptAction = createCustomActionModel("script", scriptParams); + rule.setActions(Arrays.asList(copyAction, scriptAction)); + + final RestRuleModel updatedRule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet() + .updateRule(rule.getId(), rule); + + restClient.assertStatusCodeIs(OK); + updatedRule.assertThat().isEqualTo(rule, ID) + .assertThat().field(ID).isNotNull(); + } + + /** + * Check we get a 400 error when attempting to update a rule by adding action with not allowed parameter. + */ + @Test(groups = {TestGroup.REST_API, TestGroup.RULES}) + public void updateRuleAddCheckoutActionForOutboundShouldFail() + { + final RestRuleModel rule = createAndSaveRule(createRuleModelWithModifiedValues()); + + STEP("Try to update the rule by adding checkout action"); + final Map checkOutParams = + Map.of("destination-folder", "dummy-folder-node", "assoc-name", "cm:checkout", "assoc-type", + "cm:contains"); + final RestActionBodyExecTemplateModel checkOutAction = createCustomActionModel("check-out", checkOutParams); + final Map scriptParams = Map.of("script-ref", "dummy-script-node-id"); + rule.setActions(List.of(checkOutAction)); + + restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet() + .updateRule(rule.getId(), rule); + + restClient.assertStatusCodeIs(BAD_REQUEST); + restClient.assertLastError().containsSummary("Check out action cannot be performed for the rule type outbound!"); + } + + /** + * Check we get a 500 error when attempting to update a rule by adding action with parameter with non existing namespace in value. + * In near future we need to fix this kind of negative path to return a 4xx error. + */ + @Test(groups = {TestGroup.REST_API, TestGroup.RULES}) + public void updateRuleAddActionWithInvalidParamShouldFail() + { + final RestRuleModel rule = createAndSaveRule(createRuleModelWithModifiedValues()); + + STEP("Try to update the rule by adding action with invalid parameter (non-existing namespace in value)"); + final RestActionBodyExecTemplateModel action = new RestActionBodyExecTemplateModel(); + action.setActionDefinitionId("add-features"); + action.setParams(Map.of("aspect-name", "dummy:dummy")); + rule.setActions(List.of(action)); + + restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet() + .updateRule(rule.getId(), rule); + + restClient.assertStatusCodeIs(INTERNAL_SERVER_ERROR); + restClient.assertLastError().containsSummary("Namespace prefix dummy is not mapped to a namespace URI"); + } + private RestRuleModel createAndSaveRule(String name) { return createAndSaveRule(name, List.of(createDefaultActionModel()));