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.monitoring;
22 import java.util.Arrays;
23 import org.junit.Test;
24 import org.sonar.core.platform.PluginInfo;
25 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
26 import org.sonar.server.plugins.PluginType;
27 import org.sonar.server.plugins.ServerPluginRepository;
28 import org.sonar.updatecenter.common.Version;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33 import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
35 public class PluginsSectionTest {
37 private ServerPluginRepository repo = mock(ServerPluginRepository.class);
38 private PluginsSection underTest = new PluginsSection(repo);
42 assertThat(underTest.toProtobuf().getName()).isEqualTo("Plugins");
46 public void plugin_name_and_version() {
47 when(repo.getPluginsInfoByType(PluginType.EXTERNAL)).thenReturn(Arrays.asList(
48 new PluginInfo("key-1")
50 .setVersion(Version.create("1.1")),
51 new PluginInfo("key-2")
53 .setVersion(Version.create("2.2")),
54 new PluginInfo("no-version")
55 .setName("No Version")));
57 ProtobufSystemInfo.Section section = underTest.toProtobuf();
59 assertThatAttributeIs(section, "key-1", "1.1 [Plugin 1]");
60 assertThatAttributeIs(section, "key-2", "2.2 [Plugin 2]");
61 assertThatAttributeIs(section, "no-version", "[No Version]");