org.sonar.api.server.rule.RulesDefinition Java Examples

The following examples show how to use org.sonar.api.server.rule.RulesDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomScssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 7 votes vote down vote up
@Test
public void test() {
  MyCustomScssRulesDefinition rulesDefinition = new MyCustomScssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("scss");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #2
Source File: CssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  CssRulesDefinition rulesDefinition = new CssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("css");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("css");
  assertThat(repository.rules()).hasSize(88);
  assertThat(CheckList.getEmbeddedCssChecks()).hasSize(repository.rules().size() - 6);


  RulesDefinition.Rule todoRule = repository.rule(TodoTagCheck.class.getAnnotation(Rule.class).key());
  assertThat(todoRule).isNotNull();
  assertThat(todoRule.name()).isEqualTo(TodoTagCheck.class.getAnnotation(Rule.class).name());
}
 
Example #3
Source File: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
private void loadParameters(RulesDefinition.NewRule rule, Field field) {
    RuleProperty propertyAnnotation = field.getAnnotation(RuleProperty.class);
    if (propertyAnnotation != null) {
        String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
        RulesDefinition.NewParam param = rule.createParam(fieldKey)
            .setDescription(propertyAnnotation.description())
            .setDefaultValue(propertyAnnotation.defaultValue());

        if (!StringUtils.isBlank(propertyAnnotation.type())) {
            try {
                param.setType(RuleParamType.parse(propertyAnnotation.type().trim()));
            } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException("Invalid property type [" + propertyAnnotation.type() + "]", e);
            }
        } else {
            param.setType(guessType(field.getType()));
        }
    }
}
 
Example #4
Source File: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
private RulesDefinition.NewRule createRule(RulesDefinition.NewExtendedRepository repo, Class clazz, Rule ruleAnnotation) {
    String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
    String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
    String description = StringUtils.defaultIfEmpty(loadDescription(ruleKey), "No description yet.");

    RulesDefinition.NewRule rule = repo.createRule(ruleKey);
    rule.setName(ruleName).setMarkdownDescription(description);
    rule.setSeverity(ruleAnnotation.priority().name());
    rule.setStatus(RuleStatus.valueOf(ruleAnnotation.status()));
    rule.setTags(ruleAnnotation.tags());

    setMetadata(rule, clazz);

    List<Field> fields = FieldUtils2.getFields(clazz, true);
    for (Field field : fields) {
        loadParameters(rule, field);
    }

    return rule;
}
 
Example #5
Source File: CustomGherkinRulesDefinitionTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyCustomGherkinRulesDefinition rulesDefinition = new MyCustomGherkinRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("gherkin");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #6
Source File: MyGherkinCustomRulesDefinitionTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyGherkinCustomRulesDefinition rulesDefinition = new MyGherkinCustomRulesDefinition();

  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);

  RulesDefinition.Repository repository = context.repository("custom-gherkin");

  assertThat(repository.name()).isEqualTo("My Gherkin Custom Repository");
  assertThat(repository.language()).isEqualTo("gherkin");
  assertThat(repository.rules()).hasSize(2);

  RulesDefinition.Rule forbiddenKeysRule = repository.rule(ForbiddenTagCheck.class.getAnnotation(Rule.class).key());
  assertThat(forbiddenKeysRule).isNotNull();
  assertThat(forbiddenKeysRule.name()).isEqualTo(ForbiddenTagCheck.class.getAnnotation(Rule.class).name());
}
 
Example #7
Source File: CustomCssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyCustomCssRulesDefinition rulesDefinition = new MyCustomCssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("css");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #8
Source File: CustomLessRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  MyCustomLessRulesDefinition rulesDefinition = new MyCustomLessRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(REPOSITORY_KEY);

  assertThat(repository.name()).isEqualTo(REPOSITORY_NAME);
  assertThat(repository.language()).isEqualTo("less");
  assertThat(repository.rules()).hasSize(1);

  RulesDefinition.Rule customRule = repository.rule(RULE_KEY);
  assertThat(customRule).isNotNull();
  assertThat(customRule.key()).isEqualTo(RULE_KEY);
  assertThat(customRule.name()).isEqualTo(RULE_NAME);

  RulesDefinition.Param param = repository.rules().get(0).params().get(0);
  assertThat(param.key()).isEqualTo("customParam");
  assertThat(param.description()).isEqualTo("Custom parameter");
  assertThat(param.defaultValue()).isEqualTo("Default value");
}
 
