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 ChangeLogLevelActionModuleTest {
41 private WebServer webServer = mock(WebServer.class);
42 private MapSettings settings = new MapSettings();
43 private ChangeLogLevelActionModule underTest = new ChangeLogLevelActionModule(webServer, settings.asConfig());
46 @UseDataProvider("notOnSonarCloud")
47 public void provide_returns_ChangeLogLevelClusterService_if_cluster_not_on_SonarCloud(@Nullable Boolean sonarcloudOrNot) {
48 when(webServer.isStandalone()).thenReturn(false);
49 if (sonarcloudOrNot != null) {
50 settings.setProperty("sonar.sonarcloud.enabled", sonarcloudOrNot);
52 ComponentContainer container = new ComponentContainer();
54 underTest.configure(container);
56 Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters();
58 .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 2)
59 .extracting(ComponentAdapter::getComponentKey)
60 .contains(ChangeLogLevelClusterService.class, ChangeLogLevelAction.class)
61 .doesNotContain(ChangeLogLevelStandaloneService.class);
65 public void provide_returns_ChangeLogLevelStandaloneService_on_SonarCloud() {
66 when(webServer.isStandalone()).thenReturn(false);
67 settings.setProperty("sonar.sonarcloud.enabled", true);
68 ComponentContainer container = new ComponentContainer();
70 underTest.configure(container);
72 verifyInStandaloneSQ(container);
76 @UseDataProvider("notOnSonarCloud")
77 public void provide_returns_ChangeLogLevelStandaloneService_if_SQ_standalone(@Nullable Boolean sonarcloudOrNot) {
78 when(webServer.isStandalone()).thenReturn(true);
79 if (sonarcloudOrNot != null) {
80 settings.setProperty("sonar.sonarcloud.enabled", sonarcloudOrNot);
82 ComponentContainer container = new ComponentContainer();
84 underTest.configure(container);
86 verifyInStandaloneSQ(container);
89 private void verifyInStandaloneSQ(ComponentContainer container) {
90 Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters();
92 .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 2)
93 .extracting(ComponentAdapter::getComponentKey)
94 .contains(ChangeLogLevelStandaloneService.class, ChangeLogLevelAction.class)
95 .doesNotContain(ChangeLogLevelClusterService.class);
99 public static Object[][] notOnSonarCloud() {
100 return new Object[][] {