@Override public RulesProfile createProfile(ValidationMessages validation) { final RulesProfile profile = RulesProfile.create("Sonar way", Xoo.KEY); profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.INFO); profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY), RulePriority.CRITICAL); profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HotspotSensor.RULE_KEY), RulePriority.CRITICAL); return profile; } }
@Override public List<Rule> createRules() { Rule rule = Rule.create("checkstyle", "ConstantName"); rule.createParameter("format"); return Arrays.asList(rule); } }
@Override public RulesProfile createProfile(ValidationMessages messages) { RulesProfile profile = RulesProfile.create("Sonar way", Xoo2.KEY); profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.MINOR); return profile; } }
public Rule answer(InvocationOnMock iom) throws Throwable { Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]); rule.createParameter("format"); rule.createParameter("message"); return rule; } });
@Override public RulesProfile importProfile(Reader reader, ValidationMessages messages) { RulesProfile rulesProfile = RulesProfile.create(); rulesProfile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, "x1"), RulePriority.CRITICAL); return rulesProfile; } }
@Override public List<Rule> createRules() { Rule rule = Rule.create("checkstyle", "ConstantName", "Constant Name"); rule.setDescription("Checks that constant names conform to the specified format"); rule.setConfigKey("Checker/TreeWalker/ConstantName"); rule.setSeverity(RulePriority.BLOCKER); rule.setStatus(Rule.STATUS_BETA); rule.setTags(new String[] {"style", "clumsy"}); rule.createParameter("format").setDescription("Regular expression").setDefaultValue("A-Z").setType("REGULAR_EXPRESSION"); return Arrays.asList(rule); } }
@Override public RulesProfile createProfile(ValidationMessages validation) { final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY); profile.setDefaultProfile(true); profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); return profile; } }
@Override public RulesProfile createProfile(ValidationMessages messages) { RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY); profile.setDefaultProfile(true); // so UGLY profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); return profile; } }
@Test public void should_set_valid_status() { Rule rule = Rule.create().setStatus(Rule.STATUS_DEPRECATED); assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_DEPRECATED); rule = Rule.create().setStatus(Rule.STATUS_REMOVED); assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_REMOVED); rule = Rule.create().setStatus(Rule.STATUS_BETA); assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_BETA); rule = Rule.create().setStatus(Rule.STATUS_READY); assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_READY); }
@Override public RulesProfile createProfile(ValidationMessages validation) { RulesProfile profile1 = RulesProfile.create("Profile 1", "xoo"); profile1.activateRule(Rule.create("repo1", "defaultSeverity"), null); profile1.activateRule(Rule.create("repo1", "overrideSeverity"), RulePriority.CRITICAL); Rule ruleWithParam = Rule.create("repo1", "overrideParam"); ruleWithParam.setParams(Arrays.asList(new RuleParam(ruleWithParam, "param", "", ""))); ActiveRule arWithParam = profile1.activateRule(ruleWithParam, null); arWithParam.setParameter("param", "value"); return profile1; } }
@Test public void default_priority_is_major() { Rule rule = Rule.create(); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); rule = new Rule("name", "key"); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); rule.setSeverity(RulePriority.BLOCKER); assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER); rule.setSeverity(null); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); }
@Test public void should_remove_new_line_characters_in_name_with_setter() { Rule rule = Rule.create(); for (String example : getExamplesContainingNewLineCharacter()) { rule.setName(example); assertThat(rule.getName()).isEqualTo("test"); } }
@Test public void searchRulesByConfigKey() { RulesProfile profile = RulesProfile.create(); profile.activateRule(Rule.create("repo", "key1", "name1"), null); profile.activateRule(Rule.create("repo", "key2", "name2").setConfigKey("config2"), null); assertThat(profile.getActiveRuleByConfigKey("repo", "unknown")).isNull(); assertThat(profile.getActiveRuleByConfigKey("repo", "config2").getRuleKey()).isEqualTo("key2"); }
@Test public void shouldMatchRule() { RuleKey rule = Rule.create("checkstyle", "IllegalRegexp", "").ruleKey(); assertThat(new IssuePattern("*", "*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:IllegalRegexp").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "*:*Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "pmd:IllegalRegexp").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "pmd:*").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").matchRule(rule)).isFalse(); }
@Test public void match_rule() { RuleKey rule = Rule.create("checkstyle", "IllegalRegexp", "").ruleKey(); assertThat(new IssuePattern("*", "*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:IllegalRegexp").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "*:*Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "pmd:IllegalRegexp").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "pmd:*").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").matchRule(rule)).isFalse(); }
@Test public void activateRuleWithDefaultPriority() { RulesProfile profile = RulesProfile.create(); Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL); profile.activateRule(rule, null); assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.CRITICAL); }
@Test public void activateRuleWithSpecificPriority() { RulesProfile profile = RulesProfile.create(); Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL); profile.activateRule(rule, RulePriority.MINOR); assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.MINOR); }
@Test public void exportProfile() throws IOException, SAXException { Writer writer = new StringWriter(); RulesProfile profile = RulesProfile.create("sonar way", "java"); profile.activateRule(Rule.create("checkstyle", "IllegalRegexp", "illegal regexp"), RulePriority.BLOCKER); new XMLProfileSerializer().write(profile, writer); assertSimilarXml("exportProfile.xml", writer.toString()); }
@Override public RulesProfile importProfile(Reader reader, ValidationMessages messages) { RulesProfile rulesProfile = RulesProfile.create(); rulesProfile.activateRule(Rule.create(rule.getRepositoryKey(), rule.getRuleKey()), RulePriority.CRITICAL); return rulesProfile; } }
@Test public void description_should_be_cleaned() { Rule rule = Rule.create().setDescription(" my description "); Assert.assertEquals("my description", rule.getDescription()); rule.setDescription(null); assertThat(rule.getDescription()).isNull(); }