Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / rest / search / LinkedDevices_NewvceVserverTest.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.rest.search;
21
22 import static org.junit.Assert.*;
23
24 import java.util.ArrayList;
25 import java.util.Map;
26 import java.util.List;
27
28 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
29 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
30 import org.apache.tinkerpop.gremlin.structure.T;
31 import org.apache.tinkerpop.gremlin.structure.Vertex;
32 import org.junit.Test;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
35
36 public class LinkedDevices_NewvceVserverTest extends QueryTest {
37
38         public LinkedDevices_NewvceVserverTest() throws AAIException, NoEdgeRuleFoundException {
39                 super();
40         }
41         
42         @Test
43         public void run() {
44                 super.run();
45         }
46
47         @Override
48         protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
49                 //Note: I don't know if this topology is realistic, but it doesn't really matter bc we're just testing functionality
50                 Vertex newvce1 = graph.addVertex(T.label, "newvce", T.id, "00", "aai-node-type", "newvce",
51                                                                                 "vnf-id2", "newvce1", "vnf-name", "bob", "vnf-type", "new");
52                 
53                 Vertex lint1 = graph.addVertex(T.label, "l-interface", T.id, "10", "aai-node-type", "l-interface",
54                                                                                 "interface-name", "lint1", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
55                 Vertex loglink1 = graph.addVertex(T.label, "logical-link", T.id, "20", "aai-node-type", "logical-link",
56                                                                                 "link-name", "loglink1", "in-maint", "false", "link-type", "sausage");
57                 Vertex lint2 = graph.addVertex(T.label, "l-interface", T.id, "11", "aai-node-type", "l-interface",
58                                                                                 "interface-name", "lint2", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
59                 Vertex vlan = graph.addVertex(T.label, "vlan", T.id, "40", "aai-node-type", "vlan",
60                                                                                 "vlan-interface", "vlan1");
61                 
62                 Vertex newvce2 = graph.addVertex(T.label, "newvce", T.id, "01", "aai-node-type", "newvce",
63                                                                                 "vnf-id2", "newvce2", "vnf-name", "bob", "vnf-type", "new");
64                 
65                 Vertex loglink2 = graph.addVertex(T.label, "logical-link", T.id, "21", "aai-node-type", "logical-link",
66                                                                                 "link-name", "loglink2", "in-maint", "false", "link-type", "sausage");
67                 Vertex lint3 = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface",
68                                                                                 "interface-name", "lint3", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
69                 
70                 Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "50", "aai-node-type", "cloud-region",
71                                                                                         "cloud-owner", "onap", "cloud-region-id", "crId");
72                 Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "60", "aai-node-type", "tenant",
73                                                                                 "tenant-id", "tenId", "tenant-name", "verity");
74                 Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "30", "aai-node-type", "vserver",
75                                                                                 "vserver-id", "vserv1", "vserver-name", "frank");
76                 
77                 GraphTraversalSource g = graph.traversal();
78                 rules.addTreeEdge(g, newvce1, lint1);
79                 rules.addTreeEdge(g, lint1, vlan);
80                 rules.addEdge(g, lint1, loglink1);
81                 rules.addEdge(g, lint2, loglink1);
82                 
83                 rules.addTreeEdge(g, cloudregion, tenant);
84                 rules.addTreeEdge(g, tenant, vserver);
85                 rules.addTreeEdge(g, vserver, lint2);
86                 
87                 rules.addEdge(g, vlan, loglink2);
88                 rules.addTreeEdge(g, newvce2, lint3);
89                 rules.addEdge(g, loglink2, lint3);
90                 
91                 expectedResult.add(newvce1);
92                 expectedResult.add(newvce2);
93                 expectedResult.add(vserver);
94         }
95
96         @Override
97         protected String getQueryName() {
98                 return "linked-devices";
99         }
100
101         @Override
102         protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
103                 g.has("aai-node-type", "newvce").has("vnf-id2", "newvce1");
104         }
105
106         @Override
107         protected void addParam(Map<String, Object> params) {
108                 // n/a for this query
109         }
110 }