Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

PendingActionTest.java 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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.plugins.ws;
  21. import org.junit.Test;
  22. import org.sonar.api.server.ws.Request;
  23. import org.sonar.api.server.ws.WebService;
  24. import org.sonar.core.platform.PluginInfo;
  25. import org.sonar.server.plugins.PluginDownloader;
  26. import org.sonar.server.plugins.ServerPluginRepository;
  27. import org.sonar.server.ws.WsTester;
  28. import org.sonar.updatecenter.common.Version;
  29. import static com.google.common.collect.ImmutableList.of;
  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.test.JsonAssert.assertJson;
  34. public class PendingActionTest {
  35. private static final String DUMMY_CONTROLLER_KEY = "dummy";
  36. PluginDownloader pluginDownloader = mock(PluginDownloader.class);
  37. ServerPluginRepository serverPluginRepository = mock(ServerPluginRepository.class);
  38. PendingAction underTest = new PendingAction(pluginDownloader, serverPluginRepository, new PluginWSCommons());
  39. Request request = mock(Request.class);
  40. WsTester.TestResponse response = new WsTester.TestResponse();
  41. @Test
  42. public void action_pending_is_defined() {
  43. WsTester wsTester = new WsTester();
  44. WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
  45. underTest.define(newController);
  46. newController.done();
  47. WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
  48. assertThat(controller.actions()).extracting("key").containsExactly("pending");
  49. WebService.Action action = controller.actions().iterator().next();
  50. assertThat(action.isPost()).isFalse();
  51. assertThat(action.description()).isNotEmpty();
  52. assertThat(action.responseExample()).isNotNull();
  53. }
  54. @Test
  55. public void empty_arrays_are_returned_when_there_nothing_pending() throws Exception {
  56. underTest.handle(request, response);
  57. assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(
  58. "{" +
  59. " \"installing\": []," +
  60. " \"removing\": []" +
  61. "}"
  62. );
  63. }
  64. @Test
  65. public void verify_properties_displayed_in_json_per_installing_plugin() throws Exception {
  66. when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(gitPluginInfo()));
  67. underTest.handle(request, response);
  68. assertJson(response.outputAsString()).isSimilarTo(
  69. "{" +
  70. " \"installing\": " +
  71. " [" +
  72. " {" +
  73. " \"key\": \"scmgit\"," +
  74. " \"name\": \"Git\"," +
  75. " \"description\": \"Git SCM Provider.\"," +
  76. " \"version\": \"1.0\"," +
  77. " \"license\": \"GNU LGPL 3\"," +
  78. " \"organizationName\": \"SonarSource\"," +
  79. " \"organizationUrl\": \"http://www.sonarsource.com\"," +
  80. " \"homepageUrl\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," +
  81. " \"issueTrackerUrl\": \"http://jira.sonarsource.com/browse/SONARSCGIT\"," +
  82. " \"implementationBuild\": \"9ce9d330c313c296fab051317cc5ad4b26319e07\"" +
  83. " }" +
  84. " ]," +
  85. " \"removing\": []" +
  86. "}"
  87. );
  88. }
  89. @Test
  90. public void verify_properties_displayed_in_json_per_removing_plugin() throws Exception {
  91. when(serverPluginRepository.getUninstalledPlugins()).thenReturn(of(gitPluginInfo()));
  92. underTest.handle(request, response);
  93. assertJson(response.outputAsString()).isSimilarTo(
  94. "{" +
  95. " \"installing\": []," +
  96. " \"removing\": " +
  97. " [" +
  98. " {" +
  99. " \"key\": \"scmgit\"," +
  100. " \"name\": \"Git\"," +
  101. " \"description\": \"Git SCM Provider.\"," +
  102. " \"version\": \"1.0\"," +
  103. " \"license\": \"GNU LGPL 3\"," +
  104. " \"organizationName\": \"SonarSource\"," +
  105. " \"organizationUrl\": \"http://www.sonarsource.com\"," +
  106. " \"homepageUrl\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," +
  107. " \"issueTrackerUrl\": \"http://jira.sonarsource.com/browse/SONARSCGIT\"," +
  108. " \"implementationBuild\": \"9ce9d330c313c296fab051317cc5ad4b26319e07\"" +
  109. " }" +
  110. " ]" +
  111. "}"
  112. );
  113. }
  114. @Test
  115. public void installing_plugins_are_sorted_by_name_then_key_and_are_unique() throws Exception {
  116. when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(
  117. newPluginInfo(0).setName("Foo"),
  118. newPluginInfo(3).setName("Bar"),
  119. newPluginInfo(2).setName("Bar")
  120. ));
  121. underTest.handle(request, response);
  122. assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(
  123. "{" +
  124. " \"installing\": " +
  125. " [" +
  126. " {" +
  127. " \"key\": \"key2\"," +
  128. " \"name\": \"Bar\"," +
  129. " }," +
  130. " {" +
  131. " \"key\": \"key3\"," +
  132. " \"name\": \"Bar\"," +
  133. " }," +
  134. " {" +
  135. " \"key\": \"key0\"," +
  136. " \"name\": \"Foo\"," +
  137. " }" +
  138. " ]," +
  139. " \"removing\": []" +
  140. "}"
  141. );
  142. }
  143. @Test
  144. public void removing_plugins_are_sorted_and_unique() throws Exception {
  145. when(serverPluginRepository.getUninstalledPlugins()).thenReturn(of(
  146. newPluginInfo(0).setName("Foo"),
  147. newPluginInfo(3).setName("Bar"),
  148. newPluginInfo(2).setName("Bar")
  149. ));
  150. underTest.handle(request, response);
  151. assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(
  152. "{" +
  153. " \"installing\": []," +
  154. " \"removing\": " +
  155. " [" +
  156. " {" +
  157. " \"key\": \"key2\"," +
  158. " \"name\": \"Bar\"," +
  159. " }," +
  160. " {" +
  161. " \"key\": \"key3\"," +
  162. " \"name\": \"Bar\"," +
  163. " }," +
  164. " {" +
  165. " \"key\": \"key0\"," +
  166. " \"name\": \"Foo\"," +
  167. " }" +
  168. " ]" +
  169. "}"
  170. );
  171. }
  172. public PluginInfo gitPluginInfo() {
  173. return new PluginInfo("scmgit")
  174. .setName("Git")
  175. .setDescription("Git SCM Provider.")
  176. .setVersion(Version.create("1.0"))
  177. .setLicense("GNU LGPL 3")
  178. .setOrganizationName("SonarSource")
  179. .setOrganizationUrl("http://www.sonarsource.com")
  180. .setHomepageUrl("http://redirect.sonarsource.com/plugins/scmgit.html")
  181. .setIssueTrackerUrl("http://jira.sonarsource.com/browse/SONARSCGIT")
  182. .setImplementationBuild("9ce9d330c313c296fab051317cc5ad4b26319e07");
  183. }
  184. public PluginInfo newPluginInfo(int id) {
  185. return new PluginInfo("key" + id).setName("name" + id);
  186. }
  187. }