add v16 to local config for 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 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;
58     Vertex pserver1;
59     Vertex pserver2;
60     Vertex pnf1;
61     Vertex pserver3;
62     Vertex pnf2;
63     Vertex pnf22;
64
65
66     @Before
67     public void setUp() throws Exception {
68         graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
69         tx = graph.newTransaction();
70         g = tx.traversal();
71         loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
72         dbEngine = new JanusGraphDBEngine(
73                 queryStyle,
74                 type,
75                 loader);
76          pserver1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
77                 .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Server")
78                 .next();
79          
80          pserver2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
81                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server")
82                  .next();
83          
84          pnf1 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
85                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch")
86                  .next();
87          pnf22 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
88                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "switch")
89                  .next();
90
91          pserver3 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PSERVER_NODE_TYPE)
92                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "server1")
93                  .next();
94          
95          pnf2 = g.addV().property("aai-node-type", MigratePserverAndPnfEquipType.PNF_NODE_TYPE)
96                  .property( MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY, "Switch1")
97                  .next();
98
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);
105         migration.run();
106     }
107
108     @After
109     public void cleanUp() {
110         tx.rollback();
111         graph.close();
112     }
113
114
115     /***
116      * checks if the Equip Type value was changed
117      */
118
119     @Test
120     public void confirmEquipTypeChanged() {
121
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());
126     }
127     
128     @Test
129     public void verifyEquipTypeIsNotChanged() {
130         assertEquals("server1",pserver3.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
131         assertEquals("Switch1",pnf2.property(MigratePserverAndPnfEquipType.EQUIP_TYPE_PROPERTY).value());
132     }
133     
134     
135     
136
137
138 }