Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / rest / search / PserverfromConfigurationFilterInterfaceIdTest.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 PserverfromConfigurationFilterInterfaceIdTest extends QueryTest {
34         public PserverfromConfigurationFilterInterfaceIdTest() throws AAIException, NoEdgeRuleFoundException {
35                 super();
36         }
37
38         @Test
39         public void run() {
40                 super.run();
41         }
42
43         @Override
44         protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
45
46                 // Set up the test graph
47                 Vertex config1 = graph.addVertex(T.label, "configuration", T.id, "1", "aai-node-type", "configuration", "configuration-id", "configuration1");
48                 Vertex gvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "vnf-id", "vnfid1");
49                 Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "3", "aai-node-type", "pserver", "hostname", "pservername1");
50                 Vertex loglink1 = graph.addVertex(T.label, "logical-link", T.id, "4", "aai-node-type", "logical-link", "link-name", "loglink1", "in-maint", "false",
51                                 "link-type", "link-type1");
52                 Vertex lint1 = graph.addVertex(T.label, "l-interface", T.id, "5", "aai-node-type", "l-interface", "interface-name", "lint1", "is-port-mirrored", "true",
53                                 "in-maint", "true", "is-ip-unnumbered", "false", "interface-id", "interface-id1");
54                 Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "17", "aai-node-type", "pnf", "pnf-name", "pnf1name", "equip-vendor", "equip-vendor1", "equip-model",
55                                 "equip-model1");
56
57                 // Following are extra nodes that should not be picked up in
58                 // expectedResults
59                 Vertex config2 = graph.addVertex(T.label, "configuration", T.id, "11", "aai-node-type", "configuration", "configuration-id", "configuration2");
60                 Vertex gvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "12", "aai-node-type", "generic-vnf", "vnf-id", "vnfid2");
61                 Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "13", "aai-node-type", "pserver", "hostname", "pservername2");
62                 Vertex loglink2 = graph.addVertex(T.label, "logical-link", T.id, "14", "aai-node-type", "logical-link", "link-name", "loglink2", "in-maint", "false",
63                                 "link-type", "link-type2");
64                 Vertex lint2 = graph.addVertex(T.label, "l-interface", T.id, "15", "aai-node-type", "l-interface", "interface-name", "lint1", "is-port-mirrored",
65                                 "true", "in-maint", "true", "is-ip-unnumbered", "false", "interface-id", "interface-id2");
66
67                 GraphTraversalSource g = graph.traversal();
68                 rules.addEdge(g, config1, loglink1);
69                 rules.addEdge(g, config1, loglink2);
70                 rules.addEdge(g, lint1, loglink1);
71                 rules.addEdge(g, lint2, loglink1);
72                 rules.addEdge(g, loglink1, pserver1);
73                 rules.addEdge(g, loglink1, gvnf1);
74                 rules.addEdge(g, gvnf1, pnf1);
75
76                 // These should not be picked up in expectedResults
77                 //rules.addEdge(g, config2, loglink2);
78                 rules.addEdge(g, loglink2, pserver2);
79                 rules.addEdge(g, loglink2, gvnf2);
80
81                 // Note lint2 is not in expectedResults as the filter is based on
82                 // interface-id1
83                 expectedResult.add(config1);
84                 expectedResult.add(lint1);
85                 expectedResult.add(pserver1);
86                 expectedResult.add(gvnf1);
87                 expectedResult.add(pnf1);
88
89         }
90
91         @Override
92         protected String getQueryName() {
93                 return "pserver-fromConfigurationFilterInterfaceId";
94         }
95
96         @Override
97         protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
98                 g.has("configuration-id", "configuration1");
99         }
100
101         @Override
102         protected void addParam(Map<String, Object> params) {
103                 params.put("interfaceId", "interface-id1");
104         }
105 }