package org.sonar.core.graph;
public class GraphDto {
+ private long id;
private long snapshotId;
private String format;
private String perspective;
private String rootVertexId;
private String data;
+ public long getId() {
+ return id;
+ }
+
+ public GraphDto setId(long id) {
+ this.id = id;
+ return this;
+ }
+
public long getSnapshotId() {
return snapshotId;
}
<mapper namespace="org.sonar.core.graph.GraphDtoMapper">
<select id="selectBySnapshot" parameterType="map" resultType="Graph">
- SELECT snapshot_id as snapshotId, format, version, perspective, data
+ SELECT id, snapshot_id as snapshotId, format, version, perspective, root_vertex_id as rootVertexId, data
FROM graphs
WHERE snapshot_id = #{sid} AND perspective = #{perspective}
</select>
<select id="selectByComponent" parameterType="map" resultType="Graph">
- SELECT g.snapshot_id as snapshotId, g.format, g.version, g.perspective, g.data
+ SELECT g.id, g.snapshot_id as snapshotId, g.format, g.version, g.perspective, g.root_vertex_id as rootVertexId, g.data
FROM graphs g, snapshots s
WHERE g.perspective = #{perspective} AND g.snapshot_id=s.id AND s.islast=${_true} and s.project_id=(
select id from projects where enabled=${_true} and kee=#{key} and person_id is null and copy_resource_id is null
+++ /dev/null
-/*
- * 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.component;
-
-import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
-import com.tinkerpop.gremlin.java.GremlinPipeline;
-import org.junit.Test;
-import org.sonar.core.graph.GraphUtil;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class GraphUtilTest {
- @Test
- public void subGraph() {
- TinkerGraph graph = new TinkerGraph();
- Vertex a = graph.addVertex("1");
- Vertex b = graph.addVertex("2");
- Vertex c = graph.addVertex("3");
- graph.addEdge("4", a, b, "likes");
- graph.addEdge("5", b, c, "has");
-
- TinkerGraph subGraph = new TinkerGraph();
- GremlinPipeline pipeline = new GremlinPipeline(a).outE("likes").inV().path();
- GraphUtil.subGraph(pipeline, subGraph);
-
- assertThat(subGraph.getVertices()).hasSize(2);
- assertThat(subGraph.getEdges()).hasSize(1);
- }
-}
--- /dev/null
+/*
+ * 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.graph;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class GraphDbTest extends AbstractDaoTestCase {
+ private GraphDao dao;
+
+ @Before
+ public void createDao() {
+ dao = new GraphDao(getMyBatis());
+ setupData("shared");
+ }
+
+ @Test
+ public void select_graph_by_snapshot() {
+ GraphDto testPlan = dao.selectBySnapshot("testplan", 11L);
+
+ assertThat(testPlan.getId()).isEqualTo(101L);
+ assertThat(testPlan.getSnapshotId()).isEqualTo(11L);
+ assertThat(testPlan.getFormat()).isEqualTo("graphson");
+ assertThat(testPlan.getVersion()).isEqualTo(1);
+ assertThat(testPlan.getPerspective()).isEqualTo("testplan");
+ assertThat(testPlan.getRootVertexId()).isEqualTo("3456");
+ assertThat(testPlan.getData()).isEqualTo("{testplan of snapshot 123}");
+ }
+
+ @Test
+ public void select_by_snapshot_and_missing_perspective() {
+ assertThat(dao.selectBySnapshot("duplicable", 123L)).isNull();
+ }
+
+ @Test
+ public void select_by_missing_snapshot() {
+ assertThat(dao.selectBySnapshot("duplicable", 7777L)).isNull();
+ }
+
+ @Test
+ public void select_by_component() {
+ GraphDto testPlan = dao.selectByComponent("testplan", "org.apache.struts:struts");
+
+ assertThat(testPlan.getId()).isEqualTo(101L);
+ assertThat(testPlan.getSnapshotId()).isEqualTo(11L);
+ assertThat(testPlan.getFormat()).isEqualTo("graphson");
+ assertThat(testPlan.getVersion()).isEqualTo(1);
+ assertThat(testPlan.getPerspective()).isEqualTo("testplan");
+ assertThat(testPlan.getRootVertexId()).isEqualTo("3456");
+ assertThat(testPlan.getData()).isEqualTo("{testplan of snapshot 123}");
+ }
+
+ @Test
+ public void select_by_missing_component() {
+ assertThat(dao.selectByComponent("testplan", "org.other:unknown")).isNull();
+ }
+}
--- /dev/null
+/*
+ * 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.graph;
+
+import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
+import com.tinkerpop.gremlin.java.GremlinPipeline;
+import org.junit.Test;
+import org.sonar.core.graph.GraphUtil;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class GraphUtilTest {
+ @Test
+ public void subGraph() {
+ TinkerGraph graph = new TinkerGraph();
+ Vertex a = graph.addVertex("1");
+ Vertex b = graph.addVertex("2");
+ Vertex c = graph.addVertex("3");
+ graph.addEdge("4", a, b, "likes");
+ graph.addEdge("5", b, c, "has");
+
+ TinkerGraph subGraph = new TinkerGraph();
+ GremlinPipeline pipeline = new GremlinPipeline(a).outE("likes").inV().path();
+ GraphUtil.subGraph(pipeline, subGraph);
+
+ assertThat(subGraph.getVertices()).hasSize(2);
+ assertThat(subGraph.getEdges()).hasSize(1);
+ }
+}
--- /dev/null
+<dataset>
+ <projects id="1" kee="org.apache.struts:struts" enabled="true"/>
+
+ <snapshots id="10" project_id="1" islast="false" />
+ <snapshots id="11" project_id="1" islast="true" />
+
+ <graphs id="100" snapshot_id="11" format="graphson" version="1" perspective="testable" root_vertex_id="7890" data="{testable of snapshot 123}"/>
+ <graphs id="101" snapshot_id="11" format="graphson" version="1" perspective="testplan" root_vertex_id="3456" data="{testplan of snapshot 123}"/>
+</dataset>
\ No newline at end of file