diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/CreateRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/CreateRulesTests.java
new file mode 100644
index 0000000000..daef6b7583
--- /dev/null
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/CreateRulesTests.java
@@ -0,0 +1,110 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2022 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
+package org.alfresco.rest.rules;
+
+import static java.util.stream.Collectors.toList;
+
+import static org.alfresco.utility.report.log.Step.STEP;
+import static org.junit.Assert.assertEquals;
+import static org.springframework.http.HttpStatus.CREATED;
+
+import java.util.List;
+import java.util.stream.IntStream;
+
+import org.alfresco.rest.RestTest;
+import org.alfresco.rest.model.RestRuleModel;
+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 POST /nodes/{nodeId}/rule-sets/{ruleSetId}/rules.
+ */
+@Test(groups = {TestGroup.RULES})
+public class CreateRulesTests 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 create a rule. */
+ @Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
+ public void createRule()
+ {
+ STEP("Create a folder in existing site");
+ FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
+
+ RestRuleModel ruleModel = new RestRuleModel();
+ ruleModel.setName("ruleName");
+
+ RestRuleModel rule = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet()
+ .createSingleRule(ruleModel);
+
+ restClient.assertStatusCodeIs(CREATED);
+
+ rule.assertThat().field("id").isNotNull()
+ .assertThat().field("name").is("ruleName");
+ }
+
+ /** Check we can create several rules. */
+ @Test (groups = { TestGroup.REST_API, TestGroup.RULES })
+ public void createRules()
+ {
+ STEP("Create a folder in existing site");
+ FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
+
+ STEP("Create a list of rules in one POST request");
+ List ruleNames = List.of("ruleA", "ruleB", "ruleC");
+ List ruleModels = ruleNames.stream().map(ruleName ->
+ {
+ RestRuleModel ruleModel = new RestRuleModel();
+ ruleModel.setName(ruleName);
+ return ruleModel;
+ }).collect(toList());
+
+ RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet()
+ .createListOfRules(ruleModels);
+
+ restClient.assertStatusCodeIs(CREATED);
+
+ assertEquals("Unexpected number of rules received in response.", ruleNames.size(), rules.getEntries().size());
+ IntStream.range(0, ruleModels.size()).forEach(i ->
+ rules.getEntries().get(i).onModel()
+ .assertThat().field("id").isNotNull()
+ .assertThat().field("name").is(ruleNames.get(i)));
+ }
+}
+
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
index 53c137ee12..9bc89f78d1 100644
--- 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
@@ -25,12 +25,19 @@
*/
package org.alfresco.rest.rules;
+import static java.util.stream.Collectors.toList;
+
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 java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
import org.alfresco.rest.RestTest;
+import org.alfresco.rest.model.RestRuleModel;
import org.alfresco.rest.model.RestRuleModelsCollection;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
@@ -47,16 +54,29 @@ public class GetRulesTests extends RestTest
{
private UserModel user;
private SiteModel site;
+ private FolderModel ruleFolder;
+ private List createdRules;
+ private RestRuleModel createdRuleA;
@BeforeClass(alwaysRun = true)
public void dataPreparation()
{
+ STEP("Create a user, site and folder");
user = dataUser.createRandomTestUser();
site = dataSite.usingUser(user).createPublicRandomSite();
+ ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
+
+ STEP("Create rules in the folder");
+ createdRules = Stream.of("ruleA", "ruleB").map(ruleName -> {
+ RestRuleModel ruleModel = new RestRuleModel();
+ ruleModel.setName(ruleName);
+ return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
+ }).collect(toList());
+ createdRuleA = createdRules.get(0);
}
/** Check we can get an empty list of rules. */
- @Test(groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
+ @Test(groups = { TestGroup.REST_API, TestGroup.RULES })
public void getEmptyRulesList()
{
STEP("Create a folder in existing site");
@@ -69,6 +89,21 @@ public class GetRulesTests extends RestTest
assertTrue("Expected no rules to be present.", rules.isEmpty());
}
+ /** Check we can get all the rules for a folder. */
+ @Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
+ public void getRulesList()
+ {
+ STEP("Get the rules that apply to the folder");
+ RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().getListOfRules();
+
+ restClient.assertStatusCodeIs(OK);
+ rules.assertThat().entriesListCountIs(createdRules.size());
+ IntStream.range(0, createdRules.size()).forEach(i ->
+ rules.getEntries().get(i).onModel()
+ .assertThat().field("id").is(createdRules.get(i).getId())
+ .assertThat().field("name").is(createdRules.get(i).getName()));
+ }
+
/** 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()
@@ -91,6 +126,19 @@ public class GetRulesTests extends RestTest
restClient.assertStatusCodeIs(NOT_FOUND);
}
+ /** Check we can get a rule by its id. */
+ @Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
+ public void getSingleRule()
+ {
+ STEP("Load a particular rule");
+ RestRuleModel rule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().getSingleRule(createdRuleA.getId());
+
+ restClient.assertStatusCodeIs(OK);
+
+ rule.assertThat().field("id").is(createdRuleA.getId())
+ .assertThat().field("name").is(createdRuleA.getName());
+ }
+
/** 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()
diff --git a/pom.xml b/pom.xml
index 25d2007e93..05ab86af74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -120,7 +120,7 @@
2.7.4
3.0.49
3.3.0
- 1.93
+ 1.94
1.31
1.8
1.6
diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/rules/Rule.java b/remote-api/src/main/java/org/alfresco/rest/api/model/rules/Rule.java
index 5eeae3a7c8..9dad8b55e1 100644
--- a/remote-api/src/main/java/org/alfresco/rest/api/model/rules/Rule.java
+++ b/remote-api/src/main/java/org/alfresco/rest/api/model/rules/Rule.java
@@ -27,6 +27,8 @@
package org.alfresco.rest.api.model.rules;
import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -104,6 +106,12 @@ public class Rule
this.name = name;
}
+ // TODO: Added stub for actions as it's a required field. Replace this implementation when we implement support for actions.
+ public List getActions()
+ {
+ return Collections.emptyList();
+ }
+
@Override
public boolean equals(Object o)
{