Example #9
Source File: LuaRulesDefinitionTest.java    From sonar-lua with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
  LuaRulesDefinition rulesDefinition = new LuaRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("lua");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("lua");
  assertThat(repository.rules()).hasSize(CheckList.getChecks().size());

  for (RulesDefinition.Rule rule : repository.rules()) {
      for (RulesDefinition.Param param : rule.params()) {
        assertThat(param.description()).as("description for " + param.key() + " of " + rule.key()).isNotEmpty();
      }
    }
  
}
 
Example #10
Source File: PmdProfileExporterTest.java    From sonar-p3c-pmd with MIT License 6 votes vote down vote up
private static List<Rule> convert(List<RulesDefinition.Rule> rules) {
  List<Rule> results = Lists.newArrayListWithCapacity(rules.size());
  for (RulesDefinition.Rule rule : rules) {
    Rule newRule = Rule.create(rule.repository().key(), rule.key(), rule.name())
      .setDescription(rule.htmlDescription())
      .setRepositoryKey(rule.repository().key())
      .setConfigKey(rule.internalKey());
    if (!rule.params().isEmpty()) {
      List<RuleParam> ruleParams = Lists.newArrayList();
      for (Param param : rule.params()) {
        ruleParams.add(new RuleParam().setDefaultValue(param.defaultValue()).setKey(param.name()));
      }
      newRule.setParams(ruleParams);
    }
    results.add(newRule);
  }
  return results;
}
 
Example #11
Source File: PmdProfileExporterTest.java    From sonar-p3c-pmd with MIT License 6 votes vote down vote up
static RuleFinder createRuleFinder(final List<RulesDefinition.Rule> rules) {
  RuleFinder ruleFinder = mock(RuleFinder.class);
  final List<Rule> convertedRules = convert(rules);

  when(ruleFinder.find(any(RuleQuery.class))).then(new Answer<Rule>() {
    @Override
    public Rule answer(InvocationOnMock invocation) {
      RuleQuery query = (RuleQuery) invocation.getArguments()[0];
      for (Rule rule : convertedRules) {
        if (query.getConfigKey().equals(rule.getConfigKey())) {
          return rule;
        }
      }
      return null;
    }
  });
  return ruleFinder;
}
 
Example #12
Source File: PmdRulesDefinitionTest.java    From sonar-p3c-pmd with MIT License 6 votes vote down vote up
@Test
public void should_use_text_parameter_for_xpath_rule() {
  PmdRulesDefinition definition = new PmdRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  definition.define(context);
  RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY);

  Rule xpathRule = Iterables.find(repository.rules(), new Predicate<Rule>() {
    @Override
    public boolean apply(Rule rule) {
      return rule.key().equals("XPathRule");
    }
  });

  assertThat(xpathRule.param("xpath").type().type()).isEqualTo(PropertyType.TEXT.name());
}
 
Example #13
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotSetTechnicalDebtWhenTechnicalDebtNotSetInMetadata() {
    givenRulesLoaded(List.of(RuleWithEmptyTechnicalDebt.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MINOR.toString()));
    Assert.assertThat(rule.tags().contains(Tags.AEM), is(true));
    Assert.assertThat(rule.debtRemediationFunction(), is(nullValue()));
}
 
Example #14
Source File: EsqlRulesDefinitionTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
private RulesDefinition.Repository buildRepository() {
  EsqlRulesDefinition rulesDefinition = new EsqlRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("esql");
  return repository;
}
 
Example #15
Source File: HtlSensorTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    RulesDefinition rulesDefinition = new AemRulesRulesDefinition();
    RulesDefinition.Context context = new RulesDefinition.Context();
    rulesDefinition.define(context);
    RulesDefinition.Repository htlRepository = context.repository(HtlCheckClasses.REPOSITORY_KEY);

    FileLinesContextFactory fileLinesContextFactory = getMockedFileLinesContextFactory();
    Configuration configuration = getMockedConfiguration();
    CheckFactory checkFactory = getCheckFactory(htlRepository);

    sensor = new HtlSensor(fileLinesContextFactory, configuration, checkFactory);
    tester = SensorContextTester.create(TEST_DIR);
}
 
