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.v13;
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.Mockito.spy;
24 import static org.mockito.Mockito.when;
26 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.aai.AAISetup;
32 import org.onap.aai.dbmap.DBConnectionType;
33 import org.onap.aai.introspection.Loader;
34 import org.onap.aai.introspection.LoaderFactory;
35 import org.onap.aai.introspection.ModelType;
36 import org.onap.aai.setup.SchemaVersions;
37 import org.onap.aai.setup.SchemaVersion;
38 import org.onap.aai.serialization.engines.QueryStyle;
39 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
40 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
42 import org.janusgraph.core.JanusGraphFactory;
43 import org.janusgraph.core.JanusGraph;
44 import org.janusgraph.core.JanusGraphTransaction;
47 public class MigratePServerAndPnfEquipTypeTest extends AAISetup{
49 private final static ModelType introspectorFactoryType = ModelType.MOXY;
50 private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
51 private final static DBConnectionType type = DBConnectionType.REALTIME;
52 private Loader loader;
53 private TransactionalGraphEngine dbEngine;
54 private JanusGraph graph;
55 private MigratePserverAndPnfEquipType migration;
56 private GraphTraversalSource g;
57 private JanusGraphTransaction tx;
67 public void setUp() throws Exception {
68 graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
69 tx = graph.newTransaction();
71 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
72 dbEngine = new JanusGraphDBEngine(
76 pserver1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
77 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Server")
80 pserver2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
81 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server")
84 pnf1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
85 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch")
87 pnf22 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
88 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "switch")
91 pserver3 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
92 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server1")
95 pnf2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
96 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch1")
99 TransactionalGraphEngine spy = spy(dbEngine);
100 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
101 GraphTraversalSource traversal = g;
102 when(spy.asAdmin()).thenReturn(adminSpy);
103 when(adminSpy.getTraversalSource()).thenReturn(traversal);
104 migration = new MigratePserverAndPnfEquipType(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
109 public void cleanUp() {
116 * checks if the Equip Type value was changed
120 public void confirmEquipTypeChanged() {
122 assertEquals("SERVER",pserver1.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
123 assertEquals("SERVER",pserver2.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
124 assertEquals("SWITCH",pnf1.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
125 assertEquals("SWITCH",pnf22.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
129 public void verifyEquipTypeIsNotChanged() {
130 assertEquals("server1",pserver3.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
131 assertEquals("Switch1",pnf2.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());