@@ -59,7 +59,7 @@ | |||
test_case[:name] = test.name() | |||
test_case[:status] = test.status() | |||
test_case[:time] = test.durationInMs() | |||
has_covered_lines = test.hasCoveredLines() | |||
has_covered_lines = test.doesCover() | |||
test_case[:covered_lines] = test.countCoveredLines() if has_covered_lines | |||
if test.status() != 'ok' | |||
test_case[:message] = '' |
@@ -45,4 +45,9 @@ public class ComponentVertex extends BeanVertex implements Component { | |||
setProperty("rid", ((ResourceComponent) component).resourceId()); | |||
} | |||
} | |||
@Override | |||
public String toString() { | |||
return key(); | |||
} | |||
} |
@@ -23,6 +23,7 @@ import com.tinkerpop.blueprints.Edge; | |||
import com.tinkerpop.blueprints.Element; | |||
import com.tinkerpop.blueprints.Graph; | |||
import com.tinkerpop.blueprints.Vertex; | |||
import com.tinkerpop.blueprints.impls.tg.TinkerGraph; | |||
import com.tinkerpop.blueprints.util.ElementHelper; | |||
public class BeanGraph { | |||
@@ -34,6 +35,10 @@ public class BeanGraph { | |||
this.beans = new BeanElements(); | |||
} | |||
public static BeanGraph createInMemory() { | |||
return new BeanGraph(new TinkerGraph()); | |||
} | |||
public final <T extends BeanElement> T wrap(Element element, Class<T> beanClass) { | |||
return beans.wrap(element, beanClass, this); | |||
} |
@@ -32,7 +32,10 @@ public class GraphWriter { | |||
public String write(Graph graph) { | |||
StringWriter output = new StringWriter(); | |||
try { | |||
new GraphsonWriter().write(graph, output, GraphsonMode.COMPACT); | |||
new GraphsonWriter().write(graph, output, GraphsonMode.EXTENDED); | |||
System.out.println("------------------------------------------------"); | |||
System.out.println(output.toString()); | |||
System.out.println("------------------------------------------------"); | |||
return output.toString(); | |||
} finally { | |||
IOUtils.closeQuietly(output); |
@@ -21,13 +21,10 @@ package org.sonar.core.graph.graphson; | |||
import com.tinkerpop.blueprints.Graph; | |||
import com.tinkerpop.blueprints.Vertex; | |||
import com.tinkerpop.blueprints.util.wrappers.batch.BatchGraph; | |||
import org.json.simple.JSONArray; | |||
import org.json.simple.JSONObject; | |||
import org.json.simple.parser.JSONParser; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.io.Reader; | |||
import java.util.Set; | |||
@@ -37,7 +34,7 @@ import java.util.Set; | |||
public class GraphsonReader { | |||
public Graph read(Reader jsonInput, Graph toGraph) { | |||
return read(jsonInput, toGraph, 1000, null, null); | |||
return read(jsonInput, toGraph, null, null); | |||
} | |||
/** | |||
@@ -45,20 +42,16 @@ public class GraphsonReader { | |||
* More control over how data is streamed is provided by this method. | |||
* | |||
* @param toGraph the graph to populate with the JSON data | |||
* @param input an InputStream of JSON data | |||
* @param input an InputStream of JSON data | |||
* @param bufferSize the amount of elements to hold in memory before committing a transactions (only valid for TransactionalGraphs) | |||
*/ | |||
public Graph read(Reader input, Graph toGraph, int bufferSize, Set<String> edgePropertyKeys, Set<String> vertexPropertyKeys) { | |||
public Graph read(Reader input, Graph toGraph, Set<String> edgePropertyKeys, Set<String> vertexPropertyKeys) { | |||
try { | |||
JSONParser parser = new JSONParser(); | |||
JSONObject json = (JSONObject) parser.parse(input); | |||
// if this is a transactional graph then we're buffering | |||
final BatchGraph batchGraph = BatchGraph.wrap(toGraph, bufferSize); | |||
ElementFactory elementFactory = new ElementFactory(batchGraph); | |||
final GraphsonMode mode = GraphsonMode.valueOf(json.get(GraphsonTokens.MODE).toString()); | |||
ElementFactory elementFactory = new ElementFactory(toGraph); | |||
GraphsonMode mode = GraphsonMode.valueOf(json.get(GraphsonTokens.MODE).toString()); | |||
GraphsonUtil graphson = new GraphsonUtil(mode, elementFactory, vertexPropertyKeys, edgePropertyKeys); | |||
JSONArray vertices = (JSONArray) json.get(GraphsonTokens.VERTICES); | |||
@@ -69,11 +62,11 @@ public class GraphsonReader { | |||
JSONArray edges = (JSONArray) json.get(GraphsonTokens.EDGES); | |||
for (Object edgeObject : edges) { | |||
JSONObject edge = (JSONObject) edgeObject; | |||
final Vertex inV = batchGraph.getVertex(edge.get(GraphsonTokens._IN_V)); | |||
final Vertex outV = batchGraph.getVertex(edge.get(GraphsonTokens._OUT_V)); | |||
Vertex inV = toGraph.getVertex(edge.get(GraphsonTokens._IN_V)); | |||
Vertex outV = toGraph.getVertex(edge.get(GraphsonTokens._OUT_V)); | |||
graphson.edgeFromJson(edge, outV, inV); | |||
} | |||
batchGraph.shutdown(); | |||
toGraph.shutdown(); | |||
return toGraph; | |||
} catch (Exception e) { | |||
throw new GraphsonException("Unable to parse GraphSON", e); |
@@ -630,7 +630,7 @@ class GraphsonUtil { | |||
Set<String> propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys; | |||
ElementPropertiesRule elementPropertyConfig = isEdge ? this.edgePropertiesRule : this.vertexPropertiesRule; | |||
org.json.simple.JSONObject jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig), propertyKeys, showTypes); | |||
JSONObject jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig), propertyKeys, showTypes); | |||
if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) { | |||
putObject(jsonElement, GraphsonTokens._ID, element.getId()); |
@@ -0,0 +1,43 @@ | |||
/* | |||
* Sonar, open source software quality management 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 | |||
*/ | |||
package org.sonar.core.test; | |||
import com.tinkerpop.blueprints.Direction; | |||
import org.sonar.api.test.Cover; | |||
import org.sonar.api.test.TestCase; | |||
import org.sonar.api.test.Testable; | |||
import org.sonar.core.graph.BeanEdge; | |||
import java.util.List; | |||
public class DefaultCover extends BeanEdge implements Cover { | |||
public TestCase testCase() { | |||
return getVertex(DefaultTestCase.class, Direction.OUT); | |||
} | |||
public Testable testable() { | |||
return getVertex(DefaultTestable.class, Direction.IN); | |||
} | |||
public List<Integer> lines() { | |||
return (List<Integer>) getProperty("lines"); | |||
} | |||
} |
@@ -19,12 +19,10 @@ | |||
*/ | |||
package org.sonar.core.test; | |||
import com.google.common.base.Preconditions; | |||
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.CoveredTestable; | |||
import org.sonar.api.test.exception.IllegalDurationException; | |||
import org.sonar.api.test.MutableTestCase; | |||
import org.sonar.api.test.TestPlan; | |||
import org.sonar.api.test.Testable; | |||
@@ -33,21 +31,18 @@ import org.sonar.core.graph.GraphUtil; | |||
import javax.annotation.Nullable; | |||
import java.util.Collection; | |||
import java.util.List; | |||
public class DefaultTestCase extends BeanVertex implements MutableTestCase { | |||
public String type() { | |||
return (String) getProperty("type"); | |||
} | |||
public Long durationInMs() { | |||
return (Long) getProperty("duration"); | |||
} | |||
public MutableTestCase setDurationInMs(@Nullable Long l) { | |||
Preconditions.checkArgument(l == null || l >= 0, String.format("Duration must be positive (got %d)", l)); | |||
if (l != null && l < 0) { | |||
throw new IllegalDurationException("Test duration must be positive (got: " + l + ")"); | |||
} | |||
setProperty("duration", l); | |||
return this; | |||
} | |||
@@ -100,9 +95,8 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { | |||
return this; | |||
} | |||
public void covers(Testable testable, List<Integer> lines) { | |||
BeanVertex testableVertex = ((BeanVertex) testable); | |||
beanGraph().getUnderlyingGraph().addEdge(null, element(), testableVertex.element(), "covers").setProperty("lines", lines); | |||
public void setCover(Testable testable, List<Integer> lines) { | |||
beanGraph().getUnderlyingGraph().addEdge(null, element(), ((BeanVertex) testable).element(), "covers").setProperty("lines", lines); | |||
} | |||
public TestPlan testPlan() { | |||
@@ -110,43 +104,20 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { | |||
return beanGraph().wrap(plan, DefaultTestPlan.class); | |||
} | |||
public boolean hasCoveredLines(){ | |||
return Iterables.size(element().getEdges(Direction.OUT, "covers")) > 0; | |||
public boolean doesCover() { | |||
return element().getEdges(Direction.OUT, "covers").iterator().hasNext(); | |||
} | |||
public int countCoveredLines() { | |||
int coveredBlocks = 0; | |||
for (Edge edge : element().getEdges(Direction.OUT, "covers")){ | |||
int result = 0; | |||
for (Edge edge : element().getEdges(Direction.OUT, "covers")) { | |||
List<Integer> lines = (List<Integer>) edge.getProperty("lines"); | |||
coveredBlocks = coveredBlocks + lines.size(); | |||
result = result + lines.size(); | |||
} | |||
return coveredBlocks; | |||
} | |||
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; | |||
return result; | |||
} | |||
@Override | |||
public int hashCode() { | |||
return key() != null ? key().hashCode() : 0; | |||
public Iterable covers() { | |||
return getEdges(DefaultCover.class, Direction.OUT, "covers"); | |||
} | |||
} |
@@ -19,17 +19,17 @@ | |||
*/ | |||
package org.sonar.core.test; | |||
import com.google.common.collect.Lists; | |||
import com.tinkerpop.blueprints.Direction; | |||
import com.tinkerpop.blueprints.Vertex; | |||
import org.sonar.api.component.Component; | |||
import org.sonar.api.test.exception.TestCaseAlreadyExistsException; | |||
import org.sonar.api.test.MutableTestCase; | |||
import org.sonar.api.test.MutableTestPlan; | |||
import org.sonar.core.component.ComponentVertex; | |||
import org.sonar.core.graph.BeanVertex; | |||
import org.sonar.core.graph.GraphUtil; | |||
import java.util.List; | |||
import javax.annotation.CheckForNull; | |||
public class DefaultTestPlan extends BeanVertex implements MutableTestPlan { | |||
public Component component() { | |||
@@ -37,17 +37,36 @@ public class DefaultTestPlan extends BeanVertex implements MutableTestPlan { | |||
return beanGraph().wrap(component, ComponentVertex.class); | |||
} | |||
public String type() { | |||
return (String) getProperty("type"); | |||
} | |||
public MutableTestPlan setType(String s) { | |||
setProperty("type", s); | |||
return this; | |||
} | |||
@CheckForNull | |||
public MutableTestCase testCaseByKey(String key) { | |||
for (MutableTestCase testCase : testCases()) { | |||
if (key.equals(testCase.key())) { | |||
return testCase; | |||
} | |||
} | |||
return null; | |||
} | |||
public MutableTestCase addTestCase(String key) { | |||
if (testCaseByKey(key)!=null) { | |||
throw new TestCaseAlreadyExistsException(component().key(), key); | |||
} | |||
DefaultTestCase testCase = beanGraph().createAdjacentVertex(this, DefaultTestCase.class, "testcase"); | |||
testCase.setKey(key); | |||
return testCase; | |||
} | |||
public List<MutableTestCase> testCases() { | |||
List<MutableTestCase> testCases = Lists.newArrayList(); | |||
for (Vertex testCaseVertex : element().getVertices(Direction.OUT, "testcase")) { | |||
testCases.add(beanGraph().wrap(testCaseVertex, DefaultTestCase.class)); | |||
} | |||
return testCases; | |||
public Iterable<MutableTestCase> testCases() { | |||
return (Iterable) getVertices(DefaultTestCase.class, Direction.OUT, "testcase"); | |||
} | |||
} |
@@ -32,12 +32,9 @@ import org.sonar.core.component.ComponentVertex; | |||
import org.sonar.core.graph.BeanVertex; | |||
import org.sonar.core.graph.GraphUtil; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import java.util.SortedSet; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
public class DefaultTestable extends BeanVertex implements MutableTestable { | |||
public Component component() { | |||
@@ -45,29 +42,30 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { | |||
return beanGraph().wrap(component, ComponentVertex.class); | |||
} | |||
public Collection<TestCase> testCases() { | |||
List<TestCase> testCases = newArrayList(); | |||
for (Edge edge : getCovers()) { | |||
Vertex testable = edge.getVertex(Direction.OUT); | |||
testCases.add(beanGraph().wrap(testable, DefaultTestCase.class)); | |||
public List<TestCase> testCases() { | |||
ImmutableList.Builder<TestCase> cases = ImmutableList.builder(); | |||
for (Edge coversEdge : getCovers()) { | |||
Vertex testable = coversEdge.getVertex(Direction.OUT); | |||
cases.add(beanGraph().wrap(testable, DefaultTestCase.class)); | |||
} | |||
return testCases; | |||
return cases.build(); | |||
} | |||
public int countTestCasesOfLine(int line) { | |||
int number = 0; | |||
// TODO filter on edge | |||
for (Edge edge : getCovers()) { | |||
if (Iterables.contains(testedLines(edge), Long.valueOf(line))) { | |||
if (Iterables.contains(lines(edge), line)) { | |||
number++; | |||
} | |||
} | |||
return number; | |||
} | |||
public Collection<TestCase> testCasesOfLine(int line) { | |||
public List<TestCase> testCasesOfLine(int line) { | |||
ImmutableList.Builder<TestCase> cases = ImmutableList.builder(); | |||
for (Edge edge : getCovers()) { | |||
if (Iterables.contains(testedLines(edge), Long.valueOf(line))) { | |||
if (lines(edge).contains(line)) { | |||
Vertex vertexTestable = edge.getVertex(Direction.OUT); | |||
DefaultTestCase testCase = beanGraph().wrap(vertexTestable, DefaultTestCase.class); | |||
cases.add(testCase); | |||
@@ -76,10 +74,10 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { | |||
return cases.build(); | |||
} | |||
public SortedSet<Long> testedLines() { | |||
ImmutableSortedSet.Builder<Long> coveredLines = ImmutableSortedSet.naturalOrder(); | |||
public SortedSet<Integer> testedLines() { | |||
ImmutableSortedSet.Builder<Integer> coveredLines = ImmutableSortedSet.naturalOrder(); | |||
for (Edge edge : getCovers()) { | |||
coveredLines.addAll(testedLines(edge)); | |||
coveredLines.addAll(lines(edge)); | |||
} | |||
return coveredLines.build(); | |||
} | |||
@@ -88,8 +86,8 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { | |||
return element().getEdges(Direction.IN, "covers"); | |||
} | |||
private List<Long> testedLines(Edge edge) { | |||
return (List<Long>) edge.getProperty("lines"); | |||
private List<Integer> lines(Edge edge) { | |||
return (List<Integer>) edge.getProperty("lines"); | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
/* | |||
* Sonar, open source software quality management 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 | |||
*/ | |||
package org.sonar.core.test; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.test.exception.IllegalDurationException; | |||
import org.sonar.api.test.TestCase; | |||
import org.sonar.core.graph.BeanGraph; | |||
import java.util.Arrays; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
public class DefaultTestCaseTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void no_coverage_data() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); | |||
assertThat(testCase.doesCover()).isFalse(); | |||
assertThat(testCase.countCoveredLines()).isEqualTo(0); | |||
assertThat(testCase.covers()).isEmpty(); | |||
} | |||
@Test | |||
public void should_cover_testables() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestable testable1 = beanGraph.createVertex(DefaultTestable.class); | |||
DefaultTestable testable2 = beanGraph.createVertex(DefaultTestable.class); | |||
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase.setCover(testable1, Arrays.asList(10, 11, 12)); | |||
testCase.setCover(testable2, Arrays.asList(12, 13, 14)); | |||
assertThat(testCase.doesCover()).isTrue(); | |||
assertThat(testCase.countCoveredLines()).isEqualTo(6); | |||
assertThat(testCase.covers()).hasSize(2); | |||
} | |||
@Test | |||
public void should_set_metadata() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase.setKey("T1") | |||
.setName("Test one") | |||
.setDurationInMs(1234L) | |||
.setMessage("Error msg") | |||
.setStackTrace("xxx") | |||
.setStatus(TestCase.STATUS_FAIL); | |||
assertThat(testCase.key()).isEqualTo("T1"); | |||
assertThat(testCase.name()).isEqualTo("Test one"); | |||
assertThat(testCase.message()).isEqualTo("Error msg"); | |||
assertThat(testCase.stackTrace()).isEqualTo("xxx"); | |||
assertThat(testCase.durationInMs()).isEqualTo(1234L); | |||
assertThat(testCase.status()).isEqualTo(TestCase.STATUS_FAIL); | |||
} | |||
@Test | |||
public void duration_should_be_positive() { | |||
thrown.expect(IllegalDurationException.class); | |||
thrown.expectMessage("Test duration must be positive (got: -1234)"); | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase.setDurationInMs(-1234L); | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
/* | |||
* Sonar, open source software quality management 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 | |||
*/ | |||
package org.sonar.core.test; | |||
import com.google.common.collect.Iterables; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.test.exception.TestCaseAlreadyExistsException; | |||
import org.sonar.api.test.MutableTestCase; | |||
import org.sonar.api.test.TestPlan; | |||
import org.sonar.core.component.ComponentVertex; | |||
import org.sonar.core.graph.BeanGraph; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
public class DefaultTestPlanTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void should_not_have_test_cases() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); | |||
assertThat(plan.testCases()).isEmpty(); | |||
} | |||
@Test | |||
public void should_add_test_cases() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); | |||
plan.addTestCase("T1"); | |||
plan.addTestCase("T2"); | |||
assertThat(plan.testCases()).hasSize(2); | |||
assertThat(Iterables.<MutableTestCase>get(plan.testCases(), 0).key()).isEqualTo("T1"); | |||
assertThat(Iterables.<MutableTestCase>get(plan.testCases(), 1).key()).isEqualTo("T2"); | |||
} | |||
@Test | |||
public void should_find_test_case_by_key() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); | |||
plan.addTestCase("T1"); | |||
plan.addTestCase("T2"); | |||
assertThat(plan.testCaseByKey("T1").key()).isEqualTo("T1"); | |||
assertThat(plan.testCaseByKey("T3")).isNull(); | |||
} | |||
@Test | |||
public void should_set_type() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class); | |||
assertThat(plan.type()).isNull(); | |||
plan.setType(TestPlan.TYPE_UNIT); | |||
assertThat(plan.type()).isEqualTo(TestPlan.TYPE_UNIT); | |||
} | |||
@Test | |||
public void keys_of_test_cases_should_be_unique() { | |||
thrown.expect(TestCaseAlreadyExistsException.class); | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
ComponentVertex component = beanGraph.createVertex(ComponentVertex.class); | |||
DefaultTestPlan plan = beanGraph.createAdjacentVertex(component, DefaultTestPlan.class, "testplan"); | |||
plan.addTestCase("T1"); | |||
plan.addTestCase("T1"); | |||
} | |||
} |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.core.test; | |||
import com.tinkerpop.blueprints.impls.tg.TinkerGraph; | |||
import org.junit.Test; | |||
import org.sonar.core.graph.BeanGraph; | |||
@@ -29,23 +28,39 @@ import static org.fest.assertions.Assertions.assertThat; | |||
public class DefaultTestableTest { | |||
@Test | |||
public void no_covered_lines() { | |||
BeanGraph beanGraph = new BeanGraph(new TinkerGraph()); | |||
public void should_not_have_tested_lines() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); | |||
assertThat(testable.testedLines()).isEmpty(); | |||
} | |||
@Test | |||
public void covered_lines() { | |||
BeanGraph beanGraph = new BeanGraph(new TinkerGraph()); | |||
public void should_have_tested_lines() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); | |||
DefaultTestCase testCase1 = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase1.covers(testable, Arrays.asList(10, 11, 12)); | |||
testCase1.setCover(testable, Arrays.asList(10, 11, 12)); | |||
DefaultTestCase testCase2 = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase2.covers(testable, Arrays.asList(12, 48, 49)); | |||
testCase2.setCover(testable, Arrays.asList(12, 48, 49)); | |||
assertThat(testable.testedLines()).containsOnly(10, 11, 12, 48, 49); | |||
} | |||
@Test | |||
public void should_get_test_cases() { | |||
BeanGraph beanGraph = BeanGraph.createInMemory(); | |||
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class); | |||
DefaultTestCase testCase1 = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase1.setCover(testable, Arrays.asList(10, 11, 12)); | |||
DefaultTestCase testCase2 = beanGraph.createVertex(DefaultTestCase.class); | |||
testCase2.setCover(testable, Arrays.asList(12, 48, 49)); | |||
assertThat(testable.testCases()).containsOnly(testCase1, testCase2); | |||
assertThat(testable.testCasesOfLine(5)).isEmpty(); | |||
assertThat(testable.testCasesOfLine(10)).containsExactly(testCase1); | |||
assertThat(testable.testCasesOfLine(12)).contains(testCase1, testCase2); | |||
} | |||
} |
@@ -19,11 +19,13 @@ | |||
*/ | |||
package org.sonar.api.test; | |||
import java.util.Collection; | |||
import java.util.List; | |||
public interface CoveredTestable { | |||
public interface Cover { | |||
TestCase testCase(); | |||
Testable testable(); | |||
Collection<Integer> lines(); | |||
List<Integer> lines(); | |||
} |
@@ -34,5 +34,5 @@ public interface MutableTestCase extends TestCase { | |||
MutableTestCase setStackTrace(String s); | |||
void covers(Testable testable, List<Integer> lines); | |||
void setCover(Testable testable, List<Integer> lines); | |||
} |
@@ -23,6 +23,7 @@ import org.sonar.api.component.MutablePerspective; | |||
public interface MutableTestPlan extends TestPlan<MutableTestCase>, MutablePerspective { | |||
MutableTestCase addTestCase(String key); | |||
MutableTestPlan setType(String s); | |||
MutableTestCase addTestCase(String key); | |||
} |
@@ -19,18 +19,10 @@ | |||
*/ | |||
package org.sonar.api.test; | |||
import java.util.Collection; | |||
public interface TestCase { | |||
String TYPE_UNIT = "unit"; | |||
String TYPE_INTEGRATION = "integration"; | |||
String STATUS_PASS = "pass"; | |||
String STATUS_FAIL = "fail"; | |||
// unit test/integration test/... | |||
String type(); | |||
/** | |||
* Duration in milliseconds | |||
*/ | |||
@@ -52,9 +44,9 @@ public interface TestCase { | |||
TestPlan testPlan(); | |||
boolean hasCoveredLines(); | |||
boolean doesCover(); | |||
int countCoveredLines(); | |||
Collection<CoveredTestable> coveredTestable(); | |||
Iterable<Cover> covers(); | |||
} |
@@ -24,5 +24,13 @@ import org.sonar.api.component.Perspective; | |||
import java.util.List; | |||
public interface TestPlan<T extends TestCase> extends Perspective { | |||
List<T> testCases(); | |||
String TYPE_UNIT = "unit"; | |||
String TYPE_INTEGRATION = "integration"; | |||
// unit test/integration test/... | |||
String type(); | |||
Iterable<T> testCases(); | |||
T testCaseByKey(String key); | |||
} |
@@ -21,17 +21,17 @@ package org.sonar.api.test; | |||
import org.sonar.api.component.Perspective; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import java.util.SortedSet; | |||
public interface Testable extends Perspective { | |||
Collection<TestCase> testCases(); | |||
List<TestCase> testCases(); | |||
int countTestCasesOfLine(int line); | |||
Collection<TestCase> testCasesOfLine(int line); | |||
List<TestCase> testCasesOfLine(int line); | |||
SortedSet<Long> testedLines(); | |||
SortedSet<Integer> testedLines(); | |||
} |
@@ -0,0 +1,26 @@ | |||
/* | |||
* Sonar, open source software quality management 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 | |||
*/ | |||
package org.sonar.api.test.exception; | |||
public class IllegalDurationException extends TestException { | |||
public IllegalDurationException(String message) { | |||
super(message); | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
/* | |||
* Sonar, open source software quality management 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 | |||
*/ | |||
package org.sonar.api.test.exception; | |||
public class TestCaseAlreadyExistsException extends TestException { | |||
public TestCaseAlreadyExistsException(String componentKey, String testCaseKey) { | |||
super(String.format("Test case already exists for %s: %s", componentKey, testCaseKey)); | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
/* | |||
* Sonar, open source software quality management 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 | |||
*/ | |||
package org.sonar.api.test.exception; | |||
public class TestException extends RuntimeException { | |||
public TestException(String message) { | |||
super(message); | |||
} | |||
public TestException(String message, Throwable cause) { | |||
super(message, cause); | |||
} | |||
} |