Example #16
Source File: HtlSensorTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private CheckFactory getCheckFactory(Repository htlRepository) {
    List<NewActiveRule> ar = new ArrayList<>();
    for (RulesDefinition.Rule rule : htlRepository.rules()) {
        ar.add(new NewActiveRule.Builder().setRuleKey(RuleKey.of(HtlCheckClasses.REPOSITORY_KEY, rule.key())).build());
    }
    return new CheckFactory(new DefaultActiveRules(ar));
}
 
Example #17
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadRuleWithAllSettings() {
    givenRulesLoaded(List.of(RuleWithAllSettings.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MINOR.toString()));
    Assert.assertThat(rule.tags().contains(Tags.AEM), is(true));
    Assert.assertThat(rule.debtRemediationFunction().baseEffort(), is(TECHNICAL_DEBT));
}
 
Example #18
Source File: EsqlRulesDefinitionTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
  RulesDefinition.Repository repository = buildRepository();

  assertThat(repository.name()).isEqualTo("SonarAnalyzer");
  assertThat(repository.language()).isEqualTo("esql");
  assertThat(repository.rules()).hasSize(CheckList.getChecks().size());

  assertRuleProperties(repository);
  assertParameterProperties(repository);
  assertAllRuleParametersHaveDescription(repository);
}
 
Example #19
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotSetTechnicalDebtWhenAnnotationNotPresent() {
    givenRulesLoaded(List.of(RuleWithoutMetadataAnnotation.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MINOR.toString()));
    Assert.assertThat(rule.tags().contains(Tags.AEM), is(true));
    Assert.assertThat(rule.debtRemediationFunction(), is(nullValue()));
}
 
