-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSchema04Test.scala
215 lines (189 loc) · 8.14 KB
/
Schema04Test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import overflowdb.Graph
import testschema04._
import testschema04.edges._
import testschema04.nodes._
import testschema04.traversal._
import scala.jdk.CollectionConverters.IteratorHasAsScala
import java.nio.file.Files
import scala.collection.immutable.ArraySeq
class Schema04Test extends AnyWordSpec with Matchers {
import overflowdb.traversal._
"default property values" in {
val graph = TestSchema.empty.graph
val node1 = graph.addNode(Node1.Label).asInstanceOf[Node1]
val node2 = graph.addNode(Node1.Label).asInstanceOf[Node1]
val edge1 = node1.addEdge(Edge1.Label, node2).asInstanceOf[Edge1]
node1.bool shouldBe true
node1.str shouldBe "<[empty]>"
node1.byte shouldBe 1
node1.short shouldBe 2
node1.int shouldBe 3
node1.long shouldBe 4
node1.float1 shouldBe 5.5f
node1.float2.isNaN shouldBe true
node1.double1 shouldBe 6.6
node1.double2.isNaN shouldBe true
node1.char shouldBe '?'
node1.intList.size shouldBe 0
node1.propertyKeys().contains("STR") shouldBe true
node1.propertyDefaultValue("STR") shouldBe "<[empty]>"
node1.propertyDefaultValue("DOESNT_EXIST") shouldBe null
node1.property(Node1.Properties.Str) shouldBe "<[empty]>"
node1.property("DOESNT_EXIST") shouldBe null
node1.propertiesMap.get("STR") shouldBe "<[empty]>"
node1.get.propertiesMapForStorage.isEmpty shouldBe true
edge1.bool shouldBe true
edge1.str shouldBe "<[empty]>"
edge1.byte shouldBe 1
edge1.short shouldBe 2
edge1.int shouldBe 3
edge1.long shouldBe 4
edge1.float1 shouldBe 5.5f
edge1.float2.isNaN shouldBe true
edge1.double1 shouldBe 6.6
edge1.double2.isNaN shouldBe true
edge1.char shouldBe '?'
edge1.intList.size shouldBe 0
edge1.propertyKeys().contains("STR") shouldBe true
edge1.propertyDefaultValue("STR") shouldBe "<[empty]>"
edge1.propertyDefaultValue("DOESNT_EXIST") shouldBe null
edge1.property(Edge1.Properties.Str) shouldBe "<[empty]>"
edge1.property("DOESNT_EXIST") shouldBe null
edge1.propertiesMap.get("STR") shouldBe "<[empty]>"
def node1Trav = graph.nodes(Node1.Label).asScala.cast[Node1]
def edge1Trav = graph.edges(Edge1.Label).asScala.cast[Edge1]
node1Trav.str.next() shouldBe "<[empty]>"
node1Trav.intList.l shouldBe Seq.empty
node1Trav.property(Node1.Properties.Str).next() shouldBe "<[empty]>"
edge1Trav.property(Edge1.Properties.Str).next() shouldBe "<[empty]>"
}
"defined property values" in {
val storageLocation = Files.createTempFile("overflowdb-codegen-tests", "odb.bin")
def openGraph(): Graph = TestSchema.withStorage(storageLocation).graph
val graph = openGraph()
val node1 = graph.addNode(Node1.Label)
val node2 = graph.addNode(Node1.Label).asInstanceOf[Node1]
val edge1 = node1.addEdge(Edge1.Label, node2).asInstanceOf[Edge1]
val properties = Seq(
Properties.Bool.of(false),
Properties.Str.of("foo"),
Properties.Byte.of(100: Byte),
Properties.Short.of(101: Short),
Properties.Int.of(102),
Properties.Long.of(103),
Properties.Float1.of(Float.NaN),
Properties.Float2.of(104.4f),
Properties.Double1.of(Double.NaN),
Properties.Double2.of(105.5),
Properties.Char.of('Z'),
Properties.IntList.of(ArraySeq(3, 4, 5)),
)
properties.foreach(node1.setProperty)
properties.foreach(edge1.setProperty)
node1.setProperty(Node1.Properties.Node1inner.of(node2))
val node1Id = node1.id
val node2Id = node2.id
verifyValues(graph, node1Id, node2Id)
graph.close()
verifyValues(openGraph(), node1Id, node2Id)
def verifyValues(graph: Graph, node1Id: Long, node2Id: Long): Unit = {
val node1 = graph.node(node1Id).asInstanceOf[Node1]
val node2 = graph.node(node2Id).asInstanceOf[Node1]
node1.bool shouldBe false
node1.str shouldBe "foo"
node1.byte shouldBe 100
node1.short shouldBe 101
node1.int shouldBe 102
node1.long shouldBe 103
node1.float1.isNaN shouldBe true
node1.float2 shouldBe 104.4f
node1.double1.isNaN shouldBe true
node1.double2 shouldBe 105.5
node1.char shouldBe 'Z'
node1.intList shouldBe Seq(3, 4, 5)
node1.node1Inner shouldBe node2
node1.propertyKeys().contains("STR") shouldBe true
node1.propertyDefaultValue("STR") shouldBe "<[empty]>"
node1.propertyDefaultValue("DOESNT_EXIST") shouldBe null
node1.property(Node1.Properties.Str) shouldBe "foo"
node1.property(Node1.Properties.Node1inner) shouldBe node2
node1.property("DOESNT_EXIST") shouldBe null
node1.propertiesMap.get("STR") shouldBe "foo"
node1.propertiesMap.get(Node1.PropertyNames.Node1inner) shouldBe node2
node1.get.propertiesMapForStorage.get(PropertyNames.STR) shouldBe "foo"
node1.get.propertiesMapForStorage.get(Node1.PropertyNames.Node1inner) shouldBe node2
edge1.bool shouldBe false
edge1.str shouldBe "foo"
edge1.byte shouldBe 100
edge1.short shouldBe 101
edge1.int shouldBe 102
edge1.long shouldBe 103
edge1.float1.isNaN shouldBe true
edge1.float2 shouldBe 104.4f
edge1.double1.isNaN shouldBe true
edge1.double2 shouldBe 105.5
edge1.char shouldBe 'Z'
edge1.intList shouldBe Seq(3, 4, 5)
edge1.propertyKeys().contains("STR") shouldBe true
edge1.propertyDefaultValue("STR") shouldBe "<[empty]>"
edge1.propertyDefaultValue("DOESNT_EXIST") shouldBe null
edge1.property(Node1.Properties.Str) shouldBe "foo"
edge1.property("DOESNT_EXIST") shouldBe null
edge1.propertiesMap.get("STR") shouldBe "foo"
def node1Trav = graph.nodes(Node1.Label).asScala.cast[Node1]
def edge1Trav = graph.edges(Edge1.Label).asScala.cast[Edge1]
node1Trav.str.next() shouldBe "foo"
node1Trav.intList.l shouldBe Seq(3, 4, 5)
node1Trav.property(Node1.Properties.Str).next() shouldBe "foo"
edge1Trav.property(Edge1.Properties.Str).next() shouldBe "foo"
}
}
"handle primitive arrays for list properties" in {
def openGraph(): Graph = TestSchema.empty.graph
val graph = openGraph()
val node1 = graph.addNode(Node1.Label).asInstanceOf[Node1]
val node2 = graph.addNode(Node1.Label).asInstanceOf[Node1]
val edge1 = node1.addEdge(Edge1.Label, node2).asInstanceOf[Edge1]
node1.setProperty(Properties.IntList.name, Array(1,2,3))
edge1.setProperty(Properties.IntList.name, Array(3,4,5))
node1.intList shouldBe IndexedSeq(1,2,3)
edge1.intList shouldBe IndexedSeq(3,4,5)
}
"NewNode.copy includes contained nodes" in {
val node1 = NewNode1()
.bool(true)
.str("foo")
.intList(Seq(1,2,3))
val node2 = NewNode1().node1Inner(node1)
val node1Copy = node1.copy
node1Copy.bool shouldBe true
node1Copy.str shouldBe "foo"
node1Copy.intList shouldBe Seq(1,2,3)
val node2Copy = node2.copy
node2Copy.node1Inner shouldBe node1
}
"generated string property filters" in {
val graph = TestSchema.empty.graph
val node1 = graph.addNode(Node1.Label, Node1.PropertyNames.Str, "node1 name")
val node2 = graph.addNode(Node1.Label, Node1.PropertyNames.Str,
"""node2 name line 1
|node2 name line 2""")
val node3 = graph.addNode(Node1.Label)
def node1Traversal = graph.nodes(Node1.Label).asScala.cast[Node1]
node1Traversal.size shouldBe 3
node1Traversal.str(".*").size shouldBe 3
node1Traversal.str(".*name.*").size shouldBe 2
node1Traversal.str(".*NAME.*").size shouldBe 0 // case sensitive by default
node1Traversal.str(".*(?i)NAME.*").size shouldBe 2 // case insensitive on request
node1Traversal.str(".*node1.*").size shouldBe 1
node1Traversal.str(".*line 2.*").size shouldBe 1 // testing multi line matcher
node1Traversal.str("nomatch", ".*line 2.*").size shouldBe 1
node1Traversal.strExact("node1 name").size shouldBe 1
node1Traversal.strExact("nomatch", "node1 name").size shouldBe 1
node1Traversal.strNot(".*node1.*").size shouldBe 2
node1Traversal.strNot(".*line 2.*").size shouldBe 2 // testing multi line matcher
node1Traversal.strNot("nomatch", ".*line 2.*").size shouldBe 2
}
}