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.serialization.engines.query;
22 import static org.junit.Assert.*;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
28 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
29 import org.apache.tinkerpop.gremlin.structure.Graph;
30 import org.apache.tinkerpop.gremlin.structure.T;
31 import org.apache.tinkerpop.gremlin.structure.Vertex;
32 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.aai.edges.EdgeIngestor;
36 import org.onap.aai.exceptions.AAIException;
37 import org.onap.aai.serialization.db.AAICoreFakeEdgesConfigTranslator;
38 import org.onap.aai.serialization.db.EdgeSerializer;
39 import org.onap.aai.setup.SchemaLocationsBean;
40 import org.onap.aai.setup.SchemaVersions;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.test.annotation.DirtiesContext;
43 import org.springframework.test.context.ContextConfiguration;
44 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
46 @RunWith(SpringJUnit4ClassRunner.class)
47 @ContextConfiguration(classes = {
48 SchemaLocationsBean.class,
50 AAICoreFakeEdgesConfigTranslator.class,
55 public class GraphTraversalQueryEngine_needsFakeEdgeRulesTest {
57 EdgeSerializer edgeSer;
60 public void testFindDeletable() throws AAIException {
62 Graph graph = TinkerGraph.open();
63 Vertex parent = graph.addVertex(T.id, "00", "aai-node-type", "test-parent");
64 Vertex child = graph.addVertex(T.id, "10", "aai-node-type", "test-child");
65 Vertex cousin = graph.addVertex(T.id, "20", "aai-node-type", "test-cousin");
66 Vertex grandchild = graph.addVertex(T.id, "30", "aai-node-type", "test-grandchild");
68 GraphTraversalSource g = graph.traversal();
70 edgeSer.addTreeEdge(g, parent, child); //delete-other-v=none, no cascade
71 edgeSer.addTreeEdge(g, child, grandchild); //d-o-v=out, yes from child
72 edgeSer.addEdge(g, cousin, child); //d-o-v=out, yes from cousin
74 List<Vertex> parentExpected = new ArrayList<>(Arrays.asList(parent));
75 List<Vertex> childExpected = new ArrayList<>(Arrays.asList(child, grandchild));
76 List<Vertex> cousinExpected = new ArrayList<>(Arrays.asList(cousin, child, grandchild));
78 GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
81 List<Vertex> parentDeletes = engine.findDeletable(parent);
82 assertTrue(parentExpected.containsAll(parentDeletes) && parentDeletes.containsAll(parentExpected));
84 List<Vertex> childDeletes = engine.findDeletable(child);
85 assertTrue(childExpected.containsAll(childDeletes) && childDeletes.containsAll(childExpected));
87 List<Vertex> cousinDeletes = engine.findDeletable(cousin);
88 assertTrue(cousinExpected.containsAll(cousinDeletes) && cousinDeletes.containsAll(cousinExpected));