Merge "[AAI] Fix doc config files"
[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").addV("vserver").as("v2").addV("interface")
52                 .property("name", "interface 1").as("v10").addE("hasChild").from("v2")
53                 .property(EdgeProperty.CONTAINS.toString(), true).addV("pserver").property("name", "pserver 1").as("v4")
54                 .addE("runsOn").to("v1").property(EdgeProperty.CONTAINS.toString(), false).addV("interface")
55                 .property("name", "interface 2").as("v3").addE("hasChild").from("v1")
56                 .property(EdgeProperty.CONTAINS.toString(), true).addV("address").property("name", "address 1")
57                 .addE("hasChild").from("v3").property(EdgeProperty.CONTAINS.toString(), true).addV("address")
58                 .property("name", "address 2").addE("hasChild").from("v3")
59                 .property(EdgeProperty.CONTAINS.toString(), true).addV("complex").property("name", "complex 1")
60                 .addE("locatedIn").from("v4").property(EdgeProperty.CONTAINS.toString(), false).addV("interface")
61                 .property("name", "interface 3").addE("hasChild").from("v4")
62                 .property(EdgeProperty.CONTAINS.toString(), true).addV("subnet").property("name", "subnet 1").as("v5")
63                 .addE("in").from("v3").property(EdgeProperty.CONTAINS.toString(), false).addV("address")
64                 .property("name", "address 3").as("v6").addE("hasChild").from("v5")
65                 .property(EdgeProperty.CONTAINS.toString(), true).select("v1").next();
66
67         tree = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey);
68         treeDepth1 = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 1, false);
69         treeDepth0NodeOnly = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 0, true);
70     }
71
72     @Ignore
73     @Test
74     public void oneHopViaEdges() {
75
76         // BulkSet set = (BulkSet)result;
77         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
78
79         assertEquals("locate child", v.edges(Direction.OUT).next().inVertex().property("name").orElse(""),
80                 "interface 2");
81         assertEquals("locate cousin", v.edges(Direction.IN).next().outVertex().property("name").orElse(""),
82                 "pserver 1");
83
84     }
85
86     @Ignore
87     @Test
88     public void oneHopViaVertices() {
89
90         // BulkSet set = (BulkSet)result;
91         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
92
93         assertEquals("locate child", "interface 2", v.vertices(Direction.OUT).next().property("name").orElse(""));
94         assertEquals("locate cousin", "pserver 1", v.vertices(Direction.IN).next().property("name").orElse(""));
95
96     }
97
98     @Ignore
99     @Test
100     public void twoHopCousinViaVertices() {
101
102         // BulkSet set = (BulkSet)result;
103         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
104
105         assertEquals("locate child", "subnet 1",
106                 v.vertices(Direction.OUT).next().vertices(Direction.OUT, "in").next().property("name").orElse(""));
107
108     }
109
110     @Test
111     public void walkVerticesRestrictedDepth() {
112
113         // BulkSet set = (BulkSet)result;
114         TreeBackedVertex v =
115                 new TreeBackedVertex((Vertex) treeDepth1.getObjectsAtDepth(1).iterator().next(), treeDepth1);
116
117         assertEquals("nothing returned", false,
118                 v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild").hasNext());
119
120     }
121
122     @Test
123     public void walkVertices() {
124         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
125         assertEquals("locate child", "address 2", v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild")
126                 .next().property("name").orElse(""));
127     }
128
129     @Test
130     public void walkEdges() {
131         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
132
133         assertEquals("locate child", "address 2", v.edges(Direction.OUT).next().inVertex()
134                 .edges(Direction.OUT, "hasChild").next().inVertex().property("name").orElse(""));
135     }
136
137     @Test
138     public void noEdgesFoudWithLabelVertices() {
139         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
140
141         assertEquals("missing hello label", false, v.vertices(Direction.OUT, "hello").hasNext());
142     }
143
144     @Test
145     public void noEdgesFoudWithLabelEdges() {
146         TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
147
148         assertEquals("missing hello label", false, v.edges(Direction.OUT, "hello").hasNext());
149     }
150
151     @Test
152     public void depthZeroNodeOnly() {
153         TreeBackedVertex v = new TreeBackedVertex((Vertex) treeDepth0NodeOnly.getObjectsAtDepth(1).iterator().next(),
154                 treeDepth0NodeOnly);
155         assertEquals("no edges returned", false, v.edges(Direction.BOTH).hasNext());
156     }
157
158 }