c509ab433494296062d87fedddeddfbcc90fc91d
[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.Direction;
28 import org.apache.tinkerpop.gremlin.structure.Element;
29 import org.apache.tinkerpop.gremlin.structure.Graph;
30 import org.apache.tinkerpop.gremlin.structure.Vertex;
31 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
32 import org.junit.Before;
33 import org.junit.Ignore;
34 import org.junit.Test;
35 import org.onap.aai.edges.enums.EdgeProperty;
36 import org.onap.aai.serialization.engines.query.GraphTraversalQueryEngine;
37
38 @Ignore
39 public class TreeBackedVertexTest {
40
41     private Graph graph = TinkerGraph.open();
42     private Object startKey = null;
43     private Tree<Element> tree = null;
44     private Tree<Element> treeDepth1 = null;
45     private Tree<Element> treeDepth0NodeOnly = null;
46
47     @Before
48     public void configure() {
49         GraphTraversalSource g = graph.traversal();
50
51         startKey = g.addV("vserver").as("v1").property("test", "hello")
52                     .addV("vserver").as("v2")
53                     .addV("interface").property("name", "interface 1").as("v10")
54                     .addE("hasChild").from("v2").property(EdgeProperty.CONTAINS.toString(), true)
55                     .addV("pserver").property("name", "pserver 1").as("v4")
56                     .addE("runsOn").to("v1").property(EdgeProperty.CONTAINS.toString(), false)
57                     .addV("interface").property("name", "interface 2").as("v3")
58                     .addE("hasChild").from("v1").property(EdgeProperty.CONTAINS.toString(), true)
59                     .addV("address").property("name", "address 1")
60                     .addE("hasChild").from("v3").property(EdgeProperty.CONTAINS.toString(), true)
61                     .addV("address").property("name", "address 2")
62                     .addE("hasChild").from("v3").property(EdgeProperty.CONTAINS.toString(), true)
63                     .addV("complex").property("name", "complex 1")
64                     .addE("locatedIn").from("v4").property(EdgeProperty.CONTAINS.toString(), false)
65                     .addV("interface").property("name", "interface 3")
66                     .addE("hasChild").from("v4").property(EdgeProperty.CONTAINS.toString(), true)
67                     .addV("subnet").property("name", "subnet 1").as("v5")
68                     .addE("in").from("v3").property(EdgeProperty.CONTAINS.toString(), false)
69                     .addV("address").property("name", "address 3").as("v6")
70                     .addE("hasChild").from("v5").property(EdgeProperty.CONTAINS.toString(), true)
71                     .select("v1").next();
72
73         tree = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey);
74         treeDepth1 = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 1, false);
75         treeDepth0NodeOnly = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 0, true);
76     }
77
78     @Ignore
79     @Test
80     public void oneHopViaEdges() {
81
82         // BulkSet set = (BulkSet)result;
83         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
84
85         assertEquals("locate child", v.edges(Direction.OUT).next().inVertex().property("name").orElse(""),
86                 "interface 2");
87         assertEquals("locate cousin", v.edges(Direction.IN).next().outVertex().property("name").orElse(""),
88                 "pserver 1");
89
90     }
91
92     @Ignore
93     @Test
94     public void oneHopViaVertices() {
95
96         // BulkSet set = (BulkSet)result;
97         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
98
99         assertEquals("locate child", "interface 2", v.vertices(Direction.OUT).next().property("name").orElse(""));
100         assertEquals("locate cousin", "pserver 1", v.vertices(Direction.IN).next().property("name").orElse(""));
101
102     }
103
104     @Ignore
105     @Test
106     public void twoHopCousinViaVertices() {
107
108         // BulkSet set = (BulkSet)result;
109         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
110
111         assertEquals("locate child", "subnet 1",
112                 v.vertices(Direction.OUT).next().vertices(Direction.OUT, "in").next().property("name").orElse(""));
113
114     }
115
116     @Test
117     public void walkVerticesRestrictedDepth() {
118
119         // BulkSet set = (BulkSet)result;
120         TreeBackedVertex v =
121                 new TreeBackedVertex((Vertex) treeDepth1.getObjectsAtDepth(1).iterator().next(), treeDepth1);
122
123         assertEquals("nothing returned", false,
124                 v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild").hasNext());
125
126     }
127
128     @Test
129     public void walkVertices() {
130         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
131         assertEquals("locate child", "address 2", v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild")
132                 .next().property("name").orElse(""));
133     }
134
135     @Test
136     public void walkEdges() {
137         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
138
139         assertEquals("locate child", "address 2", v.edges(Direction.OUT).next().inVertex()
140                 .edges(Direction.OUT, "hasChild").next().inVertex().property("name").orElse(""));
141     }
142
143     @Test
144     public void noEdgesFoudWithLabelVertices() {
145         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
146
147         assertEquals("missing hello label", false, v.vertices(Direction.OUT, "hello").hasNext());
148     }
149
150     @Test
151     public void noEdgesFoudWithLabelEdges() {
152         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
153
154         assertEquals("missing hello label", false, v.edges(Direction.OUT, "hello").hasNext());
155     }
156
157     @Test
158     public void depthZeroNodeOnly() {
159         TreeBackedVertex v = new TreeBackedVertex((Vertex) treeDepth0NodeOnly.getObjectsAtDepth(1).iterator().next(),
160                 treeDepth0NodeOnly);
161         assertEquals("no edges returned", false, v.edges(Direction.BOTH).hasNext());
162     }
163
164 }