You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PluginsMonitorTest.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube 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. * SonarQube 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.monitoring;
  21. import org.junit.Test;
  22. import org.sonar.core.platform.PluginInfo;
  23. import org.sonar.core.platform.PluginRepository;
  24. import org.sonar.updatecenter.common.Version;
  25. import java.util.Arrays;
  26. import java.util.LinkedHashMap;
  27. import java.util.Map;
  28. import static org.assertj.core.api.Assertions.assertThat;
  29. import static org.mockito.Mockito.mock;
  30. import static org.mockito.Mockito.when;
  31. public class PluginsMonitorTest {
  32. PluginRepository repo = mock(PluginRepository.class);
  33. PluginsMonitor sut = new PluginsMonitor(repo);
  34. @Test
  35. public void name() {
  36. assertThat(sut.name()).isEqualTo("Plugins");
  37. }
  38. @Test
  39. public void plugin_name_and_version() throws Exception {
  40. when(repo.getPluginInfos()).thenReturn(Arrays.asList(
  41. new PluginInfo("key-1")
  42. .setName("plugin-1")
  43. .setVersion(Version.create("1.1")),
  44. new PluginInfo("key-2")
  45. .setName("plugin-2")
  46. .setVersion(Version.create("2.2")),
  47. new PluginInfo("no-version")
  48. .setName("No Version")));
  49. LinkedHashMap<String, Object> attributes = sut.attributes();
  50. assertThat(attributes).containsKeys("key-1", "key-2");
  51. assertThat((Map) attributes.get("key-1"))
  52. .containsEntry("Name", "plugin-1")
  53. .containsEntry("Version", "1.1");
  54. assertThat((Map) attributes.get("key-2"))
  55. .containsEntry("Name", "plugin-2")
  56. .containsEntry("Version", "2.2");
  57. assertThat((Map) attributes.get("no-version"))
  58. .containsEntry("Name", "No Version")
  59. .doesNotContainKey("Version");
  60. }
  61. }