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 package org.onap.aai.serialization.engines.query;
23 import static org.junit.Assert.*;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
29 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
30 import org.apache.tinkerpop.gremlin.structure.Graph;
31 import org.apache.tinkerpop.gremlin.structure.T;
32 import org.apache.tinkerpop.gremlin.structure.Vertex;
33 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.onap.aai.config.ConfigConfiguration;
37 import org.onap.aai.edges.EdgeIngestor;
38 import org.onap.aai.exceptions.AAIException;
39 import org.onap.aai.serialization.db.AAICoreFakeEdgesConfigTranslator;
40 import org.onap.aai.serialization.db.EdgeSerializer;
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(
48 classes = {ConfigConfiguration.class, AAICoreFakeEdgesConfigTranslator.class, EdgeIngestor.class,
49 EdgeSerializer.class})
51 public class GraphTraversalQueryEngine_needsFakeEdgeRulesTest {
53 EdgeSerializer edgeSer;
56 public void testFindDeletable() throws AAIException {
58 Graph graph = TinkerGraph.open();
59 Vertex parent = graph.addVertex(T.id, "00", "aai-node-type", "test-parent");
60 Vertex child = graph.addVertex(T.id, "10", "aai-node-type", "test-child");
61 Vertex cousin = graph.addVertex(T.id, "20", "aai-node-type", "test-cousin");
62 Vertex grandchild = graph.addVertex(T.id, "30", "aai-node-type", "test-grandchild");
64 GraphTraversalSource g = graph.traversal();
66 edgeSer.addTreeEdge(g, parent, child); // delete-other-v=none, no cascade
67 edgeSer.addTreeEdge(g, child, grandchild); // d-o-v=out, yes from child
68 edgeSer.addEdge(g, cousin, child); // d-o-v=out, yes from cousin
70 List<Vertex> parentExpected = new ArrayList<>(Arrays.asList(parent));
71 List<Vertex> childExpected = new ArrayList<>(Arrays.asList(child, grandchild));
72 List<Vertex> cousinExpected = new ArrayList<>(Arrays.asList(cousin, child, grandchild));
74 GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
77 List<Vertex> parentDeletes = engine.findDeletable(parent);
78 assertTrue(parentExpected.containsAll(parentDeletes) && parentDeletes.containsAll(parentExpected));
80 List<Vertex> childDeletes = engine.findDeletable(child);
81 assertTrue(childExpected.containsAll(childDeletes) && childDeletes.containsAll(childExpected));
83 List<Vertex> cousinDeletes = engine.findDeletable(cousin);
84 assertTrue(cousinExpected.containsAll(cousinDeletes) && cousinDeletes.containsAll(cousinExpected));