2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.serialization.engines.query;
25 import static org.junit.Assert.*;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
31 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32 import org.apache.tinkerpop.gremlin.structure.Graph;
33 import org.apache.tinkerpop.gremlin.structure.T;
34 import org.apache.tinkerpop.gremlin.structure.Vertex;
35 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
36 import org.junit.Test;
37 import org.onap.aai.exceptions.AAIException;
38 import org.onap.aai.serialization.db.EdgeRules;
40 public class GraphTraversalQueryEngineTest {
43 public void testFindDeletable() throws AAIException {
45 EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
47 Graph graph = TinkerGraph.open();
48 Vertex parent = graph.addVertex(T.id, "00", "aai-node-type", "test-parent");
49 Vertex child = graph.addVertex(T.id, "10", "aai-node-type", "test-child");
50 Vertex cousin = graph.addVertex(T.id, "20", "aai-node-type", "test-cousin");
51 Vertex grandchild = graph.addVertex(T.id, "30", "aai-node-type", "test-grandchild");
53 GraphTraversalSource g = graph.traversal();
55 rules.addTreeEdge(g, parent, child); //delete-other-v=none, no cascade
56 rules.addTreeEdge(g, child, grandchild); //d-o-v=out, yes from child
57 rules.addEdge(g, cousin, child); //d-o-v=out, yes from cousin
59 List<Vertex> parentExpected = new ArrayList<>(Arrays.asList(parent));
60 List<Vertex> childExpected = new ArrayList<>(Arrays.asList(child, grandchild));
61 List<Vertex> cousinExpected = new ArrayList<>(Arrays.asList(cousin, child, grandchild));
63 GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
66 List<Vertex> parentDeletes = engine.findDeletable(parent);
67 assertTrue(parentExpected.containsAll(parentDeletes) && parentDeletes.containsAll(parentExpected));
69 List<Vertex> childDeletes = engine.findDeletable(child);
70 assertTrue(childExpected.containsAll(childDeletes) && childDeletes.containsAll(childExpected));
72 List<Vertex> cousinDeletes = engine.findDeletable(cousin);
73 assertTrue(cousinExpected.containsAll(cousinDeletes) && cousinDeletes.containsAll(cousinExpected));