import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.test.CoveredTestable;
import org.sonar.api.test.MutableTestCase;
import org.sonar.api.test.TestPlan;
public class DefaultTestCase extends BeanVertex implements MutableTestCase {
- private static final Logger LOG = LoggerFactory.getLogger(DefaultTestCase.class);
-
public String type() {
return (String) getProperty("type");
}
}
public void covers(Testable testable, List<Integer> lines) {
- LOG.info("Covers : " + testable.component().key(), " on "+ lines);
-
Vertex componentVertex = GraphUtil.single(beanGraph().getUnderlyingGraph().getVertices("key", testable.component().key()));
beanGraph().getUnderlyingGraph().addEdge(null, element(), componentVertex, "covers").setProperty("lines", lines);
}
public Collection<CoveredTestable> coveredTestable() {
return null;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ DefaultTestCase that = (DefaultTestCase) o;
+
+ if (key() != null ? !key().equals(that.key()) : that.key() != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return key() != null ? key().hashCode() : 0;
+ }
}
*/
package org.sonar.core.test;
+import com.google.common.collect.Iterables;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import org.sonar.core.graph.BeanVertex;
import org.sonar.core.graph.GraphUtil;
+import java.util.Collection;
import java.util.List;
+import java.util.Set;
import java.util.SortedSet;
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Sets.newHashSet;
import static com.google.common.collect.Sets.newTreeSet;
public class DefaultTestable extends BeanVertex implements MutableTestable {
return beanGraph().wrap(component, ComponentVertex.class);
}
- public List<TestCase> coveringTestCases() {
- return null;
+ public Collection<TestCase> coveringTestCases() {
+ List<TestCase> testCases = newArrayList();
+ for (Edge edge : element().getEdges(Direction.IN, "covers")){
+ Vertex testable = edge.getVertex(Direction.OUT);
+ testCases.add(beanGraph().wrap(testable, DefaultTestCase.class));
+ }
+ return testCases;
}
- public List<TestCase> testCasesCoveringLine(int line) {
- return null;
+ public Collection<TestCase> testCasesCoveringLine(int line) {
+ Set<TestCase> testCases = newHashSet();
+ for (Edge edge : element().getEdges(Direction.IN, "covers")){
+ if (Iterables.contains( (List<Integer>) edge.getProperty("lines"), line)){
+ Vertex testable = edge.getVertex(Direction.OUT);
+ testCases.add(beanGraph().wrap(testable, DefaultTestCase.class));
+ }
+ }
+ return testCases;
}
public SortedSet<Integer> coveredLines() {
import org.sonar.api.component.Perspective;
-import java.util.List;
+import java.util.Collection;
import java.util.SortedSet;
public interface Testable extends Perspective {
- List<TestCase> coveringTestCases();
+ Collection<TestCase> coveringTestCases();
- List<TestCase> testCasesCoveringLine(int line);
+ Collection<TestCase> testCasesCoveringLine(int line);
SortedSet<Integer> coveredLines();
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.test.MutableTestPlan;
+import org.sonar.api.test.MutableTestable;
import org.sonar.api.test.TestPlan;
+import org.sonar.api.test.Testable;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.api.web.Footer;
import org.sonar.api.web.NavigationSection;
return get(SnapshotPerspectives.class).as(MutableTestPlan.class, snapshotId);
}
+ public Testable getTestable(long snapshotId) {
+ return get(SnapshotPerspectives.class).as(MutableTestable.class, snapshotId);
+ }
+
}
@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)
@hits_by_line.each_pair do |line_id, hits|
line = @lines[line_id-1]
if line
+ line.covered_lines = testable.testCasesCoveringLine(line_id).size if testable && testable.testCasesCoveringLine(line_id).size > 0
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
end
class Line
- attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :highlighted, :deprecated_conditions_label
+ attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :highlighted, :deprecated_conditions_label, :covered_lines
def initialize(source)
@source=source
<% if @display_coverage %>
<% if line.highlighted? %>
- <td class="ind <%= hits_status -%>"><%= line.hits -%></td>
+ <td class="ind <%= hits_status -%>"><%= line.covered_lines if line.covered_lines -%></td>
<td class="ind <%= conditions_status -%>">
<% if line.deprecated_conditions_label -%>
<%= line.deprecated_conditions_label -%>