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 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
23 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
24 import org.apache.tinkerpop.gremlin.structure.Vertex;
25 import org.janusgraph.core.JanusGraph;
26 import org.janusgraph.core.JanusGraphFactory;
27 import org.janusgraph.core.JanusGraphTransaction;
29 import org.onap.aai.AAISetup;
30 import org.onap.aai.dbmap.DBConnectionType;
31 import org.onap.aai.introspection.Loader;
32 import org.onap.aai.introspection.ModelType;
33 import org.onap.aai.setup.SchemaVersions;
34 import org.onap.aai.setup.SchemaVersion;
35 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
36 import org.onap.aai.serialization.engines.QueryStyle;
37 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;
43 public class MigrateVnfcModelInvariantIdTest extends AAISetup{
45 private final static ModelType introspectorFactoryType = ModelType.MOXY;
46 private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
48 private Loader loader;
49 private TransactionalGraphEngine dbEngine;
50 private JanusGraph graph;
51 private MigrateVnfcModelInvariantId migration;
52 private JanusGraphTransaction tx;
53 private GraphTraversalSource g;
56 public void setUp() throws Exception {
57 graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
58 tx = graph.newTransaction();
60 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
61 dbEngine = new JanusGraphDBEngine(
65 Vertex vnfc1 = g.addV().property("aai-node-type", "vnfc").property("model-invariant-id", "vnfc-invariant-id-1")
66 .property("vnfcName", "vnfc-name-1").property("nfcNamingCode", "naming-code-1")
67 .property("nfcFunction", "function-1")
68 .property("model-version-id", "vnfc-variant-id-1").next();
70 Vertex vnfc2 = g.addV().property("aai-node-type", "vnfc").property("model-invariant-id-local", "vnfc-invariant-id-2")
71 .property("vnfcName", "vnfc-name-2").property("nfcNamingCode", "naming-code-2")
72 .property("nfcFunction", "function-2")
73 .property("model-version-id-local", "vnfc-version-id-2").next();
75 TransactionalGraphEngine spy = spy(dbEngine);
76 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
78 GraphTraversalSource traversal = g;
79 GraphTraversalSource readOnly = graph.traversal().withStrategies(ReadOnlyStrategy.instance());
80 when (spy.tx()).thenReturn(tx);
81 when(spy.asAdmin()).thenReturn(adminSpy);
82 when(adminSpy.getTraversalSource()).thenReturn(traversal);
83 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
85 migration = new MigrateVnfcModelInvariantId(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
90 public void cleanUp() {
96 public void testIdsUpdated() throws Exception {
98 g.V().has("aai-node-type", "vnfc").has("vnfcName", "vnfc-name-1").has("model-invariant-id-local").next().property("model-invariant-id-local").isPresent());
99 assertEquals("model-invariant-id renamed to model-invariant-id-local for vnfc", "vnfc-invariant-id-1",
100 g.V().has("aai-node-type", "vnfc").has("vnfcName", "vnfc-name-1").next().value("model-invariant-id-local").toString());
104 public void testIdsNotUpdated() throws Exception {
105 assertEquals("model-invariant-id-local should not be renamed for vnfc", "vnfc-invariant-id-2",
106 g.V().has("aai-node-type", "vnfc").has("vnfcName", "vnfc-name-2").next().value("model-invariant-id-local").toString());