3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.ws;
22 import com.tngtech.java.junit.dataprovider.DataProvider;
23 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
24 import com.tngtech.java.junit.dataprovider.UseDataProvider;
25 import java.util.Collection;
26 import javax.annotation.Nullable;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.picocontainer.ComponentAdapter;
30 import org.sonar.api.config.internal.MapSettings;
31 import org.sonar.core.platform.ComponentContainer;
32 import org.sonar.server.platform.WebServer;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.when;
37 import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER;
39 @RunWith(DataProviderRunner.class)
40 public class WebSystemInfoModuleTest {
41 private WebServer webServer = mock(WebServer.class);
42 private MapSettings settings = new MapSettings();
43 private WebSystemInfoModule underTest = new WebSystemInfoModule(settings.asConfig(), webServer);
46 @UseDataProvider("notOnSonarCloud")
47 public void verify_system_info_configuration_in_cluster_mode(@Nullable Boolean notOnSonarCloud) {
48 when(webServer.isStandalone()).thenReturn(false);
49 if (notOnSonarCloud != null) {
50 settings.setProperty("sonar.sonarcloud.enabled", notOnSonarCloud);
52 ComponentContainer container = new ComponentContainer();
54 underTest.configure(container);
56 Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters();
58 .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 18);
62 @UseDataProvider("notOnSonarCloud")
63 public void verify_system_info_configuration_in_standalone_mode(@Nullable Boolean notOnSonarCloud) {
64 when(webServer.isStandalone()).thenReturn(true);
65 if (notOnSonarCloud != null) {
66 settings.setProperty("sonar.sonarcloud.enabled", notOnSonarCloud);
68 ComponentContainer container = new ComponentContainer();
70 underTest.configure(container);
72 verifyConfigurationStandaloneSQ(container);
76 public void verify_system_info_configuration_on_SonarCloud() {
77 when(webServer.isStandalone()).thenReturn(false);
78 settings.setProperty("sonar.sonarcloud.enabled", true);
79 ComponentContainer container = new ComponentContainer();
81 underTest.configure(container);
83 verifyConfigurationStandaloneSQ(container);
86 public void verifyConfigurationStandaloneSQ(ComponentContainer container) {
87 Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters();
89 .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12);
93 public static Object[][] notOnSonarCloud() {
94 return new Object[][] {