Search in sources :

Example 6 with PluginRepository

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

the class PageRepositoryTest method pages_from_different_page_definitions_ordered_by_key.

@Test
public void pages_from_different_page_definitions_ordered_by_key() {
    PageDefinition firstPlugin = context -> context.addPage(Page.builder("my_plugin/K1").setName("N1").build()).addPage(Page.builder("my_plugin/K3").setName("N3").build());
    PageDefinition secondPlugin = context -> context.addPage(Page.builder("my_plugin/K2").setName("N2").build());
    underTest = new PageRepository(pluginRepository, new PageDefinition[] { firstPlugin, secondPlugin });
    underTest.start();
    List<Page> result = underTest.getAllPages();
    assertThat(result).extracting(Page::getKey, Page::getName).containsExactly(tuple("my_plugin/K1", "N1"), tuple("my_plugin/K2", "N2"), tuple("my_plugin/K3", "N3"));
}
Also used : PageDefinition(org.sonar.api.web.page.PageDefinition) Qualifier(org.sonar.api.web.page.Page.Qualifier) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PluginRepository(org.sonar.core.platform.PluginRepository) Matchers.anyString(org.mockito.Matchers.anyString) List(java.util.List) Page(org.sonar.api.web.page.Page) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) Qualifiers(org.sonar.api.resources.Qualifiers) COMPONENT(org.sonar.api.web.page.Page.Scope.COMPONENT) ExpectedException(org.junit.rules.ExpectedException) GLOBAL(org.sonar.api.web.page.Page.Scope.GLOBAL) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) PageDefinition(org.sonar.api.web.page.PageDefinition) Page(org.sonar.api.web.page.Page) Test(org.junit.Test)

Example 7 with PluginRepository

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

the class PageRepositoryTest method filter_pages_without_qualifier.

@Test
public void filter_pages_without_qualifier() {
    PageDefinition plugin = context -> context.addPage(Page.builder("my_plugin/K1").setName("N1").build()).addPage(Page.builder("my_plugin/K2").setName("N2").build()).addPage(Page.builder("my_plugin/K3").setName("N3").build());
    underTest = new PageRepository(pluginRepository, new PageDefinition[] { plugin });
    underTest.start();
    List<Page> result = underTest.getGlobalPages(false);
    assertThat(result).extracting(Page::getKey).containsExactly("my_plugin/K1", "my_plugin/K2", "my_plugin/K3");
}
Also used : PageDefinition(org.sonar.api.web.page.PageDefinition) Qualifier(org.sonar.api.web.page.Page.Qualifier) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PluginRepository(org.sonar.core.platform.PluginRepository) Matchers.anyString(org.mockito.Matchers.anyString) List(java.util.List) Page(org.sonar.api.web.page.Page) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) Qualifiers(org.sonar.api.resources.Qualifiers) COMPONENT(org.sonar.api.web.page.Page.Scope.COMPONENT) ExpectedException(org.junit.rules.ExpectedException) GLOBAL(org.sonar.api.web.page.Page.Scope.GLOBAL) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) PageDefinition(org.sonar.api.web.page.PageDefinition) Page(org.sonar.api.web.page.Page) Test(org.junit.Test)

Example 8 with PluginRepository

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

the class PageRepositoryTest method fail_if_page_with_unknown_plugin.

@Test
public void fail_if_page_with_unknown_plugin() {
    PageDefinition governance = context -> context.addPage(Page.builder("governance/my_key").setName("N1").build());
    PageDefinition plugin42 = context -> context.addPage(Page.builder("plugin_42/my_key").setName("N2").build());
    pluginRepository = mock(PluginRepository.class);
    when(pluginRepository.hasPlugin("governance")).thenReturn(true);
    underTest = new PageRepository(pluginRepository, new PageDefinition[] { governance, plugin42 });
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Page 'N2' references plugin 'plugin_42' that does not exist");
    underTest.start();
}
Also used : PageDefinition(org.sonar.api.web.page.PageDefinition) Qualifier(org.sonar.api.web.page.Page.Qualifier) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PluginRepository(org.sonar.core.platform.PluginRepository) Matchers.anyString(org.mockito.Matchers.anyString) List(java.util.List) Page(org.sonar.api.web.page.Page) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) Qualifiers(org.sonar.api.resources.Qualifiers) COMPONENT(org.sonar.api.web.page.Page.Scope.COMPONENT) ExpectedException(org.junit.rules.ExpectedException) GLOBAL(org.sonar.api.web.page.Page.Scope.GLOBAL) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) PageDefinition(org.sonar.api.web.page.PageDefinition) PluginRepository(org.sonar.core.platform.PluginRepository) Test(org.junit.Test)

Example 9 with PluginRepository

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

the class SettingsActionTest method init.

private void init(Page... pages) {
    PluginRepository pluginRepository = mock(PluginRepository.class);
    when(pluginRepository.hasPlugin(anyString())).thenReturn(true);
    PageRepository pageRepository = new PageRepository(pluginRepository, new PageDefinition[] { context -> {
        for (Page page : pages) {
            context.addPage(page);
        }
    } });
    ws = new WsActionTester(new SettingsAction(pageRepository, settings, userSessionRule));
    pageRepository.start();
}
Also used : PluginRepository(org.sonar.core.platform.PluginRepository) PageRepository(org.sonar.server.ui.PageRepository) Page(org.sonar.api.web.page.Page) WsActionTester(org.sonar.server.ws.WsActionTester)

Example 10 with PluginRepository

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

the class GlobalContainer method installPlugins.

private void installPlugins() {
    PluginRepository pluginRepository = getComponentByType(PluginRepository.class);
    for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
        Plugin instance = pluginRepository.getPluginInstance(pluginInfo.getKey());
        addExtension(pluginInfo, instance);
    }
}
Also used : PluginRepository(org.sonar.core.platform.PluginRepository) PluginInfo(org.sonar.core.platform.PluginInfo) Plugin(org.sonar.api.Plugin)

Aggregations

PluginRepository (org.sonar.core.platform.PluginRepository)15 Test (org.junit.Test)9 Page (org.sonar.api.web.page.Page)8 Before (org.junit.Before)6 Matchers.anyString (org.mockito.Matchers.anyString)6 List (java.util.List)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Assertions.tuple (org.assertj.core.api.Assertions.tuple)5 Rule (org.junit.Rule)5 ExpectedException (org.junit.rules.ExpectedException)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 Qualifiers (org.sonar.api.resources.Qualifiers)5 LogTester (org.sonar.api.utils.log.LogTester)5 Qualifier (org.sonar.api.web.page.Page.Qualifier)5 COMPONENT (org.sonar.api.web.page.Page.Scope.COMPONENT)5 GLOBAL (org.sonar.api.web.page.Page.Scope.GLOBAL)5 PageDefinition (org.sonar.api.web.page.PageDefinition)5 PluginInfo (org.sonar.core.platform.PluginInfo)5 PageRepository (org.sonar.server.ui.PageRepository)3