2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.migration.v12;
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;
29 import java.util.Optional;
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;
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;
45 import org.janusgraph.core.JanusGraphFactory;
46 import org.janusgraph.core.JanusGraph;
47 import org.janusgraph.core.JanusGraphTransaction;
49 public class MigratePATHPhysicalInventoryTest extends AAISetup {
51 private final static ModelType introspectorFactoryType = ModelType.MOXY;
52 private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
53 private final static DBConnectionType type = DBConnectionType.REALTIME;
55 private Loader loader;
56 private TransactionalGraphEngine dbEngine;
57 private MigratePATHPhysicalInventory migration;
58 private GraphTraversalSource g;
61 public void setUp() throws Exception {
63 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
64 dbEngine = new JanusGraphDBEngine(
69 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources");
71 Vertex pnf2 = g.addV()
72 .property("aai-node-type", "pnf")
73 .property("pnf-name", "pnf-name-2")
75 Vertex port21 = g.addV()
76 .property("aai-node-type", "lag-interface")
77 .property("interface-name", "ae1")
80 Vertex pnf3 = g.addV()
81 .property("aai-node-type", "pnf")
82 .property("pnf-name", "pnf-name-3")
84 Vertex pnf4 = g.addV()
85 .property("aai-node-type", "pnf")
86 .property("pnf-name", "pnf-name-4")
88 Vertex pnf5 = g.addV()
89 .property("aai-node-type", "pnf")
90 .property("pnf-name", "pnf-name-5")
94 edgeSerializer.addTreeEdge(g, pnf2, port21);
97 TransactionalGraphEngine spy = spy(dbEngine);
98 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
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);
107 migration = new MigratePATHPhysicalInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
112 public void testRun_checkPnfsAndPInterfacesExist() throws Exception {
113 // check if graph nodes exist
115 testGetMigrationName();
116 testGetAffectedNodeTypes();
118 // check if pnf node gets created
119 assertEquals("4 PNFs exist", new Long(4L),
120 g.V().has("aai-node-type", "pnf")
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());
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());
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")
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());
145 public void testGetAffectedNodeTypes() {
146 Optional<String[]> types = migration.getAffectedNodeTypes();
147 Optional<String[]> expected = Optional.of(new String[]{"lag-interface"});
149 assertNotNull(types);
150 assertArrayEquals(expected.get(), types.get());
153 public void testGetMigrationName() {
154 String migrationName = migration.getMigrationName();
156 assertNotNull(migrationName);
157 assertEquals("MigratePATHPhysicalInventory", migrationName);