You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/04/06 14:25:18 UTC

[2/3] tinkerpop git commit: TINKERPOP-1608 Added test for GraphML transform

TINKERPOP-1608 Added test for GraphML transform


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/22bcad58
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/22bcad58
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/22bcad58

Branch: refs/heads/TINKERPOP-1608
Commit: 22bcad585e2df84f6521296c41b6173563c56d15
Parents: cfef836
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 6 09:41:29 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 6 09:41:29 2017 -0400

----------------------------------------------------------------------
 .../src/main/resources/tp2-to-tp3-graphml.xslt  | 19 +++++++
 .../tinkerpop/gremlin/structure/io/IoTest.java  | 31 +++++++++++
 .../io/graphml/tinkerpop-classic-tp2.xml        | 54 ++++++++++++++++++++
 3 files changed, 104 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/22bcad58/gremlin-core/src/main/resources/tp2-to-tp3-graphml.xslt
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/resources/tp2-to-tp3-graphml.xslt b/gremlin-core/src/main/resources/tp2-to-tp3-graphml.xslt
index 1944bcf..40d553b 100644
--- a/gremlin-core/src/main/resources/tp2-to-tp3-graphml.xslt
+++ b/gremlin-core/src/main/resources/tp2-to-tp3-graphml.xslt
@@ -1,4 +1,22 @@
 <?xml version="1.0" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+
 <!-- XSL stylesheet to convert TinkerPop v2 GraphML files for Apache TinkerPop v3 -->
 <xsl:stylesheet version="1.0"
                 xmlns="http://graphml.graphdrawing.org/xmlns"
@@ -34,6 +52,7 @@
             <data key="labelE">
                 <xsl:value-of select="@label"/>
             </data>
+            <xsl:apply-templates select="node()|@*"/>
         </edge>
     </xsl:template>
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/22bcad58/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
index 428a0d8..2c13c2f 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoTest.java
@@ -55,6 +55,9 @@ import org.slf4j.LoggerFactory;
 
 import javax.xml.XMLConstants;
 import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -286,6 +289,34 @@ public class IoTest {
             assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
             assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges()));
         }
+
+        @Test
+        @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+        @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_FLOAT_VALUES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_BOOLEAN_VALUES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_LONG_VALUES)
+        @FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_DOUBLE_VALUES)
+        @FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
+        public void shouldTransformGraphMLV2ToV3ViaXSLT() throws Exception {
+            final InputStream stylesheet = Thread.currentThread().getContextClassLoader().getResourceAsStream("tp2-to-tp3-graphml.xslt");
+            final InputStream datafile = IoTest.class.getResourceAsStream(TestHelper.convertPackageToResourcePath(GraphMLResourceAccess.class) + "tinkerpop-classic-tp2.xml");
+            final ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+            final TransformerFactory tFactory = TransformerFactory.newInstance();
+            final StreamSource stylesource = new StreamSource(stylesheet);
+            final Transformer transformer = tFactory.newTransformer(stylesource);
+
+            final StreamSource source = new StreamSource(datafile);
+            final StreamResult result = new StreamResult(output);
+            transformer.transform(source, result);
+
+            final GraphReader reader = GraphMLReader.build().create();
+            reader.readGraph(new ByteArrayInputStream(output.toByteArray()), graph);
+            assertClassicGraph(graph, false, true);
+        }
     }
 
     public static final class GryoTest extends AbstractGremlinTest {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/22bcad58/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-tp2.xml
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-tp2.xml b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-tp2.xml
new file mode 100644
index 0000000..b056732
--- /dev/null
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/tinkerpop-classic-tp2.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
+        http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
+    <key id="weight" for="edge" attr.name="weight" attr.type="float"/>
+    <key id="name" for="node" attr.name="name" attr.type="string"/>
+    <key id="age" for="node" attr.name="age" attr.type="int"/>
+    <key id="lang" for="node" attr.name="lang" attr.type="string"/>
+    <graph id="G" edgedefault="directed">
+        <node id="1">
+            <data key="name">marko</data>
+            <data key="age">29</data>
+        </node>
+        <node id="2">
+            <data key="name">vadas</data>
+            <data key="age">27</data>
+        </node>
+        <node id="3">
+            <data key="name">lop</data>
+            <data key="lang">java</data>
+        </node>
+        <node id="4">
+            <data key="name">josh</data>
+            <data key="age">32</data>
+        </node>
+        <node id="5">
+            <data key="name">ripple</data>
+            <data key="lang">java</data>
+        </node>
+        <node id="6">
+            <data key="name">peter</data>
+            <data key="age">35</data>
+        </node>
+        <edge id="7" source="1" target="2" label="knows">
+            <data key="weight">0.5</data>
+        </edge>
+        <edge id="8" source="1" target="4" label="knows">
+            <data key="weight">1.0</data>
+        </edge>
+        <edge id="9" source="1" target="3" label="created">
+            <data key="weight">0.4</data>
+        </edge>
+        <edge id="10" source="4" target="5" label="created">
+            <data key="weight">1.0</data>
+        </edge>
+        <edge id="11" source="4" target="3" label="created">
+            <data key="weight">0.4</data>
+        </edge>
+        <edge id="12" source="6" target="3" label="created">
+            <data key="weight">0.2</data>
+        </edge>
+    </graph>
+</graphml>
\ No newline at end of file