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=========================================================
21 * ============LICENSE_START=======================================================
23 * ================================================================================
24 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
25 * ================================================================================
26 * Licensed under the Apache License, Version 2.0 (the "License");
27 * you may not use this file except in compliance with the License.
28 * You may obtain a copy of the License at
30 * http://www.apache.org/licenses/LICENSE-2.0
32 * Unless required by applicable law or agreed to in writing, software
33 * distributed under the License is distributed on an "AS IS" BASIS,
34 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 * See the License for the specific language governing permissions and
36 * limitations under the License.
37 * ============LICENSE_END=========================================================
39 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
41 package org.onap.aai.rest.search;
43 import static org.junit.Assert.*;
47 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
48 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
49 import org.apache.tinkerpop.gremlin.structure.T;
50 import org.apache.tinkerpop.gremlin.structure.Vertex;
51 import org.junit.Test;
52 import org.onap.aai.exceptions.AAIException;
53 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
55 public class AccessServiceFromServiceInstanceTest extends QueryTest {
57 public AccessServiceFromServiceInstanceTest() throws AAIException, NoEdgeRuleFoundException {
67 protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
68 //Set up the test graph
69 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");
70 Vertex serviceSubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-type", "service-subcription-1");
71 Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "global-customer-id", "customer-id-1", "subscriber-name", "customer-name1", "subscriber-type", "customer-type1");
72 Vertex forwardingPath = graph.addVertex(T.label, "forwarding-path", T.id, "4", "aai-node-type", "forwarding-path", "forwarding-path-id", "forwarding-path-id-1", "forwarding-path-name", "forwarding-path-name-1");
73 Vertex configuration = graph.addVertex(T.label, "configuration", T.id, "5", "aai-node-type", "configuration", "configuration-id", "configuration-1", "configuration-type", "configuration-type-1", "configuration-sub-type", "configuration-sub-type-1");
74 Vertex evc = graph.addVertex(T.label, "evc", T.id, "6", "aai-node-type", "evc", "evc-id", "evc-1");
75 Vertex forwarder = graph.addVertex(T.label, "forwarder", T.id,"7", "aai-node-type", "forwarder", "sequence", "forwarder-1");
76 Vertex forwarderEvc = graph.addVertex(T.label, "forwarder-evc", T.id, "8", "aai-node-type", "forwarder-evc", "forwarder-evc-id", "forwarder-evc-1");
77 Vertex pInterface = graph.addVertex(T.label, "p-interface", T.id, "9", "aai-node-type", "p-interface", "interface-name", "p-interface-1");
78 Vertex pnf = graph.addVertex(T.label, "pnf", T.id, "10", "aai-node-type", "pnf", "pnf-name", "pnf1name");
79 Vertex lagInterface = graph.addVertex(T.label, "lag-interface", T.id, "11", "aai-node-type", "lag-interface","interface-name", "lagint1");
80 Vertex logicalLink = graph.addVertex(T.label, "logical-link", T.id, "12", "aai-node-type", "logical-link", "link-name", "logical-link-1", "link-type", "LAG");
81 Vertex badLogicalLink = graph.addVertex(T.label, "logical-link", T.id, "13", "aai-node-type", "logical-link", "link-name", "logical-link-bad", "link-type", "BAD");
82 Vertex wrongInterfaceOne = graph.addVertex(T.label, "l-interface", T.id, "14", "aai-node-type", "l-interface", "interface-name", "wrong-interface-1");
83 Vertex wrongInterfaceTwo = graph.addVertex(T.label, "l-interface", T.id, "15", "aai-node-type", "l-interface", "interface-name", "wrong-interface-2");
84 Vertex wrongInterfaceThree = graph.addVertex(T.label, "l-interface", T.id, "16", "aai-node-type", "l-interface", "interface-name", "wrong-interface-3");
85 Vertex wrongInterfaceFour = graph.addVertex(T.label, "l-interface", T.id, "17", "aai-node-type", "l-interface", "interface-name", "wrong-interface-4");
87 GraphTraversalSource g = graph.traversal();
89 rules.addTreeEdge(g, serviceInstance, serviceSubscription);
90 rules.addTreeEdge(g, serviceSubscription, customer);
91 rules.addEdge(g, serviceInstance,forwardingPath);
92 rules.addEdge(g, forwardingPath, configuration);
93 rules.addTreeEdge(g, configuration,evc);
94 rules.addTreeEdge(g, forwardingPath,forwarder);
95 rules.addEdge(g, forwarder, configuration);
96 rules.addTreeEdge(g, configuration,forwarderEvc);
97 rules.addEdge(g, forwarder, pInterface);
98 rules.addTreeEdge(g, pnf,pInterface);
99 rules.addEdge(g, forwarder, lagInterface);
100 rules.addTreeEdge(g, lagInterface,pnf);
101 rules.addEdge(g, logicalLink,lagInterface);
104 rules.addEdge(g, badLogicalLink, lagInterface);
105 rules.addEdge(g, configuration, wrongInterfaceOne);
106 rules.addEdge(g, forwarder, wrongInterfaceTwo);
107 rules.addTreeEdge(g, pInterface, wrongInterfaceThree);
108 rules.addTreeEdge(g, lagInterface, wrongInterfaceFour);
111 expectedResult.add(serviceInstance);
112 expectedResult.add(serviceSubscription);
113 expectedResult.add(customer);
114 expectedResult.add(forwardingPath);
115 expectedResult.add(configuration);
116 expectedResult.add(evc);
117 expectedResult.add(forwarder);
118 expectedResult.add(forwarderEvc);
119 expectedResult.add(pInterface);
120 expectedResult.add(pnf);
121 expectedResult.add(lagInterface);
122 expectedResult.add(logicalLink);
127 protected String getQueryName() {
128 return "access-service-fromServiceInstance";
132 protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
133 g.has("aai-node-type", "customer").has("global-customer-id", "customer-id-1").in("org.onap.relationships.inventory.BelongsTo")
134 .has("aai-node-type", "service-subscription").has("service-type", "service-subcription-1").in("org.onap.relationships.inventory.BelongsTo")
135 .has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1");
139 protected void addParam(Map<String, Object> params) {