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