Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / rest / search / PserversFromVnfQueryTest.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 java.util.Map;
23
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
26 import org.apache.tinkerpop.gremlin.structure.T;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.junit.Test;
29
30 import org.onap.aai.exceptions.AAIException;
31 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
32
33 public class PserversFromVnfQueryTest extends QueryTest {
34         public PserversFromVnfQueryTest() throws AAIException, NoEdgeRuleFoundException {
35                 super();
36         }
37         
38         @Test
39         public void run() {
40                 super.run();
41         }
42         @Override
43         protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
44                 
45                 
46                 //Set up the test graph
47                 Vertex complex = graph.addVertex(T.label, "complex", T.id, "0", "aai-node-type", "complex", "physical-location-id", "clli");
48                 
49                 Vertex vnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "1", "aai-node-type", "generic-vnf", "vnf-id", "vnfid1");
50                 Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname", "pservername1");
51                                 
52                 Vertex vnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "3", "aai-node-type", "generic-vnf", "vnf-id", "vnfid2");
53                 Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "4", "aai-node-type", "pserver", "hostname", "pservername2");
54                 Vertex pserver3 = graph.addVertex(T.label, "pserver", T.id, "5", "aai-node-type", "pserver", "hostname", "pservername3");                               
55                 Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "6", "aai-node-type", "vserver", "vserver-name", "vservername");
56                 Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "7", "aai-node-type", "tenant", "tenant-id", "tenantuuid", "tenant-name", "tenantname");
57                 Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "8", "aai-node-type", "cloud-region", "cloud-region-id", "clouduuid", "cloud-region-owner", "cloudOwnername");              
58                 
59                 GraphTraversalSource g = graph.traversal();
60                 rules.addEdge(g, pserver1, complex);
61                 rules.addEdge(g, pserver2, complex);            
62                 
63                 rules.addEdge(g, pserver1, vnf1);
64                 rules.addEdge(g, pserver2, vnf2);
65                 
66                 rules.addEdge(g, pserver3, complex);
67                 rules.addTreeEdge(g, tenant, cloudregion);              
68                 rules.addTreeEdge(g, vserver, tenant);
69                 rules.addEdge(g, vserver, pserver3);
70                 rules.addEdge(g, vserver, vnf2);
71                                 
72                 expectedResult.add(pserver2);
73                 expectedResult.add(pserver3);
74
75         }
76         @Override
77         protected String getQueryName() {
78                 return "pservers-fromVnf";
79         }
80         @Override
81         protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
82                 g.has("vnf-id", "vnfid2");
83         }
84         
85         @Override
86         protected void addParam(Map<String, Object> params) {
87                 return;
88         }
89 }