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