Example #20
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadRuleWithPropertyWithoutAttributes() {
    givenRulesLoaded(List.of(RuleWithRulePropertyWithoutAttributes.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);
    RulesDefinition.Param param = rule.param("testProperty");

    Assert.assertThat(param.description(), is(nullValue()));
    Assert.assertThat(param.defaultValue(), is(nullValue()));
    Assert.assertThat(param.type().type(), is("STRING"));
}
 
Example #21
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotLoadRuleWhenRuleAnnotationIsNotPresent() {
    givenRulesLoaded(List.of(RuleWithoutRuleAnnotation.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);

    Assert.assertThat(rule, is(nullValue()));
}
 
Example #22
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetDefaultValuesWhenRuleAttributeWithNameOnly() {
    givenRulesLoaded(List.of(RuleWithOnlyNameAttribute.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule("com.cognifide.aemrules.extensions.RulesLoaderTest.RuleWithOnlyNameAttribute");

    Assert.assertThat(rule.markdownDescription(), is("No description yet."));
    Assert.assertThat(rule.name(), is(RULE_NAME));
    Assert.assertThat(rule.severity(), is(Priority.MAJOR.toString()));
    Assert.assertThat(rule.tags().size(), is(0));
    Assert.assertThat(rule.debtRemediationFunction().baseEffort(), is(TECHNICAL_DEBT));
}
 
Example #23
Source File: RulesLoaderTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadRuleWithProperty() {
    givenRulesLoaded(List.of(RuleWithRuleProperty.class));

    RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
    RulesDefinition.Rule rule = repository.rule(RULE_KEY);
    RulesDefinition.Param param = rule.param(RULE_PROPERTY_KEY);

    Assert.assertThat(param.description(), is(RULE_PROPERTY_DESCRIPTION));
    Assert.assertThat(param.defaultValue(), is(RULES_PROPERTY_DEFAULT_VALUE));
    Assert.assertThat(param.type().type(), is(RULES_PROPERTY_TYPE));
}
 
Example #24
Source File: GherkinRulesDefinitionTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  GherkinRulesDefinition rulesDefinition = new GherkinRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("gherkin");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("gherkin");
  assertThat(repository.rules()).hasSize(46);

  RulesDefinition.Rule lineLengthRule = repository.rule(TabCharacterCheck.class.getAnnotation(Rule.class).key());
  assertThat(lineLengthRule).isNotNull();
  assertThat(lineLengthRule.name()).isEqualTo(TabCharacterCheck.class.getAnnotation(Rule.class).name());
}
 
Example #25
Source File: CustomEsqlRulesDefinition.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Defines rule repository with check metadata from check classes' annotations.
 * This method should be overridden if check metadata are provided via another format,
 * e.g: XMl, JSON.
 */
@Override
public void define(RulesDefinition.Context context) {
  RulesDefinition.NewRepository repo = context.createRepository(repositoryKey(), "esql").setName(repositoryName());

  // Load metadata from check classes' annotations
  new AnnotationBasedRulesDefinition(repo, "esql").addRuleClasses(false, ImmutableList.copyOf(checkClasses()));

  repo.done();
}
 
Example #26
Source File: RulesLoader.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private void setTechnicalDebt(RulesDefinition.NewRule rule, Metadata metadataAnnotation) {
    String technicalDebt = metadataAnnotation.technicalDebt();
    if (StringUtils.isNotEmpty(technicalDebt)) {
        DebtRemediationFunctions remediationFunction = rule.debtRemediationFunctions();
        rule.setDebtRemediationFunction(remediationFunction.constantPerIssue(technicalDebt));
    }
}
 
Example #27
Source File: ApexRulesDefinitionTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void test() {
    rulesDefinition = new ApexRulesDefinition();
    RulesDefinition.Context context = new RulesDefinition.Context();
    rulesDefinition.define(context);
    RulesDefinition.Repository repository = context.repository("apex");

    assertThat(repository.name(), equalTo("SonarQube"));
    assertThat(repository.language(), equalTo("apex"));
    assertThat(repository.rules().size(), is(CheckList.getChecks().size()));
}
 
Example #28
Source File: CheckstyleRulesDefinitionTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
    final CheckstyleRulesDefinition definition = new CheckstyleRulesDefinition();
    final RulesDefinition.Context context = new RulesDefinition.Context();
    definition.define(context);
    final RulesDefinition.Repository repository = context
            .repository(CheckstyleConstants.REPOSITORY_KEY);

    assertThat(repository.name()).isEqualTo(CheckstyleConstants.REPOSITORY_NAME);
    assertThat(repository.language()).isEqualTo("java");

    final List<RulesDefinition.Rule> rules = repository.rules();
    assertThat(rules).hasSize(174);

    for (RulesDefinition.Rule rule : rules) {
        assertThat(rule.key()).isNotNull();
        assertThat(rule.internalKey()).isNotNull();
        assertThat(rule.name()).isNotNull();
        assertThat(rule.htmlDescription()).isNotNull();
        assertThat(rule.severity()).isNotNull();

        for (RulesDefinition.Param param : rule.params()) {
            assertThat(param.name()).isNotNull();
            assertThat(param.description()).overridingErrorMessage(
                    "Description is not set for parameter '" + param.name() + "' of rule '"
                            + rule.key()).isNotNull();
        }

        if (NO_SQALE.contains(rule.key())) {
            assertThat(rule.debtRemediationFunction()).overridingErrorMessage(
                    "Sqale remediation function is set for rule '" + rule.key()).isNull();
        }
        else {
            assertThat(rule.debtRemediationFunction()).overridingErrorMessage(
                    "Sqale remediation function is not set for rule '" + rule.key())
                    .isNotNull();
        }
    }
}
 
Example #29
Source File: RubyRulesDefinitionTest.java    From sonar-ruby-plugin with MIT License 5 votes vote down vote up
@Test
public void testDefine() {
    RulesDefinition.Context context = new RulesDefinition.Context();

    rules.define(context);

    assertThat(context.repositories().size()).isEqualTo(1);
    assertThat(context.repository("rubocop")).isNotNull();
    assertThat(context.repository("rubocop").language()).isEqualTo("rb");
    assertThat(context.repository("rubocop").rules().size()).isEqualTo(341);
}
 
Example #30
Source File: ScssRulesDefinitionTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
  ScssRulesDefinition rulesDefinition = new ScssRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository("scss");

  assertThat(repository.name()).isEqualTo("SonarQube");
  assertThat(repository.language()).isEqualTo("scss");
  assertThat(repository.rules()).hasSize(100);

  RulesDefinition.Rule rule = repository.rule(ScssVariableNamingConventionCheck.class.getAnnotation(Rule.class).key());
  assertThat(rule).isNotNull();
  assertThat(rule.name()).isEqualTo(ScssVariableNamingConventionCheck.class.getAnnotation(Rule.class).name());
}