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