Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / rest / search / QueryPnfFromModelByRegionTest.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 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
23 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
24 import org.apache.tinkerpop.gremlin.structure.T;
25 import org.apache.tinkerpop.gremlin.structure.Vertex;
26 import org.junit.Test;
27 import org.onap.aai.exceptions.AAIException;
28 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
29
30 import java.util.Map;
31
32 public class QueryPnfFromModelByRegionTest extends QueryTest {
33         public QueryPnfFromModelByRegionTest() throws AAIException, NoEdgeRuleFoundException {
34                 super();
35         }
36
37         @Test
38         public void run() {
39                 super.run();
40         }
41
42         @Override
43         protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
44                 
45
46                 //serviceInstance 1,2,3 are good and 4 is bad based upon the filters
47                 Vertex serviceInst1 = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id",
48                                 "service-instance1", "model-invariant-id", "miid1", "model-version-id", "mvid1");
49                 Vertex serviceInst2 = graph.addVertex(T.label, "service-instance", T.id, "2", "aai-node-type", "service-instance", "service-instance-id",
50                                 "service-instance2", "model-invariant-id", "miid1", "model-version-id", "mvid1");               
51                 Vertex serviceInst3 = graph.addVertex(T.label, "service-instance", T.id, "3", "aai-node-type", "service-instance", "service-instance-id",
52                                 "service-instance3", "model-invariant-id", "miid1", "model-version-id", "mvid1");               
53                 Vertex serviceInst4 = graph.addVertex(T.label, "service-instance", T.id, "4", "aai-node-type", "service-instance", "service-instance-id",
54                                 "service-instance4", "model-invariant-id", "miid2", "model-version-id", "mvid2");
55
56                 //pnf 1,2 & 3 are good based upon the filters
57                 Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "5", "aai-node-type", "pnf", "pnf-name", "pnf1name", "equip-vendor", "equip-vendor1", "equip-model",
58                                 "equip-model1");
59                 Vertex pnf2 = graph.addVertex(T.label, "pnf", T.id, "6", "aai-node-type", "pnf", "pnf-name", "pnf2name", "equip-vendor", "equip-vendor1", "equip-model",
60                                 "equip-model1");
61                 Vertex pnf3 = graph.addVertex(T.label, "pnf", T.id, "7", "aai-node-type", "pnf", "pnf-name", "pnf3name", "equip-vendor", "equip-vendor1", "equip-model",
62                                 "equip-model1");
63                 Vertex pnf4 = graph.addVertex(T.label, "pnf", T.id, "12", "aai-node-type", "pnf", "pnf-name", "pnf4name", "equip-vendor", "equip-vendor4",
64                                 "equip-model", "equip-model4");
65                 
66                 Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "8", "aai-node-type", "complex", "physical-location-id", "physical-location-id-1");
67                 Vertex complex2 = graph.addVertex(T.label, "complex", T.id, "9", "aai-node-type", "complex", "physical-location-id", "physical-location-id-2");
68                 
69                 //cr 1 is good based upon the filter
70                 Vertex cloudRegion1 = graph.addVertex(T.label, "cloud-region", T.id, "10", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region1");
71                 Vertex cloudRegion2 = graph.addVertex(T.label, "cloud-region", T.id, "11", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region2");
72
73
74                 GraphTraversalSource g = graph.traversal();
75                 rules.addEdge(g, serviceInst1, pnf1);
76                 rules.addEdge(g, serviceInst2, pnf2);
77                 rules.addEdge(g, serviceInst3, pnf3);
78                 rules.addEdge(g, serviceInst4, pnf4);
79                 
80                 rules.addEdge(g, pnf1, complex1);
81                 rules.addEdge(g, pnf2, complex1);
82                 rules.addEdge(g, pnf3, complex2);
83                 rules.addEdge(g, pnf4, complex2);
84                 
85                 rules.addEdge(g, cloudRegion1, complex1);
86                 rules.addEdge(g, cloudRegion2, complex2);
87
88
89                 expectedResult.add(pnf1);
90                 expectedResult.add(pnf2);       
91         }
92
93         @Override
94         protected String getQueryName() {
95                 return "pnf-fromModel-byRegion";
96         }
97
98         @Override
99         protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
100                 g.has("model-invariant-id", "miid1").has("model-version-id", "mvid1");
101         }
102
103         @Override
104         protected void addParam(Map<String, Object> params) {
105                 params.put("cloudRegionId", "cloud-region1");
106                 params.put("equipVendor", "equip-vendor1");
107                 params.put("equipModel", "equip-model1");
108         }
109 }