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