[AAI] Fix doc config files
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / serialization / engines / query / GraphTraversalQueryEngine_needsFakeEdgeRulesTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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.onap.aai.serialization.engines.query;
22
23 import static org.junit.Assert.*;
24
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28
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.onap.aai.setup.SchemaLocationsBean;
42 import org.onap.aai.setup.SchemaVersions;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.test.annotation.DirtiesContext;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
47
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ContextConfiguration(
50         classes = {ConfigConfiguration.class, AAICoreFakeEdgesConfigTranslator.class, EdgeIngestor.class,
51                 EdgeSerializer.class})
52 @DirtiesContext
53 public class GraphTraversalQueryEngine_needsFakeEdgeRulesTest {
54     @Autowired
55     EdgeSerializer edgeSer;
56
57     @Test
58     public void testFindDeletable() throws AAIException {
59         // setup
60         Graph graph = TinkerGraph.open();
61         Vertex parent = graph.addVertex(T.id, "00", "aai-node-type", "test-parent");
62         Vertex child = graph.addVertex(T.id, "10", "aai-node-type", "test-child");
63         Vertex cousin = graph.addVertex(T.id, "20", "aai-node-type", "test-cousin");
64         Vertex grandchild = graph.addVertex(T.id, "30", "aai-node-type", "test-grandchild");
65
66         GraphTraversalSource g = graph.traversal();
67
68         edgeSer.addTreeEdge(g, parent, child); // delete-other-v=none, no cascade
69         edgeSer.addTreeEdge(g, child, grandchild); // d-o-v=out, yes from child
70         edgeSer.addEdge(g, cousin, child); // d-o-v=out, yes from cousin
71
72         List<Vertex> parentExpected = new ArrayList<>(Arrays.asList(parent));
73         List<Vertex> childExpected = new ArrayList<>(Arrays.asList(child, grandchild));
74         List<Vertex> cousinExpected = new ArrayList<>(Arrays.asList(cousin, child, grandchild));
75
76         GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
77
78         // tests
79         List<Vertex> parentDeletes = engine.findDeletable(parent);
80         assertTrue(parentExpected.containsAll(parentDeletes) && parentDeletes.containsAll(parentExpected));
81
82         List<Vertex> childDeletes = engine.findDeletable(child);
83         assertTrue(childExpected.containsAll(childDeletes) && childDeletes.containsAll(childExpected));
84
85         List<Vertex> cousinDeletes = engine.findDeletable(cousin);
86         assertTrue(cousinExpected.containsAll(cousinDeletes) && cousinDeletes.containsAll(cousinExpected));
87     }
88 }