quality_profiles.remove_projects_confirm_button=Remove All
quality_profiles.copy_x_title=Copy Profile {0}
quality_profiles.copy_new_name=New name
-quality_profiles.restore_default_profiles=Restore Default Profiles
-quality_profiles.restore_default_profiles_x_language=Restore default profiles for language '{0}'
-quality_profiles.restore_default_profiles_confirmation=Are you sure you want to restore '{0}' profile(s) for '{1}' ?
-quality_profiles.restore_default_profiles_warning=Before restoring default profiles for '{0}', you have to rename or delete profile(s) '{1}'.
+quality_profiles.recreate_built_in_profiles=Recreate Built-in Profiles
+quality_profiles.recreate_built_in_profiles_confirmation=Are you sure you want to recreate '{0}' profile(s) for '{1}' ?
+quality_profiles.recreate_built_in_profiles_warning=Before recreating built-in profiles for '{0}', you have to rename or delete profile(s) '{1}'.
#------------------------------------------------------------------------------
#
import org.sonar.server.qualityprofile.*;
import org.sonar.server.qualityprofile.ws.ActivateRuleAction;
import org.sonar.server.qualityprofile.ws.ProfilesWs;
-import org.sonar.server.qualityprofile.ws.QProfileRestoreDefaultAction;
+import org.sonar.server.qualityprofile.ws.QProfileRecreateBuiltInAction;
import org.sonar.server.qualityprofile.ws.QProfilesWs;
import org.sonar.server.rule.*;
import org.sonar.server.rule.ws.*;
pico.addSingleton(QProfileRepositoryExporter.class);
pico.addSingleton(DefaultProfilesCache.class);
pico.addSingleton(ESActiveRule.class);
- pico.addSingleton(QProfileRestoreDefaultAction.class);
+ pico.addSingleton(QProfileRecreateBuiltInAction.class);
pico.addSingleton(QProfilesWs.class);
pico.addSingleton(ProfilesWs.class);
pico.addSingleton(ActivateRuleAction.class);
}
/**
- * Restore provided profile for a given language.
+ * Recreate built-in profile for a given language.
* If a profile with same name than default profile already exists, an exception will be thrown.
*/
- public QProfileResult restoreDefaultProfilesByLanguage(String language) {
+ public QProfileResult recreateBuiltInProfilesByLanguage(String language) {
checkPermission(UserSession.get());
QProfileResult result = new QProfileResult();
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.server.qualityprofile.QProfileBackup;
+import org.sonar.server.qualityprofile.QProfileResult;
+
+public class QProfileRecreateBuiltInAction implements RequestHandler {
+
+ private final QProfileBackup qProfileBackup;
+
+ public QProfileRecreateBuiltInAction(QProfileBackup qProfileBackup) {
+ this.qProfileBackup = qProfileBackup;
+ }
+
+ void define(WebService.NewController controller){
+ WebService.NewAction restoreDefault = controller.createAction("recreate_built_in")
+ .setDescription("Recreate Built-in Profiles")
+ .setSince("4.4")
+ .setPost(true)
+ .setHandler(this);
+ restoreDefault.createParam("language")
+ .setDescription("Recreate built-in profiles for this language")
+ .setExampleValue("java");
+ }
+
+ @Override
+ public void handle(Request request, Response response) {
+ final String language = request.mandatoryParam("language");
+ QProfileResult result = qProfileBackup.recreateBuiltInProfilesByLanguage(language);
+
+ if (!result.infos().isEmpty() || !result.warnings().isEmpty()) {
+ JsonWriter json = response.newJsonWriter();
+ json.beginObject();
+ if (!result.infos().isEmpty()) {
+ json.name("infos").beginArray();
+ for (String info : result.infos()) {
+ json.value(info);
+ }
+ json.endArray();
+ }
+ if (!result.warnings().isEmpty()) {
+ json.name("warnings").beginArray();
+ for (String warning : result.warnings()) {
+ json.value(warning);
+ }
+ json.endArray();
+ }
+ json.endObject().close();
+ } else {
+ response.noContent();
+ }
+ }
+
+}
+++ /dev/null
-/*
- * 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.qualityprofile.ws;
-
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.server.qualityprofile.QProfileBackup;
-import org.sonar.server.qualityprofile.QProfileResult;
-
-public class QProfileRestoreDefaultAction implements RequestHandler {
-
- private final QProfileBackup qProfileBackup;
-
- public QProfileRestoreDefaultAction(QProfileBackup qProfileBackup) {
- this.qProfileBackup = qProfileBackup;
- }
-
- void define(WebService.NewController controller){
- WebService.NewAction restoreDefault = controller.createAction("restore_default")
- .setDescription("Restore default profiles")
- .setSince("4.4")
- .setHandler(this);
- restoreDefault.createParam("language")
- .setDescription("Restore default profiles for this language")
- .setExampleValue("java");
- }
-
- @Override
- public void handle(Request request, Response response) {
- final String language = request.mandatoryParam("language");
- QProfileResult result = qProfileBackup.restoreDefaultProfilesByLanguage(language);
-
- if (!result.infos().isEmpty() || !result.warnings().isEmpty()) {
- JsonWriter json = response.newJsonWriter();
- json.beginObject();
- if (!result.infos().isEmpty()) {
- json.name("infos").beginArray();
- for (String info : result.infos()) {
- json.value(info);
- }
- json.endArray();
- }
- if (!result.warnings().isEmpty()) {
- json.name("warnings").beginArray();
- for (String warning : result.warnings()) {
- json.value(warning);
- }
- json.endArray();
- }
- json.endObject().close();
- } else {
- response.noContent();
- }
- }
-
-}
public class QProfilesWs implements WebService {
- private final QProfileRestoreDefaultAction restoreDefaultAction;
+ private final QProfileRecreateBuiltInAction recreateBuiltInAction;
private final ActivateRuleAction activateRuleAction;
- public QProfilesWs(QProfileRestoreDefaultAction qProfileRestoreDefaultAction, ActivateRuleAction activateRuleAction) {
- this.restoreDefaultAction = qProfileRestoreDefaultAction;
+ public QProfilesWs(QProfileRecreateBuiltInAction recreateBuiltInAction, ActivateRuleAction activateRuleAction) {
+ this.recreateBuiltInAction = recreateBuiltInAction;
this.activateRuleAction = activateRuleAction;
}
@Override
public void define(Context context) {
NewController controller = context.createController("api/qualityprofiles")
- .setDescription("Quality profiles management");
+ .setDescription("Quality profiles management")
+ .setSince("4.4");
- restoreDefaultAction.define(controller);
+ recreateBuiltInAction.define(controller);
activateRuleAction.define(controller);
controller.done();
redirect_to :action => 'index'
end
- # Modal window to restore default profiles
- # GET /profiles/restore_default_form/<profile id>
- def restore_default_form
+ # Modal window to recreate built-in profiles
+ # GET /profiles/recreate_built_in_form/<profile id>
+ def recreate_built_in_form
verify_ajax_request
require_parameters 'language'
@language = java_facade.getLanguages().find { |l| l.getKey()==params[:language].to_s }
profiles = Internal.quality_profiles.profilesByLanguage(@language.getKey()).to_a
@existing_default_profiles = profiles.select{|p| @default_profile_names.find{|default_profile| default_profile == p.name()}}.collect{|p| p.name()}
end
- render :partial => 'profiles/restore_default_form'
+ render :partial => 'profiles/recreate_built_in_form'
end
- # POST /profiles/restore_default?language=<language>
- def restore_default
+ # POST /profiles/recreate_built_in_form?language=<language>
+ def recreate_built_in
verify_post_request
require_parameters 'language'
call_backend do
- @result = Internal.profile_backup.restoreDefaultProfilesByLanguage(params[:language].to_s)
+ @result = Internal.profile_backup.recreateBuiltInProfilesByLanguage(params[:language].to_s)
flash_result(@result)
end
redirect_to :action => 'index'
--- /dev/null
+<form id="recreate-built-in-profiles-form" action="profiles/recreate_built_in" method="POST">
+ <fieldset>
+ <input type="hidden" name="language" value="<%= @language.getKey() -%>"/>
+
+ <div class="modal-head">
+ <h2><%= h message('quality_profiles.recreate_built_in_profiles') -%></h2>
+ </div>
+
+ <div class="modal-body">
+ <% if @existing_default_profiles.empty? %>
+ <%= h message('quality_profiles.recreate_built_in_profiles_confirmation', :params => [@default_profile_names.join('\', \''), @language.getName()]) -%>
+ <% else %>
+ <%= h message('quality_profiles.recreate_built_in_profiles_warning', :params => [@language.getName(), @existing_default_profiles.join('\', \'')]) -%>
+ <% end %>
+ </div>
+
+ <div class="modal-foot">
+ <input type="submit" value="<%= h message('restore') -%>" id="recreate-built-in-profiles-submit" <%= 'disabled=disabled' unless @existing_default_profiles.empty? -%>/>
+ <a href="#" onclick="return closeModalWindow()" id="recreate-built-in-profiles-cancel"><%= h message('cancel') -%></a>
+ </div>
+ </fieldset>
+</form>
+++ /dev/null
-<form id="restore-default-profiles-form" action="profiles/restore_default" method="POST">
- <fieldset>
- <input type="hidden" name="language" value="<%= @language.getKey() -%>"/>
-
- <div class="modal-head">
- <h2><%= h message('quality_profiles.restore_default_profiles_x_language', :params => @language.getName()) -%></h2>
- </div>
-
- <div class="modal-body">
- <% if @existing_default_profiles.empty? %>
- <%= h message('quality_profiles.restore_default_profiles_confirmation', :params => [@default_profile_names.join('\', \''), @language.getName()]) -%>
- <% else %>
- <%= h message('quality_profiles.restore_default_profiles_warning', :params => [@language.getName(), @existing_default_profiles.join('\', \'')]) -%>
- <% end %>
- </div>
-
- <div class="modal-foot">
- <input type="submit" value="<%= h message('restore') -%>" id="restore-default-profiles-submit" <%= 'disabled=disabled' unless @existing_default_profiles.empty? -%>/>
- <a href="#" onclick="return closeModalWindow()" id="restore-default-profiles-cancel"><%= h message('cancel') -%></a>
- </div>
- </fieldset>
-</form>
</ul>
<ul style="float: right" class="horizontal">
<li class="marginleft10">
- <a id="create-link-<%= language.getKey() -%>" href="<%= ApplicationController.root_context -%>/profiles/restore_default_form?language=<%= u language.getKey() -%>"
- class="open-modal link-action"><%= message('quality_profiles.restore_default_profiles') -%></a>
+ <a id="create-link-<%= language.getKey() -%>" href="<%= ApplicationController.root_context -%>/profiles/recreate_built_in_form?language=<%= u language.getKey() -%>"
+ class="open-modal link-action"><%= message('quality_profiles.recreate_built_in_profiles') -%></a>
</li>
</ul>
<% end %>
}
@Test
- public void restore_default_profiles_from_language() throws Exception {
+ public void recreate_built_in_profiles_from_language() throws Exception {
String name = "Default";
String language = "java";
when(qProfileOperations.newProfile(eq(name), eq(language), eq(true), any(UserSession.class), eq(session))).thenReturn(new QProfile().setId(1));
- backup.restoreDefaultProfilesByLanguage(language);
+ backup.recreateBuiltInProfilesByLanguage(language);
verify(qProfileActiveRuleOperations).createActiveRule(eq(1), eq(10), eq("BLOCKER"), eq(session));
verify(qProfileActiveRuleOperations).updateActiveRuleParam(any(ActiveRuleDto.class), eq("max"), eq("10"), eq(session));
}
@Test
- public void restore_default_profiles_from_language_with_multiple_profiles_with_same_name_and_same_language() throws Exception {
+ public void recreate_built_in_profiles_from_language_with_multiple_profiles_with_same_name_and_same_language() throws Exception {
RulesProfile profile1 = RulesProfile.create("Default", "java");
profile1.activateRule(Rule.create("pmd", "rule").setSeverity(RulePriority.BLOCKER), null);
ProfileDefinition profileDefinition1 = mock(ProfileDefinition.class);
when(qProfileOperations.newProfile(eq("Default"), eq("java"), eq(true), any(UserSession.class), eq(session))).thenReturn(new QProfile().setId(1));
- backup.restoreDefaultProfilesByLanguage("java");
+ backup.recreateBuiltInProfilesByLanguage("java");
verify(qProfileActiveRuleOperations).createActiveRule(eq(1), eq(10), eq("BLOCKER"), eq(session));
verify(qProfileActiveRuleOperations).createActiveRule(eq(1), eq(11), eq("MAJOR"), eq(session));
}
@Test
- public void fail_to_restore_profile_when_rule_not_found() throws Exception {
+ public void fail_to_recreate_built_in_profile_when_rule_not_found() throws Exception {
String name = "Default";
String language = "java";
when(qProfileOperations.newProfile(eq(name), eq(language), eq(true), any(UserSession.class), eq(session))).thenReturn(new QProfile().setId(1));
try {
- backup.restoreDefaultProfilesByLanguage(language);
+ backup.recreateBuiltInProfilesByLanguage(language);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(NotFoundException.class);
}
@Test
- public void not_restore_default_profiles_from_another_language() throws Exception {
+ public void not_recreate_built_in_profiles_from_another_language() throws Exception {
RulesProfile profile = RulesProfile.create("Default", "java");
profile.activateRule(Rule.create("pmd", "rule").setSeverity(RulePriority.BLOCKER), null);
ProfileDefinition profileDefinition = mock(ProfileDefinition.class);
when(profileDefinition.createProfile(any(ValidationMessages.class))).thenReturn(profile);
definitions.add(profileDefinition);
- backup.restoreDefaultProfilesByLanguage("js");
+ backup.recreateBuiltInProfilesByLanguage("js");
verifyZeroInteractions(qProfileOperations);
verifyZeroInteractions(qProfileActiveRuleOperations);
}
@Test
- public void restore_provided_profile_from_language() throws Exception {
+ public void recreate_built_in_profile_from_language() throws Exception {
MockUserSession.set().setLogin("julien").setName("Julien").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
QProfiles qProfiles = serverTester.get(QProfiles.class);
qProfiles.renameProfile(profile.id(), "Old Basic");
// Restore default profiles of xoo
- qProfileBackup.restoreDefaultProfilesByLanguage("xoo");
+ qProfileBackup.recreateBuiltInProfilesByLanguage("xoo");
// Reload profile
profile = qProfiles.profile("Basic", "xoo");
}
@Test
- public void fail_to_restore_provided_profile_from_language_if_default_profile_already_exists() throws Exception {
+ public void fail_to_recreate_built_in_profile_from_language_if_default_profile_already_exists() throws Exception {
MockUserSession.set().setLogin("julien").setName("Julien").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
QProfileBackup qProfileBackup = serverTester.get(QProfileBackup.class);
try {
// Restore default profiles of xoo -> fail as it already exists
- qProfileBackup.restoreDefaultProfilesByLanguage("xoo");
+ qProfileBackup.recreateBuiltInProfilesByLanguage("xoo");
fail();
} catch (BadRequestException e) {
assertThat(e.l10nKey()).isEqualTo("quality_profiles.profile_x_already_exists");
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.server.qualityprofile.QProfileBackup;
+import org.sonar.server.qualityprofile.QProfileResult;
+import org.sonar.server.qualityprofile.RuleActivationService;
+import org.sonar.server.ws.WsTester;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QProfileRecreateBuiltInActionTest {
+
+ @Mock
+ QProfileBackup qProfileBackup;
+
+ WsTester tester;
+
+ @Before
+ public void setUp() throws Exception {
+ tester = new WsTester(new QProfilesWs(
+ new QProfileRecreateBuiltInAction(qProfileBackup),
+ new ActivateRuleAction(mock(RuleActivationService.class))));
+ }
+
+ @Test
+ public void return_empty_result_when_no_infos_or_warnings() throws Exception {
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult());
+
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
+ request.execute().assertNoContent();
+ }
+
+ @Test
+ public void show_infos() throws Exception {
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")));
+
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
+ request.execute().assertJson(getClass(), "show_infos.json");
+ }
+
+ @Test
+ public void show_warnings() throws Exception {
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addWarnings(newArrayList("Some warning")));
+
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
+ request.execute().assertJson(getClass(), "show_warnings.json");
+ }
+
+ @Test
+ public void show_infos_and_warnings() throws Exception {
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")).addWarnings(newArrayList("Some warning")));
+
+ WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "recreate_built_in").setParam("language", "java");
+ request.execute().assertJson(getClass(), "show_infos_and_warnings.json");
+ }
+}
+++ /dev/null
-/*
- * 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.qualityprofile.ws;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.server.qualityprofile.QProfileBackup;
-import org.sonar.server.qualityprofile.QProfileResult;
-import org.sonar.server.qualityprofile.RuleActivationService;
-import org.sonar.server.ws.WsTester;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class QProfileRestoreDefaultActionTest {
-
- @Mock
- QProfileBackup qProfileBackup;
-
- WsTester tester;
-
- @Before
- public void setUp() throws Exception {
- tester = new WsTester(new QProfilesWs(
- new QProfileRestoreDefaultAction(qProfileBackup),
- new ActivateRuleAction(mock(RuleActivationService.class))));
- }
-
- @Test
- public void return_empty_result_when_no_infos_or_warnings() throws Exception {
- when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult());
-
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
- request.execute().assertNoContent();
- }
-
- @Test
- public void show_infos() throws Exception {
- when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")));
-
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
- request.execute().assertJson(getClass(), "show_infos.json");
- }
-
- @Test
- public void show_warnings() throws Exception {
- when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addWarnings(newArrayList("Some warning")));
-
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
- request.execute().assertJson(getClass(), "show_warnings.json");
- }
-
- @Test
- public void show_infos_and_warnings() throws Exception {
- when(qProfileBackup.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")).addWarnings(newArrayList("Some warning")));
-
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
- request.execute().assertJson(getClass(), "show_infos_and_warnings.json");
- }
-}
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.qualityprofile.QProfileBackup;
+import org.sonar.server.qualityprofile.RuleActivationService;
+import org.sonar.server.ws.WsTester;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class QProfilesWsTest {
+
+ WebService.Controller controller;
+
+ @Before
+ public void setUp() {
+ controller = new WsTester(new QProfilesWs(new QProfileRecreateBuiltInAction(mock(QProfileBackup.class)), new ActivateRuleAction(mock(RuleActivationService.class))))
+ .controller("api/qualityprofiles");
+ }
+
+ @Test
+ public void define_controller() throws Exception {
+ assertThat(controller).isNotNull();
+ assertThat(controller.path()).isEqualTo("api/qualityprofiles");
+ assertThat(controller.description()).isNotEmpty();
+ assertThat(controller.actions()).hasSize(2);
+ }
+
+ @Test
+ public void define_recreate_built_in_action() throws Exception {
+ WebService.Action restoreProfiles = controller.action("recreate_built_in");
+ assertThat(restoreProfiles).isNotNull();
+ assertThat(restoreProfiles.isPost()).isTrue();
+ assertThat(restoreProfiles.params()).hasSize(1);
+ }
+
+ @Test
+ public void define_activate_rule_in_action() throws Exception {
+ WebService.Action restoreProfiles = controller.action("activate_rule");
+ assertThat(restoreProfiles).isNotNull();
+ assertThat(restoreProfiles.isPost()).isTrue();
+ assertThat(restoreProfiles.params()).hasSize(6);
+ }
+
+}
--- /dev/null
+{"infos":["Some info"]}
--- /dev/null
+{
+ "infos": ["Some info"],
+ "warnings": ["Some warning"]
+}
--- /dev/null
+{"warnings":["Some warning"]}
+++ /dev/null
-{"infos":["Some info"]}
+++ /dev/null
-{
- "infos": ["Some info"],
- "warnings": ["Some warning"]
-}
+++ /dev/null
-{"warnings":["Some warning"]}