Search in sources :

Example 1 with RuleFinder

use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.

the class FakeRule method shouldParseOnlyWantedProfile.

@Test
public void shouldParseOnlyWantedProfile() {
    RuleFinder ruleFinder = mock(RuleFinder.class);
    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {

        public Rule answer(InvocationOnMock iom) throws Throwable {
            return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
        }
    });
    ValidationMessages messages = ValidationMessages.create();
    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
    assertThat(profile.getActiveRule("squid", "fake")).isNotNull();
    assertThat(profile.getActiveRule("squid", "other")).isNull();
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Rule(org.sonar.api.rules.Rule) Matchers.anyString(org.mockito.Matchers.anyString) RuleFinder(org.sonar.api.rules.RuleFinder) ValidationMessages(org.sonar.api.utils.ValidationMessages) Test(org.junit.Test)

Example 2 with RuleFinder

use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.

the class FakeRule method shouldParseAnnotatedClasses.

@Test
public void shouldParseAnnotatedClasses() {
    RuleFinder ruleFinder = mock(RuleFinder.class);
    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {

        public Rule answer(InvocationOnMock iom) throws Throwable {
            return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
        }
    });
    ValidationMessages messages = ValidationMessages.create();
    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages);
    assertThat(profile.getName()).isEqualTo("Foo way");
    assertThat(profile.getLanguage()).isEqualTo("java");
    assertThat(profile.getActiveRule("squid", "fake").getSeverity()).isEqualTo(RulePriority.BLOCKER);
    assertThat(messages.hasErrors()).isFalse();
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Rule(org.sonar.api.rules.Rule) Matchers.anyString(org.mockito.Matchers.anyString) RuleFinder(org.sonar.api.rules.RuleFinder) ValidationMessages(org.sonar.api.utils.ValidationMessages) Test(org.junit.Test)

Example 3 with RuleFinder

use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.

the class DefaultIndexTest method createIndex.

@Before
public void createIndex() throws IOException {
    ruleFinder = mock(RuleFinder.class);
    componentStore = mock(InputComponentStore.class);
    componentTree = mock(InputComponentTree.class);
    index = new DefaultIndex(componentStore, componentTree, mock(MeasureCache.class), mock(MetricFinder.class));
    baseDir = temp.newFolder();
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("project").setBaseDir(baseDir);
    ProjectDefinition moduleADef = ProjectDefinition.create().setKey("moduleA").setBaseDir(new java.io.File(baseDir, "moduleA"));
    ProjectDefinition moduleBDef = ProjectDefinition.create().setKey("moduleB").setBaseDir(new java.io.File(baseDir, "moduleB"));
    ProjectDefinition moduleB1Def = ProjectDefinition.create().setKey("moduleB1").setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1"));
    rootDef.addSubProject(moduleADef);
    rootDef.addSubProject(moduleBDef);
    moduleBDef.addSubProject(moduleB1Def);
    project = new Project(rootDef);
    moduleA = new Project(moduleADef);
    moduleB = new Project(moduleBDef);
    moduleB1 = new Project(moduleB1Def);
    RulesProfile rulesProfile = RulesProfile.create();
    rule = Rule.create("repoKey", "ruleKey", "Rule");
    rule.setId(1);
    rulesProfile.activateRule(rule, null);
    index.setCurrentStorage(mock(DefaultSensorStorage.class));
}
Also used : Project(org.sonar.api.resources.Project) RulesProfile(org.sonar.api.profiles.RulesProfile) InputComponentTree(org.sonar.api.batch.fs.internal.InputComponentTree) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) DefaultSensorStorage(org.sonar.scanner.sensor.DefaultSensorStorage) RuleFinder(org.sonar.api.rules.RuleFinder) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Before(org.junit.Before)

Example 4 with RuleFinder

use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.

the class WebServerRuleFinderImplTest method stopCaching_restores_non_caching_delegate.

@Test
public void stopCaching_restores_non_caching_delegate() {
    RuleFinder nonCachingDelegate = underTest.delegate;
    underTest.startCaching();
    underTest.stopCaching();
    assertThat(underTest.delegate).isSameAs(nonCachingDelegate);
}
Also used : RuleFinder(org.sonar.api.rules.RuleFinder) Test(org.junit.Test)

Example 5 with RuleFinder

use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.

the class XMLProfileParserTest method newRuleFinder.

private RuleFinder newRuleFinder() {
    RuleFinder ruleFinder = mock(RuleFinder.class);
    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {

        public Rule answer(InvocationOnMock iom) {
            Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
            rule.createParameter("format");
            rule.createParameter("message");
            return rule;
        }
    });
    return ruleFinder;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Rule(org.sonar.api.rules.Rule) ActiveRule(org.sonar.api.rules.ActiveRule) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuleFinder(org.sonar.api.rules.RuleFinder)

Aggregations

RuleFinder (org.sonar.api.rules.RuleFinder)5 Test (org.junit.Test)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Rule (org.sonar.api.rules.Rule)3 Matchers.anyString (org.mockito.Matchers.anyString)2 ValidationMessages (org.sonar.api.utils.ValidationMessages)2 Before (org.junit.Before)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1 InputComponentTree (org.sonar.api.batch.fs.internal.InputComponentTree)1 RulesProfile (org.sonar.api.profiles.RulesProfile)1 Project (org.sonar.api.resources.Project)1 ActiveRule (org.sonar.api.rules.ActiveRule)1 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)1 DefaultSensorStorage (org.sonar.scanner.sensor.DefaultSensorStorage)1