2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.rest.search;
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;
32 public class QueryVnfFromModelByRegionTest extends QueryTest {
33 public QueryVnfFromModelByRegionTest() throws AAIException, NoEdgeRuleFoundException {
43 protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
44 Vertex serviceInst1 = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance",
45 "service-instance-id", "service-instance1", "model-invariant-id", "miid1", "model-version-id", "mvid1");
46 Vertex serviceInst2 = graph.addVertex(T.label, "service-instance", T.id, "12", "aai-node-type", "service-instance",
47 "service-instance-id", "service-instance2", "model-invariant-id", "miid2", "model-version-id", "mvid2");
49 Vertex genericVnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "generic-vnf-id", "generic-vnf1");
50 Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver1");
51 Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "4", "aai-node-type", "tenant", "tenant-id", "tenant1");
52 Vertex cloudRegion1 = graph.addVertex(T.label, "cloud-region", T.id, "5", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region1");
54 // Right invariant and version IDs, wrong cloud region
55 Vertex genericVnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "6", "aai-node-type", "generic-vnf",
56 "generic-vnf-id", "generic-vnf2");
57 Vertex vserver2 = graph.addVertex(T.label, "vserver", T.id, "7", "aai-node-type", "vserver", "vserver-id", "vserver2");
58 Vertex tenant2 = graph.addVertex(T.label, "tenant", T.id, "8", "aai-node-type", "tenant", "tenant-id", "tenant2");
59 Vertex cloudRegion2 = graph.addVertex(T.label, "cloud-region", T.id, "9", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region2");
61 // On both the right and the wrong service-instance, with the right cloud-region
62 Vertex genericVnf3 = graph.addVertex(T.label, "generic-vnf", T.id, "10", "aai-node-type", "generic-vnf",
63 "generic-vnf-id", "generic-vnf3");
64 Vertex vserver3 = graph.addVertex(T.label, "vserver", T.id, "11", "aai-node-type", "vserver", "vserver-id", "vserver3");
66 GraphTraversalSource g = graph.traversal();
67 rules.addEdge(g, serviceInst1, genericVnf1);
68 rules.addEdge(g, genericVnf1, vserver1);
69 rules.addTreeEdge(g, tenant1, vserver1);
70 rules.addTreeEdge(g, cloudRegion1, tenant1);
72 rules.addEdge(g, serviceInst1, genericVnf2);
73 rules.addEdge(g, genericVnf2, vserver2);
74 rules.addTreeEdge(g, tenant2, vserver2);
75 rules.addTreeEdge(g, cloudRegion2, tenant2);
77 rules.addEdge(g, serviceInst2, genericVnf3);
78 rules.addEdge(g, genericVnf3, vserver3);
79 rules.addTreeEdge(g, tenant1, vserver3);
81 expectedResult.add(genericVnf1);
85 protected String getQueryName() {
86 return "queryvnfFromModelbyRegion";
90 protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
91 g.has("model-invariant-id", "miid1").has("model-version-id", "mvid1");
95 protected void addParam(Map<String, Object> params) {
96 params.put("cloudRegionId", "cloud-region1");