Merge "Added docs directory and index file for traversal"
[aai/traversal.git] / aai-traversal / src / test / java / org / openecomp / aai / rest / search / VnfsFromServiceInstanceTest.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 import org.openecomp.aai.exceptions.AAIException;
31 import org.openecomp.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
32
33 public class VnfsFromServiceInstanceTest extends QueryTest {
34         public VnfsFromServiceInstanceTest() throws AAIException, NoEdgeRuleFoundException {
35                 super();
36         }
37         
38         @Test
39         public void run() {
40                 super.run();
41         }
42         @Override
43         protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
44                 
45                 
46                 //Set up the test graph 
47         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");
48         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");
49         Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "customer-id", "customer-id-1", "customer-name", "customer-name1");
50                 Vertex vnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "4", "aai-node-type", "generic-vnf", "vnf-id", "vnfid1", "vnf-name", "vnfname1", "vnf-type", "vnftype1");
51                 Vertex serviceinstance2 = graph.addVertex(T.label, "service-instance", T.id, "5", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-2", "service-instance-name", "service-instance-name-2");
52                 Vertex vnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "6", "aai-node-type", "generic-vnf", "vnf-id", "vnfid2", "vnf-name", "vnfname2", "vnf-type", "vnftype1");
53                 
54                 GraphTraversalSource g = graph.traversal();
55
56                 rules.addEdge(g, vnf1, serviceinstance);//true
57                 rules.addEdge(g, vnf2, serviceinstance2);
58
59         rules.addTreeEdge(g, serviceinstance, servicesubscription);//true
60         rules.addTreeEdge(g, serviceinstance2, servicesubscription);
61         rules.addTreeEdge(g, servicesubscription, customer);//true
62         
63                 expectedResult.add(vnf1);
64
65         }
66         @Override
67         protected String getQueryName() {
68                 return "vnfs-fromServiceInstance";
69         }
70         @Override
71         protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
72                 g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1");
73         }
74         
75         @Override
76         protected void addParam(Map<String, Object> params) {
77                 return;
78         }
79 }