ACS-3377 Fix review comments.

This commit is contained in:
Tom Page
2022-10-03 15:40:52 +01:00
parent e9105f0f0c
commit f707906943
3 changed files with 30 additions and 6 deletions

View File

@@ -103,7 +103,7 @@ public class RuleSetsImpl implements RuleSets
// Check that the set of rule ids hasn't changed.
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);
}

View File

@@ -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. */
@Test
public void testUpdateRuleSet_dontIncludeRuleIds()