f80229c1b1936c911bca549d5bdc51761baf5084
[aai/resources.git] /
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.migration.v12;
21
22 import org.janusgraph.core.JanusGraphFactory;
23 import org.janusgraph.core.JanusGraph;
24 import org.janusgraph.core.schema.JanusGraphManagement;
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
26 import org.apache.tinkerpop.gremlin.structure.Edge;
27 import org.apache.tinkerpop.gremlin.structure.Graph;
28 import org.apache.tinkerpop.gremlin.structure.Vertex;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.onap.aai.AAISetup;
34 import org.onap.aai.dbmap.DBConnectionType;
35 import org.onap.aai.introspection.Loader;
36 import org.onap.aai.introspection.LoaderFactory;
37 import org.onap.aai.introspection.ModelType;
38 import org.onap.aai.introspection.Version;
39 import org.onap.aai.serialization.db.AAIDirection;
40 import org.onap.aai.serialization.db.EdgeProperty;
41 import org.onap.aai.serialization.engines.QueryStyle;
42 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
43 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
44
45 import static org.junit.Assert.assertEquals;
46 import static org.mockito.Mockito.spy;
47 import static org.mockito.Mockito.when;
48
49 public class ContainmentDeleteOtherVPropertyMigrationTest extends AAISetup {
50
51         private final static Version version = Version.v12;
52         private final static ModelType introspectorFactoryType = ModelType.MOXY;
53         private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
54         private final static DBConnectionType type = DBConnectionType.REALTIME;
55         private Loader loader;
56         private TransactionalGraphEngine dbEngine;
57         private JanusGraph graph;
58         private ContainmentDeleteOtherVPropertyMigration migration;
59         private GraphTraversalSource g;
60         private Graph tx;
61
62         @Before
63         public void setUp() throws Exception {
64                 graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
65                 JanusGraphManagement janusgraphManagement = graph.openManagement();
66                 tx = graph.newTransaction();
67                 g = tx.traversal();
68                 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
69                 dbEngine = new JanusGraphDBEngine(
70                                 queryStyle,
71                                 type,
72                                 loader);
73                 Vertex v = g.addV().property("aai-node-type", "generic-vnf")
74                                                         .property("vnf-id", "delcontains-test-vnf")
75                                                         .next();
76                 Vertex v2 = g.addV().property("aai-node-type", "l-interface")
77                                                         .property("interface-name", "delcontains-test-lint")
78                                                         .next();
79                 Edge e = v.addEdge("hasLInterface", v2, EdgeProperty.CONTAINS.toString(), AAIDirection.OUT.toString(), 
80                                                                                                         EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString());
81                 
82                 Vertex v3 = g.addV().property("aai-node-type", "allotted-resource").next();
83                 
84                 Edge e2 = v2.addEdge("uses", v3, EdgeProperty.CONTAINS.toString(), AAIDirection.NONE.toString(),
85                                                                                         EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString());
86                 TransactionalGraphEngine spy = spy(dbEngine);
87                 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
88                 GraphTraversalSource traversal = g;
89                 when(spy.asAdmin()).thenReturn(adminSpy);
90                 when(adminSpy.getTraversalSource()).thenReturn(traversal);
91                 Mockito.doReturn(janusgraphManagement).when(adminSpy).getManagementSystem();
92                 migration = new ContainmentDeleteOtherVPropertyMigration(spy, "/edgeMigrationTestRules.json");
93                 migration.run();
94         }
95         
96         @After
97         public void cleanUp() {
98                 tx.tx().rollback();
99                 graph.close();
100         }
101         
102         @Test
103         public void run() {
104                 assertEquals("del other now OUT", true, 
105                                 g.E().hasLabel("hasLInterface").has(EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.OUT.toString()).hasNext());
106                 assertEquals("contains val still same", true, 
107                                 g.E().hasLabel("hasLInterface").has(EdgeProperty.CONTAINS.toString(), AAIDirection.OUT.toString()).hasNext());
108                 assertEquals("non-containment unchanged", true,
109                                 g.E().hasLabel("uses").has(EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString()).hasNext());
110         }
111
112 }