Update schema service to fail to start
[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 package org.onap.aai.serialization.engines.query;
21
22 import static org.junit.Assert.*;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27
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.config.ConfigConfiguration;
36 import org.onap.aai.edges.EdgeIngestor;
37 import org.onap.aai.exceptions.AAIException;
38 import org.onap.aai.serialization.db.AAICoreFakeEdgesConfigTranslator;
39 import org.onap.aai.serialization.db.EdgeSerializer;
40 import org.onap.aai.setup.SchemaLocationsBean;
41 import org.onap.aai.setup.SchemaVersions;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.test.annotation.DirtiesContext;
44 import org.springframework.test.context.ContextConfiguration;
45 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
46
47 @RunWith(SpringJUnit4ClassRunner.class)
48 @ContextConfiguration(classes = {
49                 ConfigConfiguration.class,
50                 AAICoreFakeEdgesConfigTranslator.class,
51                 EdgeIngestor.class,
52                 EdgeSerializer.class
53 })
54 @DirtiesContext
55 public class GraphTraversalQueryEngine_needsFakeEdgeRulesTest {
56         @Autowired
57         EdgeSerializer edgeSer;
58         
59         @Test
60         public void testFindDeletable() throws AAIException {
61                 //setup
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");
67
68                 GraphTraversalSource g = graph.traversal();
69                 
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
73                 
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));
77                 
78                 GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
79                 
80                 //tests
81                 List<Vertex> parentDeletes = engine.findDeletable(parent);
82                 assertTrue(parentExpected.containsAll(parentDeletes) && parentDeletes.containsAll(parentExpected));
83                 
84                 List<Vertex> childDeletes = engine.findDeletable(child);
85                 assertTrue(childExpected.containsAll(childDeletes) && childDeletes.containsAll(childExpected));
86                 
87                 List<Vertex> cousinDeletes = engine.findDeletable(cousin);
88                 assertTrue(cousinExpected.containsAll(cousinDeletes) && cousinDeletes.containsAll(cousinExpected));
89         }
90 }