Initial seed code for graphadmin
[aai/graphadmin.git] / src / test / java / org / onap / aai / migration / v12 / MigrateModelVerDistributionStatusPropertyTest.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.v12;
21
22 import org.janusgraph.core.JanusGraphFactory;
23 import org.janusgraph.core.JanusGraph;
24 import org.janusgraph.core.JanusGraphTransaction;
25 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
26 import org.apache.tinkerpop.gremlin.structure.Vertex;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.aai.AAISetup;
31 import org.onap.aai.dbmap.DBConnectionType;
32 import org.onap.aai.introspection.Loader;
33 import org.onap.aai.introspection.ModelType;
34 import org.onap.aai.setup.SchemaVersions;
35 import org.onap.aai.setup.SchemaVersion;
36 import org.onap.aai.serialization.engines.QueryStyle;
37 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
38 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
39 import static org.junit.Assert.assertEquals;
40 import static org.mockito.Mockito.spy;
41 import static org.mockito.Mockito.when;
42
43
44 public class MigrateModelVerDistributionStatusPropertyTest extends AAISetup{
45
46     private final static ModelType introspectorFactoryType = ModelType.MOXY;
47     private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
48     private final static DBConnectionType type = DBConnectionType.REALTIME;
49     private Loader loader;
50     private TransactionalGraphEngine dbEngine;
51     private JanusGraph graph;
52     private MigrateModelVerDistriubutionStatusProperty migration;
53     private GraphTraversalSource g;
54     private JanusGraphTransaction tx;
55     Vertex modelVer1;
56     Vertex modelVer2;
57
58     @Before
59     public void setUp() throws Exception {
60         graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
61         tx = graph.newTransaction();
62         g = tx.traversal();
63         loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
64         dbEngine = new JanusGraphDBEngine(
65                 queryStyle,
66                 type,
67                 loader);
68          modelVer1 = g.addV().property("aai-node-type", "model-ver")
69                 .property("model-version-id", "modelVer1")
70                 .property("distribution-status", "test1")
71                 .next();
72
73         modelVer2 = g.addV().property("aai-node-type", "model-ver")
74                 .property("model-version-id", "modelVer1")
75                 .next();
76
77         TransactionalGraphEngine spy = spy(dbEngine);
78         TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
79         GraphTraversalSource traversal = g;
80         when(spy.asAdmin()).thenReturn(adminSpy);
81         when(adminSpy.getTraversalSource()).thenReturn(traversal);
82         migration = new MigrateModelVerDistriubutionStatusProperty(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
83         migration.run();
84     }
85
86     @After
87     public void cleanUp() {
88         tx.rollback();
89         graph.close();
90     }
91
92
93     /***
94      * checks if the Distribution Status value was changed
95      */
96
97     @Test
98     public void confirmDistributionStatusChanged() {
99
100         assertEquals("DISTRIBUTION_COMPLETE_OK",modelVer1.property("distribution-status").value());
101         assertEquals("DISTRIBUTION_COMPLETE_OK",modelVer2.property("distribution-status").value());
102
103     }
104
105
106 }