*/
package org.sonar.server.qualityprofile.ws;
-import com.google.common.io.Resources;
import org.sonar.api.server.ws.RailsHandler;
import org.sonar.api.server.ws.WebService;
NewController controller = context.createController("api/profiles")
.setDescription("Former quality profiles web service");
- defineIndexAction(controller);
defineBackupAction(controller);
defineRestoreAction(controller);
controller.done();
}
- private static void defineIndexAction(NewController controller) {
- WebService.NewAction action = controller.createAction("index")
- .setDescription("Get a profile")
- .setSince("3.3")
- .setHandler(RailsHandler.INSTANCE)
- .setResponseExample(Resources.getResource(ProfilesWs.class, "example-index.json"));
-
- action.createParam("language")
- .setDescription("Profile language")
- .setRequired(true)
- .setExampleValue("java");
- action.createParam("name")
- .setDescription("Profile name. If no profile name is given, default profile for the given language will be returned")
- .setExampleValue("Sonar way");
- RailsHandler.addFormatParam(action);
- }
-
private static void defineBackupAction(NewController controller) {
WebService.NewAction action = controller.createAction("backup")
.setDescription("Backup a quality profile. Requires Administer Quality Profiles permission")
assertThat(controller).isNotNull();
assertThat(controller.path()).isEqualTo("api/profiles");
assertThat(controller.description()).isNotEmpty();
- assertThat(controller.actions()).hasSize(3);
- }
-
- @Test
- public void define_index_action() {
- WebService.Controller controller = tester.controller("api/profiles");
-
- WebService.Action restoreProfiles = controller.action("index");
- assertThat(restoreProfiles).isNotNull();
- assertThat(restoreProfiles.handler()).isInstanceOf(RailsHandler.class);
- assertThat(restoreProfiles.responseExampleAsString()).isNotEmpty();
- assertThat(restoreProfiles.params()).hasSize(3);
+ assertThat(controller.actions()).hasSize(2);
}
@Test
class Api::ProfilesController < Api::ApiController
- # GET /api/profiles?language=<language>[&name=<name>]
- def index
- require_parameters :language
-
- language=params[:language]
- name=params[:name]
- if name.blank?
- @profile=Profile.by_default(language)
- else
- @profile=Profile.find_by_name_and_language(name, language)
- end
- not_found('Profile not found') unless @profile
-
- @active_rules=filter_rules()
-
- respond_to do |format|
- format.json { render :json => jsonp(to_json) }
- format.xml { render :xml => to_xml }
- format.text { render :text => text_not_supported }
- end
- end
-
# Backup a profile. If output format is xml, then backup is directly returned.
# GET /api/profiles/backup?language=<language>[&name=my_profile] -v
def backup