/
AbstractTraversalTest.java
97 lines (76 loc) · 3.13 KB
/
AbstractTraversalTest.java
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
/*
*
* Copyright (c) 2017 Otávio Santana and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*
*/
package org.eclipse.jnosql.artemis.graph;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.eclipse.jnosql.artemis.graph.model.Book;
import org.eclipse.jnosql.artemis.graph.model.Person;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import javax.inject.Inject;
public abstract class AbstractTraversalTest {
static final String READS = "reads";
@Inject
protected GraphTemplate graphTemplate;
@Inject
protected Graph graph;
protected Person otavio;
protected Person poliana;
protected Person paulo;
protected Book shack;
protected Book license;
protected Book effectiveJava;
protected EdgeEntity reads;
protected EdgeEntity reads2;
protected EdgeEntity reads3;
@BeforeEach
public void setUp() {
graph.traversal().V().toList().forEach(Vertex::remove);
graph.traversal().E().toList().forEach(Edge::remove);
otavio = graphTemplate.insert(Person.builder().withAge(27)
.withName("Otavio").build());
poliana = graphTemplate.insert(Person.builder().withAge(26)
.withName("Poliana").build());
paulo = graphTemplate.insert(Person.builder().withAge(50)
.withName("Paulo").build());
shack = graphTemplate.insert(Book.builder().withAge(2007).withName("The Shack").build());
license = graphTemplate.insert(Book.builder().withAge(2013).withName("Software License").build());
effectiveJava = graphTemplate.insert(Book.builder().withAge(2001).withName("Effective Java").build());
reads = graphTemplate.edge(otavio, READS, effectiveJava);
reads2 = graphTemplate.edge(poliana, READS, shack);
reads3 = graphTemplate.edge(paulo, READS, license);
reads.add("motivation", "hobby");
reads.add("language", "Java");
reads2.add("motivation", "love");
reads3.add("motivation", "job");
}
@AfterEach
public void after() {
graphTemplate.delete(otavio.getId());
graphTemplate.delete(poliana.getId());
graphTemplate.delete(paulo.getId());
graphTemplate.deleteEdge(shack.getId());
graphTemplate.deleteEdge(license.getId());
graphTemplate.deleteEdge(effectiveJava.getId());
reads.delete();
reads2.delete();
reads3.delete();
graph.traversal().V().toList().forEach(Vertex::remove);
graph.traversal().E().toList().forEach(Edge::remove);
}
}