@Test public void use_l10n_bundles() { RulesDefinition.Context context = new RulesDefinition.Context(); when(i18n.getName("checkstyle", "ConstantName")).thenReturn("Constant Name"); when(i18n.getDescription("checkstyle", "ConstantName")).thenReturn("Checks that constant names conform to the specified format"); when(i18n.getParamDescription("checkstyle", "ConstantName", "format")).thenReturn("Regular expression"); new DeprecatedRulesDefinitionLoader(i18n, debtModelRepository, importer, pluginRepository, new RuleRepository[] {new UseBundles()}).complete(context); RulesDefinition.Repository checkstyle = context.repository("checkstyle"); RulesDefinition.Rule rule = checkstyle.rule("ConstantName"); assertThat(rule.key()).isEqualTo("ConstantName"); assertThat(rule.name()).isEqualTo("Constant Name"); assertThat(rule.htmlDescription()).isEqualTo("Checks that constant names conform to the specified format"); RulesDefinition.Param param = rule.param("format"); assertThat(param.key()).isEqualTo("format"); assertThat(param.name()).isEqualTo("format"); assertThat(param.description()).isEqualTo("Regular expression"); }
@Test public void wrap_deprecated_rule_repositories() { RulesDefinition.Context context = new RulesDefinition.Context(); CheckstyleRules checkstyleRules = new CheckstyleRules(); when(pluginRepository.getPluginKey(checkstyleRules)).thenReturn("unittest");
@Test public void fail_on_invalid_rule_debt() { RulesDefinition.Context context = new RulesDefinition.Context(); List<DebtModelXMLExporter.RuleDebt> ruleDebts = newArrayList( new DebtModelXMLExporter.RuleDebt() .setRuleKey(RuleKey.of("checkstyle", "ConstantName")) .setFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()) .setCoefficient("1d")); Reader javaModelReader = mock(Reader.class); when(debtModelRepository.createReaderForXMLFile("java")).thenReturn(javaModelReader); when(debtModelRepository.getContributingPluginList()).thenReturn(newArrayList("java")); when(importer.importXML(eq(javaModelReader), any(ValidationMessages.class))).thenReturn(ruleDebts); try { new DeprecatedRulesDefinitionLoader(i18n, debtModelRepository, importer, pluginRepository, new RuleRepository[] {new CheckstyleRules()}).complete(context); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalArgumentException.class); } assertThat(context.repositories()).isEmpty(); }
public StandaloneRuleDefinitionsLoader() { // No plugin installed context = new RulesDefinition.Context(); }
@Test void test() { GoRulesDefinition rulesDefinition = new GoRulesDefinition(false); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); assertThat(context.repositories()).hasSize(1); RulesDefinition.Repository goRepository = context.repository("go"); assertThat(goRepository.name()).isEqualTo("SonarAnalyzer"); assertThat(goRepository.language()).isEqualTo("go"); assertThat(goRepository.rules()).hasSize(GoChecks.getChecks().size()); assertRuleProperties(goRepository); assertAllRuleParametersHaveDescription(goRepository); }
public RulesDefinition.Context load() { RulesDefinition.Context context = new RulesDefinition.Context(); for (RulesDefinition pluginDefinition : pluginDefs) { context.setCurrentPluginKey(serverPluginRepository.getPluginKey(pluginDefinition)); pluginDefinition.define(context); } deprecatedDefConverter.complete(context); context.setCurrentPluginKey(null); coreCommonDefs.define(context); return context; } }
public StandaloneRuleDefinitionsLoader(RulesDefinition[] pluginDefs) { context = new RulesDefinition.Context(); for (RulesDefinition pluginDefinition : pluginDefs) { pluginDefinition.define(context); } }
@Test public void override_annotation_programmatically() { RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java"); NewRule newRule = annotationLoader.loadRule(newRepository, RuleWithProperty.class); newRule.setName("Overridden name"); newRule.param("property").setDefaultValue("true"); newRule.param("property").setDescription("Overridden"); newRepository.done(); RulesDefinition.Repository repository = context.repository("squid"); assertThat(repository.rules()).hasSize(1); RulesDefinition.Rule rule = repository.rules().get(0); assertThat(rule.key()).isEqualTo("foo"); assertThat(rule.status()).isEqualTo(RuleStatus.BETA); assertThat(rule.name()).isEqualTo("Overridden name"); assertThat(rule.htmlDescription()).isEqualTo("Foo Bar"); assertThat(rule.severity()).isEqualTo(Severity.BLOCKER); assertThat(rule.params()).hasSize(1); RulesDefinition.Param prop = rule.param("property"); assertThat(prop.key()).isEqualTo("property"); assertThat(prop.description()).isEqualTo("Overridden"); assertThat(prop.defaultValue()).isEqualTo("true"); assertThat(prop.type()).isEqualTo(RuleParamType.STRING); }
@Test public void define_rule_debt() { RulesDefinition.Context context = new RulesDefinition.Context(); List<DebtModelXMLExporter.RuleDebt> ruleDebts = newArrayList( new DebtModelXMLExporter.RuleDebt() .setRuleKey(RuleKey.of("checkstyle", "ConstantName")) .setFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()) .setCoefficient("1d") .setOffset("10min")); Reader javaModelReader = mock(Reader.class); when(debtModelRepository.createReaderForXMLFile("java")).thenReturn(javaModelReader); when(debtModelRepository.getContributingPluginList()).thenReturn(newArrayList("java")); when(importer.importXML(eq(javaModelReader), any(ValidationMessages.class))).thenReturn(ruleDebts); new DeprecatedRulesDefinitionLoader(i18n, debtModelRepository, importer, pluginRepository, new RuleRepository[] {new CheckstyleRules()}).complete(context); assertThat(context.repositories()).hasSize(1); RulesDefinition.Repository checkstyle = context.repository("checkstyle"); assertThat(checkstyle.rules()).hasSize(1); RulesDefinition.Rule rule = checkstyle.rule("ConstantName"); assertThat(rule).isNotNull(); assertThat(rule.key()).isEqualTo("ConstantName"); assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET); assertThat(rule.debtRemediationFunction().gapMultiplier()).isEqualTo("1d"); assertThat(rule.debtRemediationFunction().baseEffort()).isEqualTo("10min"); }
@Test public void complete_rule_name_and_description() { when(i18n.getName("squid", "S0001")).thenReturn("SOne"); when(i18n.getDescription("squid", "S0001")).thenReturn("S One"); RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository repo = context.createRepository("squid", "java"); // rule without description repo.createRule("S0001"); loader.load(repo); repo.done(); RulesDefinition.Rule rule = context.repository("squid").rule("S0001"); assertThat(rule.name()).isEqualTo("SOne"); assertThat(rule.htmlDescription()).isEqualTo("S One"); }
@Test public void override_existing() { when(i18n.getName("squid", "S0001")).thenReturn("SOne"); when(i18n.getDescription("squid", "S0001")).thenReturn("S One"); RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository repo = context.createRepository("squid", "java"); repo.createRule("S0001").setName("Bad").setHtmlDescription("Bad"); loader.load(repo); repo.done(); RulesDefinition.Rule rule = context.repository("squid").rule("S0001"); assertThat(rule.name()).isEqualTo("SOne"); assertThat(rule.htmlDescription()).isEqualTo("S One"); }
@Before public void setUp() { XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER)); context = new RulesDefinition.Context(); def.define(context); }
public ScannerMediumTester addRules(RulesDefinition rulesDefinition) { RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); List<Repository> repositories = context.repositories(); for (Repository repo : repositories) { for (RulesDefinition.Rule rule : repo.rules()) { this.addRule(rule.key(), rule.repository().key(), rule.internalKey(), rule.name()); } } return this; }
private RulesDefinition.Repository load(InputStream input, String encoding) { RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java"); underTest.load(newRepository, input, encoding); newRepository.done(); return context.repository("squid"); }
private RulesDefinition.Repository load(Class annotatedClass) { RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewExtendedRepository newRepository = context.createRepository("squid", "java"); annotationLoader.load(newRepository, annotatedClass); newRepository.done(); return context.repository("squid"); }
@Test public void emulate_the_day_deprecated_api_can_be_dropped() { RulesDefinition.Context context = new RulesDefinition.Context(); // no more RuleRepository ! new DeprecatedRulesDefinitionLoader(i18n, debtModelRepository, importer, pluginRepository); assertThat(context.repositories()).isEmpty(); }
private RulesDefinition.Repository load(String xml) { RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java"); underTest.load(newRepository, new StringReader(xml)); newRepository.done(); return context.repository("squid"); } }
@Test public void do_not_override_if_no_bundle() { // i18n returns null values RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository repo = context.createRepository("squid", "java"); repo.createRule("S0001").setName("SOne").setHtmlDescription("S One"); loader.load(repo); repo.done(); RulesDefinition.Rule rule = context.repository("squid").rule("S0001"); assertThat(rule.name()).isEqualTo("SOne"); assertThat(rule.htmlDescription()).isEqualTo("S One"); }
@Test public void complete_param_description() { when(i18n.getParamDescription("squid", "S0001", "max")).thenReturn("Maximum"); RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository repo = context.createRepository("squid", "java"); repo.createRule("S0001").setName("SOne").setHtmlDescription("S One").createParam("max"); loader.load(repo); repo.done(); RulesDefinition.Rule rule = context.repository("squid").rule("S0001"); assertThat(rule.param("max").description()).isEqualTo("Maximum"); } }
public RulesDefinition.Context load() { RulesDefinition.Context context = new RulesDefinition.Context(); for (RulesDefinition pluginDefinition : pluginDefs) { context.setCurrentPluginKey(serverPluginRepository.getPluginKey(pluginDefinition)); pluginDefinition.define(context); } deprecatedDefConverter.complete(context); context.setCurrentPluginKey(null); coreCommonDefs.define(context); return context; } }