@@ -1131,6 +1131,7 @@ overall_coverage_viewer.by=by all tests | |||
coverage_viewer.unit_tests=Unit Tests | |||
coverage_viewer.integration_tests=Integration Tests | |||
coverage_viewer.overall_tests=All Tests | |||
lines_covered_per_test=Lines covered per test | |||
#------------------------------------------------------------------------------ |
@@ -19,9 +19,12 @@ | |||
*/ | |||
package org.sonar.core.test; | |||
import com.google.common.base.Predicate; | |||
import com.google.common.collect.Iterables; | |||
import com.tinkerpop.blueprints.Direction; | |||
import com.tinkerpop.blueprints.Edge; | |||
import com.tinkerpop.blueprints.Vertex; | |||
import org.sonar.api.test.Cover; | |||
import org.sonar.api.test.MutableTestCase; | |||
import org.sonar.api.test.TestPlan; | |||
import org.sonar.api.test.Testable; | |||
@@ -120,4 +123,14 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { | |||
public Iterable covers() { | |||
return getEdges(DefaultCover.class, Direction.OUT, "covers"); | |||
} | |||
public Cover coverOfTestable(final Testable testable) { | |||
return Iterables.find(getEdges(DefaultCover.class, Direction.OUT, "covers"), new Predicate<Cover>() { | |||
public boolean apply(Cover input) { | |||
return input.testable().component().key().equals(testable.component().key()); | |||
} | |||
}, null); | |||
} | |||
} |
@@ -19,6 +19,7 @@ | |||
*/ | |||
package org.sonar.core.test; | |||
import com.google.common.base.Predicate; | |||
import com.google.common.collect.ImmutableList; | |||
import com.google.common.collect.ImmutableSortedSet; | |||
import com.google.common.collect.Iterables; | |||
@@ -51,6 +52,14 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { | |||
return cases.build(); | |||
} | |||
public TestCase testCaseByKey(final String key) { | |||
return Iterables.find(testCases(), new Predicate<TestCase>() { | |||
public boolean apply(TestCase input) { | |||
return input.key().equals(key); | |||
} | |||
}, null); | |||
} | |||
public int countTestCasesOfLine(int line) { | |||
int number = 0; | |||
// TODO filter on edge |
@@ -23,9 +23,12 @@ import com.google.common.collect.Iterables; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.component.mock.MockSourceFile; | |||
import org.sonar.api.test.Cover; | |||
import org.sonar.api.test.TestCase; | |||
import org.sonar.api.test.exception.IllegalDurationException; | |||
import org.sonar.core.component.ComponentVertex; | |||
import org.sonar.core.component.ScanGraph; | |||
import org.sonar.core.graph.BeanGraph; | |||
import java.util.Arrays; | |||
@@ -79,6 +82,25 @@ public class DefaultTestCaseTest { | |||
assertThat(testCase.covers()).hasSize(2); | |||
} | |||
@Test | |||
public void should_return_cover_of_testable(){ | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
ScanGraph graph = ScanGraph.create(); | |||
ComponentVertex file1 = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); | |||
DefaultTestable testable1 = beanGraph.createAdjacentVertex(file1, DefaultTestable.class, "testable"); | |||
ComponentVertex file2 = graph.addComponent(MockSourceFile.createMain("org.foo.File")); | |||
DefaultTestable testable2 = beanGraph.createAdjacentVertex(file2, DefaultTestable.class, "testable"); | |||
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase.setCover(testable1, Arrays.asList(10, 11, 12)); | |||
assertThat(testCase.coverOfTestable(testable1).testable()).isEqualTo(testable1); | |||
assertThat(testCase.coverOfTestable(testable1).testCase()).isEqualTo(testCase); | |||
assertThat(testCase.coverOfTestable(testable2)).isNull(); | |||
} | |||
@Test | |||
public void should_set_metadata() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); |
@@ -19,7 +19,9 @@ | |||
*/ | |||
package org.sonar.core.test; | |||
import com.google.common.collect.Iterables; | |||
import org.junit.Test; | |||
import org.sonar.api.test.MutableTestCase; | |||
import org.sonar.core.graph.BeanGraph; | |||
import java.util.Arrays; | |||
@@ -66,4 +68,23 @@ public class DefaultTestableTest { | |||
assertThat(testable.testCasesOfLine(10)).containsExactly(testCase1); | |||
assertThat(testable.testCasesOfLine(12)).contains(testCase1, testCase2); | |||
} | |||
@Test | |||
public void should_get_test_case_by_key() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); | |||
plan.addTestCase("T1"); | |||
plan.addTestCase("T2"); | |||
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); | |||
MutableTestCase testCase1 = Iterables.get(plan.testCases(), 0); | |||
testCase1.setCover(testable, Arrays.asList(10, 11, 12)); | |||
MutableTestCase testCase2 = Iterables.get(plan.testCases(), 1); | |||
testCase2.setCover(testable, Arrays.asList(12, 48, 49)); | |||
assertThat(testable.testCaseByKey("T1")).isEqualTo(testCase1); | |||
assertThat(testable.testCaseByKey("T2")).isEqualTo(testCase2); | |||
assertThat(testable.testCaseByKey("Unknown")).isNull(); | |||
} | |||
} |
@@ -49,4 +49,6 @@ public interface TestCase { | |||
int countCoveredLines(); | |||
Iterable<Cover> covers(); | |||
Cover coverOfTestable(Testable testable); | |||
} |
@@ -28,6 +28,8 @@ public interface Testable extends Perspective { | |||
List<TestCase> testCases(); | |||
TestCase testCaseByKey(String key); | |||
int countTestCasesOfLine(int line); | |||
List<TestCase> testCasesOfLine(int line); |
@@ -191,12 +191,12 @@ 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.getTestable(@snapshot.id) | |||
@hits_by_line.each_pair do |line_id, hits| | |||
line = @lines[line_id-1] | |||
if line | |||
line.covered_lines = 0 | |||
line.covered_lines = testable.countTestCasesOfLine(line_id) if testable | |||
line.covered_lines = @testable.countTestCasesOfLine(line_id) if @testable | |||
line.hits = hits.to_i | |||
line.conditions = @conditions_by_line[line_id].to_i | |||
line.covered_conditions = @covered_conditions_by_line[line_id].to_i | |||
@@ -248,6 +248,12 @@ class ResourceController < ApplicationController | |||
end | |||
end | |||
@test_case_filter = params[:test_case_filter] | |||
if @test_case_filter && @testable | |||
#lines = @testable.coverOfTestable(@testable.testCaseByKey(@test_case_filter)).lines | |||
#filter_lines { |line| lines.include? line } | |||
end | |||
render :action => 'index', :layout => !request.xhr? | |||
end | |||
@@ -20,7 +20,7 @@ | |||
class TestController < ApplicationController | |||
def working_view | |||
#verify_ajax_request | |||
verify_ajax_request | |||
require_parameters :sid, :value, :type | |||
type = params[:type].to_s | |||
snapshot_id = params[:sid].to_i |
@@ -91,6 +91,18 @@ | |||
<% end %> | |||
</select> | |||
</td> | |||
<% if @testable && !@testable.testCases.empty? %> | |||
<td class="<%= 'first' if first -%>"> | |||
<select id="test_case_filter" name="test_case_filter" onchange="applyOptions()"> | |||
<option value=""><%= message('lines_covered_per_test') -%></option> | |||
<% @testable.testCases.each do |test_case| %> | |||
<option value="<%= test_case.key -%>" <%= 'selected' if @test_case_filter==test_case.key -%>><%= test_case.name -%></option> | |||
<% end %> | |||
</select> | |||
</td> | |||
<% end %> | |||
<% first=false | |||
end %> | |||
</tr> |