From: Julien Lancelot Date: Tue, 6 May 2014 12:52:00 +0000 (+0200) Subject: SONAR-4764 Rename "Restore Default Profiles" by "Recreate Built-in Profiles" X-Git-Tag: 4.4-RC1~1188 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1d8f1252dc00a71cfa890dd9984a9bcab205d97c;p=sonarqube.git SONAR-4764 Rename "Restore Default Profiles" by "Recreate Built-in Profiles" --- diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 9ea0b618707..ffc8bc14b22 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1631,10 +1631,9 @@ quality_profiles.remove_projects_confirm_message=Are you sure that you want to d 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}'. #------------------------------------------------------------------------------ # diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index d0d64be9d18..e61d52791cd 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -115,7 +115,7 @@ import org.sonar.server.qualitygate.ws.*; 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.*; @@ -284,7 +284,7 @@ class ServerComponents { 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); diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackup.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackup.java index 624bfbfa349..e39857d4dc8 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackup.java @@ -138,10 +138,10 @@ public class QProfileBackup implements ServerComponent { } /** - * 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(); diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInAction.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInAction.java new file mode 100644 index 00000000000..3d0d0cb7b75 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInAction.java @@ -0,0 +1,78 @@ +/* + * 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(); + } + } + +} diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultAction.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultAction.java deleted file mode 100644 index 85520e219b7..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultAction.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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(); - } - } - -} diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java index 292e529d8bb..d3dc74ae334 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java @@ -23,20 +23,21 @@ import org.sonar.api.server.ws.WebService; 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(); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index a6f64601464..aba0138c600 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -59,9 +59,9 @@ class ProfilesController < ApplicationController redirect_to :action => 'index' end - # Modal window to restore default profiles - # GET /profiles/restore_default_form/ - def restore_default_form + # Modal window to recreate built-in profiles + # GET /profiles/recreate_built_in_form/ + def recreate_built_in_form verify_ajax_request require_parameters 'language' @language = java_facade.getLanguages().find { |l| l.getKey()==params[:language].to_s } @@ -70,15 +70,15 @@ class ProfilesController < ApplicationController 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= - def restore_default + # POST /profiles/recreate_built_in_form?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' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_recreate_built_in_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_recreate_built_in_form.html.erb new file mode 100644 index 00000000000..2f424ac06e8 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_recreate_built_in_form.html.erb @@ -0,0 +1,22 @@ +
+
+ + + + + + + +
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_default_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_default_form.html.erb deleted file mode 100644 index f650cfbecaa..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_default_form.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
-
- - - - - - - -
-
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb index f75e7cbf5bd..61f1e566309 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb @@ -29,8 +29,8 @@ <% end %> diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackupTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackupTest.java index 3a970d2a29e..689776e6444 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackupTest.java @@ -306,7 +306,7 @@ public class QProfileBackupTest { } @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"; @@ -324,7 +324,7 @@ public class QProfileBackupTest { 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)); @@ -336,7 +336,7 @@ public class QProfileBackupTest { } @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); @@ -354,7 +354,7 @@ public class QProfileBackupTest { 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)); @@ -366,7 +366,7 @@ public class QProfileBackupTest { } @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"; @@ -383,7 +383,7 @@ public class QProfileBackupTest { 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); @@ -393,14 +393,14 @@ public class QProfileBackupTest { } @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); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesMediumTest.java index 397cdc2ca22..91a0db112dd 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesMediumTest.java @@ -82,7 +82,7 @@ public class QProfilesMediumTest { } @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); @@ -106,7 +106,7 @@ public class QProfilesMediumTest { qProfiles.renameProfile(profile.id(), "Old Basic"); // Restore default profiles of xoo - qProfileBackup.restoreDefaultProfilesByLanguage("xoo"); + qProfileBackup.recreateBuiltInProfilesByLanguage("xoo"); // Reload profile profile = qProfiles.profile("Basic", "xoo"); @@ -123,14 +123,14 @@ public class QProfilesMediumTest { } @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"); diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest.java new file mode 100644 index 00000000000..0c66654af1e --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest.java @@ -0,0 +1,83 @@ +/* + * 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"); + } +} diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java deleted file mode 100644 index d68648cc57f..00000000000 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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"); - } -} diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java new file mode 100644 index 00000000000..d9d3feefd9b --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java @@ -0,0 +1,67 @@ +/* + * 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); + } + +} diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos.json b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos.json new file mode 100644 index 00000000000..b71854a2def --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos.json @@ -0,0 +1 @@ +{"infos":["Some info"]} diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos_and_warnings.json b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos_and_warnings.json new file mode 100644 index 00000000000..49b287019d0 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos_and_warnings.json @@ -0,0 +1,4 @@ +{ + "infos": ["Some info"], + "warnings": ["Some warning"] +} diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_warnings.json b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_warnings.json new file mode 100644 index 00000000000..256ac20abf9 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_warnings.json @@ -0,0 +1 @@ +{"warnings":["Some warning"]} diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos.json b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos.json deleted file mode 100644 index b71854a2def..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos.json +++ /dev/null @@ -1 +0,0 @@ -{"infos":["Some info"]} diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos_and_warnings.json b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos_and_warnings.json deleted file mode 100644 index 49b287019d0..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos_and_warnings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "infos": ["Some info"], - "warnings": ["Some warning"] -} diff --git a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_warnings.json b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_warnings.json deleted file mode 100644 index 256ac20abf9..00000000000 --- a/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_warnings.json +++ /dev/null @@ -1 +0,0 @@ -{"warnings":["Some warning"]}