]> source.dussan.org Git - sonarqube.git/blob
53c887f53224d94111c60d9d61294ae17628d5f1
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2022 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.platform.ws;
21
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.stream.Collectors;
25 import org.junit.Test;
26 import org.picocontainer.ComponentAdapter;
27 import org.sonar.core.platform.ComponentContainer;
28 import org.sonar.server.health.DbConnectionNodeCheck;
29 import org.sonar.server.health.EsStatusNodeCheck;
30 import org.sonar.server.health.HealthCheckerImpl;
31 import org.sonar.server.health.NodeHealthCheck;
32 import org.sonar.server.health.WebServerSafemodeNodeCheck;
33
34 import static org.assertj.core.api.Assertions.assertThat;
35
36 public class SafeModeHealthCheckerModuleTest {
37   private SafeModeHealthCheckerModule underTest = new SafeModeHealthCheckerModule();
38
39   @Test
40   public void verify_HealthChecker() {
41     ComponentContainer container = new ComponentContainer();
42
43     underTest.configure(container);
44
45     assertThat(classesAddedToContainer(container))
46       .contains(HealthCheckerImpl.class)
47       .doesNotContain(HealthActionSupport.class)
48       .doesNotContain(SafeModeHealthAction.class)
49       .doesNotContain(HealthAction.class);
50   }
51
52   @Test
53   public void verify_installed_HealthChecks_implementations() {
54     ComponentContainer container = new ComponentContainer();
55
56     underTest.configure(container);
57
58     List<Class<?>> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList());
59     assertThat(checks)
60       .hasSize(3)
61       .contains(WebServerSafemodeNodeCheck.class)
62       .contains(DbConnectionNodeCheck.class)
63       .contains(EsStatusNodeCheck.class);
64   }
65
66   private List<Class<?>> classesAddedToContainer(ComponentContainer container) {
67     Collection<ComponentAdapter<?>> componentAdapters = container.getPicoContainer().getComponentAdapters();
68     return componentAdapters.stream().map(ComponentAdapter::getComponentImplementation).collect(Collectors.toList());
69   }
70
71 }