ae683f4637a6121cdc38be9ce2305552d1cc070f
[aai/traversal.git] /
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 VnfInstancesFromServiceInstancebyModelVersionTest extends QueryTest {
35         public VnfInstancesFromServiceInstancebyModelVersionTest() throws AAIException, NoEdgeRuleFoundException {
36                 super();
37         }
38         
39         @Test
40         public void run() {
41                 super.run();
42         }
43         @Override
44         protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
45                 
46                 
47                 //Set up the test graph 
48         Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1");
49         Vertex servicesubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-1","service-subscription-name","service-subscription-name1");
50         Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "customer-id", "customer-id-1", "customer-name", "customer-name1");
51         
52                 Vertex model1 = graph.addVertex(T.label, "model", T.id, "4", "aai-node-type", "model", "model-invariant-id", "modinvariant-id1", "model-type", "modtype");
53                 Vertex modelver1 = graph.addVertex(T.label, "model-ver", T.id, "5", "aai-node-type", "model-ver", "model-version-id", "modver-id1", "model-version-id-local", "modver-id1", "model-name", "modname1", "model-version", "v1.0");
54                 Vertex vnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "6", "aai-node-type", "generic-vnf", "vnf-id", "vnfid1", "vnf-name", "vnfname1", "vnf-type", "vnftype1", "model-invariant-id", "modinvariant-id1", "model-version-id", "modver-id1", "model-version-id-local", "modver-id1");
55                 
56 //              Vertex model2 = graph.addVertex(T.label, "model", T.id, "7", "aai-node-type", "model", "model-invariant-id", "modinvariant-id2", "model-type", "modtype");
57 //              Vertex modelver2 = graph.addVertex(T.label, "model-ver", T.id, "8", "aai-node-type", "model-ver", "model-version-id", "modver-id2", "model-name", "modname2", "model-version", "v1.0");
58                 Vertex vnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "9", "aai-node-type", "generic-vnf", "vnf-id", "vnfid2", "vnf-name", "vnfname2", "vnf-type", "vnftype2", "model-invariant-id", "modinvariant-id1", "model-version-id", "modver-id1", "model-version-id-local", "modver-id1");
59
60                 
61                 GraphTraversalSource g = graph.traversal();
62                 rules.addTreeEdge(g, model1, modelver1);//true
63                 rules.addEdge(g, vnf1, serviceinstance);//true
64                 rules.addEdge(g, vnf2, serviceinstance);//false
65         rules.addTreeEdge(g, serviceinstance, servicesubscription);//true
66         rules.addTreeEdge(g, servicesubscription, customer);//true
67        
68                 expectedResult.add(vnf1);
69
70         }
71         @Override
72         protected String getQueryName() {
73                 return "vnf-instances-fromServiceInstancebyModelVersion";
74         }
75         @Override
76         protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
77                 g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1");;
78         }
79         
80         @Override
81         protected void addParam(Map<String, Object> params) {
82                 params.put("vnfType", "vnftype1");
83                 params.put("modelVersionId", "modver-id1");
84         }
85 }