/
PendingPluginsWsActionTest.java
214 lines (188 loc) · 7.39 KB
/
PendingPluginsWsActionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2014 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.plugins.ws;
import org.junit.Test;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.WebService;
import org.sonar.core.platform.PluginInfo;
import org.sonar.server.plugins.PluginDownloader;
import org.sonar.server.plugins.ServerPluginRepository;
import org.sonar.server.ws.WsTester;
import org.sonar.updatecenter.common.Version;
import java.io.IOException;
import static com.google.common.collect.ImmutableList.of;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.test.JsonAssert.assertJson;
public class PendingPluginsWsActionTest {
private static final String DUMMY_CONTROLLER_KEY = "dummy";
PluginDownloader pluginDownloader = mock(PluginDownloader.class);
ServerPluginRepository serverPluginRepository = mock(ServerPluginRepository.class);
PendingPluginsWsAction underTest = new PendingPluginsWsAction(pluginDownloader, serverPluginRepository, new PluginWSCommons());
Request request = mock(Request.class);
WsTester.TestResponse response = new WsTester.TestResponse();
@Test
public void action_pending_is_defined() {
WsTester wsTester = new WsTester();
WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
underTest.define(newController);
newController.done();
WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
assertThat(controller.actions()).extracting("key").containsExactly("pending");
WebService.Action action = controller.actions().iterator().next();
assertThat(action.isPost()).isFalse();
assertThat(action.description()).isNotEmpty();
assertThat(action.responseExample()).isNotNull();
}
@Test
public void empty_arrays_are_returned_when_there_nothing_pending() throws Exception {
underTest.handle(request, response);
assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(
"{" +
" \"installing\": []," +
" \"removing\": []" +
"}"
);
}
@Test
public void verify_properties_displayed_in_json_per_installing_plugin() throws Exception {
when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(gitPluginInfo()));
underTest.handle(request, response);
assertJson(response.outputAsString()).isSimilarTo(
"{" +
" \"installing\": " +
" [" +
" {" +
" \"key\": \"scmgit\"," +
" \"name\": \"Git\"," +
" \"description\": \"Git SCM Provider.\"," +
" \"version\": \"1.0\"," +
" \"license\": \"GNU LGPL 3\"," +
" \"organizationName\": \"SonarSource\"," +
" \"organizationUrl\": \"http://www.sonarsource.com\"," +
" \"homepageUrl\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," +
" \"issueTrackerUrl\": \"http://jira.codehaus.org/browse/SONARSCGIT\"," +
" \"implementationBuild\": \"9ce9d330c313c296fab051317cc5ad4b26319e07\"" +
" }" +
" ]," +
" \"removing\": []" +
"}"
);
}
@Test
public void verify_properties_displayed_in_json_per_removing_plugin() throws Exception {
when(serverPluginRepository.getUninstalledPlugins()).thenReturn(of(gitPluginInfo()));
underTest.handle(request, response);
assertJson(response.outputAsString()).isSimilarTo(
"{" +
" \"installing\": []," +
" \"removing\": " +
" [" +
" {" +
" \"key\": \"scmgit\"," +
" \"name\": \"Git\"," +
" \"description\": \"Git SCM Provider.\"," +
" \"version\": \"1.0\"," +
" \"license\": \"GNU LGPL 3\"," +
" \"organizationName\": \"SonarSource\"," +
" \"organizationUrl\": \"http://www.sonarsource.com\"," +
" \"homepageUrl\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," +
" \"issueTrackerUrl\": \"http://jira.codehaus.org/browse/SONARSCGIT\"," +
" \"implementationBuild\": \"9ce9d330c313c296fab051317cc5ad4b26319e07\"" +
" }" +
" ]" +
"}"
);
}
@Test
public void installing_plugins_are_sorted_by_name_then_key_and_are_unique() throws Exception {
when(pluginDownloader.getDownloadedPlugins()).thenReturn(of(
newPluginInfo(0).setName("Foo"),
newPluginInfo(3).setName("Bar"),
newPluginInfo(2).setName("Bar")
));
underTest.handle(request, response);
assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(
"{" +
" \"installing\": " +
" [" +
" {" +
" \"key\": \"key2\"," +
" \"name\": \"Bar\"," +
" }," +
" {" +
" \"key\": \"key3\"," +
" \"name\": \"Bar\"," +
" }," +
" {" +
" \"key\": \"key0\"," +
" \"name\": \"Foo\"," +
" }" +
" ]," +
" \"removing\": []" +
"}"
);
}
@Test
public void removing_plugins_are_sorted_and_unique() throws Exception {
when(serverPluginRepository.getUninstalledPlugins()).thenReturn(of(
newPluginInfo(0).setName("Foo"),
newPluginInfo(3).setName("Bar"),
newPluginInfo(2).setName("Bar")
));
underTest.handle(request, response);
assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo(
"{" +
" \"installing\": []," +
" \"removing\": " +
" [" +
" {" +
" \"key\": \"key2\"," +
" \"name\": \"Bar\"," +
" }," +
" {" +
" \"key\": \"key3\"," +
" \"name\": \"Bar\"," +
" }," +
" {" +
" \"key\": \"key0\"," +
" \"name\": \"Foo\"," +
" }" +
" ]" +
"}"
);
}
public PluginInfo gitPluginInfo() {
return new PluginInfo("scmgit")
.setName("Git")
.setDescription("Git SCM Provider.")
.setVersion(Version.create("1.0"))
.setLicense("GNU LGPL 3")
.setOrganizationName("SonarSource")
.setOrganizationUrl("http://www.sonarsource.com")
.setHomepageUrl("http://redirect.sonarsource.com/plugins/scmgit.html")
.setIssueTrackerUrl("http://jira.codehaus.org/browse/SONARSCGIT")
.setImplementationBuild("9ce9d330c313c296fab051317cc5ad4b26319e07");
}
public PluginInfo newPluginInfo(int id) throws IOException {
return new PluginInfo("key" + id).setName("name" + id);
}
}