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