mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3377 Fix review comments.
This commit is contained in:
@@ -27,7 +27,7 @@ package org.alfresco.rest.rules;
|
|||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModelWithDefaultValues;
|
||||||
import static org.alfresco.utility.report.log.Step.STEP;
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
@@ -161,13 +161,13 @@ public class ReorderRules extends RestTest
|
|||||||
RestRuleSetModel ruleSetBody = new RestRuleSetModel();
|
RestRuleSetModel ruleSetBody = new RestRuleSetModel();
|
||||||
ruleSetBody.setId("-default-");
|
ruleSetBody.setId("-default-");
|
||||||
ruleSetBody.setRuleIds(reversedRuleIds);
|
ruleSetBody.setRuleIds(reversedRuleIds);
|
||||||
RestRuleSetModel ruleSet = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||||
.include("ruleIds").updateRuleSet(ruleSetBody);
|
.include("ruleIds").updateRuleSet(ruleSetBody);
|
||||||
|
|
||||||
restClient.assertStatusCodeIs(FORBIDDEN);
|
restClient.assertStatusCodeIs(FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check that a user cannot reorder the rules in a rule set if they only have read permission. */
|
/** Check that a user can reorder the rules in a rule set if they have write permission. */
|
||||||
@Test
|
@Test
|
||||||
public void reorderRulesWithPermission()
|
public void reorderRulesWithPermission()
|
||||||
{
|
{
|
||||||
@@ -197,7 +197,7 @@ public class ReorderRules extends RestTest
|
|||||||
{
|
{
|
||||||
return IntStream.range(0, 3).mapToObj(index ->
|
return IntStream.range(0, 3).mapToObj(index ->
|
||||||
{
|
{
|
||||||
RestRuleModel ruleModel = createRuleModel("ruleName");
|
RestRuleModel ruleModel = createRuleModelWithDefaultValues();
|
||||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
return restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||||
}).collect(toList());
|
}).collect(toList());
|
||||||
}
|
}
|
||||||
|
@@ -103,7 +103,7 @@ public class RuleSetsImpl implements RuleSets
|
|||||||
|
|
||||||
// Check that the set of rule ids hasn't changed.
|
// Check that the set of rule ids hasn't changed.
|
||||||
Set<String> existingRuleIds = new HashSet<>(ruleSetLoader.loadRuleIds(folderNode));
|
Set<String> existingRuleIds = new HashSet<>(ruleSetLoader.loadRuleIds(folderNode));
|
||||||
if (!suppliedRuleIdSet.equals(existingRuleIds))
|
if (suppliedRuleIdSet.size() != suppliedRuleIds.size() || !suppliedRuleIdSet.equals(existingRuleIds))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Unexpected set of rule ids - received " + suppliedRuleIds + " but expected " + existingRuleIds);
|
throw new InvalidArgumentException("Unexpected set of rule ids - received " + suppliedRuleIds + " but expected " + existingRuleIds);
|
||||||
}
|
}
|
||||||
|
@@ -402,6 +402,30 @@ public class RuleSetsImplTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check that we can't include a rule twice in a rule set. */
|
||||||
|
@Test
|
||||||
|
public void testUpdateRuleSet_DuplicateRuleId()
|
||||||
|
{
|
||||||
|
List<String> dbOrder = List.of("RuleA", "RuleB");
|
||||||
|
List<String> newOrder = List.of("RuleA", "RuleB", "RuleA");
|
||||||
|
List<String> includes = List.of(RULE_IDS);
|
||||||
|
|
||||||
|
RuleSet dbRuleSet = mock(RuleSet.class);
|
||||||
|
RuleSet requestRuleSet = mock(RuleSet.class);
|
||||||
|
given(requestRuleSet.getId()).willReturn(RULE_SET_ID);
|
||||||
|
given(requestRuleSet.getRuleIds()).willReturn(newOrder);
|
||||||
|
|
||||||
|
given(ruleSetLoaderMock.loadRuleSet(RULE_SET_NODE, FOLDER_NODE, includes)).willReturn(dbRuleSet);
|
||||||
|
given(ruleSetLoaderMock.loadRuleIds(FOLDER_NODE)).willReturn(dbOrder);
|
||||||
|
given(nodeValidatorMock.validateFolderNode(FOLDER_ID, false)).willReturn(FOLDER_NODE);
|
||||||
|
given(nodeValidatorMock.validateRuleSetNode(RULE_SET_ID, FOLDER_NODE)).willReturn(RULE_SET_NODE);
|
||||||
|
|
||||||
|
//when
|
||||||
|
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||||
|
() -> ruleSets.updateRuleSet(FOLDER_ID, requestRuleSet, includes)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Check that we can update the rule ids without returning them. */
|
/** Check that we can update the rule ids without returning them. */
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateRuleSet_dontIncludeRuleIds()
|
public void testUpdateRuleSet_dontIncludeRuleIds()
|
||||||
|
Reference in New Issue
Block a user