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();
}
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);
}
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();
}
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();
}
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);
}
Aggregations