aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-06 14:52:00 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-05-06 14:52:11 +0200
commit1d8f1252dc00a71cfa890dd9984a9bcab205d97c (patch)
tree44d224f8f4a7d312d9053a0924fc117ba5fbcfb0
parent1c6019e505d59ca9fa1dcf8825ac6289adc4a74f (diff)
downloadsonarqube-1d8f1252dc00a71cfa890dd9984a9bcab205d97c.tar.gz
sonarqube-1d8f1252dc00a71cfa890dd9984a9bcab205d97c.zip
SONAR-4764 Rename "Restore Default Profiles" by "Recreate Built-in Profiles"
-rw-r--r--sonar-core/src/main/resources/org/sonar/l10n/core.properties7
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackup.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInAction.java (renamed from sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultAction.java)13
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWs.java11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_recreate_built_in_form.html.erb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_restore_default_form.html.erb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackupTest.java16
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesMediumTest.java8
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest.java (renamed from sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java)20
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java67
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos.json (renamed from sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos.json)0
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos_and_warnings.json (renamed from sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_infos_and_warnings.json)0
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_warnings.json (renamed from sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest/show_warnings.json)0
16 files changed, 140 insertions, 72 deletions
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/QProfileRestoreDefaultAction.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInAction.java
index 85520e219b7..3d0d0cb7b75 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultAction.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInAction.java
@@ -28,28 +28,29 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.server.qualityprofile.QProfileBackup;
import org.sonar.server.qualityprofile.QProfileResult;
-public class QProfileRestoreDefaultAction implements RequestHandler {
+public class QProfileRecreateBuiltInAction implements RequestHandler {
private final QProfileBackup qProfileBackup;
- public QProfileRestoreDefaultAction(QProfileBackup qProfileBackup) {
+ public QProfileRecreateBuiltInAction(QProfileBackup qProfileBackup) {
this.qProfileBackup = qProfileBackup;
}
void define(WebService.NewController controller){
- WebService.NewAction restoreDefault = controller.createAction("restore_default")
- .setDescription("Restore default profiles")
+ WebService.NewAction restoreDefault = controller.createAction("recreate_built_in")
+ .setDescription("Recreate Built-in Profiles")
.setSince("4.4")
+ .setPost(true)
.setHandler(this);
restoreDefault.createParam("language")
- .setDescription("Restore default profiles for this 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.restoreDefaultProfilesByLanguage(language);
+ QProfileResult result = qProfileBackup.recreateBuiltInProfilesByLanguage(language);
if (!result.infos().isEmpty() || !result.warnings().isEmpty()) {
JsonWriter json = response.newJsonWriter();
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/<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 }
@@ -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=<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'
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 @@
+<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>
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 @@
-<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>
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 @@
</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 %>
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/QProfileRestoreDefaultActionTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest.java
index d68648cc57f..0c66654af1e 100644
--- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRestoreDefaultActionTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest.java
@@ -35,7 +35,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
-public class QProfileRestoreDefaultActionTest {
+public class QProfileRecreateBuiltInActionTest {
@Mock
QProfileBackup qProfileBackup;
@@ -45,39 +45,39 @@ public class QProfileRestoreDefaultActionTest {
@Before
public void setUp() throws Exception {
tester = new WsTester(new QProfilesWs(
- new QProfileRestoreDefaultAction(qProfileBackup),
+ new QProfileRecreateBuiltInAction(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());
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult());
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
+ 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.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")));
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")));
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
+ 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.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addWarnings(newArrayList("Some warning")));
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addWarnings(newArrayList("Some warning")));
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
+ 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.restoreDefaultProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")).addWarnings(newArrayList("Some warning")));
+ when(qProfileBackup.recreateBuiltInProfilesByLanguage("java")).thenReturn(new QProfileResult().addInfos(newArrayList("Some info")).addWarnings(newArrayList("Some warning")));
- WsTester.TestRequest request = tester.newPostRequest("api/qualityprofiles", "restore_default").setParam("language", "java");
+ 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/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/QProfileRestoreDefaultActionTest/show_infos.json b/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileRecreateBuiltInActionTest/show_infos.json
index b71854a2def..b71854a2def 100644
--- 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/QProfileRecreateBuiltInActionTest/show_infos.json
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/QProfileRecreateBuiltInActionTest/show_infos_and_warnings.json
index 49b287019d0..49b287019d0 100644
--- 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/QProfileRecreateBuiltInActionTest/show_infos_and_warnings.json
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/QProfileRecreateBuiltInActionTest/show_warnings.json
index 256ac20abf9..256ac20abf9 100644
--- 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/QProfileRecreateBuiltInActionTest/show_warnings.json