package it.updateCenter;
import com.sonar.orchestrator.Orchestrator;
-import java.util.List;
-import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.wsclient.Host;
-import org.sonar.wsclient.Sonar;
-import org.sonar.wsclient.connectors.HttpClient4Connector;
-import org.sonar.wsclient.services.Plugin;
-import org.sonar.wsclient.services.UpdateCenterQuery;
import util.user.UserRule;
-import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.pluginArtifact;
import static util.selenium.Selenese.runSelenese;
*/
public class UpdateCenterTest {
-
@ClassRule
public static final Orchestrator orchestrator = Orchestrator.builderEnv()
.setServerProperty("sonar.updatecenter.url", UpdateCenterTest.class.getResource("/updateCenter/UpdateCenterTest/update-center.properties").toString())
userRule.resetUsers();
}
- @Test
- public void web_service_installed_plugins_requires_root_and_returns_installed_plugins() {
- userRule.createUser("new_root", "bar");
- userRule.setRoot("new_root");
-
- Sonar newRootSonarWsClient = new Sonar(new HttpClient4Connector(new Host(orchestrator.getServer().getUrl(), "new_root", "bar")));
- List < Plugin > plugins = newRootSonarWsClient.findAll(UpdateCenterQuery.createForInstalledPlugins());
- assertThat(plugins.size()).isGreaterThan(0);
-
- Plugin installedPlugin = findPlugin(plugins, "fake");
-
- assertThat(installedPlugin).isNotNull();
- assertThat(installedPlugin.getName()).isEqualTo("Plugins :: Fake");
- assertThat(installedPlugin.getVersion()).isEqualTo("1.0-SNAPSHOT");
- }
-
@Test
public void test_console() {
runSelenese(orchestrator, "/updateCenter/installed-plugins.html");
}
- private Plugin findPlugin(List<Plugin> plugins, String pluginKey) {
- for (Plugin plugin : plugins) {
- if (StringUtils.equals(pluginKey, plugin.getKey())) {
- return plugin;
- }
- }
- return null;
- }
-
}
*/
package org.sonar.server.updatecenter.ws;
-import com.google.common.io.Resources;
-import org.sonar.api.server.ws.RailsHandler;
+import java.util.Arrays;
import org.sonar.api.server.ws.WebService;
public class UpdateCenterWs implements WebService {
NewController controller = context.createController("api/updatecenter")
.setDescription("Get list of installed plugins")
.setSince("2.10");
-
- defineInstalledPluginsAction(controller);
- for (UpdateCenterWsAction action : actions) {
- action.define(controller);
- }
-
+ Arrays.stream(actions).forEach(action -> action.define(controller));
controller.done();
}
-
- private void defineInstalledPluginsAction(NewController controller) {
- NewAction action = controller.createAction("installed_plugins")
- .setDescription("Get the list of all the plugins installed on the SonarQube instance")
- .setSince("2.10")
- .setHandler(RailsHandler.INSTANCE)
- .setInternal(true)
- .setResponseExample(Resources.getResource(this.getClass(), "example-installed_plugins.json"));
- RailsHandler.addFormatParam(action);
- }
-
}
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.server.ws.RailsHandler;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.platform.ServerFileSystem;
import org.sonar.server.ws.WsTester;
@Before
public void setUp() {
- tester = new WsTester(new UpdateCenterWs(
- new UploadAction(null, mock(ServerFileSystem.class))));
+ tester = new WsTester(new UpdateCenterWs(new UploadAction(null, mock(ServerFileSystem.class))));
}
@Test
assertThat(controller).isNotNull();
assertThat(controller.since()).isEqualTo("2.10");
assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(2);
- }
-
- @Test
- public void define_installed_plugins_action() {
- WebService.Controller controller = tester.controller("api/updatecenter");
-
- WebService.Action action = controller.action("installed_plugins");
- assertThat(action).isNotNull();
- assertThat(action.handler()).isInstanceOf(RailsHandler.class);
- assertThat(action.responseExampleAsString()).isNotEmpty();
- assertThat(action.params()).hasSize(1);
+ assertThat(controller.actions()).hasSize(1);
}
@Test
+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2016 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.
-#
-
-require 'json'
-
-class Api::UpdatecenterController < Api::ApiController
-
- #
- # GET /api/updatecenter/installed_plugins
- # curl http://localhost:9000/api/updatecenter/installed_plugins -v
- #
- def installed_plugins
- respond_to do |format|
- format.json { render :json => jsonp(plugins_to_json(user_plugins())) }
- format.xml { render :xml => plugins_to_xml(user_plugins()) }
- format.text { render :text => text_not_supported }
- end
- end
-
- private
-
- def plugins_to_json(plugins=[])
- json=[]
- plugins.each do |p|
- json<<plugin_to_json(p)
- end
- json
- end
-
- def plugin_to_json(plugin)
- hash={}
- hash['key']=plugin.getKey()
- hash['name']=plugin.getName()
- hash['version']=plugin.getVersion().getName()
- hash
- end
-
- def plugins_to_xml(plugins, xml=Builder::XmlMarkup.new(:indent => 0))
- xml.plugins do
- plugins.each do |plugin|
- xml.plugin do
- xml.key(plugin.getKey())
- xml.name(plugin.getName())
- xml.version(plugin.getVersion().getName())
- end
- end
- end
- end
-
- def user_plugins
- java_facade.getPluginInfos().to_a.sort
- end
-end