Search in sources :

Example 1 with ExtensionContainer

use of org.sonar.core.platform.ExtensionContainer in project sonarqube by SonarSource.

the class RequestIdFilterTest method setUp.

@Before
public void setUp() {
    ExtensionContainer container = mock(ExtensionContainer.class);
    when(container.getOptionalComponentByType(RequestIdGenerator.class)).thenReturn(Optional.of(requestIdGenerator));
    when(platform.getContainer()).thenReturn(container);
}
Also used : ExtensionContainer(org.sonar.core.platform.ExtensionContainer) Before(org.junit.Before)

Example 2 with ExtensionContainer

use of org.sonar.core.platform.ExtensionContainer in project sonarqube by SonarSource.

the class ModuleSensorExtensionDictionaryTest method shouldSearchInParentContainers.

@Test
public void shouldSearchInParentContainers() {
    Sensor a = new FakeSensor();
    Sensor b = new FakeSensor();
    Sensor c = new FakeSensor();
    ExtensionContainer grandParent = mock(ExtensionContainer.class);
    when(grandParent.getComponentsByType(Sensor.class)).thenReturn(List.of(a));
    ExtensionContainer parent = mock(ExtensionContainer.class);
    when(parent.getComponentsByType(Sensor.class)).thenReturn(List.of(b));
    when(parent.getParent()).thenReturn(grandParent);
    ExtensionContainer child = mock(ExtensionContainer.class);
    when(child.getComponentsByType(Sensor.class)).thenReturn(List.of(c));
    when(child.getParent()).thenReturn(parent);
    ModuleSensorExtensionDictionary dictionnary = new ModuleSensorExtensionDictionary(child, mock(ModuleSensorContext.class), mock(ModuleSensorOptimizer.class), fileSystem, branchConfiguration);
    assertThat(dictionnary.select(Sensor.class, true, null)).containsOnly(a, b, c);
}
Also used : ModuleSensorOptimizer(org.sonar.scanner.sensor.ModuleSensorOptimizer) ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ModuleSensorContext(org.sonar.scanner.sensor.ModuleSensorContext) ExtensionContainer(org.sonar.core.platform.ExtensionContainer) Sensor(org.sonar.api.batch.sensor.Sensor) Test(org.junit.Test)

Example 3 with ExtensionContainer

use of org.sonar.core.platform.ExtensionContainer in project sonarqube by SonarSource.

the class CoreExtensionsInstallerTest method install_provides_Configuration_from_container_when_getBootConfiguration_is_called.

@Test
public void install_provides_Configuration_from_container_when_getBootConfiguration_is_called() {
    CoreExtension coreExtension1 = newCoreExtension();
    CoreExtension coreExtension2 = newCoreExtension();
    when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension1, coreExtension2));
    Configuration configuration = new MapSettings().asConfig();
    ExtensionContainer container = mock(ExtensionContainer.class);
    when(container.getComponentByType(Configuration.class)).thenReturn(configuration);
    underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());
    verify(coreExtension1).load(contextCaptor.capture());
    verify(coreExtension2).load(contextCaptor.capture());
    assertThat(contextCaptor.getAllValues()).extracting(CoreExtension.Context::getBootConfiguration).containsOnly(configuration);
}
Also used : Configuration(org.sonar.api.config.Configuration) MapSettings(org.sonar.api.config.internal.MapSettings) ExtensionContainer(org.sonar.core.platform.ExtensionContainer) Test(org.junit.Test)

Example 4 with ExtensionContainer

use of org.sonar.core.platform.ExtensionContainer in project sonarqube by SonarSource.

the class CoreExtensionsInstallerTest method install_adds_PropertyDefinition_with_extension_name_as_default_category.

@Test
@UseDataProvider("allMethodsToAddExtension")
public void install_adds_PropertyDefinition_with_extension_name_as_default_category(BiConsumer<CoreExtension.Context, Collection<Object>> extensionAdder) {
    PropertyDefinition propertyDefinitionNoCategory = PropertyDefinition.builder("fooKey").build();
    PropertyDefinition propertyDefinitionWithCategory = PropertyDefinition.builder("barKey").category("donut").build();
    List<Object> extensions = ImmutableList.of(propertyDefinitionNoCategory, propertyDefinitionWithCategory);
    CoreExtension coreExtension = newCoreExtension(context -> extensionAdder.accept(context, extensions));
    when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension));
    ExtensionContainer container = mock(ExtensionContainer.class);
    underTest.install(container, noExtensionFilter(), noAdditionalSideFilter());
    verify(container).declareExtension(coreExtension.getName(), propertyDefinitionNoCategory);
    verify(container).declareExtension(coreExtension.getName(), propertyDefinitionWithCategory);
    verifyNoMoreInteractions(container);
}
Also used : PropertyDefinition(org.sonar.api.config.PropertyDefinition) ExtensionContainer(org.sonar.core.platform.ExtensionContainer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with ExtensionContainer

use of org.sonar.core.platform.ExtensionContainer in project sonarqube by SonarSource.

the class CoreExtensionsInstallerTest method install_does_not_install_extensions_annotated_with_expected_annotation_but_filtered_out.

@Test
@UseDataProvider("allMethodsToAddExtension")
public void install_does_not_install_extensions_annotated_with_expected_annotation_but_filtered_out(BiConsumer<CoreExtension.Context, Collection<Object>> extensionAdder) {
    List<Object> extensions = ImmutableList.of(WestSideClass.class, EastSideClass.class, OtherSideClass.class, Latitude.class);
    CoreExtension coreExtension = newCoreExtension(context -> extensionAdder.accept(context, extensions));
    when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension));
    ExtensionContainer container = mock(ExtensionContainer.class);
    underTest.install(container, noExtensionFilter(), t -> t != Latitude.class);
    verify(container).addExtension(coreExtension.getName(), WestSideClass.class);
    verify(container).declareExtension(coreExtension.getName(), OtherSideClass.class);
    verify(container).declareExtension(coreExtension.getName(), EastSideClass.class);
    verify(container).declareExtension(coreExtension.getName(), Latitude.class);
    verifyNoMoreInteractions(container);
}
Also used : ExtensionContainer(org.sonar.core.platform.ExtensionContainer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

ExtensionContainer (org.sonar.core.platform.ExtensionContainer)11 Test (org.junit.Test)8 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 ModuleSensorContext (org.sonar.scanner.sensor.ModuleSensorContext)2 ModuleSensorExtensionDictionary (org.sonar.scanner.sensor.ModuleSensorExtensionDictionary)2 Before (org.junit.Before)1 PostJobContext (org.sonar.api.batch.postjob.PostJobContext)1 Sensor (org.sonar.api.batch.sensor.Sensor)1 Configuration (org.sonar.api.config.Configuration)1 PropertyDefinition (org.sonar.api.config.PropertyDefinition)1 MapSettings (org.sonar.api.config.internal.MapSettings)1 ModuleSensorOptimizer (org.sonar.scanner.sensor.ModuleSensorOptimizer)1