add v16 to local config for graphadmin
[aai/graphadmin.git] / src / test / java / org / onap / aai / migration / v12 / MigratePATHPhysicalInventoryTest.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.migration.v12;
21
22 import static org.junit.Assert.assertArrayEquals;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Matchers.shortThat;
26 import static org.mockito.Mockito.spy;
27 import static org.mockito.Mockito.when;
28
29 import java.util.Optional;
30
31 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
33 import org.apache.tinkerpop.gremlin.structure.Vertex;
34 import org.junit.*;
35 import org.onap.aai.AAISetup;
36 import org.onap.aai.dbmap.DBConnectionType;
37 import org.onap.aai.introspection.Loader;
38 import org.onap.aai.introspection.ModelType;
39 import org.onap.aai.setup.SchemaVersions;
40 import org.onap.aai.setup.SchemaVersion;
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 org.janusgraph.core.JanusGraphFactory;
46 import org.janusgraph.core.JanusGraph;
47 import org.janusgraph.core.JanusGraphTransaction;
48
49 public class MigratePATHPhysicalInventoryTest extends AAISetup {
50
51         private final static ModelType introspectorFactoryType = ModelType.MOXY;
52         private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
53         private final static DBConnectionType type = DBConnectionType.REALTIME;
54
55         private Loader loader;
56         private TransactionalGraphEngine dbEngine;
57         private MigratePATHPhysicalInventory migration;
58         private GraphTraversalSource g;
59
60         @Before
61         public void setUp() throws Exception {
62                 g = tx.traversal();
63                 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
64                 dbEngine = new JanusGraphDBEngine(
65                                 queryStyle,
66                                 type,
67                                 loader);
68                 
69                 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources");
70
71                 Vertex pnf2 = g.addV()
72                                 .property("aai-node-type", "pnf")
73                                 .property("pnf-name", "pnf-name-2")
74                                 .next();
75                 Vertex  port21 = g.addV()
76                                 .property("aai-node-type", "lag-interface")
77                                 .property("interface-name", "ae1")
78                                 .next();
79                 
80                 Vertex pnf3 = g.addV()
81                                 .property("aai-node-type", "pnf")
82                                 .property("pnf-name", "pnf-name-3")
83                                 .next();
84                 Vertex pnf4 = g.addV()
85                                 .property("aai-node-type", "pnf")
86                                 .property("pnf-name", "pnf-name-4")
87                                 .next();
88                 Vertex pnf5 = g.addV()
89                                 .property("aai-node-type", "pnf")
90                                 .property("pnf-name", "pnf-name-5")
91                                 .next();
92                 // graph 1
93                                 
94                 edgeSerializer.addTreeEdge(g, pnf2, port21);
95
96
97                 TransactionalGraphEngine spy = spy(dbEngine);
98                 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
99
100                 GraphTraversalSource traversal = g;
101                 GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance()));
102                 when (spy.tx()).thenReturn(tx);
103                 when(spy.asAdmin()).thenReturn(adminSpy);
104                 when(adminSpy.getTraversalSource()).thenReturn(traversal);
105                 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
106                 
107                 migration = new MigratePATHPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
108                 migration.run();
109         }
110         
111         @Test
112         public void testRun_checkPnfsAndPInterfacesExist() throws Exception {
113                 // check if graph nodes exist
114
115                 testGetMigrationName();
116                 testGetAffectedNodeTypes();
117                 
118                 // check if pnf node gets created
119                 assertEquals("4 PNFs exist", new Long(4L), 
120                                 g.V().has("aai-node-type", "pnf")
121                                 .count().next());
122                 
123                 assertEquals("5 lag-interfaces were created", new Long (5L), g.V().has("aai-node-type", "lag-interface")
124                                 .out("tosca.relationships.network.BindsTo").count().next());
125                                 
126                 assertEquals("lag-interfaces created for pnfs", new Long(1L),
127                                 g.V().has("aai-node-type", "pnf")
128                                 .has("pnf-name", "pnf-name-3").count().next());
129                 
130                 assertEquals("lag-interface ae1 created for pnf-name-3", true,
131                                 g.V().has("aai-node-type", "pnf")
132                                 .has("pnf-name", "pnf-name-3")
133                                 .in("tosca.relationships.network.BindsTo")
134                                 .has("aai-node-type", "lag-interface")
135                                 .has("interface-name","ae1")
136                                 .hasNext());
137                 
138                 assertEquals("lag-interfaces created for pnfs", new Long(2L),
139                                 g.V().has("aai-node-type", "pnf")
140                                 .has("pnf-name", "pnf-name-5")
141                                 .in("tosca.relationships.network.BindsTo")
142                                 .has("aai-node-type", "lag-interface").count().next());
143         }
144         
145         public void testGetAffectedNodeTypes() {
146                 Optional<String[]> types = migration.getAffectedNodeTypes();
147                 Optional<String[]> expected = Optional.of(new String[]{"lag-interface"});
148                 
149                 assertNotNull(types);
150                 assertArrayEquals(expected.get(), types.get());
151         }
152
153         public void testGetMigrationName() {
154                 String migrationName = migration.getMigrationName();
155
156                 assertNotNull(migrationName);
157                 assertEquals("MigratePATHPhysicalInventory", migrationName);
158         }
159 }