-
Notifications
You must be signed in to change notification settings - Fork 75
/
GraphSerialisationSpec.scala
67 lines (55 loc) · 1.98 KB
/
GraphSerialisationSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gremlin.scala
import java.io.FileOutputStream
import org.apache.tinkerpop.gremlin.structure.io.IoCore
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion
import org.apache.tinkerpop.gremlin.tinkergraph.structure.{TinkerFactory, TinkerGraph}
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers
class GraphSerialisationSpec extends AnyWordSpec with Matchers {
"serialising from/to" should {
"support graphML" in {
val file = "target/tinkerpop-modern.graphml"
graph.io(IoCore.graphml).writeGraph(file)
val newGraph = TinkerGraph.open
newGraph.io(IoCore.graphml).readGraph(file)
newGraph.V().count().head() shouldBe 6
newGraph.E().count().head() shouldBe 6
}
"support graphson" in {
val file = "target/tinkerpop-modern.graphson.json"
graph.io(IoCore.graphson).writeGraph(file)
val newGraph = TinkerGraph.open
newGraph.io(IoCore.graphson).readGraph(file)
newGraph.V().count().head() shouldBe 6
newGraph.E().count().head() shouldBe 6
}
"support graphson v2" in {
val file = "target/tinkerpop-modern.graphson2.json"
val mapper = graph
.io(IoCore.graphson)
.mapper
.normalize(true)
.version(GraphSONVersion.V2_0)
.create
graph
.io(IoCore.graphson)
.writer
.mapper(mapper)
.create
.writeGraph(new FileOutputStream(file), graph)
val newGraph = TinkerGraph.open
newGraph.io(IoCore.graphson).readGraph(file)
newGraph.V().count().head() shouldBe 6
newGraph.E().count().head() shouldBe 6
}
"support gryo/kryo" in {
val file = "target/tinkerpop-modern.gryo"
graph.io(IoCore.gryo).writeGraph(file)
val newGraph = TinkerGraph.open
newGraph.io(IoCore.gryo).readGraph(file)
newGraph.V().count().head() shouldBe 6
newGraph.E().count().head() shouldBe 6
}
}
def graph = TinkerFactory.createModern
}