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.v12;
22 import static org.junit.Assert.assertArrayEquals;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Mockito.spy;
26 import static org.mockito.Mockito.when;
28 import java.util.Optional;
30 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
31 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
32 import org.apache.tinkerpop.gremlin.structure.Vertex;
34 import org.onap.aai.AAISetup;
35 import org.onap.aai.dbmap.DBConnectionType;
36 import org.onap.aai.introspection.Loader;
37 import org.onap.aai.introspection.ModelType;
38 import org.onap.aai.setup.SchemaVersions;
39 import org.onap.aai.setup.SchemaVersion;
40 import org.onap.aai.serialization.engines.QueryStyle;
41 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
42 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
44 import org.janusgraph.core.JanusGraphFactory;
45 import org.janusgraph.core.JanusGraph;
46 import org.janusgraph.core.JanusGraphTransaction;
48 public class MigrateInvEvcInventoryTest extends AAISetup {
50 private final static ModelType introspectorFactoryType = ModelType.MOXY;
51 private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
53 private static Loader loader;
54 private static TransactionalGraphEngine dbEngine;
55 private static JanusGraph graph;
56 private static MigrateINVEvcInventory migration;
57 private static JanusGraphTransaction tx;
58 private static GraphTraversalSource g;
61 public void setUp() throws Exception {
62 graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
63 tx = graph.newTransaction();
65 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
66 dbEngine = new JanusGraphDBEngine(
70 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources");
73 .property("aai-node-type", "evc")
74 .property("evc-id", "evc-name-1")
77 Vertex evc2 = g.addV()
78 .property("aai-node-type", "evc")
79 .property("evc-id", "evc-name-2")
82 TransactionalGraphEngine spy = spy(dbEngine);
83 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
85 GraphTraversalSource traversal = g;
86 GraphTraversalSource readOnly = graph.traversal().withStrategies(ReadOnlyStrategy.instance());
87 when (spy.tx()).thenReturn(tx);
88 when(spy.asAdmin()).thenReturn(adminSpy);
89 when(adminSpy.getTraversalSource()).thenReturn(traversal);
90 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
92 migration = new MigrateINVEvcInventory(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
97 public void cleanUp() {
103 public void testRun_updateEvcNode() throws Exception {
104 // check if graph nodes exist
105 assertEquals("evc node exists", true,
106 g.V().has("aai-node-type", "evc")
107 .has("evc-id", "evc-name-1")
110 // check if evc object is updated to set the value for inter-connect-type-ingress
111 assertEquals("evc is updated", true,
112 g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-1")
113 .has("inter-connect-type-ingress", "SHARED")
118 public void testRun_evcNotCreated() throws Exception {
120 assertEquals("evc node does not exist", false,
121 g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-3")
124 //inter-connect-type-ingress is not present on the evc
125 assertEquals("evc node exists", true,
126 g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-2")
128 assertEquals("evc node not updated with inter-connect-type-ingress", false,
129 g.V().has("aai-node-type", "evc").has("evc-id", "evc-name-2").has("inter-connect-type-ingress")
135 public void testGetAffectedNodeTypes() {
136 Optional<String[]> types = migration.getAffectedNodeTypes();
137 Optional<String[]> expected = Optional.of(new String[]{"evc"});
139 assertNotNull(types);
140 assertArrayEquals(expected.get(), types.get());
144 public void testGetMigrationName() {
145 String migrationName = migration.getMigrationName();
147 assertNotNull(migrationName);
148 assertEquals("MigrateINVEvcInventory", migrationName);