use of org.sonar.api.server.rule.RulesDefinition.NewRule in project sonarqube by SonarSource.
the class RulesDefinitionAnnotationLoaderTest method override_annotation_programmatically.
@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("Overriden name");
newRule.param("property").setDefaultValue("true");
newRule.param("property").setDescription("Overriden");
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("Overriden 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("Overriden");
assertThat(prop.defaultValue()).isEqualTo("true");
assertThat(prop.type()).isEqualTo(RuleParamType.STRING);
}