AAI-1523 Batch reformat aai-core
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / serialization / tinkerpop / TreeBackedVertexTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aai.serialization.tinkerpop;
22
23 import static org.junit.Assert.assertEquals;
24
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
26 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
27 import org.apache.tinkerpop.gremlin.structure.*;
28 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
29 import org.junit.Before;
30 import org.junit.Ignore;
31 import org.junit.Test;
32 import org.onap.aai.edges.enums.EdgeProperty;
33 import org.onap.aai.serialization.engines.query.GraphTraversalQueryEngine;
34
35 @Ignore
36 public class TreeBackedVertexTest {
37
38     private Graph graph = TinkerGraph.open();
39     private Object startKey = null;
40     private Tree<Element> tree = null;
41     private Tree<Element> treeDepth1 = null;
42     private Tree<Element> treeDepth0NodeOnly = null;
43
44     @Before
45     public void configure() {
46         GraphTraversalSource g = graph.traversal();
47
48         startKey = g.addV(T.label, "vserver").as("v1").property("test", "hello").addV(T.label, "vserver").as("v2")
49                 .addV(T.label, "interface").property("name", "interface 1").as("v10").addInE("hasChild", "v2")
50                 .property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "pserver").property("name", "pserver 1")
51                 .as("v4").addOutE("runsOn", "v1").property(EdgeProperty.CONTAINS.toString(), false)
52                 .addV(T.label, "interface").property("name", "interface 2").as("v3").addInE("hasChild", "v1")
53                 .property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "address").property("name", "address 1")
54                 .addInE("hasChild", "v3").property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "address")
55                 .property("name", "address 2").addInE("hasChild", "v3").property(EdgeProperty.CONTAINS.toString(), true)
56                 .addV(T.label, "complex").property("name", "complex 1").addInE("locatedIn", "v4")
57                 .property(EdgeProperty.CONTAINS.toString(), false).addV(T.label, "interface")
58                 .property("name", "interface 3").addInE("hasChild", "v4")
59                 .property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "subnet").property("name", "subnet 1")
60                 .as("v5").addInE("in", "v3").property(EdgeProperty.CONTAINS.toString(), false).addV(T.label, "address")
61                 .property("name", "address 3").as("v6").addInE("hasChild", "v5")
62                 .property(EdgeProperty.CONTAINS.toString(), true).select("v1").next();
63
64         tree = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey);
65         treeDepth1 = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 1, false);
66         treeDepth0NodeOnly = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 0, true);
67     }
68
69     @Ignore
70     @Test
71     public void oneHopViaEdges() {
72
73         // BulkSet set = (BulkSet)result;
74         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
75
76         assertEquals("locate child", v.edges(Direction.OUT).next().inVertex().property("name").orElse(""),
77                 "interface 2");
78         assertEquals("locate cousin", v.edges(Direction.IN).next().outVertex().property("name").orElse(""),
79                 "pserver 1");
80
81     }
82
83     @Ignore
84     @Test
85     public void oneHopViaVertices() {
86
87         // BulkSet set = (BulkSet)result;
88         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
89
90         assertEquals("locate child", "interface 2", v.vertices(Direction.OUT).next().property("name").orElse(""));
91         assertEquals("locate cousin", "pserver 1", v.vertices(Direction.IN).next().property("name").orElse(""));
92
93     }
94
95     @Ignore
96     @Test
97     public void twoHopCousinViaVertices() {
98
99         // BulkSet set = (BulkSet)result;
100         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
101
102         assertEquals("locate child", "subnet 1",
103                 v.vertices(Direction.OUT).next().vertices(Direction.OUT, "in").next().property("name").orElse(""));
104
105     }
106
107     @Test
108     public void walkVerticesRestrictedDepth() {
109
110         // BulkSet set = (BulkSet)result;
111         TreeBackedVertex v =
112                 new TreeBackedVertex((Vertex) treeDepth1.getObjectsAtDepth(1).iterator().next(), treeDepth1);
113
114         assertEquals("nothing returned", false,
115                 v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild").hasNext());
116
117     }
118
119     @Test
120     public void walkVertices() {
121         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
122         assertEquals("locate child", "address 2", v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild")
123                 .next().property("name").orElse(""));
124     }
125
126     @Test
127     public void walkEdges() {
128         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
129
130         assertEquals("locate child", "address 2", v.edges(Direction.OUT).next().inVertex()
131                 .edges(Direction.OUT, "hasChild").next().inVertex().property("name").orElse(""));
132     }
133
134     @Test
135     public void noEdgesFoudWithLabelVertices() {
136         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
137
138         assertEquals("missing hello label", false, v.vertices(Direction.OUT, "hello").hasNext());
139     }
140
141     @Test
142     public void noEdgesFoudWithLabelEdges() {
143         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
144
145         assertEquals("missing hello label", false, v.edges(Direction.OUT, "hello").hasNext());
146     }
147
148     @Test
149     public void depthZeroNodeOnly() {
150         TreeBackedVertex v = new TreeBackedVertex((Vertex) treeDepth0NodeOnly.getObjectsAtDepth(1).iterator().next(),
151                 treeDepth0NodeOnly);
152         assertEquals("no edges returned", false, v.edges(Direction.BOTH).hasNext());
153     }
154
155 }