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