3 * Copyright (C) 2009-2021 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.core.platform.PluginRepository;
26 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
27 import org.sonar.updatecenter.common.Version;
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
32 import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
34 public class PluginsSectionTest {
36 private PluginRepository repo = mock(PluginRepository.class);
37 private PluginsSection underTest = new PluginsSection(repo);
41 assertThat(underTest.toProtobuf().getName()).isEqualTo("Plugins");
45 public void plugin_name_and_version() {
46 when(repo.getPluginInfos()).thenReturn(Arrays.asList(
47 new PluginInfo("key-1")
49 .setVersion(Version.create("1.1")),
50 new PluginInfo("key-2")
52 .setVersion(Version.create("2.2")),
53 new PluginInfo("no-version")
54 .setName("No Version")));
56 ProtobufSystemInfo.Section section = underTest.toProtobuf();
58 assertThatAttributeIs(section, "key-1", "1.1 [Plugin 1]");
59 assertThatAttributeIs(section, "key-2", "2.2 [Plugin 2]");
60 assertThatAttributeIs(section, "no-version", "[No Version]");