diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-05 19:07:42 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-02-05 19:10:17 +0100 |
commit | b58601cce773c23cdef9feb56e0cc486f000001a (patch) | |
tree | 1acd3da6c4cdaabb0e7375f5613beb3da418e079 /sonar-server | |
parent | f0e662a2b73e0e9ae70b005e7093c5c27fab24d8 (diff) | |
download | sonarqube-b58601cce773c23cdef9feb56e0cc486f000001a.tar.gz sonarqube-b58601cce773c23cdef9feb56e0cc486f000001a.zip |
SONAR-2501 a test plan can have multiple test cases with the same name (see TestNG)
Diffstat (limited to 'sonar-server')
4 files changed, 85 insertions, 10 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 5127fe218a8..082e08fb34f 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -325,7 +325,7 @@ public final class JRubyFacade { public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) { getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId], - RulePriority.values()[newSeverityId], userName); + RulePriority.values()[newSeverityId], userName); } public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) { @@ -521,10 +521,10 @@ public final class JRubyFacade { // notifier is null when creating the administrator in the migration script 011. if (notifier != null) { notifier.onNewUser(NewUserHandler.Context.builder() - .setLogin(fields.get("login")) - .setName(fields.get("name")) - .setEmail(fields.get("email")) - .build()); + .setLogin(fields.get("login")) + .setName(fields.get("name")) + .setEmail(fields.get("email")) + .build()); } } @@ -544,11 +544,15 @@ public final class JRubyFacade { return get(Periods.class).abbreviation(periodIndex); } - public TestPlan getTestPlan(long snapshotId) { + public TestPlan testPlan(long snapshotId) { return get(SnapshotPerspectives.class).as(MutableTestPlan.class, snapshotId); } - public Testable getTestable(long snapshotId) { + public TestPlan testPlan(String componentKey) { + return get(SnapshotPerspectives.class).as(MutableTestPlan.class, componentKey); + } + + public Testable testable(long snapshotId) { return get(SnapshotPerspectives.class).as(MutableTestable.class, snapshotId); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb new file mode 100644 index 00000000000..8c2eda47153 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb @@ -0,0 +1,71 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2012 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar 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. +# +# Sonar 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 Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# +class Api::TestsController < Api::ApiController + + # GET /api/tests/plan?resource=<test file id or key> + # + # Get the details of a given test plan : + # - test cases + # - resources covered by test cases + # + # Since v.3.5 + # + # ==== Examples + # - get the test plan defined by the file com/mycompany/FooTest.c of my_project : GET /api/tests/plan?resource=my_project:com/mycompany/FooTest.c + # + def plan + require_parameters :resource + + resource=Project.by_key(params[:resource]) + not_found("Not found: #{params[:resource]}") unless resource + access_denied unless has_role?(:user, resource) + + plan = java_facade.testPlan(resource.key) + json = {} + if plan + json[:type] = plan.type + json[:test_cases] = plan.testCases.map do |test_case| + test_case_json = {:name => test_case.name} + test_case_json[:message] = test_case.message if test_case.message + test_case_json[:durationInMs] = test_case.durationInMs if test_case.durationInMs + test_case_json[:status] = test_case.status.to_s if test_case.status + test_case_json[:stackTrace] = test_case.stackTrace if test_case.stackTrace + if test_case.doesCover() + test_case_json[:covers] = test_case.covers.map do |cover| + cover_json = {} + resource = cover.testable.component + cover_json[:resourceKey] = resource.key + cover_json[:resourceName] = resource.name + cover_json[:resourceQualifier] = resource.qualifier + cover_json[:lines] = cover.lines + cover_json + end + end + test_case_json + end + + respond_to do |format| + format.json { render :json => jsonp(json) } + format.xml { render :xml => xml_not_supported } + format.text { render :text => text_not_supported } + end + end + end +end
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index cd18218585d..4fb0999f00f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -205,7 +205,7 @@ class ResourceController < ApplicationController @conditions_by_line = load_distribution("#{it_prefix}conditions_by_line") @covered_conditions_by_line = load_distribution("#{it_prefix}covered_conditions_by_line") - @testable = java_facade.getTestable(@snapshot.id) + @testable = java_facade.testable(@snapshot.id) @hits_by_line.each_pair do |line_id, hits| line = @lines[line_id-1] if line diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/test_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/test_controller.rb index dfb93c79808..13bdc012ec7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/test_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/test_controller.rb @@ -25,7 +25,7 @@ class TestController < ApplicationController snapshot_id = params[:sid].to_i @test = params[:test].to_s - @test_plan = java_facade.getTestPlan(snapshot_id) + @test_plan = java_facade.testPlan(snapshot_id) @test_case = @test_plan.testCaseByKey(@test) render :partial => 'test/testcase_working_view' end @@ -36,7 +36,7 @@ class TestController < ApplicationController snapshot_id = params[:sid].to_i @line = params[:line].to_i - @testable = java_facade.getTestable(snapshot_id) + @testable = java_facade.testable(snapshot_id) @test_case_by_test_plan = {} @testable.testCasesOfLine(@line).each do |test_case| test_plan = test_case.testPlan |