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 Loader loader;
52 private TransactionalGraphEngine dbEngine;
53 private JanusGraph graph;
54 private MigratePserverAndPnfEquipType migration;
55 private GraphTraversalSource g;
56 private JanusGraphTransaction tx;
66 public void setUp() throws Exception {
67 graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
68 tx = graph.newTransaction();
70 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
71 dbEngine = new JanusGraphDBEngine(
74 pserver1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
75 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Server")
78 pserver2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
79 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server")
82 pnf1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
83 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch")
85 pnf22 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
86 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "switch")
89 pserver3 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
90 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server1")
93 pnf2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
94 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch1")
97 TransactionalGraphEngine spy = spy(dbEngine);
98 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
99 GraphTraversalSource traversal = g;
100 when(spy.asAdmin()).thenReturn(adminSpy);
101 when(adminSpy.getTraversalSource()).thenReturn(traversal);
102 migration = new MigratePserverAndPnfEquipType(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
107 public void cleanUp() {
114 * checks if the Equip Type value was changed
118 public void confirmEquipTypeChanged() {
120 assertEquals("SERVER",pserver1.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
121 assertEquals("SERVER",pserver2.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
122 assertEquals("SWITCH",pnf1.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
123 assertEquals("SWITCH",pnf22.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
127 public void verifyEquipTypeIsNotChanged() {
128 assertEquals("server1",pserver3.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
129 assertEquals("Switch1",pnf2.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());