Search in sources :

Example 1 with ModuleSensorsExecutor

use of org.sonar.scanner.sensor.ModuleSensorsExecutor in project sonarqube by SonarSource.

the class ModuleSensorsExecutorTest method should_restrict_filesystem_when_pull_request_and_expected_sensor.

@Test
@UseDataProvider("sensorsOnlyChangedInPR")
public void should_restrict_filesystem_when_pull_request_and_expected_sensor(String sensorName) throws IOException {
    when(branchConfiguration.branchType()).thenReturn(BranchType.PULL_REQUEST);
    ModuleSensorsExecutor executor = createModuleExecutor(sensorName);
    executor.execute();
    verify(fileSystem, times(2)).setRestrictToChangedFiles(true);
    assertThat(logTester.logs().stream().anyMatch(p -> p.contains(String.format("Sensor %s is restricted to changed files only", sensorName)))).isTrue();
}
Also used : ModuleSensorsExecutor(org.sonar.scanner.sensor.ModuleSensorsExecutor) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 2 with ModuleSensorsExecutor

use of org.sonar.scanner.sensor.ModuleSensorsExecutor in project sonarqube by SonarSource.

the class ModuleSensorsExecutorTest method createModuleExecutor.

private ModuleSensorsExecutor createModuleExecutor(String sensorName) throws IOException {
    Sensor sensor = new TestSensor(sensorName);
    ModuleSensorWrapper sensorWrapper = new ModuleSensorWrapper(sensor, context, optimizer, fileSystem, branchConfiguration);
    ModuleSensorExtensionDictionary selector = mock(ModuleSensorExtensionDictionary.class);
    when(selector.selectSensors(false)).thenReturn(Collections.singleton(sensorWrapper));
    when(selector.selectSensors(true)).thenReturn(Collections.singleton(sensorWrapper));
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("root").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
    InputModuleHierarchy hierarchy = mock(InputModuleHierarchy.class);
    when(hierarchy.isRoot(rootModule)).thenReturn(true);
    return new ModuleSensorsExecutor(selector, rootModule, hierarchy, strategy, pluginRepo);
}
Also used : ModuleSensorWrapper(org.sonar.scanner.sensor.ModuleSensorWrapper) InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ModuleSensorsExecutor(org.sonar.scanner.sensor.ModuleSensorsExecutor) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Sensor(org.sonar.api.batch.sensor.Sensor) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 3 with ModuleSensorsExecutor

use of org.sonar.scanner.sensor.ModuleSensorsExecutor in project sonarqube by SonarSource.

the class ModuleSensorsExecutorTest method should_not_restrict_filesystem_when_pull_request_and_non_expected_sensor.

@Test
public void should_not_restrict_filesystem_when_pull_request_and_non_expected_sensor() throws IOException {
    String sensorName = "NonRestrictedSensor";
    when(branchConfiguration.branchType()).thenReturn(BranchType.PULL_REQUEST);
    ModuleSensorsExecutor executor = createModuleExecutor(sensorName);
    executor.execute();
    verify(fileSystem, times(2)).setRestrictToChangedFiles(false);
    assertThat(logTester.logs().stream().anyMatch(p -> p.contains(String.format("Sensor %s is restricted to changed files only", sensorName)))).isFalse();
}
Also used : ModuleSensorsExecutor(org.sonar.scanner.sensor.ModuleSensorsExecutor) Test(org.junit.Test)

Example 4 with ModuleSensorsExecutor

use of org.sonar.scanner.sensor.ModuleSensorsExecutor in project sonarqube by SonarSource.

the class ModuleSensorsExecutorTest method should_not_restrict_filesystem_when_branch.

@Test
@UseDataProvider("sensorsOnlyChangedInPR")
public void should_not_restrict_filesystem_when_branch(String sensorName) throws IOException {
    when(branchConfiguration.branchType()).thenReturn(BranchType.BRANCH);
    ModuleSensorsExecutor executor = createModuleExecutor(sensorName);
    executor.execute();
    verify(fileSystem, times(2)).setRestrictToChangedFiles(false);
    assertThat(logTester.logs().stream().anyMatch(p -> p.contains(String.format("Sensor %s is restricted to changed files only", sensorName)))).isFalse();
}
Also used : ModuleSensorsExecutor(org.sonar.scanner.sensor.ModuleSensorsExecutor) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with ModuleSensorsExecutor

use of org.sonar.scanner.sensor.ModuleSensorsExecutor in project sonarqube by SonarSource.

the class ModuleSensorsExecutorTest method setUp.

@Before
public void setUp() throws IOException {
    when(perModuleSensor.isGlobal()).thenReturn(false);
    when(perModuleSensor.shouldExecute()).thenReturn(true);
    when(perModuleSensor.wrappedSensor()).thenReturn(mock(Sensor.class));
    when(globalSensor.isGlobal()).thenReturn(true);
    when(globalSensor.shouldExecute()).thenReturn(true);
    when(globalSensor.wrappedSensor()).thenReturn(mock(Sensor.class));
    ModuleSensorExtensionDictionary selector = mock(ModuleSensorExtensionDictionary.class);
    when(selector.selectSensors(false)).thenReturn(Collections.singleton(perModuleSensor));
    when(selector.selectSensors(true)).thenReturn(Collections.singleton(globalSensor));
    ProjectDefinition childDef = ProjectDefinition.create().setKey("sub").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("root").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
    DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(childDef);
    InputModuleHierarchy hierarchy = mock(InputModuleHierarchy.class);
    when(hierarchy.isRoot(rootModule)).thenReturn(true);
    rootModuleExecutor = new ModuleSensorsExecutor(selector, rootModule, hierarchy, strategy, pluginRepository);
    subModuleExecutor = new ModuleSensorsExecutor(selector, subModule, hierarchy, strategy, pluginRepository);
}
Also used : InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ModuleSensorsExecutor(org.sonar.scanner.sensor.ModuleSensorsExecutor) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Sensor(org.sonar.api.batch.sensor.Sensor) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Before(org.junit.Before)

Aggregations

ModuleSensorsExecutor (org.sonar.scanner.sensor.ModuleSensorsExecutor)5 Test (org.junit.Test)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 Sensor (org.sonar.api.batch.sensor.Sensor)2 InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)2 ModuleSensorExtensionDictionary (org.sonar.scanner.sensor.ModuleSensorExtensionDictionary)2 Before (org.junit.Before)1 ModuleSensorWrapper (org.sonar.scanner.sensor.ModuleSensorWrapper)1