3 * Copyright (C) 2009-2022 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 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;
34 import static org.assertj.core.api.Assertions.assertThat;
36 public class SafeModeHealthCheckerModuleTest {
37 private SafeModeHealthCheckerModule underTest = new SafeModeHealthCheckerModule();
40 public void verify_HealthChecker() {
41 ComponentContainer container = new ComponentContainer();
43 underTest.configure(container);
45 assertThat(classesAddedToContainer(container))
46 .contains(HealthCheckerImpl.class)
47 .doesNotContain(HealthActionSupport.class)
48 .doesNotContain(SafeModeHealthAction.class)
49 .doesNotContain(HealthAction.class);
53 public void verify_installed_HealthChecks_implementations() {
54 ComponentContainer container = new ComponentContainer();
56 underTest.configure(container);
58 List<Class<?>> checks = classesAddedToContainer(container).stream().filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList());
61 .contains(WebServerSafemodeNodeCheck.class)
62 .contains(DbConnectionNodeCheck.class)
63 .contains(EsStatusNodeCheck.class);
66 private List<Class<?>> classesAddedToContainer(ComponentContainer container) {
67 Collection<ComponentAdapter<?>> componentAdapters = container.getPicoContainer().getComponentAdapters();
68 return componentAdapters.stream().map(ComponentAdapter::getComponentImplementation).collect(Collectors.toList());