diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/RestTest.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/RestTest.java
deleted file mode 100644
index 92fff70016..0000000000
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/RestTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.alfresco.rest;
-
-import java.lang.reflect.Method;
-
-import org.alfresco.dataprep.WorkflowService;
-import org.alfresco.rest.core.RestProperties;
-import org.alfresco.rest.core.RestWrapper;
-import org.alfresco.rest.rules.RulesTestsUtils;
-import org.alfresco.utility.LogFactory;
-import org.alfresco.utility.TasProperties;
-import org.alfresco.utility.data.DataContent;
-import org.alfresco.utility.data.DataGroup;
-import org.alfresco.utility.data.DataLink;
-import org.alfresco.utility.data.DataSite;
-import org.alfresco.utility.data.DataUserAIS;
-import org.alfresco.utility.data.DataWorkflow;
-import org.alfresco.utility.model.SiteModel;
-import org.alfresco.utility.network.ServerHealth;
-import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeSuite;
-
-@ContextConfiguration("classpath:alfresco-restapi-context.xml")
-public abstract class RestTest extends AbstractTestNGSpringContextTests
-{
- private static Logger LOG = LogFactory.getLogger();
-
- @Autowired
- protected RestProperties restProperties;
-
- @Autowired
- protected TasProperties properties;
-
- @Autowired
- protected ServerHealth serverHealth;
-
- @Autowired
- protected RestWrapper restClient;
-
- @Autowired
- protected DataUserAIS dataUser;
-
- @Autowired
- protected DataSite dataSite;
-
- @Autowired
- protected DataContent dataContent;
-
- @Autowired
- protected DataGroup dataGroup;
-
- @Autowired
- protected DataWorkflow dataWorkflow;
-
- @Autowired
- protected DataLink dataLink;
-
- @Autowired
- protected WorkflowService workflow;
-
- @Autowired
- protected RulesTestsUtils rulesUtils;
-
- protected SiteModel testSite;
-
- @BeforeSuite(alwaysRun = true)
- public void checkServerHealth() throws Exception
- {
- super.springTestContextPrepareTestInstance();
- serverHealth.assertServerIsOnline();
- testSite = dataSite.createPublicRandomSite();
- }
-
- @BeforeMethod(alwaysRun=true)
- public void showStartTestInfo(Method method)
- {
- LOG.info(String.format("*** STARTING Test: [%s] ***",method.getName()));
- }
-
- @AfterMethod(alwaysRun=true)
- public void showEndTestInfo(Method method)
- {
- LOG.info(String.format("*** ENDING Test: [%s] ***", method.getName()));
- }
-}
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
index 3cfc1902a0..cf4888952b 100644
--- 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
@@ -26,7 +26,6 @@
package org.alfresco.rest.rules;
import static java.util.stream.Collectors.toList;
-
import static org.alfresco.rest.actions.access.AccessRestrictionUtil.ERROR_MESSAGE_ACCESS_RESTRICTED;
import static org.alfresco.rest.actions.access.AccessRestrictionUtil.MAIL_ACTION;
import static org.alfresco.rest.rules.RulesTestsUtils.CHECKIN_ACTION;
@@ -58,11 +57,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
-
import javax.json.Json;
import javax.json.JsonObject;
-import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
import org.alfresco.rest.model.RestActionConstraintModel;
import org.alfresco.rest.model.RestCompositeConditionDefinitionModel;
@@ -83,7 +80,7 @@ import org.testng.annotations.Test;
* Tests for POST /nodes/{nodeId}/rule-sets/{ruleSetId}/rules.
*/
@Test(groups = {TestGroup.RULES})
-public class CreateRulesTests extends RestTest
+public class CreateRulesTests extends RulesRestTest
{
private UserModel user;
private SiteModel site;
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/DeleteRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/DeleteRulesTests.java
index 94b36eabce..7fe17b3ac5 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/DeleteRulesTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/DeleteRulesTests.java
@@ -26,7 +26,6 @@
package org.alfresco.rest.rules;
import static java.util.stream.Collectors.toList;
-
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
import static org.alfresco.utility.constants.UserRole.SiteContributor;
import static org.alfresco.utility.constants.UserRole.SiteManager;
@@ -41,7 +40,6 @@ import java.util.Set;
import java.util.stream.Collectors;
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;
@@ -56,7 +54,7 @@ import org.testng.annotations.Test;
* Tests for DELETE /nodes/{nodeId}/rule-sets/{ruleSetId}/rules/{ruleId}.
*/
@Test(groups = {TestGroup.RULES})
-public class DeleteRulesTests extends RestTest
+public class DeleteRulesTests extends RulesRestTest
{
private static final String FAKE_NODE_REF = "fake-node-id";
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ExecuteRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ExecuteRulesTests.java
index 39764a0379..b5cc2a43c6 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ExecuteRulesTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ExecuteRulesTests.java
@@ -36,7 +36,6 @@ import java.util.List;
import java.util.Map;
import org.alfresco.dataprep.CMISUtil;
-import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.model.RestRuleExecutionModel;
@@ -56,7 +55,7 @@ import org.testng.annotations.Test;
* Tests for POST /nodes/{nodeId}/rule-executions.
*/
@Test(groups = { TestGroup.RULES})
-public class ExecuteRulesTests extends RestTest
+public class ExecuteRulesTests extends RulesRestTest
{
private UserModel user;
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetInheritedRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetInheritedRulesTests.java
index 4267c5aa76..6fceb7b3a3 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetInheritedRulesTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetInheritedRulesTests.java
@@ -32,7 +32,6 @@ import java.util.List;
import java.util.stream.Collectors;
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.rest.model.RestRuleSetLinkModel;
@@ -49,7 +48,7 @@ import org.testng.annotations.Test;
* Tests for GET /nodes/{nodeId}/rule-sets/{ruleSetId}/rules with rule inheritance.
*/
@Test(groups = {TestGroup.RULES})
-public class GetInheritedRulesTests extends RestTest
+public class GetInheritedRulesTests extends RulesRestTest
{
private UserModel user;
private SiteModel site;
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetRuleSetsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetRuleSetsTests.java
index aed3d9f0b0..630c1a9dc3 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetRuleSetsTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/GetRuleSetsTests.java
@@ -36,8 +36,6 @@ import static org.springframework.http.HttpStatus.OK;
import java.util.List;
import com.google.common.collect.ImmutableMap;
-
-import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestRuleModel;
import org.alfresco.rest.model.RestRuleSetLinkModel;
import org.alfresco.rest.model.RestRuleSetModel;
@@ -57,7 +55,7 @@ import org.testng.annotations.Test;
* Tests for GET /nodes/{nodeId}/rule-sets and /nodes/{nodeId}/rule-sets/{ruleSetId}.
*/
@Test (groups = { TestGroup.RULES })
-public class GetRuleSetsTests extends RestTest
+public class GetRuleSetsTests extends RulesRestTest
{
private UserModel user;
private SiteModel site;
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 f33a3e8703..0f4aaeb142 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
@@ -26,7 +26,6 @@
package org.alfresco.rest.rules;
import static java.util.stream.Collectors.toList;
-
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.junit.Assert.assertTrue;
@@ -39,7 +38,6 @@ 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;
@@ -53,7 +51,7 @@ 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
+public class GetRulesTests extends RulesRestTest
{
private UserModel user;
private SiteModel site;
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ReorderRules.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ReorderRulesTests.java
similarity index 97%
rename from packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ReorderRules.java
rename to packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ReorderRulesTests.java
index 7a60dbc70e..58b8ef3420 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ReorderRules.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/ReorderRulesTests.java
@@ -1,203 +1,200 @@
-/*
- * #%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.springframework.http.HttpStatus.FORBIDDEN;
-import static org.springframework.http.HttpStatus.OK;
-
-import java.util.List;
-import java.util.stream.IntStream;
-
-import com.google.common.collect.Lists;
-
-import org.alfresco.rest.RestTest;
-import org.alfresco.rest.model.RestRuleModel;
-import org.alfresco.rest.model.RestRuleSetModel;
-import org.alfresco.utility.constants.UserRole;
-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;
-
-@Test (groups = { TestGroup.RULES })
-public class ReorderRules extends RestTest
-{
- private UserModel user;
- private SiteModel site;
-
- @BeforeClass (alwaysRun = true)
- public void dataPreparation()
- {
- STEP("Create a user and site.");
- user = dataUser.createRandomTestUser();
- site = dataSite.usingUser(user).createPublicRandomSite();
- }
-
- /** Check we can get the ordered list of rules in a rule set. */
- @Test (groups = { TestGroup.REST_API, TestGroup.RULES })
- public void getOrderedRuleIds()
- {
- STEP("Create a folder containing three rules in the existing site");
- FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
- List rules = createRulesInFolder(folder, user);
-
- STEP("Get the default rule set for the folder including the ordered rule ids");
- RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
- .include("ruleIds").getDefaultRuleSet();
-
- List expectedRuleIds = rules.stream().map(RestRuleModel::getId).collect(toList());
- restClient.assertStatusCodeIs(OK);
- ruleSet.assertThat().field("ruleIds").is(expectedRuleIds);
- }
-
- /** Check that a user can view the order of the rules in a rule set if they only have read permission. */
- @Test
- public void getRuleSetAndRuleIdsWithReadOnlyPermission()
- {
- STEP("Create a site owned by admin and add user as a consumer");
- SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
- dataUser.addUserToSite(user, siteModel, UserRole.SiteConsumer);
-
- STEP("Use admin to create a folder with a rule set and three rules in it");
- FolderModel ruleFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
- dataContent.usingAdmin().usingResource(ruleFolder).createFolder();
- List rules = createRulesInFolder(ruleFolder, dataUser.getAdminUser());
-
- STEP("Get the rule set with the ordered list of rules");
- RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder)
- .include("ruleIds").getDefaultRuleSet();
-
- restClient.assertStatusCodeIs(OK);
- List ruleIds = rules.stream().map(RestRuleModel::getId).collect(toList());
- ruleSet.assertThat().field("ruleIds").is(ruleIds);
- }
-
- /** Check we can reorder the rules in a rule set. */
- @Test (groups = { TestGroup.REST_API, TestGroup.RULES })
- public void reorderRules()
- {
- STEP("Create a folder containing three rules in the existing site");
- FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
- List rules = createRulesInFolder(folder, user);
-
- STEP("Reverse the order of the rules within the rule set");
- List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
- RestRuleSetModel ruleSetBody = new RestRuleSetModel();
- ruleSetBody.setId("-default-");
- ruleSetBody.setRuleIds(reversedRuleIds);
- RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
- .include("ruleIds").updateRuleSet(ruleSetBody);
-
- restClient.assertStatusCodeIs(OK);
- ruleSet.assertThat().field("ruleIds").is(reversedRuleIds);
- }
-
- /** Check we can reorder the rules in a rule set by editing the response from the GET. */
- @Test (groups = { TestGroup.REST_API, TestGroup.RULES })
- public void reorderRulesUsingResponseFromGET()
- {
- STEP("Create a folder containing three rules in the existing site");
- FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
- List rules = createRulesInFolder(folder, user);
-
- STEP("Get the rule set with its id.");
- RestRuleSetModel ruleSetResponse = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
- .include("ruleIds").getDefaultRuleSet();
-
- STEP("Reverse the order of the rules within the rule set");
- ruleSetResponse.setRuleIds(Lists.reverse(ruleSetResponse.getRuleIds()));
- RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
- .include("ruleIds").updateRuleSet(ruleSetResponse);
-
- restClient.assertStatusCodeIs(OK);
- List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
- ruleSet.assertThat().field("ruleIds").is(reversedRuleIds);
- }
-
- /** Check that a user cannot reorder the rules in a rule set if they only have read permission. */
- @Test
- public void reorderRulesWithoutPermission()
- {
- STEP("Create a site owned by admin and add user as a consumer");
- SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
- dataUser.addUserToSite(user, siteModel, UserRole.SiteContributor);
-
- STEP("Use admin to create a folder with a rule set and three rules in it");
- FolderModel ruleFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
- dataContent.usingAdmin().usingResource(ruleFolder).createFolder();
- List rules = createRulesInFolder(ruleFolder, dataUser.getAdminUser());
-
- STEP("Try to reorder the rules as the contributor");
- List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
- RestRuleSetModel ruleSetBody = new RestRuleSetModel();
- ruleSetBody.setId("-default-");
- ruleSetBody.setRuleIds(reversedRuleIds);
- restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder)
- .include("ruleIds").updateRuleSet(ruleSetBody);
-
- restClient.assertStatusCodeIs(FORBIDDEN);
- }
-
- /** Check that a user can reorder the rules in a rule set if they have write permission. */
- @Test
- public void reorderRulesWithPermission()
- {
- STEP("Create a site owned by admin and add user as a collaborator");
- SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
- dataUser.addUserToSite(user, siteModel, UserRole.SiteCollaborator);
-
- STEP("Use admin to create a folder with a rule set and three rules in it");
- FolderModel ruleFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
- dataContent.usingAdmin().usingResource(ruleFolder).createFolder();
- List rules = createRulesInFolder(ruleFolder, dataUser.getAdminUser());
-
- STEP("Try to reorder the rules as the contributor");
- List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
- RestRuleSetModel ruleSetBody = new RestRuleSetModel();
- ruleSetBody.setId("-default-");
- ruleSetBody.setRuleIds(reversedRuleIds);
- RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder)
- .include("ruleIds").updateRuleSet(ruleSetBody);
-
- restClient.assertStatusCodeIs(OK);
- ruleSet.assertThat().field("ruleIds").is(reversedRuleIds);
- }
-
- /** Create three rules in the given folder. */
- private List createRulesInFolder(FolderModel folder, UserModel user)
- {
- return IntStream.range(0, 3).mapToObj(index ->
- {
- RestRuleModel ruleModel = rulesUtils.createRuleModelWithDefaultValues();
- return restClient.authenticateUser(user).withPrivateAPI().usingNode(folder).usingDefaultRuleSet().createSingleRule(ruleModel);
- }).collect(toList());
- }
-}
+/*
+ * #%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.springframework.http.HttpStatus.FORBIDDEN;
+import static org.springframework.http.HttpStatus.OK;
+
+import java.util.List;
+import java.util.stream.IntStream;
+
+import com.google.common.collect.Lists;
+import org.alfresco.rest.model.RestRuleModel;
+import org.alfresco.rest.model.RestRuleSetModel;
+import org.alfresco.utility.constants.UserRole;
+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;
+
+@Test (groups = { TestGroup.RULES })
+public class ReorderRulesTests extends RulesRestTest
+{
+ private UserModel user;
+ private SiteModel site;
+
+ @BeforeClass (alwaysRun = true)
+ public void dataPreparation()
+ {
+ STEP("Create a user and site.");
+ user = dataUser.createRandomTestUser();
+ site = dataSite.usingUser(user).createPublicRandomSite();
+ }
+
+ /** Check we can get the ordered list of rules in a rule set. */
+ @Test (groups = { TestGroup.REST_API, TestGroup.RULES })
+ public void getOrderedRuleIds()
+ {
+ STEP("Create a folder containing three rules in the existing site");
+ FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
+ List rules = createRulesInFolder(folder, user);
+
+ STEP("Get the default rule set for the folder including the ordered rule ids");
+ RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
+ .include("ruleIds").getDefaultRuleSet();
+
+ List expectedRuleIds = rules.stream().map(RestRuleModel::getId).collect(toList());
+ restClient.assertStatusCodeIs(OK);
+ ruleSet.assertThat().field("ruleIds").is(expectedRuleIds);
+ }
+
+ /** Check that a user can view the order of the rules in a rule set if they only have read permission. */
+ @Test
+ public void getRuleSetAndRuleIdsWithReadOnlyPermission()
+ {
+ STEP("Create a site owned by admin and add user as a consumer");
+ SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
+ dataUser.addUserToSite(user, siteModel, UserRole.SiteConsumer);
+
+ STEP("Use admin to create a folder with a rule set and three rules in it");
+ FolderModel ruleFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
+ dataContent.usingAdmin().usingResource(ruleFolder).createFolder();
+ List rules = createRulesInFolder(ruleFolder, dataUser.getAdminUser());
+
+ STEP("Get the rule set with the ordered list of rules");
+ RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder)
+ .include("ruleIds").getDefaultRuleSet();
+
+ restClient.assertStatusCodeIs(OK);
+ List ruleIds = rules.stream().map(RestRuleModel::getId).collect(toList());
+ ruleSet.assertThat().field("ruleIds").is(ruleIds);
+ }
+
+ /** Check we can reorder the rules in a rule set. */
+ @Test (groups = { TestGroup.REST_API, TestGroup.RULES })
+ public void reorderRules()
+ {
+ STEP("Create a folder containing three rules in the existing site");
+ FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
+ List rules = createRulesInFolder(folder, user);
+
+ STEP("Reverse the order of the rules within the rule set");
+ List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
+ RestRuleSetModel ruleSetBody = new RestRuleSetModel();
+ ruleSetBody.setId("-default-");
+ ruleSetBody.setRuleIds(reversedRuleIds);
+ RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
+ .include("ruleIds").updateRuleSet(ruleSetBody);
+
+ restClient.assertStatusCodeIs(OK);
+ ruleSet.assertThat().field("ruleIds").is(reversedRuleIds);
+ }
+
+ /** Check we can reorder the rules in a rule set by editing the response from the GET. */
+ @Test (groups = { TestGroup.REST_API, TestGroup.RULES })
+ public void reorderRulesUsingResponseFromGET()
+ {
+ STEP("Create a folder containing three rules in the existing site");
+ FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
+ List rules = createRulesInFolder(folder, user);
+
+ STEP("Get the rule set with its id.");
+ RestRuleSetModel ruleSetResponse = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
+ .include("ruleIds").getDefaultRuleSet();
+
+ STEP("Reverse the order of the rules within the rule set");
+ ruleSetResponse.setRuleIds(Lists.reverse(ruleSetResponse.getRuleIds()));
+ RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(folder)
+ .include("ruleIds").updateRuleSet(ruleSetResponse);
+
+ restClient.assertStatusCodeIs(OK);
+ List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
+ ruleSet.assertThat().field("ruleIds").is(reversedRuleIds);
+ }
+
+ /** Check that a user cannot reorder the rules in a rule set if they only have read permission. */
+ @Test
+ public void reorderRulesWithoutPermission()
+ {
+ STEP("Create a site owned by admin and add user as a consumer");
+ SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
+ dataUser.addUserToSite(user, siteModel, UserRole.SiteContributor);
+
+ STEP("Use admin to create a folder with a rule set and three rules in it");
+ FolderModel ruleFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
+ dataContent.usingAdmin().usingResource(ruleFolder).createFolder();
+ List rules = createRulesInFolder(ruleFolder, dataUser.getAdminUser());
+
+ STEP("Try to reorder the rules as the contributor");
+ List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
+ RestRuleSetModel ruleSetBody = new RestRuleSetModel();
+ ruleSetBody.setId("-default-");
+ ruleSetBody.setRuleIds(reversedRuleIds);
+ restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder)
+ .include("ruleIds").updateRuleSet(ruleSetBody);
+
+ restClient.assertStatusCodeIs(FORBIDDEN);
+ }
+
+ /** Check that a user can reorder the rules in a rule set if they have write permission. */
+ @Test
+ public void reorderRulesWithPermission()
+ {
+ STEP("Create a site owned by admin and add user as a collaborator");
+ SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
+ dataUser.addUserToSite(user, siteModel, UserRole.SiteCollaborator);
+
+ STEP("Use admin to create a folder with a rule set and three rules in it");
+ FolderModel ruleFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
+ dataContent.usingAdmin().usingResource(ruleFolder).createFolder();
+ List rules = createRulesInFolder(ruleFolder, dataUser.getAdminUser());
+
+ STEP("Try to reorder the rules as the contributor");
+ List reversedRuleIds = Lists.reverse(rules.stream().map(RestRuleModel::getId).collect(toList()));
+ RestRuleSetModel ruleSetBody = new RestRuleSetModel();
+ ruleSetBody.setId("-default-");
+ ruleSetBody.setRuleIds(reversedRuleIds);
+ RestRuleSetModel ruleSet = restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder)
+ .include("ruleIds").updateRuleSet(ruleSetBody);
+
+ restClient.assertStatusCodeIs(OK);
+ ruleSet.assertThat().field("ruleIds").is(reversedRuleIds);
+ }
+
+ /** Create three rules in the given folder. */
+ private List createRulesInFolder(FolderModel folder, UserModel user)
+ {
+ return IntStream.range(0, 3).mapToObj(index ->
+ {
+ RestRuleModel ruleModel = rulesUtils.createRuleModelWithDefaultValues();
+ return restClient.authenticateUser(user).withPrivateAPI().usingNode(folder).usingDefaultRuleSet().createSingleRule(ruleModel);
+ }).collect(toList());
+ }
+}
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java
index 844dfda7ee..823dcd12dc 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java
@@ -35,7 +35,6 @@ import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import org.alfresco.dataprep.CMISUtil;
-import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestRuleModel;
import org.alfresco.rest.model.RestRuleModelsCollection;
import org.alfresco.rest.model.RestRuleSetLinkModel;
@@ -53,7 +52,7 @@ import org.testng.annotations.Test;
* Tests for /nodes/{nodeId}/rule-set-links.
*/
@Test(groups = {TestGroup.RULES})
-public class RuleSetLinksTests extends RestTest
+public class RuleSetLinksTests extends RulesRestTest
{
private UserModel user;
private SiteModel site;
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RulesRestTest.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RulesRestTest.java
new file mode 100644
index 0000000000..39dd363001
--- /dev/null
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RulesRestTest.java
@@ -0,0 +1,36 @@
+/*
+ * #%L
+ * Alfresco Remote API
+ * %%
+ * 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 org.alfresco.rest.RestTest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class RulesRestTest extends RestTest
+{
+ @Autowired
+ protected RulesTestsUtils rulesUtils;
+}
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java
index aeee780598..8858cc50b9 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java
@@ -33,7 +33,6 @@ import static org.springframework.http.HttpStatus.FORBIDDEN;
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.RestRuleSettingsModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
@@ -46,7 +45,7 @@ import org.testng.annotations.Test;
* Tests for GET and PUT /nodes/{nodeId}/rule-settings/{ruleSettingKey}.
*/
@Test (groups = { TestGroup.RULES })
-public class SetInheritanceTests extends RestTest
+public class SetInheritanceTests extends RulesRestTest
{
private UserModel siteOwner;
private SiteModel site;
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 17d55ed555..8fb7ad2749 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
@@ -48,8 +48,6 @@ import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
-
-import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
import org.alfresco.rest.model.RestCompositeConditionDefinitionModel;
import org.alfresco.rest.model.RestRuleModel;
@@ -64,7 +62,7 @@ import org.testng.annotations.Test;
* Tests for PUT /nodes/{nodeId}/rule-sets/{ruleSetId}/rules.
*/
@Test (groups = { TestGroup.RULES })
-public class UpdateRulesTests extends RestTest
+public class UpdateRulesTests extends RulesRestTest
{
private UserModel user;
private SiteModel site;