Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / rest / search / NetworkNameFromNetworkRoleQueryTest.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.Map;
25
26 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
27 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
28 import org.apache.tinkerpop.gremlin.structure.T;
29 import org.apache.tinkerpop.gremlin.structure.Vertex;
30 import org.junit.Test;
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
33
34 public class NetworkNameFromNetworkRoleQueryTest extends QueryTest {
35
36         public NetworkNameFromNetworkRoleQueryTest() throws AAIException, NoEdgeRuleFoundException {
37                 super();
38         }
39
40         @Test
41         public void run() {
42                 super.run();
43         }
44
45         @Override
46         protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
47                 Vertex cr1 = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region", "cloud-owner", "foo", "cloud-region-id", "cr1");
48                 Vertex cr2 = graph.addVertex(T.id, "01", "aai-node-type", "cloud-region", "cloud-owner", "bar", "cloud-region-id", "cr2");
49                 
50                 Vertex l3net1 = graph.addVertex(T.id, "10", "aai-node-type", "l3-network", 
51                                                         "network-id", "net1", "network-name", "netname1", "network-role", "correct-role");
52                 Vertex l3net2 = graph.addVertex(T.id, "11", "aai-node-type", "l3-network",
53                                                         "network-id", "net2", "network-name", "netname2", "network-role", "wrong-role");
54                 Vertex l3net3 = graph.addVertex(T.id, "12", "aai-node-type", "l3-network",
55                                                         "network-id", "net3", "network-name", "netname3", "network-role", "correct-role");
56                 
57                 Vertex np1 = graph.addVertex(T.id, "20", "aai-node-type", "network-policy", "network-policy-id", "npId1");
58                 Vertex np2 = graph.addVertex(T.id, "21", "aai-node-type", "network-policy", "network-policy-id", "npId2");
59                 Vertex np3 = graph.addVertex(T.id, "22", "aai-node-type", "network-policy", "network-policy-id", "npId3");
60                 
61                 GraphTraversalSource g = graph.traversal();
62                 rules.addEdge(g, cr1, l3net1);
63                 rules.addEdge(g, l3net1, np1);
64                 rules.addEdge(g, cr1, l3net2);
65                 rules.addEdge(g, l3net2, np2);
66                 rules.addEdge(g, cr2, l3net3);
67                 rules.addEdge(g, l3net3, np3);
68                 
69                 expectedResult.add(l3net1);
70                 expectedResult.add(np1);
71         }
72
73         @Override
74         protected String getQueryName() {
75                 return "network-name-fromNetwork-role";
76         }
77
78         @Override
79         protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
80                 g.has("aai-node-type", "cloud-region").has("cloud-owner", "foo").has("cloud-region-id", "cr1");
81         }
82
83         @Override
84         protected void addParam(Map<String, Object> params) {
85                 params.put("networkRole", "correct-role");
86         }
87 }