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=========================================================
21 package org.onap.aai.serialization.db;
23 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
24 import org.apache.tinkerpop.gremlin.structure.Edge;
25 import org.apache.tinkerpop.gremlin.structure.Graph;
26 import org.apache.tinkerpop.gremlin.structure.T;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
29 import org.janusgraph.core.JanusGraphFactory;
31 import org.junit.rules.ExpectedException;
32 import org.junit.runner.RunWith;
33 import org.junit.runners.Parameterized;
34 import org.onap.aai.AAISetup;
35 import org.onap.aai.db.props.AAIProperties;
36 import org.onap.aai.edges.EdgeIngestor;
37 import org.onap.aai.edges.enums.EdgeType;
38 import org.onap.aai.exceptions.AAIException;
39 import org.onap.aai.introspection.Introspector;
40 import org.onap.aai.introspection.Loader;
41 import org.onap.aai.introspection.ModelType;
42 import org.onap.aai.parsers.query.QueryParser;
43 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
44 import org.onap.aai.serialization.engines.QueryStyle;
45 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
46 import org.onap.aai.setup.SchemaVersion;
47 import org.onap.aai.util.AAIConstants;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.test.annotation.DirtiesContext;
51 import java.io.UnsupportedEncodingException;
53 import java.net.URISyntaxException;
56 import static org.hamcrest.CoreMatchers.is;
57 import static org.junit.Assert.*;
58 import static org.mockito.Mockito.spy;
59 import static org.mockito.Mockito.when;
61 @RunWith(value = Parameterized.class)
62 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
63 public class DbSerializerTest extends AAISetup {
65 // to use, set thrown.expect to whatever your test needs
66 // this line establishes default of expecting no exception to be thrown
68 public ExpectedException thrown = ExpectedException.none();
70 protected static Graph graph;
73 protected EdgeSerializer edgeSer;
75 protected EdgeIngestor ei;
77 private SchemaVersion version;
78 private final ModelType introspectorFactoryType = ModelType.MOXY;
79 private Loader loader;
80 private TransactionalGraphEngine dbEngine;
81 private TransactionalGraphEngine engine; // for tests that aren't mocking the engine
82 private DBSerializer dbser;
83 private TransactionalGraphEngine spy;
84 private TransactionalGraphEngine.Admin adminSpy;
86 @Parameterized.Parameter
87 public QueryStyle queryStyle;
89 @Parameterized.Parameters(name = "QueryStyle.{0}")
90 public static Collection<Object[]> data() {
91 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
95 public static void init() {
96 graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
101 public void setup() throws Exception {
103 version = schemaVersions.getDefaultVersion();
104 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
105 dbEngine = new JanusGraphDBEngine(queryStyle, loader);
107 adminSpy = spy(dbEngine.asAdmin());
109 engine = new JanusGraphDBEngine(queryStyle, loader);
110 dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
114 public void testFindDeletableDoesNotReturnDuplicates() throws AAIException {
116 Vertex genericVnf1 = graph.addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf1", "vnf-name", "vnfName1");
118 Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface1");
119 Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface2");
121 Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink1");
122 Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink2");
124 GraphTraversalSource g = graph.traversal();
126 edgeSer.addTreeEdge(g, genericVnf1, lInterface1);
127 edgeSer.addTreeEdge(g, genericVnf1, lInterface2);
128 edgeSer.addEdge(g, lInterface1, logicalLink1);
129 edgeSer.addEdge(g, lInterface1, logicalLink2);
130 // This line will cause the logical link2 to be found twice under linterface 1
131 // and also under the linterface 2 and since in the past deletable returned
132 // duplicates this test checks that it shouldn't return duplicates
133 edgeSer.addEdge(g, lInterface2, logicalLink2);
135 when(spy.asAdmin()).thenReturn(adminSpy);
136 when(adminSpy.getTraversalSource()).thenReturn(g);
137 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(g);
139 List<Vertex> deletableVertexes = spy.getQueryEngine().findDeletable(genericVnf1);
140 Set<Vertex> vertexSet = new HashSet<>();
142 for (Vertex deletableVertex : deletableVertexes) {
143 if (!vertexSet.contains(deletableVertex)) {
144 vertexSet.add(deletableVertex);
146 fail("Find deletable is returning a list of duplicate vertexes");
152 public void tearDown() {
157 public static void destroy() throws Exception {
161 private void subnetSetup() throws AAIException, UnsupportedEncodingException {
163 * This setus up the test graph, For future junits , add more vertices
167 Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
168 "l3-interface-ipv4-address", "l3-interface-ipv4-address-1",
169 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
170 AAIProperties.CREATED_TS, 123L,
171 AAIProperties.SOURCE_OF_TRUTH, "sot",
172 AAIProperties.RESOURCE_VERSION, "123",
173 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
174 AAIProperties.LAST_MOD_TS, 333L);
175 Vertex subnet_2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-2",
176 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
177 AAIProperties.CREATED_TS, 123L,
178 AAIProperties.SOURCE_OF_TRUTH, "sot",
179 AAIProperties.RESOURCE_VERSION, "123",
180 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
181 AAIProperties.LAST_MOD_TS, 333L);
182 Vertex l3interipv6addresslist_3 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
183 "l3-interface-ipv6-address", "l3-interface-ipv6-address-3",
184 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
185 AAIProperties.CREATED_TS, 123L,
186 AAIProperties.SOURCE_OF_TRUTH, "sot",
187 AAIProperties.RESOURCE_VERSION, "123",
188 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
189 AAIProperties.LAST_MOD_TS, 333L);
190 Vertex subnet_4 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-4",
191 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
192 AAIProperties.CREATED_TS, 123L,
193 AAIProperties.SOURCE_OF_TRUTH, "sot",
194 AAIProperties.RESOURCE_VERSION, "123",
195 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
196 AAIProperties.LAST_MOD_TS, 333L);
197 Vertex subnet_5 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-5",
198 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
199 AAIProperties.CREATED_TS, 123L,
200 AAIProperties.SOURCE_OF_TRUTH, "sot",
201 AAIProperties.RESOURCE_VERSION, "123",
202 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
203 AAIProperties.LAST_MOD_TS, 333L);
204 Vertex l3network_6 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-6", "network-name", "network-name-6",
205 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
206 AAIProperties.CREATED_TS, 123L,
207 AAIProperties.SOURCE_OF_TRUTH, "sot",
208 AAIProperties.RESOURCE_VERSION, "123",
209 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
210 AAIProperties.LAST_MOD_TS, 333L);
212 GraphTraversalSource g = graph.traversal();
213 edgeSer.addEdge(g, l3interipv4addresslist_1, subnet_2);
214 edgeSer.addEdge(g, l3interipv6addresslist_3, subnet_4);
215 edgeSer.addTreeEdge(g, subnet_5, l3network_6);
217 l3interipv4addresslist_1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3interipv4addresslist_1).toString());
218 subnet_2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet_2).toString());
219 l3interipv6addresslist_3.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3interipv6addresslist_3).toString());
220 subnet_4.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet_4).toString());
221 subnet_5.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet_5).toString());
222 l3network_6.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3network_6).toString());
226 private void l3NetworkSetup() throws AAIException, UnsupportedEncodingException {
228 * This setus up the test graph, For future junits , add more vertices
232 Vertex l3network1 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v1",
233 "network-name", "network-name-v1",
234 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
235 AAIProperties.CREATED_TS, 123L,
236 AAIProperties.SOURCE_OF_TRUTH, "sot",
237 AAIProperties.RESOURCE_VERSION, "123",
238 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
239 AAIProperties.LAST_MOD_TS, 333L);
240 Vertex l3network2 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v2",
241 "network-name", "network-name-v2",
242 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
243 AAIProperties.CREATED_TS, 123L,
244 AAIProperties.SOURCE_OF_TRUTH, "sot",
245 AAIProperties.RESOURCE_VERSION, "123",
246 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
247 AAIProperties.LAST_MOD_TS, 333L);
248 Vertex subnet1 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v1",
249 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
250 AAIProperties.CREATED_TS, 123L,
251 AAIProperties.SOURCE_OF_TRUTH, "sot",
252 AAIProperties.RESOURCE_VERSION, "123",
253 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
254 AAIProperties.LAST_MOD_TS, 333L);
255 Vertex subnet2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v2",
256 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
257 AAIProperties.CREATED_TS, 123L,
258 AAIProperties.SOURCE_OF_TRUTH, "sot",
259 AAIProperties.RESOURCE_VERSION, "123",
260 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
261 AAIProperties.LAST_MOD_TS, 333L);
263 Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
264 "l3-interface-ipv4-address", "l3-intr-v1",
265 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
266 AAIProperties.CREATED_TS, 123L,
267 AAIProperties.SOURCE_OF_TRUTH, "sot",
268 AAIProperties.RESOURCE_VERSION, "123",
269 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
270 AAIProperties.LAST_MOD_TS, 333L);
271 Vertex l3interipv6addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
272 "l3-interface-ipv6-address", "l3-interface-ipv6-v1",
273 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
274 AAIProperties.CREATED_TS, 123L,
275 AAIProperties.SOURCE_OF_TRUTH, "sot",
276 AAIProperties.RESOURCE_VERSION, "123",
277 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
278 AAIProperties.LAST_MOD_TS, 333L);
280 GraphTraversalSource g = graph.traversal();
281 edgeSer.addTreeEdge(g, subnet1, l3network1);
282 edgeSer.addEdge(g, l3interipv4addresslist_1, subnet1);
283 edgeSer.addEdge(g, l3interipv6addresslist_1, subnet1);
285 edgeSer.addTreeEdge(g, subnet2, l3network2);
287 subnet1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet1).toString());
288 l3interipv4addresslist_1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3interipv4addresslist_1).toString());
289 l3network1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3network1).toString());
290 subnet2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet2).toString());
291 l3network2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3network2).toString());
297 private void vserverSetup() throws AAIException, UnsupportedEncodingException {
299 * This setus up the test graph, For future junits , add more vertices
303 Vertex vserver1 = graph.addVertex("aai-node-type", "vserver", "vserver-id", "vss1",
304 AAIProperties.AAI_URI, "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vss1",
305 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
306 AAIProperties.CREATED_TS, 123L,
307 AAIProperties.SOURCE_OF_TRUTH, "sot",
308 AAIProperties.RESOURCE_VERSION, "123",
309 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
310 AAIProperties.LAST_MOD_TS, 333L);
312 Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr1",
313 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
314 AAIProperties.CREATED_TS, 123L,
315 AAIProperties.SOURCE_OF_TRUTH, "sot",
316 AAIProperties.RESOURCE_VERSION, "123",
317 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
318 AAIProperties.LAST_MOD_TS, 333L);
319 Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr2",
320 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
321 AAIProperties.CREATED_TS, 123L,
322 AAIProperties.SOURCE_OF_TRUTH, "sot",
323 AAIProperties.RESOURCE_VERSION, "123",
324 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
325 AAIProperties.LAST_MOD_TS, 333L);
327 Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink1",
328 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
329 AAIProperties.CREATED_TS, 123L,
330 AAIProperties.SOURCE_OF_TRUTH, "sot",
331 AAIProperties.RESOURCE_VERSION, "123",
332 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
333 AAIProperties.LAST_MOD_TS, 333L);
334 Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink2",
335 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
336 AAIProperties.CREATED_TS, 123L,
337 AAIProperties.SOURCE_OF_TRUTH, "sot",
338 AAIProperties.RESOURCE_VERSION, "123",
339 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
340 AAIProperties.LAST_MOD_TS, 333L);
342 Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
343 "l3-interface-ipv4-address", "l3-intr-ipv4-address-1",
344 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
345 AAIProperties.CREATED_TS, 123L,
346 AAIProperties.SOURCE_OF_TRUTH, "sot",
347 AAIProperties.RESOURCE_VERSION, "123",
348 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
349 AAIProperties.LAST_MOD_TS, 333L);
350 Vertex l3interipv6addresslist_2 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
351 "l3-interface-ipv4-address", "l3-intr-ipv6-address-1",
352 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
353 AAIProperties.CREATED_TS, 123L,
354 AAIProperties.SOURCE_OF_TRUTH, "sot",
355 AAIProperties.RESOURCE_VERSION, "123",
356 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
357 AAIProperties.LAST_MOD_TS, 333L);
359 GraphTraversalSource g = graph.traversal();
361 edgeSer.addTreeEdge(g, lInterface1, vserver1);
362 edgeSer.addTreeEdge(g, lInterface2, vserver1);
363 edgeSer.addTreeEdge(g, l3interipv4addresslist_1, lInterface1);
364 edgeSer.addTreeEdge(g, l3interipv6addresslist_2, lInterface2);
366 edgeSer.addEdge(g, lInterface1, logicalLink1);
367 edgeSer.addEdge(g, lInterface2, logicalLink2);
369 vserver1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(vserver1).toString());
370 lInterface1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(lInterface1).toString());
371 lInterface2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(lInterface2).toString());
372 l3interipv4addresslist_1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3interipv4addresslist_1).toString());
373 l3interipv6addresslist_2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3interipv6addresslist_2).toString());
374 logicalLink1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(logicalLink1).toString());
375 logicalLink2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(logicalLink2).toString());
379 public void subnetDelWithInEdgesIpv4Test() throws AAIException, UnsupportedEncodingException {
381 String expected_message =
382 "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list]";
385 * This subnet has in-edges with l3-ipv4 and NOT ok to delete
387 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-2").next();
389 String exceptionMessage = testCascadeDelete(subnet);
390 assertEquals(expected_message, exceptionMessage);
395 public void subnetDelWithInEdgesIpv6Test() throws AAIException, UnsupportedEncodingException {
397 String expected_message =
398 "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv6-address-list]";
401 * This subnet has in-edges with l3-ipv6 and NOT ok to delete
403 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-4").next();
404 String exceptionMessage = testCascadeDelete(subnet);
405 assertEquals(expected_message, exceptionMessage);
410 public void subnetDelWithInEdgesL3network() throws AAIException, UnsupportedEncodingException {
412 String expected_message = "";
415 * This subnet has in-edges with l3-network and ok to delete
417 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-5").next();
419 String exceptionMessage = testCascadeDelete(subnet);
420 assertEquals(expected_message, exceptionMessage);
424 private String testCascadeDelete(Vertex v) throws AAIException {
426 GraphTraversalSource traversal = graph.traversal();
427 when(spy.asAdmin()).thenReturn(adminSpy);
428 when(adminSpy.getTraversalSource()).thenReturn(traversal);
429 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
431 String exceptionMessage = "";
432 DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
433 List<Vertex> deletableVertices = spy.getQueryEngine().findDeletable(v);
436 serializer.delete(v, deletableVertices, "resourceVersion", false);
437 } catch (AAIException exception) {
438 exception.printStackTrace();
439 exceptionMessage = exception.getMessage();
441 return exceptionMessage;
446 public void createNewVertexTest() throws AAIException {
447 engine.startTransaction();
449 Introspector testObj = loader.introspectorFromName("generic-vnf");
451 Vertex testVertex = dbser.createNewVertex(testObj);
452 Vertex fromGraph = engine.tx().traversal().V().has("aai-node-type", "generic-vnf").toList().get(0);
453 assertEquals(testVertex.id(), fromGraph.id());
454 assertEquals("AAI-TEST", fromGraph.property(AAIProperties.SOURCE_OF_TRUTH).value());
459 public void touchStandardVertexPropertiesTest() throws AAIException, InterruptedException {
460 engine.startTransaction();
462 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
465 DBSerializer dbser2 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-2");
466 Vertex vert = graph.addVertex("aai-node-type", "generic-vnf", "aai-uri", "a");
468 // Upon first creation of the Vertex and the DBSerializer
469 // the source of truth and created-ts should be the same as their modified counterparts
470 dbser2.touchStandardVertexProperties(vert, true);
471 String createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
472 String modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
473 String sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
474 String lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
475 assertEquals(createTS, modTS);
476 assertEquals(sot, lastModSOT);
478 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
482 // Not new vertex && new DBSerializer (A new serializer since a new one will be created per transaction)
483 // Here the vertex will be modified by a different source of truth
484 DBSerializer dbser3 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-3");
485 dbser3.touchStandardVertexProperties(vert, false);
486 createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
487 modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
488 sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
489 lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
490 assertNotEquals(createTS, modTS);
491 assertNotEquals(sot, lastModSOT);
493 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
497 // The currentTimeMillis used for the created-ts and modified-ts is created at DBSerializer instantiation
498 // Every REST transaction should create a new DBSerializer - thus a new currentTimeMillis is used at the time of
500 // Using an existing vertex, but treating it as new && using an older DBSerializer
501 dbser.touchStandardVertexProperties(vert, true);
502 String resverStart = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
503 String lastModTimeStart = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
504 createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
505 modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
506 assertEquals(createTS, modTS);
507 assertEquals("AAI-TEST", vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value());
509 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
513 dbser2.touchStandardVertexProperties(vert, false);
514 String resourceVer = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
515 String lastModTs = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
516 String lastModSoT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
518 assertNotEquals(resverStart, resourceVer);
519 assertNotEquals(lastModTimeStart, lastModTs);
520 assertEquals("AAI-TEST-2", lastModSoT);
524 public void touchStandardVertexPropertiesAAIUUIDTest() {
525 engine.startTransaction();
527 Graph graph = TinkerGraph.open();
528 Vertex v = graph.addVertex("aai-node-type", "generic-vnf");
530 dbser.touchStandardVertexProperties(v, true);
532 assertTrue(v.property(AAIProperties.AAI_UUID).isPresent());
534 UUID.fromString((String) v.property(AAIProperties.AAI_UUID).value());
535 } catch (IllegalArgumentException e) {
536 fail("Vertex uuid is not valid uuid");
541 public void verifyResourceVersion_SunnyDayTest() throws AAIException {
542 engine.startTransaction();
544 assertTrue(dbser.verifyResourceVersion("delete", "vnfc", "abc", "abc", "vnfcs/vnfc/vnfcId"));
549 public void verifyResourceVersion_CreateWithRVTest() throws AAIException {
550 engine.startTransaction();
552 thrown.expect(AAIException.class);
553 thrown.expectMessage("resource-version passed for create of generic-vnfs/generic-vnf/myid");
554 dbser.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid");
559 public void verifyResourceVersion_MissingRVTest() throws AAIException {
560 engine.startTransaction();
562 thrown.expect(AAIException.class);
563 thrown.expectMessage("resource-version not passed for update of generic-vnfs/generic-vnf/myid");
564 dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid");
569 public void verifyResourceVersion_MismatchRVTest() throws AAIException {
570 engine.startTransaction();
572 thrown.expect(AAIException.class);
573 thrown.expectMessage("resource-version MISMATCH for update of generic-vnfs/generic-vnf/myid");
574 dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver",
575 "generic-vnfs/generic-vnf/myid");
580 public void verifyResourceVersion_DeleteTest() throws AAIException {
581 engine.startTransaction();
583 assertTrue(dbser.verifyResourceVersion("delete", "generic-vnf", "current-res-ver",
584 AAIConstants.AAI_RESVERSION_DISABLED_UUID_DEFAULT, "generic-vnfs/generic-vnf/myid"));
589 public void trimClassNameTest() {
590 assertEquals("GenericVnf", dbser.trimClassName("GenericVnf"));
591 assertEquals("GenericVnf", dbser.trimClassName("org.onap.aai.GenericVnf"));
595 public void getURIForVertexTest() throws AAIException, URISyntaxException, UnsupportedEncodingException {
596 engine.startTransaction();
598 Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
599 "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
600 Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
602 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
604 ten.property("aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
606 URI compare = new URI("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
607 assertEquals(compare, dbser.getURIForVertex(ten));
609 URI compareFailure = new URI("/unknown-uri");
610 ten.property("aai-uri").remove();
611 assertEquals(compareFailure, dbser.getURIForVertex(ten));
616 public void getVertexPropertiesTest() throws AAIException, UnsupportedEncodingException {
617 engine.startTransaction();
619 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
620 "/network/generic-vnfs/generic-vnf/myvnf",
621 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
622 AAIProperties.CREATED_TS, 123L,
623 AAIProperties.SOURCE_OF_TRUTH, "sot",
624 AAIProperties.RESOURCE_VERSION, "123",
625 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
626 AAIProperties.LAST_MOD_TS, 333L);
627 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
628 "/network/vnfcs/vnfc/a-name",
629 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
630 AAIProperties.CREATED_TS, 123L,
631 AAIProperties.SOURCE_OF_TRUTH, "sot",
632 AAIProperties.RESOURCE_VERSION, "123",
633 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
634 AAIProperties.LAST_MOD_TS, 333L);
636 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
638 Introspector vnf = dbser.getVertexProperties(gvnf);
639 assertEquals("generic-vnf", vnf.getDbName());
640 assertEquals("myvnf", vnf.getValue("vnf-id"));
642 assertFalse(vnf.marshal(false).contains("relationship-list"));
647 public void getEdgeBetweenTest() throws AAIException {
648 engine.startTransaction();
651 engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
652 Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
654 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
656 Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr, null);
657 assertEquals("org.onap.relationships.inventory.BelongsTo", e.label());
662 public void deleteEdgeTest() throws AAIException, UnsupportedEncodingException {
663 engine.startTransaction();
665 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
666 "/network/generic-vnfs/generic-vnf/myvnf",
667 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
668 AAIProperties.CREATED_TS, 123L,
669 AAIProperties.SOURCE_OF_TRUTH, "sot",
670 AAIProperties.RESOURCE_VERSION, "123",
671 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
672 AAIProperties.LAST_MOD_TS, 333L);
673 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
674 "/network/vnfcs/vnfc/a-name",
675 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
676 AAIProperties.CREATED_TS, 123L,
677 AAIProperties.SOURCE_OF_TRUTH, "sot",
678 AAIProperties.RESOURCE_VERSION, "123",
679 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
680 AAIProperties.LAST_MOD_TS, 333L);
682 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
684 Introspector relData = loader.introspectorFromName("relationship-data");
685 relData.setValue("relationship-key", "vnfc.vnfc-name");
686 relData.setValue("relationship-value", "a-name");
687 Introspector relationship = loader.introspectorFromName("relationship");
688 relationship.setValue("related-to", "vnfc");
689 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
690 relationship.setValue("relationship-data", relData);
692 assertTrue(dbser.deleteEdge(relationship, gvnf).isPresent());
694 assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext());
695 assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext());
700 public void createEdgeTest() throws AAIException, UnsupportedEncodingException {
701 engine.startTransaction();
703 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
704 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
705 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
706 "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
709 Introspector relData = loader.introspectorFromName("relationship-data");
710 relData.setValue("relationship-key", "vnfc.vnfc-name");
711 relData.setValue("relationship-value", "a-name");
712 Introspector relationship = loader.introspectorFromName("relationship");
713 relationship.setValue("related-to", "vnfc");
714 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
715 relationship.setValue("relationship-data", relData);
717 assertNotNull(dbser.createEdge(relationship, gvnf));
718 assertTrue(engine.tx().traversal().V(gvnf).both("org.onap.relationships.inventory.BelongsTo").hasNext());
719 assertTrue(engine.tx().traversal().V(vnfc).both("org.onap.relationships.inventory.BelongsTo").hasNext());
724 public void createCousinEdgeThatShouldBeTreeTest()
725 throws AAIException, UnsupportedEncodingException, URISyntaxException {
726 engine.startTransaction();
728 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
729 "/network/generic-vnfs/generic-vnf/myvnf");
730 Vertex vf = engine.tx().addVertex("aai-node-type", "vf-module", "vf-module-id", "vf-id", "aai-uri",
731 "/network/generic-vnfs/generic-vnf/myvnf/vf-modules/vf-module/vf-id");
733 edgeSer.addTreeEdge(engine.tx().traversal(), gvnf, vf);
735 Introspector relationship = loader.introspectorFromName("relationship");
736 relationship.setValue("related-to", "vf-module");
737 relationship.setValue("related-link", dbser.getURIForVertex(vf).toString());
738 Introspector relationshipList = loader.introspectorFromName("relationship-list");
739 relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
741 Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
742 Vertex gvnf2 = dbser.createNewVertex(gvnfObj);
743 gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
744 gvnfObj.setValue("vnf-id", "myvnf-1");
746 QueryParser uriQuery =
747 dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
750 dbser.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
751 } catch (AAIException e) {
752 assertEquals("AAI_6145", e.getCode());
757 public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
758 engine.startTransaction();
760 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
761 "/network/generic-vnfs/generic-vnf/myvnf");
763 // rainy day case, edge to non-existent object
764 Introspector relData = loader.introspectorFromName("relationship-data");
765 relData.setValue("relationship-key", "vnfc.vnfc-name");
766 relData.setValue("relationship-value", "b-name");
767 Introspector relationship = loader.introspectorFromName("relationship");
768 relationship.setValue("related-to", "vnfc");
769 relationship.setValue("related-link", "/network/vnfcs/vnfc/b-name");
770 relationship.setValue("relationship-data", relData);
772 thrown.expect(AAIException.class);
773 thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
774 dbser.createEdge(relationship, gvnf);
779 public void serializeSingleVertexTopLevelTest() throws AAIException, UnsupportedEncodingException {
780 engine.startTransaction();
782 Introspector gvnf = loader.introspectorFromName("generic-vnf");
783 Vertex gvnfVert = dbser.createNewVertex(gvnf);
785 gvnf.setValue("vnf-id", "myvnf");
786 gvnf.setValue("vnf-type", "typo");
787 dbser.serializeSingleVertex(gvnfVert, gvnf, "test");
788 assertTrue(engine.tx().traversal().V().has("aai-node-type", "generic-vnf").has("vnf-id", "myvnf").hasNext());
792 public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException {
793 engine.startTransaction();
795 Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
796 "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
797 Introspector tenIn = loader.introspectorFromName("tenant");
798 Vertex ten = dbser.createNewVertex(tenIn);
799 ten.property("aai-uri", cr.property("aai-uri").value().toString() + "/tenants/tenant/453");
801 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
803 tenIn.setValue("tenant-id", "453");
804 tenIn.setValue("tenant-name", "mytenant");
806 dbser.serializeSingleVertex(ten, tenIn, "test");
808 assertTrue(engine.tx().traversal().V().has("aai-node-type", "tenant").has("tenant-id", "453")
809 .has("tenant-name", "mytenant").hasNext());
814 public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
815 engine.startTransaction();
817 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
818 "/network/generic-vnfs/generic-vnf/vnf-123", "aai-uuid", "a");
819 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
820 "/network/vnfcs/vnfc/vnfc-123", "aai-uuid", "b");
822 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
824 Introspector obj = loader.introspectorFromName("generic-vnf");
825 obj = this.dbser.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
827 assertEquals("edge label between generic-vnf and vnfs is uses", "org.onap.relationships.inventory.BelongsTo",
828 obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0)
829 .getValue("relationship-label"));
834 public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest()
835 throws AAIException, UnsupportedEncodingException {
837 SchemaVersion version = schemaVersions.getAppRootVersion();
838 DBSerializer dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
839 Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
841 engine.startTransaction();
843 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
844 "/network/generic-vnfs/generic-vnf/vnf-123");
845 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
846 "/network/vnfcs/vnfc/vnfc-123");
848 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
850 Introspector obj = loader.introspectorFromName("generic-vnf");
851 obj = dbser.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
853 assertFalse("Relationship does not contain edge-property", obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
858 public void createEdgeWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException,
859 SecurityException, IllegalArgumentException {
861 engine.startTransaction();
863 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
864 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
865 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
867 Introspector relData = loader.introspectorFromName("relationship-data");
868 relData.setValue("relationship-key", "vnfc.vnfc-name");
869 relData.setValue("relationship-value", "a-name");
870 Introspector relationship = loader.introspectorFromName("relationship");
871 relationship.setValue("related-to", "vnfc");
872 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
873 relationship.setValue("relationship-data", relData);
874 relationship.setValue("relationship-label", "NA");
876 thrown.expect(AAIException.class);
877 thrown.expectMessage("No rule found");
878 thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
879 dbser.createEdge(relationship, gvnf);
884 public void createEdgeUsingIntrospectorTest() throws AAIException, UnsupportedEncodingException, SecurityException, IllegalArgumentException {
886 engine.startTransaction();
888 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
889 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
890 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
892 Introspector relData = loader.introspectorFromName("relationship-data");
893 relData.setValue("relationship-key", "vnfc.vnfc-name");
894 relData.setValue("relationship-value", "a-name");
895 Introspector relationship = loader.introspectorFromName("relationship");
896 relationship.setValue("related-to", "vnfc");
897 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
898 relationship.setValue("relationship-data", relData);
900 assertEquals("/network/vnfcs/vnfc/a-name", relationship.getValue("related-link"));
902 dbser.createEdge(relationship, gvnf);
906 public void addRelatedToPropertyTest() throws AAIException {
907 engine.startTransaction();
909 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myname", "vnf-name", "myname",
910 "aai-uri", "/network/generic-vnfs/generic-vnf/myname");
911 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
912 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
913 Introspector gv = loader.introspectorFromName("generic-vnf");
914 gv.setValue("vnf-name", "myname");
916 Introspector rel = loader.introspectorFromName("relationship");
917 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
918 dbser.addRelatedToProperty(rel, gvnf, "generic-vnf");
919 List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
920 assertThat(relToProps.size(), is(1));
921 Introspector relToProp = relToProps.get(0);
922 assertThat(relToProp.getValue("property-key"), is("generic-vnf.vnf-name"));
923 assertThat(relToProp.getValue("property-value"), is("myname"));
927 public void dbToObjectContainerMismatchTest() throws AAIException, UnsupportedEncodingException {
928 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
929 Graph vertexMaker = TinkerGraph.open();
930 Vertex a = vertexMaker.addVertex(T.id, "0");
931 Vertex b = vertexMaker.addVertex(T.id, "1");
932 List<Vertex> vertices = Arrays.asList(a, b);
934 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
935 Introspector intro = loader.introspectorFromName("image"); // just need any non-container object
937 thrown.expect(AAIException.class);
938 thrown.expectMessage("query object mismatch: this object cannot hold multiple items.");
940 dbser.dbToObject(vertices, intro, Integer.MAX_VALUE, true, "doesn't matter");
944 public void dbToObjectTest() throws AAIException, UnsupportedEncodingException {
945 engine.startTransaction();
947 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
948 Vertex gv1 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
949 Vertex gv2 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id2");
950 List<Vertex> vertices = Arrays.asList(gv1, gv2);
952 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version);
953 Introspector gvContainer = loader.introspectorFromName("generic-vnfs");
955 Introspector res = dbser.dbToObject(vertices, gvContainer, 0, true, "true");
956 List<Introspector> gvs = res.getWrappedListValue("generic-vnf");
957 assertEquals(2, gvs.size());
958 for (Introspector i : gvs) {
959 String vnfId = i.getValue("vnf-id");
960 assertTrue("id1".equals(vnfId) || "id2".equals(vnfId));
966 public void getEdgeBetweenNoLabelTest() throws AAIException {
967 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
968 engine.startTransaction();
969 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
970 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
971 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
973 Edge res = dbser.getEdgeBetween(EdgeType.TREE, gv, lint);
974 assertEquals("org.onap.relationships.inventory.BelongsTo", res.label());
979 public void deleteItemsWithTraversal() throws AAIException {
980 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
981 engine.startTransaction();
982 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1",
983 AAIProperties.AAI_URI, "/network/generic-vnfs/generic-vnf/id1",
984 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
985 AAIProperties.CREATED_TS, 123L,
986 AAIProperties.SOURCE_OF_TRUTH, "sot",
987 AAIProperties.RESOURCE_VERSION, "123",
988 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
989 AAIProperties.LAST_MOD_TS, 333L);
990 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1",
991 AAIProperties.AAI_URI, "/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1",
992 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
993 AAIProperties.CREATED_TS, 123L,
994 AAIProperties.SOURCE_OF_TRUTH, "sot",
995 AAIProperties.RESOURCE_VERSION, "123",
996 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
997 AAIProperties.LAST_MOD_TS, 333L);
999 assertTrue(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
1000 assertTrue(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
1002 dbser.deleteWithTraversal(gv);
1003 dbser.deleteWithTraversal(lint);
1005 assertFalse(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
1006 assertFalse(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
1011 public void serializeToDbWithParentTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
1012 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
1013 engine.startTransaction();
1014 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", "aai-uri",
1015 "/network/generic-vnfs/generic-vnf/id1", "aai-uuid", "a",
1016 AAIProperties.CREATED_TS, 123L,
1017 AAIProperties.SOURCE_OF_TRUTH, "sot",
1018 AAIProperties.RESOURCE_VERSION, "123",
1019 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
1020 AAIProperties.LAST_MOD_TS, 333L);
1021 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface",
1024 AAIProperties.CREATED_TS, 123L,
1025 AAIProperties.SOURCE_OF_TRUTH, "sot",
1026 AAIProperties.RESOURCE_VERSION, "123",
1027 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
1028 AAIProperties.LAST_MOD_TS, 333L);
1029 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
1031 Introspector lintIntro = loader.introspectorFromName("l-interface");
1032 lintIntro.setValue("interface-name", "name1");
1033 lintIntro.setValue("interface-role", "actor");
1034 URI lintURI = new URI("/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1");
1035 QueryParser uriQuery = engine.getQueryBuilder(gv).createQueryFromURI(lintURI);
1036 dbser.serializeToDb(lintIntro, lint, uriQuery, "test-identifier", "AAI-TEST");
1038 assertTrue(engine.tx().traversal().V(lint).has("interface-role", "actor").hasNext());
1043 public void getLatestVersionViewTest() throws AAIException, UnsupportedEncodingException {
1044 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
1045 engine.startTransaction();
1046 Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo", "speed-value",
1047 "very-fast", "service-provider-bandwidth-up-units", "things");
1049 Introspector res = dbser.getLatestVersionView(phys);
1050 assertEquals("zaldo", res.getValue("link-name"));
1051 assertEquals("very-fast", res.getValue("speed-value"));
1052 assertEquals("things", res.getValue("service-provider-bandwidth-up-units"));
1056 public void cascadeVserverDeleteTest() throws AAIException, UnsupportedEncodingException {
1058 String expected_message = "";
1061 * vserver-->l-interface -->logical-link
1064 Vertex vserver = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id", "vss1").next();
1066 String exceptionMessage = testCascadeDelete(vserver);
1067 assertEquals(expected_message, exceptionMessage);
1072 public void cascadeL3NetworkPreventDeleteTest() throws AAIException, UnsupportedEncodingException {
1074 ArrayList expected_messages = new ArrayList<String>();
1075 expected_messages.add(
1076 "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list, l3-interface-ipv6-address-list]");
1077 expected_messages.add(
1078 "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv6-address-list, l3-interface-ipv4-address-list]");
1081 * vserver-->l-interface -->logical-link
1085 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v1").next();
1087 String exceptionMessage = testCascadeDelete(l3network);
1088 assertTrue(expected_messages.contains(exceptionMessage));
1093 public void cascadeL3NetworkDeleteTest() throws AAIException, UnsupportedEncodingException {
1095 String expected_message = "";
1098 * vserver-->l-interface -->logical-link
1102 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v2").next();
1104 String exceptionMessage = testCascadeDelete(l3network);
1105 assertEquals(expected_message, exceptionMessage);