diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-28 17:13:22 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-28 17:13:22 +0100 |
commit | 2067476497ed6aff6a0f71599428a554a98a694d (patch) | |
tree | 907e7c54099daa0bb0e1f391b238117639ca2444 /sonar-core | |
parent | b0ef7836c2492c3c9cc4a0fc0873064815bf6897 (diff) | |
download | sonarqube-2067476497ed6aff6a0f71599428a554a98a694d.tar.gz sonarqube-2067476497ed6aff6a0f71599428a554a98a694d.zip |
SONAR-2501 Add message and stackTrace to TestCase
Diffstat (limited to 'sonar-core')
4 files changed, 40 insertions, 38 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java index 203b25f9aee..c303226de0d 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java +++ b/sonar-core/src/main/java/org/sonar/core/component/PerspectiveLoaders.java @@ -19,21 +19,29 @@ */ package org.sonar.core.component; +import com.google.common.collect.Maps; import org.sonar.api.ServerComponent; import org.sonar.api.component.Perspective; +import org.sonar.api.test.MutableTestPlan; +import org.sonar.api.test.MutableTestable; import org.sonar.core.graph.GraphDao; import org.sonar.core.graph.GraphDto; -import org.sonar.core.test.DefaultTestPlan; -import org.sonar.core.test.DefaultTestable; import javax.annotation.CheckForNull; +import java.util.Map; + public class PerspectiveLoaders implements ServerComponent { private final GraphDao dao; + private Map<Class<?>, PerspectiveBuilder<?>> builders = Maps.newHashMap(); - public PerspectiveLoaders(GraphDao dao) { + public PerspectiveLoaders(GraphDao dao, PerspectiveBuilder[] builders) { this.dao = dao; + for (PerspectiveBuilder builder : builders) { + // TODO check duplications + this.builders.put(builder.getPerspectiveClass(), builder); + } } @CheckForNull @@ -52,10 +60,11 @@ public class PerspectiveLoaders implements ServerComponent { Perspective result = null; if (graphDto != null) { ComponentGraph graph = new GraphReader().read(graphDto.getData(), graphDto.getRootVertexId()); + ComponentWrapper componentWrapper = graph.wrap(graph.getRootVertex(), ComponentWrapper.class); if (perspectiveKey.equals("testplan")) { - result = graph.wrap(graph.getRootVertex(), DefaultTestPlan.class); + result = builders.get(MutableTestPlan.class).load(componentWrapper); } else if (perspectiveKey.equals("testable")) { - result = graph.wrap(graph.getRootVertex(), DefaultTestable.class); + result = builders.get(MutableTestable.class).load(componentWrapper); } } return result; diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java index a7fc0355e88..ef7e27e0f3f 100644 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java +++ b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java @@ -102,7 +102,7 @@ class GraphsonUtil { } /** - * Creates a Jettison JSONObject from a graph element. + * Creates a JSONObject from a graph element. * * @param element the graph element to convert to JSON. * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized. @@ -115,22 +115,9 @@ class GraphsonUtil { } /** - * Creates a Jackson ObjectNode from a graph element. - * - * @param element the graph element to convert to JSON. - * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized. - * @param mode The type of GraphSON to generate. - */ - static JSONObject objectNodeFromElement(Element element, Set<String> propertyKeys, GraphsonMode mode) { - GraphsonUtil graphson = element instanceof Edge ? new GraphsonUtil(mode, null, null, propertyKeys) - : new GraphsonUtil(mode, null, propertyKeys, null); - return graphson.objectNodeFromElement(element); - } - - /** * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format. * - * @param json a single vertex in GraphSON format as Jettison JSONObject + * @param json a single vertex in GraphSON format as JSONObject * @param factory the factory responsible for constructing graph elements * @param mode the mode of the GraphSON * @param propertyKeys a list of keys to include on reading of element properties @@ -233,7 +220,7 @@ class GraphsonUtil { /** * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format. * - * @param json a single edge in GraphSON format as a Jackson JsonNode + * @param json a single edge in GraphSON format as a JSONObject * @param factory the factory responsible for constructing graph elements * @param mode the mode of the GraphSON * @param propertyKeys a list of keys to include when reading of element properties @@ -269,7 +256,7 @@ class GraphsonUtil { JSONArray jsonList = new JSONArray(); for (Object item : list) { if (item instanceof Element) { - jsonList.add(objectNodeFromElement((Element) item, propertyKeys, + jsonList.add(jsonFromElement((Element) item, propertyKeys, showTypes ? GraphsonMode.EXTENDED : GraphsonMode.NORMAL)); } else if (item instanceof List) { jsonList.add(createJSONList((List) item, propertyKeys, showTypes)); @@ -295,7 +282,7 @@ class GraphsonUtil { } else if (value instanceof Map) { value = createJSONMap((Map) value, propertyKeys, showTypes); } else if (value instanceof Element) { - value = objectNodeFromElement((Element) value, propertyKeys, + value = jsonFromElement((Element) value, propertyKeys, showTypes ? GraphsonMode.EXTENDED : GraphsonMode.NORMAL); } else if (value.getClass().isArray()) { value = createJSONList(convertArrayToList(value), propertyKeys, showTypes); @@ -591,7 +578,6 @@ class GraphsonUtil { Edge edgeFromJson(JSONObject json, Vertex out, Vertex in) throws IOException { Map<String, Object> props = GraphsonUtil.readProperties(json, true, this.hasEmbeddedTypes); -// Object edgeId = getTypedValueFromJsonNode(json.get(GraphsonTokens._ID)); Object edgeId = json.get(GraphsonTokens._ID); Object nodeLabel = json.get(GraphsonTokens._LABEL); @@ -600,7 +586,6 @@ class GraphsonUtil { Edge e = factory.createEdge(edgeId, out, in, label); for (Map.Entry<String, Object> entry : props.entrySet()) { - // if (this.edgePropertyKeys == null || this.edgePropertyKeys.contains(entry.getKey())) { if (includeKey(entry.getKey(), edgePropertyKeys, this.edgePropertiesRule)) { e.setProperty(entry.getKey(), entry.getValue()); } @@ -622,12 +607,10 @@ class GraphsonUtil { Vertex vertexFromJson(JSONObject json) { Map<String, Object> props = readProperties(json, true, this.hasEmbeddedTypes); - //Object vertexId = getTypedValueFromJsonNode((JSONObject)json.get(GraphsonTokens._ID)); Object vertexId = json.get(GraphsonTokens._ID); Vertex v = factory.createVertex(vertexId); for (Map.Entry<String, Object> entry : props.entrySet()) { - //if (this.vertexPropertyKeys == null || vertexPropertyKeys.contains(entry.getKey())) { if (includeKey(entry.getKey(), vertexPropertyKeys, this.vertexPropertiesRule)) { v.setProperty(entry.getKey(), entry.getValue()); } @@ -640,14 +623,6 @@ class GraphsonUtil { * Creates GraphSON for a single graph element. */ JSONObject jsonFromElement(Element element) { - JSONObject objectNode = this.objectNodeFromElement(element); - return objectNode; - } - - /** - * Creates GraphSON for a single graph element. - */ - org.json.simple.JSONObject objectNodeFromElement(Element element) { boolean isEdge = element instanceof Edge; boolean showTypes = mode == GraphsonMode.EXTENDED; Set<String> propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys; diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java index ef97d89dc09..becdf3443fe 100644 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java +++ b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonWriter.java @@ -59,13 +59,13 @@ public class GraphsonWriter { JSONArray verticesArray = new JSONArray(); for (Vertex v : graph.getVertices()) { - verticesArray.add(graphson.objectNodeFromElement(v)); + verticesArray.add(graphson.jsonFromElement(v)); } root.put(GraphsonTokens.VERTICES, verticesArray); JSONArray edgesArray = new JSONArray(); for (Edge e : graph.getEdges()) { - edgesArray.add(graphson.objectNodeFromElement(e)); + edgesArray.add(graphson.jsonFromElement(e)); } root.put(GraphsonTokens.EDGES, edgesArray); diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java index 3c01e7cebeb..6a15a79e223 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java +++ b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java @@ -45,7 +45,7 @@ public class DefaultTestCase extends ElementWrapper<Vertex> implements MutableTe public MutableTestCase setDurationInMs(@Nullable Long l) { Preconditions.checkArgument(l==null || l >=0, String.format("Duration must be positive (got %d)", l)); - element().removeProperty("duration"); + element().setProperty("duration", l); return this; } @@ -79,6 +79,24 @@ public class DefaultTestCase extends ElementWrapper<Vertex> implements MutableTe return this; } + public String message() { + return (String) element().getProperty("message"); + } + + public MutableTestCase setMessage(String s) { + element().setProperty("message", s); + return this; + } + + public String stackTrace() { + return (String) element().getProperty("stackTrace"); + } + + public MutableTestCase setStackTrace(String s) { + element().setProperty("stackTrace", s); + return this; + } + public void covers(Testable component, Collection<Integer> lines) { } |