@Test public void testThatBranchesCanBeEmpty() { when(settings.getString(SETTING_BRANCHES)).thenReturn(""); configValidator.validate(settings, errors, repository); assertEquals("", on(",").join(fieldErrors.keySet())); assertEquals("", on(",").join(fieldErrors.values())); }
@Test public void testThatBranchesMustHaveAValidRegexp() { when(settings.getString(SETTING_BRANCHES)).thenReturn("[notok"); configValidator.validate(settings, errors, repository); assertEquals(SETTING_BRANCHES, on(",").join(fieldErrors.keySet())); assertEquals( "Invalid Regexp: Unclosed character class near index 5 [notok ^", on(",").join(fieldErrors.values())); }
@Test public void testThatRulesWithoutMatchDoesNotValidate() { when(settings.getString(SETTING_GROUP_ACCEPT + "[0]")) .thenReturn(SSCCGroup.Accept.SHOW_MESSAGE.toString()); when(settings.getString(SETTING_RULE_REGEXP + "[0][0]")).thenReturn("ok"); configValidator.validate(settings, errors, repository); assertEquals(SETTING_GROUP_MATCH + "[0]", on(",").join(fieldErrors.keySet())); assertEquals( "Cannot add a rule group without matching criteria!", on(",").join(fieldErrors.values())); }
@Test public void testThatRulesWithoutRegexpDoesNotValidate() { when(settings.getString(SETTING_GROUP_ACCEPT + "[0]")) .thenReturn(SSCCGroup.Accept.SHOW_MESSAGE.toString()); when(settings.getString(SETTING_GROUP_MATCH + "[0]")) .thenReturn(SSCCGroup.Match.ALL.toString()); when(settings.getString(SETTING_RULE_MESSAGE + "[0][0]")).thenReturn("A Message"); configValidator.validate(settings, errors, repository); assertEquals("ruleRegexp[0][0]", on(",").join(fieldErrors.keySet())); assertEquals("Cannot add a rule without regexp!", on(",").join(fieldErrors.values())); }
@Test public void testThatRulesWithAcceptMatchAndRegexpDoesValidate() throws ValidationException { when(settings.getString(SETTING_GROUP_MATCH + "[0]")) .thenReturn(SSCCGroup.Match.ALL.toString().toLowerCase()); when(settings.getString(SETTING_GROUP_ACCEPT + "[0]")) .thenReturn(SSCCGroup.Accept.SHOW_MESSAGE.toString().toLowerCase()); when(settings.getString(SETTING_RULE_REGEXP + "[0][0]")).thenReturn("ok"); configValidator.validate(settings, errors, repository); assertEquals("", on(",").join(fieldErrors.keySet())); assertEquals("", on(",").join(fieldErrors.values())); assertEquals("ok", sscSettings(settings).getGroups().get(0).getRules().get(0).getRegexp()); }
@Test public void testThatRuleMustHaveAValidRegexp() { when(settings.getString(SETTING_GROUP_ACCEPT + "[0]")) .thenReturn(SSCCGroup.Accept.SHOW_MESSAGE.toString()); when(settings.getString(SETTING_GROUP_MATCH + "[0]")) .thenReturn(SSCCGroup.Match.ALL.toString()); when(settings.getString(SETTING_RULE_REGEXP + "[0][0]")).thenReturn("[notok"); configValidator.validate(settings, errors, repository); assertEquals("ruleRegexp[0][0]", on(",").join(fieldErrors.keySet())); assertEquals( "Invalid Regexp: Unclosed character class near index 5 [notok ^", on(",").join(fieldErrors.values())); }
@Test public void testThatValidationDoesNotFailIfNoValuesAreEntered() { configValidator.validate(settings, errors, repository); }