Release 1.14.3 docker artifact of aai-graphadmin
[aai/graphadmin.git] / src / test / java / org / onap / aai / migration / v13 / MigratePServerAndPnfEquipTypeTest.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.v13;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.Mockito.spy;
24 import static org.mockito.Mockito.when;
25
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;
41
42 import org.janusgraph.core.JanusGraphFactory;
43 import org.janusgraph.core.JanusGraph;
44 import org.janusgraph.core.JanusGraphTransaction;
45
46
47 public class MigratePServerAndPnfEquipTypeTest extends AAISetup{
48
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;
57     Vertex pserver1;
58     Vertex pserver2;
59     Vertex pnf1;
60     Vertex pserver3;
61     Vertex pnf2;
62     Vertex pnf22;
63
64
65     @Before
66     public void setUp() throws Exception {
67         graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
68         tx = graph.newTransaction();
69         g = tx.traversal();
70         loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
71         dbEngine = new JanusGraphDBEngine(
72                 queryStyle,
73                 loader);
74          pserver1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
75                 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Server")
76                 .next();
77          
78          pserver2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
79                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server")
80                  .next();
81          
82          pnf1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
83                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch")
84                  .next();
85          pnf22 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
86                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "switch")
87                  .next();
88
89          pserver3 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
90                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server1")
91                  .next();
92          
93          pnf2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
94                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch1")
95                  .next();
96
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);
103         migration.run();
104     }
105
106     @After
107     public void cleanUp() {
108         tx.rollback();
109         graph.close();
110     }
111
112
113     /***
114      * checks if the Equip Type value was changed
115      */
116
117     @Test
118     public void confirmEquipTypeChanged() {
119
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());
124     }
125     
126     @Test
127     public void verifyEquipTypeIsNotChanged() {
128         assertEquals("server1",pserver3.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
129         assertEquals("Switch1",pnf2.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
130     }
131     
132     
133     
134
135
136 }