diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetRulesTests.java new file mode 100644 index 0000000000..b767d98b82 --- /dev/null +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetRulesTests.java @@ -0,0 +1,91 @@ +package org.alfresco.rest.rules; + +import static org.alfresco.utility.report.log.Step.STEP; +import static org.junit.Assert.assertTrue; +import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.OK; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.model.RestRuleModelsCollection; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests for GET /nodes/{nodeId}/rule-sets/{ruleSetId}/rules and GET /nodes/{nodeId}/rule-sets/{ruleSetId}/rules/{ruleId}. + */ +@Test(groups = {TestGroup.RULES}) +public class GetRulesTests extends RestTest +{ + private UserModel user; + private SiteModel site; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() + { + user = dataUser.createRandomTestUser(); + site = dataSite.usingUser(user).createPublicRandomSite(); + } + + /** Check we can get an empty list of rules. */ + @Test(groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY }) + public void getEmptyRulesList() + { + STEP("Create a folder in existing site"); + FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder(); + + STEP("Get the rules that apply to the folder"); + RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet().getListOfRules(); + + restClient.assertStatusCodeIs(OK); + assertTrue("Expected no rules to be present.", rules.isEmpty()); + } + + /** Check we get a 404 if trying to load rules for a folder that doesn't exist. */ + @Test (groups = { TestGroup.REST_API, TestGroup.RULES }) + public void getRulesForNonExistentFolder() + { + STEP("Try to load rules for a non-existent folder."); + FolderModel nonExistentFolder = FolderModel.getRandomFolderModel(); + nonExistentFolder.setNodeRef("fake-id"); + restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistentFolder).usingDefaultRuleSet().getListOfRules(); + restClient.assertStatusCodeIs(NOT_FOUND); + } + + /** Check we get a 404 if trying to load rules with a rule set id that doesn't exist. */ + @Test (groups = { TestGroup.REST_API, TestGroup.RULES }) + public void getRulesFromNonExistentRuleSet() + { + STEP("Create a folder in existing site"); + FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder(); + STEP("Try to load rules for a non-existent rule set."); + restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingRuleSet("fake-id").getListOfRules(); + restClient.assertStatusCodeIs(NOT_FOUND); + } + + /** Check we get a 404 if trying to load a rule from a folder that doesn't exist. */ + @Test (groups = { TestGroup.REST_API, TestGroup.RULES }) + public void getSingleRuleFromNonExistentFolder() + { + STEP("Try to load a rule from a non-existent folder."); + FolderModel nonExistentFolder = FolderModel.getRandomFolderModel(); + nonExistentFolder.setNodeRef("fake-id"); + restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistentFolder).usingDefaultRuleSet().getSingleRule("fake-rule-id"); + restClient.assertStatusCodeIs(NOT_FOUND); + } + + /** Check we get a 404 if trying to load a rule with a rule set id that doesn't exist. */ + @Test (groups = { TestGroup.REST_API, TestGroup.RULES }) + public void getSingleRuleFromNonExistentRuleSet() + { + STEP("Create a folder in existing site"); + FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder(); + STEP("Try to load rules for a non-existent rule set."); + restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingRuleSet("fake-id").getSingleRule("fake-rule-id"); + restClient.assertStatusCodeIs(NOT_FOUND); + } +} + diff --git a/packaging/tests/tas-restapi/src/test/resources/test-suites/part1-suite.xml b/packaging/tests/tas-restapi/src/test/resources/test-suites/part1-suite.xml index ff2ffaed47..e74476b4c6 100644 --- a/packaging/tests/tas-restapi/src/test/resources/test-suites/part1-suite.xml +++ b/packaging/tests/tas-restapi/src/test/resources/test-suites/part1-suite.xml @@ -1,11 +1,11 @@ - + - + @@ -14,6 +14,7 @@ + diff --git a/pom.xml b/pom.xml index 8dadc8891b..25d2007e93 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ 2.7.4 3.0.49 3.3.0 - 1.90 + 1.93 1.31 1.8 1.6