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();
620 engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
622 Introspector crIntro = dbser.getVertexProperties(cr);
623 assertEquals("cloud-region", crIntro.getDbName());
624 assertEquals("me", crIntro.getValue("cloud-owner"));
625 assertEquals("123", crIntro.getValue("cloud-region-id"));
630 public void getEdgeBetweenTest() throws AAIException {
631 engine.startTransaction();
634 engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
635 Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
637 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
639 Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr, null);
640 assertEquals("org.onap.relationships.inventory.BelongsTo", e.label());
645 public void deleteEdgeTest() throws AAIException, UnsupportedEncodingException {
646 engine.startTransaction();
648 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
649 "/network/generic-vnfs/generic-vnf/myvnf",
650 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
651 AAIProperties.CREATED_TS, 123L,
652 AAIProperties.SOURCE_OF_TRUTH, "sot",
653 AAIProperties.RESOURCE_VERSION, "123",
654 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
655 AAIProperties.LAST_MOD_TS, 333L);
656 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
657 "/network/vnfcs/vnfc/a-name",
658 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
659 AAIProperties.CREATED_TS, 123L,
660 AAIProperties.SOURCE_OF_TRUTH, "sot",
661 AAIProperties.RESOURCE_VERSION, "123",
662 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
663 AAIProperties.LAST_MOD_TS, 333L);
665 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
667 Introspector relData = loader.introspectorFromName("relationship-data");
668 relData.setValue("relationship-key", "vnfc.vnfc-name");
669 relData.setValue("relationship-value", "a-name");
670 Introspector relationship = loader.introspectorFromName("relationship");
671 relationship.setValue("related-to", "vnfc");
672 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
673 relationship.setValue("relationship-data", relData);
675 assertTrue(dbser.deleteEdge(relationship, gvnf).isPresent());
677 assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext());
678 assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext());
683 public void createEdgeTest() throws AAIException, UnsupportedEncodingException {
684 engine.startTransaction();
686 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
687 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
688 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
689 "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
692 Introspector relData = loader.introspectorFromName("relationship-data");
693 relData.setValue("relationship-key", "vnfc.vnfc-name");
694 relData.setValue("relationship-value", "a-name");
695 Introspector relationship = loader.introspectorFromName("relationship");
696 relationship.setValue("related-to", "vnfc");
697 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
698 relationship.setValue("relationship-data", relData);
700 assertNotNull(dbser.createEdge(relationship, gvnf));
701 assertTrue(engine.tx().traversal().V(gvnf).both("org.onap.relationships.inventory.BelongsTo").hasNext());
702 assertTrue(engine.tx().traversal().V(vnfc).both("org.onap.relationships.inventory.BelongsTo").hasNext());
707 public void createCousinEdgeThatShouldBeTreeTest()
708 throws AAIException, UnsupportedEncodingException, URISyntaxException {
709 engine.startTransaction();
711 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
712 "/network/generic-vnfs/generic-vnf/myvnf");
713 Vertex vf = engine.tx().addVertex("aai-node-type", "vf-module", "vf-module-id", "vf-id", "aai-uri",
714 "/network/generic-vnfs/generic-vnf/myvnf/vf-modules/vf-module/vf-id");
716 edgeSer.addTreeEdge(engine.tx().traversal(), gvnf, vf);
718 Introspector relationship = loader.introspectorFromName("relationship");
719 relationship.setValue("related-to", "vf-module");
720 relationship.setValue("related-link", dbser.getURIForVertex(vf).toString());
721 Introspector relationshipList = loader.introspectorFromName("relationship-list");
722 relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
724 Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
725 Vertex gvnf2 = dbser.createNewVertex(gvnfObj);
726 gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
727 gvnfObj.setValue("vnf-id", "myvnf-1");
729 QueryParser uriQuery =
730 dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
733 dbser.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
734 } catch (AAIException e) {
735 assertEquals("AAI_6145", e.getCode());
740 public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
741 engine.startTransaction();
743 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
744 "/network/generic-vnfs/generic-vnf/myvnf");
746 // rainy day case, edge to non-existent object
747 Introspector relData = loader.introspectorFromName("relationship-data");
748 relData.setValue("relationship-key", "vnfc.vnfc-name");
749 relData.setValue("relationship-value", "b-name");
750 Introspector relationship = loader.introspectorFromName("relationship");
751 relationship.setValue("related-to", "vnfc");
752 relationship.setValue("related-link", "/network/vnfcs/vnfc/b-name");
753 relationship.setValue("relationship-data", relData);
755 thrown.expect(AAIException.class);
756 thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
757 dbser.createEdge(relationship, gvnf);
762 public void serializeSingleVertexTopLevelTest() throws AAIException, UnsupportedEncodingException {
763 engine.startTransaction();
765 Introspector gvnf = loader.introspectorFromName("generic-vnf");
766 Vertex gvnfVert = dbser.createNewVertex(gvnf);
768 gvnf.setValue("vnf-id", "myvnf");
769 gvnf.setValue("vnf-type", "typo");
770 dbser.serializeSingleVertex(gvnfVert, gvnf, "test");
771 assertTrue(engine.tx().traversal().V().has("aai-node-type", "generic-vnf").has("vnf-id", "myvnf").hasNext());
775 public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException {
776 engine.startTransaction();
778 Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
779 "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
780 Introspector tenIn = loader.introspectorFromName("tenant");
781 Vertex ten = dbser.createNewVertex(tenIn);
782 ten.property("aai-uri", cr.property("aai-uri").value().toString() + "/tenants/tenant/453");
784 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
786 tenIn.setValue("tenant-id", "453");
787 tenIn.setValue("tenant-name", "mytenant");
789 dbser.serializeSingleVertex(ten, tenIn, "test");
791 assertTrue(engine.tx().traversal().V().has("aai-node-type", "tenant").has("tenant-id", "453")
792 .has("tenant-name", "mytenant").hasNext());
797 public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
798 engine.startTransaction();
800 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
801 "/network/generic-vnfs/generic-vnf/vnf-123", "aai-uuid", "a");
802 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
803 "/network/vnfcs/vnfc/vnfc-123", "aai-uuid", "b");
805 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
807 Introspector obj = loader.introspectorFromName("generic-vnf");
808 obj = this.dbser.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
810 assertEquals("edge label between generic-vnf and vnfs is uses", "org.onap.relationships.inventory.BelongsTo",
811 obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0)
812 .getValue("relationship-label"));
817 public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest()
818 throws AAIException, UnsupportedEncodingException {
820 SchemaVersion version = schemaVersions.getAppRootVersion();
821 DBSerializer dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
822 Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
824 engine.startTransaction();
826 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
827 "/network/generic-vnfs/generic-vnf/vnf-123");
828 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
829 "/network/vnfcs/vnfc/vnfc-123");
831 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
833 Introspector obj = loader.introspectorFromName("generic-vnf");
834 obj = dbser.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
836 assertFalse("Relationship does not contain edge-property", obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
841 public void createEdgeWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException,
842 SecurityException, IllegalArgumentException {
844 engine.startTransaction();
846 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
847 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
848 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
850 Introspector relData = loader.introspectorFromName("relationship-data");
851 relData.setValue("relationship-key", "vnfc.vnfc-name");
852 relData.setValue("relationship-value", "a-name");
853 Introspector relationship = loader.introspectorFromName("relationship");
854 relationship.setValue("related-to", "vnfc");
855 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
856 relationship.setValue("relationship-data", relData);
857 relationship.setValue("relationship-label", "NA");
859 thrown.expect(AAIException.class);
860 thrown.expectMessage("No rule found");
861 thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
862 dbser.createEdge(relationship, gvnf);
867 public void createEdgeUsingIntrospectorTest() throws AAIException, UnsupportedEncodingException, SecurityException, IllegalArgumentException {
869 engine.startTransaction();
871 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
872 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
873 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
875 Introspector relData = loader.introspectorFromName("relationship-data");
876 relData.setValue("relationship-key", "vnfc.vnfc-name");
877 relData.setValue("relationship-value", "a-name");
878 Introspector relationship = loader.introspectorFromName("relationship");
879 relationship.setValue("related-to", "vnfc");
880 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
881 relationship.setValue("relationship-data", relData);
883 dbser.createEdge(relationship, gvnf);
887 public void addRelatedToPropertyTest() throws AAIException {
888 engine.startTransaction();
890 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myname", "vnf-name", "myname",
891 "aai-uri", "/network/generic-vnfs/generic-vnf/myname");
892 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
893 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
894 Introspector gv = loader.introspectorFromName("generic-vnf");
895 gv.setValue("vnf-name", "myname");
897 Introspector rel = loader.introspectorFromName("relationship");
898 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
899 dbser.addRelatedToProperty(rel, gvnf, "generic-vnf");
900 List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
901 assertThat(relToProps.size(), is(1));
902 Introspector relToProp = relToProps.get(0);
903 assertThat(relToProp.getValue("property-key"), is("generic-vnf.vnf-name"));
904 assertThat(relToProp.getValue("property-value"), is("myname"));
908 public void dbToObjectContainerMismatchTest() throws AAIException, UnsupportedEncodingException {
909 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
910 Graph vertexMaker = TinkerGraph.open();
911 Vertex a = vertexMaker.addVertex(T.id, "0");
912 Vertex b = vertexMaker.addVertex(T.id, "1");
913 List<Vertex> vertices = Arrays.asList(a, b);
915 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
916 Introspector intro = loader.introspectorFromName("image"); // just need any non-container object
918 thrown.expect(AAIException.class);
919 thrown.expectMessage("query object mismatch: this object cannot hold multiple items.");
921 dbser.dbToObject(vertices, intro, Integer.MAX_VALUE, true, "doesn't matter");
925 public void dbToObjectTest() throws AAIException, UnsupportedEncodingException {
926 engine.startTransaction();
928 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
929 Vertex gv1 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
930 Vertex gv2 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id2");
931 List<Vertex> vertices = Arrays.asList(gv1, gv2);
933 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version);
934 Introspector gvContainer = loader.introspectorFromName("generic-vnfs");
936 Introspector res = dbser.dbToObject(vertices, gvContainer, 0, true, "true");
937 List<Introspector> gvs = res.getWrappedListValue("generic-vnf");
938 assertEquals(2, gvs.size());
939 for (Introspector i : gvs) {
940 String vnfId = i.getValue("vnf-id");
941 assertTrue("id1".equals(vnfId) || "id2".equals(vnfId));
947 public void getEdgeBetweenNoLabelTest() throws AAIException {
948 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
949 engine.startTransaction();
950 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
951 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
952 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
954 Edge res = dbser.getEdgeBetween(EdgeType.TREE, gv, lint);
955 assertEquals("org.onap.relationships.inventory.BelongsTo", res.label());
960 public void deleteItemsWithTraversal() throws AAIException {
961 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
962 engine.startTransaction();
963 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1",
964 AAIProperties.AAI_URI, "/network/generic-vnfs/generic-vnf/id1",
965 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
966 AAIProperties.CREATED_TS, 123L,
967 AAIProperties.SOURCE_OF_TRUTH, "sot",
968 AAIProperties.RESOURCE_VERSION, "123",
969 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
970 AAIProperties.LAST_MOD_TS, 333L);
971 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1",
972 AAIProperties.AAI_URI, "/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1",
973 AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
974 AAIProperties.CREATED_TS, 123L,
975 AAIProperties.SOURCE_OF_TRUTH, "sot",
976 AAIProperties.RESOURCE_VERSION, "123",
977 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
978 AAIProperties.LAST_MOD_TS, 333L);
980 assertTrue(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
981 assertTrue(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
983 dbser.deleteWithTraversal(gv);
984 dbser.deleteWithTraversal(lint);
986 assertFalse(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
987 assertFalse(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
992 public void serializeToDbWithParentTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
993 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
994 engine.startTransaction();
995 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", "aai-uri",
996 "/network/generic-vnfs/generic-vnf/id1", "aai-uuid", "a",
997 AAIProperties.CREATED_TS, 123L,
998 AAIProperties.SOURCE_OF_TRUTH, "sot",
999 AAIProperties.RESOURCE_VERSION, "123",
1000 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
1001 AAIProperties.LAST_MOD_TS, 333L);
1002 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface",
1005 AAIProperties.CREATED_TS, 123L,
1006 AAIProperties.SOURCE_OF_TRUTH, "sot",
1007 AAIProperties.RESOURCE_VERSION, "123",
1008 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
1009 AAIProperties.LAST_MOD_TS, 333L);
1010 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
1012 Introspector lintIntro = loader.introspectorFromName("l-interface");
1013 lintIntro.setValue("interface-name", "name1");
1014 lintIntro.setValue("interface-role", "actor");
1015 URI lintURI = new URI("/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1");
1016 QueryParser uriQuery = engine.getQueryBuilder(gv).createQueryFromURI(lintURI);
1017 dbser.serializeToDb(lintIntro, lint, uriQuery, "test-identifier", "AAI-TEST");
1019 assertTrue(engine.tx().traversal().V(lint).has("interface-role", "actor").hasNext());
1024 public void getLatestVersionViewTest() throws AAIException, UnsupportedEncodingException {
1025 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
1026 engine.startTransaction();
1027 Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo", "speed-value",
1028 "very-fast", "service-provider-bandwidth-up-units", "things");
1030 Introspector res = dbser.getLatestVersionView(phys);
1031 assertEquals("zaldo", res.getValue("link-name"));
1032 assertEquals("very-fast", res.getValue("speed-value"));
1033 assertEquals("things", res.getValue("service-provider-bandwidth-up-units"));
1037 public void cascadeVserverDeleteTest() throws AAIException, UnsupportedEncodingException {
1039 String expected_message = "";
1042 * vserver-->l-interface -->logical-link
1045 Vertex vserver = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id", "vss1").next();
1047 String exceptionMessage = testCascadeDelete(vserver);
1048 assertEquals(expected_message, exceptionMessage);
1053 public void cascadeL3NetworkPreventDeleteTest() throws AAIException, UnsupportedEncodingException {
1055 ArrayList expected_messages = new ArrayList<String>();
1056 expected_messages.add(
1057 "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]");
1058 expected_messages.add(
1059 "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]");
1062 * vserver-->l-interface -->logical-link
1066 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v1").next();
1068 String exceptionMessage = testCascadeDelete(l3network);
1069 assertTrue(expected_messages.contains(exceptionMessage));
1074 public void cascadeL3NetworkDeleteTest() throws AAIException, UnsupportedEncodingException {
1076 String expected_message = "";
1079 * vserver-->l-interface -->logical-link
1083 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v2").next();
1085 String exceptionMessage = testCascadeDelete(l3network);
1086 assertEquals(expected_message, exceptionMessage);