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.LoaderFactory;
38 import org.onap.aai.introspection.ModelType;
39 import org.onap.aai.setup.SchemaVersions;
40 import org.onap.aai.setup.SchemaVersion;
41 import org.onap.aai.serialization.engines.QueryStyle;
42 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
43 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
45 import org.janusgraph.core.JanusGraphFactory;
46 import org.janusgraph.core.JanusGraph;
47 import org.janusgraph.core.JanusGraphTransaction;
49 public class MigrateServiceInstanceToConfigurationTestPreMigrationMock extends AAISetup {
51 private final static ModelType introspectorFactoryType = ModelType.MOXY;
52 private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL;
54 private Loader loader;
55 private TransactionalGraphEngine dbEngine;
56 private JanusGraph graph;
57 private MigrateServiceInstanceToConfiguration migration;
58 private JanusGraphTransaction tx;
59 private GraphTraversalSource g;
62 public void setUp() throws Exception {
63 graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
64 tx = graph.newTransaction();
66 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
67 dbEngine = new JanusGraphDBEngine(
71 Vertex customer = g.addV()
72 .property("aai-node-type", "customer")
73 .property("global-customer-id", "customer-9972-BandwidthMigration")
74 .property("subscriber-type", "CUST")
77 Vertex servSubSDNEI = g.addV()
78 .property("aai-node-type", "service-subscription")
79 .property("service-type", "SDN-ETHERNET-INTERNET")
82 Vertex servInstance22 = g.addV()
83 .property("aai-node-type", "service-instance")
84 .property("service-instance-id", "servInstance-9972-22-BandwidthMigration")
85 .property("operational-status", "activated")
86 .property("bandwidth-total", "bandwidth-total-22-BandwidthMigration")
89 Vertex servInstance11 = g.addV()
90 .property("aai-node-type", "service-instance")
91 .property("service-instance-id", "servInstance-9972-11-BandwidthMigration")
92 .property("operational-status", "activated")
93 .property("bandwidth-total", "bandwidth-total-11-BandwidthMigration")
96 Vertex servSubDHV = g.addV()
97 .property("aai-node-type", "service-subscription")
98 .property("service-type", "DHV")
101 Vertex servInstance4 = g.addV()
102 .property("aai-node-type", "service-instance")
103 .property("service-instance-id", "servInstance-9972-4-BandwidthMigration")
104 .property("operational-status", "activated")
105 .property("bandwidth-total", "bandwidth-total-4-BandwidthMigration")
108 Vertex servInstance1 = g.addV()
109 .property("aai-node-type", "service-instance")
110 .property("service-instance-id", "ServInstance-9972-1-BandwidthMigration")
111 .property("operational-status", "activated")
112 .property("bandwidth-total", "2380")
115 Vertex servInstance3 = g.addV()
116 .property("aai-node-type", "service-instance")
117 .property("service-instance-id", "servInstance-9972-3-BandwidthMigration")
118 .property("operational-status", "activated")
119 .property("bandwidth-total", "bandwidth-total-3-BandwidthMigration")
122 Vertex servInstance2 = g.addV()
123 .property("aai-node-type", "service-instance")
124 .property("service-instance-id", "servInstance-9972-2-BandwidthMigration")
125 .property("operational-status", "activated")
126 .property("bandwidth-total", "bandwidth-total-2-BandwidthMigration")
129 Vertex config1 = g.addV()
130 .property("aai-node-type", "configuration")
131 .property("configuration-id", "9972-config-LB1113")
132 .property("configuration-type", "DHV")
133 .property("tunnel-bandwidth", "12")
136 Vertex config2 = g.addV()
137 .property("aai-node-type", "configuration")
138 .property("configuration-id", "9972-1config-LB1113")
139 .property("configuration-type", "configuration-type1-9972")
142 Vertex allottedResource = g.addV()
143 .property("aai-node-type", "allotted-resource")
144 .property("id", "allResource-9972-BandwidthMigration")
147 edgeSerializer.addTreeEdge(g, customer, servSubSDNEI);
148 edgeSerializer.addTreeEdge(g, customer, servSubDHV);
149 edgeSerializer.addTreeEdge(g, servSubSDNEI, servInstance22);
150 edgeSerializer.addTreeEdge(g, servSubSDNEI, servInstance11);
151 edgeSerializer.addTreeEdge(g, servSubDHV, servInstance4);
152 edgeSerializer.addTreeEdge(g, servSubDHV, servInstance1);
153 edgeSerializer.addTreeEdge(g, servSubDHV, servInstance3);
154 edgeSerializer.addTreeEdge(g, servSubDHV, servInstance2);
155 edgeSerializer.addEdge(g, servInstance1, allottedResource);
156 edgeSerializer.addEdge(g, servInstance1, config1);
157 edgeSerializer.addEdge(g, servInstance2, config2);
159 TransactionalGraphEngine spy = spy(dbEngine);
160 TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
162 GraphTraversalSource traversal = g;
163 GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance()));
164 when (spy.tx()).thenReturn(tx);
165 when(spy.asAdmin()).thenReturn(adminSpy);
166 when(adminSpy.getTraversalSource()).thenReturn(traversal);
167 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
169 migration = new MigrateServiceInstanceToConfiguration(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
174 public void cleanUp() {
180 public void testRun() throws Exception {
181 // check if graph nodes exist
182 assertEquals("customer node exists", true,
183 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
186 assertEquals("service subscription node, service-type=SDN-ETHERNET-INTERNET", true,
187 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
188 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SDN-ETHERNET-INTERNET")
191 assertEquals("service instance node, bandwidth-total=bandwidth-total-22-BandwidthMigration", true,
192 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
193 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SDN-ETHERNET-INTERNET")
194 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-22-BandwidthMigration")
195 .has("bandwidth-total", "bandwidth-total-22-BandwidthMigration")
198 assertEquals("service instance node, bandwidth-total=bandwidth-total-11-BandwidthMigration", true,
199 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
200 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "SDN-ETHERNET-INTERNET")
201 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-11-BandwidthMigration")
202 .has("bandwidth-total", "bandwidth-total-11-BandwidthMigration")
205 assertEquals("service subscription node, service-type=DHV", true,
206 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
207 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
210 assertEquals("service instance node, bandwidth-total=servInstance-9972-4-BandwidthMigration", true,
211 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
212 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
213 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-4-BandwidthMigration")
214 .has("bandwidth-total", "bandwidth-total-4-BandwidthMigration")
217 assertEquals("service instance node, bandwidth-total=ServInstance-9972-1-BandwidthMigration", true,
218 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
219 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
220 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "ServInstance-9972-1-BandwidthMigration")
221 .has("bandwidth-total", "2380")
224 assertEquals("service instance node, bandwidth-total=servInstance-9972-3-BandwidthMigration", true,
225 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
226 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
227 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-3-BandwidthMigration")
228 .has("bandwidth-total", "bandwidth-total-3-BandwidthMigration")
231 assertEquals("service instance node, bandwidth-total=servInstance-9972-2-BandwidthMigration", true,
232 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
233 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
234 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-2-BandwidthMigration")
235 .has("bandwidth-total", "bandwidth-total-2-BandwidthMigration")
238 assertEquals("configuration node with type=configuration-type1-9972, tunnel-bandwidth does not exist", true,
239 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
240 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
241 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-2-BandwidthMigration")
242 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
243 .has("configuration-type", "configuration-type1-9972")
246 // check if configuration node gets created for 2, 3, 4
247 assertEquals("configuration node created with type=DHV, tunnel-bandwidth=servInstance-9972-4-BandwidthMigration", true,
248 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
249 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
250 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-4-BandwidthMigration")
251 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
252 .has("configuration-type", "DHV").has("tunnel-bandwidth", "bandwidth-total-4-BandwidthMigration")
255 assertEquals("configuration node created with type=DHV, tunnel-bandwidth=servInstance-9972-3-BandwidthMigration", true,
256 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
257 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
258 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-3-BandwidthMigration")
259 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
260 .has("configuration-type", "DHV").has("tunnel-bandwidth", "bandwidth-total-3-BandwidthMigration")
263 assertEquals("configuration node created with type=DHV, tunnel-bandwidth=servInstance-9972-2-BandwidthMigration", true,
264 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
265 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
266 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "servInstance-9972-2-BandwidthMigration")
267 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
268 .has("configuration-type", "DHV").has("tunnel-bandwidth", "bandwidth-total-2-BandwidthMigration")
271 // configuration modified for ServInstance-9972-1-BandwidthMigration
272 assertEquals("configuration node modified for ServInstance-9972-1-BandwidthMigration, tunnel-bandwidth=2380", true,
273 g.V().has("global-customer-id", "customer-9972-BandwidthMigration")
274 .in("org.onap.relationships.inventory.BelongsTo").has("service-type", "DHV")
275 .in("org.onap.relationships.inventory.BelongsTo").has("service-instance-id", "ServInstance-9972-1-BandwidthMigration")
276 .out("org.onap.relationships.inventory.Uses").has("aai-node-type", "configuration")
277 .has("configuration-type", "DHV").has("tunnel-bandwidth", "2380")
282 public void testGetAffectedNodeTypes() {
283 Optional<String[]> types = migration.getAffectedNodeTypes();
284 Optional<String[]> expected = Optional.of(new String[]{"service-instance"});
286 assertNotNull(types);
287 assertArrayEquals(expected.get(), types.get());
291 public void testGetMigrationName() {
292 String migrationName = migration.getMigrationName();
294 assertNotNull(migrationName);
295 assertEquals("service-instance-to-configuration", migrationName);