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 static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertThat;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
31 import static org.mockito.Mockito.spy;
32 import static org.mockito.Mockito.when;
34 import java.io.UnsupportedEncodingException;
36 import java.net.URISyntaxException;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.Collection;
40 import java.util.Collections;
41 import java.util.HashSet;
42 import java.util.List;
44 import java.util.UUID;
46 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
47 import org.apache.tinkerpop.gremlin.structure.Edge;
48 import org.apache.tinkerpop.gremlin.structure.Graph;
49 import org.apache.tinkerpop.gremlin.structure.T;
50 import org.apache.tinkerpop.gremlin.structure.Vertex;
51 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
52 import org.janusgraph.core.JanusGraphFactory;
53 import org.junit.After;
54 import org.junit.AfterClass;
55 import org.junit.Before;
56 import org.junit.BeforeClass;
57 import org.junit.Rule;
58 import org.junit.Test;
59 import org.junit.rules.ExpectedException;
60 import org.junit.runner.RunWith;
61 import org.junit.runners.Parameterized;
62 import org.onap.aai.AAISetup;
63 import org.onap.aai.db.props.AAIProperties;
64 import org.onap.aai.edges.EdgeIngestor;
65 import org.onap.aai.edges.enums.EdgeType;
66 import org.onap.aai.exceptions.AAIException;
67 import org.onap.aai.introspection.Introspector;
68 import org.onap.aai.introspection.Loader;
69 import org.onap.aai.introspection.ModelType;
70 import org.onap.aai.parsers.query.QueryParser;
71 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
72 import org.onap.aai.serialization.engines.QueryStyle;
73 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
74 import org.onap.aai.setup.SchemaVersion;
75 import org.onap.aai.util.AAIConstants;
76 import org.springframework.beans.factory.annotation.Autowired;
77 import org.springframework.test.annotation.DirtiesContext;
79 @RunWith(value = Parameterized.class)
80 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
81 public class DbSerializerTest extends AAISetup {
83 // to use, set thrown.expect to whatever your test needs
84 // this line establishes default of expecting no exception to be thrown
86 public ExpectedException thrown = ExpectedException.none();
88 protected static Graph graph;
91 protected EdgeSerializer edgeSer;
93 protected EdgeIngestor ei;
95 private SchemaVersion version;
96 private final ModelType introspectorFactoryType = ModelType.MOXY;
97 private Loader loader;
98 private TransactionalGraphEngine dbEngine;
99 private TransactionalGraphEngine engine; // for tests that aren't mocking the engine
100 private DBSerializer serializer;
101 private TransactionalGraphEngine spy;
102 private TransactionalGraphEngine.Admin adminSpy;
104 @Parameterized.Parameter
105 public QueryStyle queryStyle;
107 @Parameterized.Parameters(name = "QueryStyle.{0}")
108 public static Collection<Object[]> data() {
109 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
113 public static void init() {
114 graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
119 public void setup() throws Exception {
121 version = schemaVersions.getDefaultVersion();
122 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
123 dbEngine = new JanusGraphDBEngine(queryStyle, loader);
125 adminSpy = spy(dbEngine.asAdmin());
127 engine = new JanusGraphDBEngine(queryStyle, loader);
128 serializer = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
132 public void testFindDeletableDoesNotReturnDuplicates() throws AAIException {
134 Vertex genericVnf1 = graph.addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf1", "vnf-name", "vnfName1");
136 Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface1");
137 Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface2");
139 Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink1");
140 Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink2");
142 GraphTraversalSource g = graph.traversal();
144 edgeSer.addTreeEdge(g, genericVnf1, lInterface1);
145 edgeSer.addTreeEdge(g, genericVnf1, lInterface2);
146 edgeSer.addEdge(g, lInterface1, logicalLink1);
147 edgeSer.addEdge(g, lInterface1, logicalLink2);
148 // This line will cause the logical link2 to be found twice under linterface 1
149 // and also under the linterface 2 and since in the past deletable returned
150 // duplicates this test checks that it shouldn't return duplicates
151 edgeSer.addEdge(g, lInterface2, logicalLink2);
153 when(spy.asAdmin()).thenReturn(adminSpy);
154 when(adminSpy.getTraversalSource()).thenReturn(g);
155 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(g);
157 List<Vertex> deletableVertexes = spy.getQueryEngine().findDeletable(genericVnf1);
158 Set<Vertex> vertexSet = new HashSet<>();
160 for (Vertex deletableVertex : deletableVertexes) {
161 if (!vertexSet.contains(deletableVertex)) {
162 vertexSet.add(deletableVertex);
164 fail("Find deletable is returning a list of duplicate vertexes");
170 public void tearDown() {
175 public static void destroy() throws Exception {
179 private void subnetSetup() throws AAIException, UnsupportedEncodingException {
181 * This setus up the test graph, For future junits , add more vertices
185 Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
186 "l3-interface-ipv4-address", "l3-interface-ipv4-address-1", AAIProperties.AAI_UUID,
187 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
188 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
189 AAIProperties.LAST_MOD_TS, 333L);
190 Vertex subnet_2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-2", AAIProperties.AAI_UUID,
191 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
192 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
193 AAIProperties.LAST_MOD_TS, 333L);
194 Vertex l3interipv6addresslist_3 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
195 "l3-interface-ipv6-address", "l3-interface-ipv6-address-3", AAIProperties.AAI_UUID,
196 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
197 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
198 AAIProperties.LAST_MOD_TS, 333L);
199 Vertex subnet_4 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-4", AAIProperties.AAI_UUID,
200 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
201 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
202 AAIProperties.LAST_MOD_TS, 333L);
203 Vertex subnet_5 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-5", AAIProperties.AAI_UUID,
204 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
205 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
206 AAIProperties.LAST_MOD_TS, 333L);
207 Vertex l3network_6 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-6",
208 "network-name", "network-name-6", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
209 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
210 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", 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,
218 serializer.getURIForVertex(l3interipv4addresslist_1).toString());
219 subnet_2.property(AAIProperties.AAI_URI, serializer.getURIForVertex(subnet_2).toString());
220 l3interipv6addresslist_3.property(AAIProperties.AAI_URI,
221 serializer.getURIForVertex(l3interipv6addresslist_3).toString());
222 subnet_4.property(AAIProperties.AAI_URI, serializer.getURIForVertex(subnet_4).toString());
223 subnet_5.property(AAIProperties.AAI_URI, serializer.getURIForVertex(subnet_5).toString());
224 l3network_6.property(AAIProperties.AAI_URI, serializer.getURIForVertex(l3network_6).toString());
228 private void l3NetworkSetup() throws AAIException, UnsupportedEncodingException {
230 * This setus up the test graph, For future junits , add more vertices
234 Vertex l3network1 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v1",
235 "network-name", "network-name-v1", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
236 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
237 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
238 Vertex l3network2 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v2",
239 "network-name", "network-name-v2", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
240 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
241 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
242 Vertex subnet1 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v1", AAIProperties.AAI_UUID,
243 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
244 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
245 AAIProperties.LAST_MOD_TS, 333L);
246 Vertex subnet2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v2", AAIProperties.AAI_UUID,
247 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
248 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
249 AAIProperties.LAST_MOD_TS, 333L);
251 Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
252 "l3-interface-ipv4-address", "l3-intr-v1", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
253 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
254 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
255 Vertex l3interipv6addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
256 "l3-interface-ipv6-address", "l3-interface-ipv6-v1", AAIProperties.AAI_UUID,
257 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
258 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
259 AAIProperties.LAST_MOD_TS, 333L);
261 GraphTraversalSource g = graph.traversal();
262 edgeSer.addTreeEdge(g, subnet1, l3network1);
263 edgeSer.addEdge(g, l3interipv4addresslist_1, subnet1);
264 edgeSer.addEdge(g, l3interipv6addresslist_1, subnet1);
266 edgeSer.addTreeEdge(g, subnet2, l3network2);
268 subnet1.property(AAIProperties.AAI_URI, serializer.getURIForVertex(subnet1).toString());
269 l3interipv4addresslist_1.property(AAIProperties.AAI_URI,
270 serializer.getURIForVertex(l3interipv4addresslist_1).toString());
271 l3network1.property(AAIProperties.AAI_URI, serializer.getURIForVertex(l3network1).toString());
272 subnet2.property(AAIProperties.AAI_URI, serializer.getURIForVertex(subnet2).toString());
273 l3network2.property(AAIProperties.AAI_URI, serializer.getURIForVertex(l3network2).toString());
277 private void vserverSetup() throws AAIException, UnsupportedEncodingException {
279 * This setus up the test graph, For future junits , add more vertices
283 Vertex vserver1 = graph.addVertex("aai-node-type", "vserver", "vserver-id", "vss1", AAIProperties.AAI_URI,
284 "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vss1",
285 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
286 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
287 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
289 Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr1",
290 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
291 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
292 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
293 Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr2",
294 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
295 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
296 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
298 Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink1",
299 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
300 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
301 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
302 Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink2",
303 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
304 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
305 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
307 Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
308 "l3-interface-ipv4-address", "l3-intr-ipv4-address-1", AAIProperties.AAI_UUID,
309 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
310 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
311 AAIProperties.LAST_MOD_TS, 333L);
312 Vertex l3interipv6addresslist_2 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
313 "l3-interface-ipv4-address", "l3-intr-ipv6-address-1", AAIProperties.AAI_UUID,
314 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
315 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
316 AAIProperties.LAST_MOD_TS, 333L);
318 GraphTraversalSource g = graph.traversal();
320 edgeSer.addTreeEdge(g, lInterface1, vserver1);
321 edgeSer.addTreeEdge(g, lInterface2, vserver1);
322 edgeSer.addTreeEdge(g, l3interipv4addresslist_1, lInterface1);
323 edgeSer.addTreeEdge(g, l3interipv6addresslist_2, lInterface2);
325 edgeSer.addEdge(g, lInterface1, logicalLink1);
326 edgeSer.addEdge(g, lInterface2, logicalLink2);
328 vserver1.property(AAIProperties.AAI_URI, serializer.getURIForVertex(vserver1).toString());
329 lInterface1.property(AAIProperties.AAI_URI, serializer.getURIForVertex(lInterface1).toString());
330 lInterface2.property(AAIProperties.AAI_URI, serializer.getURIForVertex(lInterface2).toString());
331 l3interipv4addresslist_1.property(AAIProperties.AAI_URI,
332 serializer.getURIForVertex(l3interipv4addresslist_1).toString());
333 l3interipv6addresslist_2.property(AAIProperties.AAI_URI,
334 serializer.getURIForVertex(l3interipv6addresslist_2).toString());
335 logicalLink1.property(AAIProperties.AAI_URI, serializer.getURIForVertex(logicalLink1).toString());
336 logicalLink2.property(AAIProperties.AAI_URI, serializer.getURIForVertex(logicalLink2).toString());
340 public void subnetDelWithInEdgesIpv4Test() throws AAIException, UnsupportedEncodingException {
342 String expected_message =
343 "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]";
346 * This subnet has in-edges with l3-ipv4 and NOT ok to delete
348 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-2").next();
350 String exceptionMessage = testCascadeDelete(subnet);
351 assertEquals(expected_message, exceptionMessage);
356 public void subnetDelWithInEdgesIpv6Test() throws AAIException, UnsupportedEncodingException {
358 String expected_message =
359 "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]";
362 * This subnet has in-edges with l3-ipv6 and NOT ok to delete
364 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-4").next();
365 String exceptionMessage = testCascadeDelete(subnet);
366 assertEquals(expected_message, exceptionMessage);
371 public void subnetDelWithInEdgesL3network() throws AAIException, UnsupportedEncodingException {
373 String expected_message = "";
376 * This subnet has in-edges with l3-network and ok to delete
378 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-5").next();
380 String exceptionMessage = testCascadeDelete(subnet);
381 assertEquals(expected_message, exceptionMessage);
385 private String testCascadeDelete(Vertex v) throws AAIException {
387 GraphTraversalSource traversal = graph.traversal();
388 when(spy.asAdmin()).thenReturn(adminSpy);
389 when(adminSpy.getTraversalSource()).thenReturn(traversal);
390 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
392 String exceptionMessage = "";
393 DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
394 List<Vertex> deletableVertices = spy.getQueryEngine().findDeletable(v);
397 serializer.delete(v, deletableVertices, "resourceVersion", false);
398 } catch (AAIException exception) {
399 exception.printStackTrace();
400 exceptionMessage = exception.getMessage();
402 return exceptionMessage;
407 public void createNewVertexTest() throws AAIException {
408 engine.startTransaction();
410 Introspector testObj = loader.introspectorFromName("generic-vnf");
412 Vertex testVertex = serializer.createNewVertex(testObj);
413 Vertex fromGraph = engine.tx().traversal().V().has("aai-node-type", "generic-vnf").toList().get(0);
414 assertEquals(testVertex.id(), fromGraph.id());
415 assertEquals("AAI-TEST", fromGraph.property(AAIProperties.SOURCE_OF_TRUTH).value());
420 public void touchStandardVertexPropertiesTest() throws AAIException, InterruptedException {
421 engine.startTransaction();
423 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
426 DBSerializer dbser2 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-2");
427 Vertex vert = graph.addVertex("aai-node-type", "generic-vnf", "aai-uri", "a");
429 // Upon first creation of the Vertex and the DBSerializer
430 // the source of truth and created-ts should be the same as their modified counterparts
431 dbser2.touchStandardVertexProperties(vert, true);
432 String createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
433 String modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
434 String sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
435 String lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
436 assertEquals(createTS, modTS);
437 assertEquals(sot, lastModSOT);
439 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
443 // Not new vertex && new DBSerializer (A new serializer since a new one will be created per transaction)
444 // Here the vertex will be modified by a different source of truth
445 DBSerializer dbser3 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-3");
446 dbser3.touchStandardVertexProperties(vert, false);
447 createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
448 modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
449 sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
450 lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
451 assertNotEquals(createTS, modTS);
452 assertNotEquals(sot, lastModSOT);
454 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
458 // The currentTimeMillis used for the created-ts and modified-ts is created at DBSerializer instantiation
459 // Every REST transaction should create a new DBSerializer - thus a new currentTimeMillis is used at the time of
461 // Using an existing vertex, but treating it as new && using an older DBSerializer
462 serializer.touchStandardVertexProperties(vert, true);
463 String resverStart = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
464 String lastModTimeStart = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
465 createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
466 modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
467 assertEquals(createTS, modTS);
468 assertEquals("AAI-TEST", vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value());
470 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
474 dbser2.touchStandardVertexProperties(vert, false);
475 String resourceVer = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
476 String lastModTs = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
477 String lastModSoT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
479 assertNotEquals(resverStart, resourceVer);
480 assertNotEquals(lastModTimeStart, lastModTs);
481 assertEquals("AAI-TEST-2", lastModSoT);
485 public void touchStandardVertexPropertiesAAIUUIDTest() {
486 engine.startTransaction();
488 Graph graph = TinkerGraph.open();
489 Vertex v = graph.addVertex("aai-node-type", "generic-vnf");
491 serializer.touchStandardVertexProperties(v, true);
493 assertTrue(v.property(AAIProperties.AAI_UUID).isPresent());
495 UUID.fromString((String) v.property(AAIProperties.AAI_UUID).value());
496 } catch (IllegalArgumentException e) {
497 fail("Vertex uuid is not valid uuid");
502 public void thatDeleteWithMatchingResourceVersionsIsValid() throws AAIException {
503 engine.startTransaction();
505 assertTrue(serializer.verifyResourceVersion("delete", "vnfc", "abc", "abc", "vnfcs/vnfc/vnfcId"));
510 public void thatDeleteWithResourceVersionDisabledConstantUUIDIsValid() throws AAIException {
511 engine.startTransaction();
513 assertTrue(serializer.verifyResourceVersion("delete", "generic-vnf", "current-res-ver",
514 AAIConstants.AAI_RESVERSION_DISABLED_UUID_DEFAULT, "generic-vnfs/generic-vnf/myid"));
518 public void thatDeleteWithMismatchingResourceVersionsIsInvalid() throws AAIException {
519 engine.startTransaction();
521 thrown.expect(AAIException.class);
522 thrown.expectMessage("resource-version MISMATCH for delete of vnfcs/vnfc/vnfcId");
523 assertTrue(serializer.verifyResourceVersion("delete", "vnfc", "currentResourceVersion", "mismatchingResourceVersion", "vnfcs/vnfc/vnfcId"));
528 public void thatCreateWithoutResourceVersionsIsValid() throws AAIException {
529 engine.startTransaction();
531 assertTrue(serializer.verifyResourceVersion("create", "generic-vnf", null, null, "generic-vnfs/generic-vnf/myid"));
535 public void thatCreateWithResourceVersionIsInvalid() throws AAIException {
536 engine.startTransaction();
538 thrown.expect(AAIException.class);
539 thrown.expectMessage("resource-version passed for create of generic-vnfs/generic-vnf/myid");
540 serializer.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid");
544 public void thatUpdateWithMatchingResourceVersionsIsValid() throws AAIException {
545 engine.startTransaction();
547 assertTrue(serializer.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "current-res-ver", "generic-vnfs/generic-vnf/myid"));
551 public void thatUpdateWithoutResourceVersionIsInvalid() throws AAIException {
552 engine.startTransaction();
554 thrown.expect(AAIException.class);
555 thrown.expectMessage("resource-version not passed for update of generic-vnfs/generic-vnf/myid");
556 serializer.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid");
561 public void thatUpdateWithResourceVersionMismatchIsInvalid() throws AAIException {
562 engine.startTransaction();
564 thrown.expect(AAIException.class);
565 thrown.expectMessage("resource-version MISMATCH for update of generic-vnfs/generic-vnf/myid");
566 serializer.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver",
567 "generic-vnfs/generic-vnf/myid");
572 public void trimClassNameTest() {
573 assertEquals("GenericVnf", serializer.trimClassName("GenericVnf"));
574 assertEquals("GenericVnf", serializer.trimClassName("org.onap.aai.GenericVnf"));
578 public void getURIForVertexTest() throws AAIException, URISyntaxException, UnsupportedEncodingException {
579 engine.startTransaction();
581 Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
582 "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
583 Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
585 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
587 ten.property("aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
589 URI compare = new URI("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
590 assertEquals(compare, serializer.getURIForVertex(ten));
592 URI compareFailure = new URI("/unknown-uri");
593 ten.property("aai-uri").remove();
594 assertEquals(compareFailure, serializer.getURIForVertex(ten));
599 public void getVertexPropertiesTest() throws AAIException, UnsupportedEncodingException {
600 engine.startTransaction();
602 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
603 "/network/generic-vnfs/generic-vnf/myvnf", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
604 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
605 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
606 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
607 "/network/vnfcs/vnfc/a-name", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
608 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
609 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
611 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
613 Introspector vnf = serializer.getVertexProperties(gvnf);
614 assertEquals("generic-vnf", vnf.getDbName());
615 assertEquals("myvnf", vnf.getValue("vnf-id"));
617 assertFalse(vnf.marshal(false).contains("relationship-list"));
622 public void getEdgeBetweenTest() throws AAIException {
623 engine.startTransaction();
626 engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
627 Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
629 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
631 Edge e = serializer.getEdgeBetween(EdgeType.TREE, ten, cr, null);
632 assertEquals("org.onap.relationships.inventory.BelongsTo", e.label());
637 public void deleteEdgeTest() throws AAIException, UnsupportedEncodingException {
638 engine.startTransaction();
640 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
641 "/network/generic-vnfs/generic-vnf/myvnf", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
642 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
643 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
644 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
645 "/network/vnfcs/vnfc/a-name", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
646 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
647 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
649 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
651 Introspector relData = loader.introspectorFromName("relationship-data");
652 relData.setValue("relationship-key", "vnfc.vnfc-name");
653 relData.setValue("relationship-value", "a-name");
654 Introspector relationship = loader.introspectorFromName("relationship");
655 relationship.setValue("related-to", "vnfc");
656 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
657 relationship.setValue("relationship-data", relData);
659 assertTrue(serializer.deleteEdge(relationship, gvnf).isPresent());
661 assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext());
662 assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext());
667 public void createEdgeTest() throws AAIException, UnsupportedEncodingException {
668 engine.startTransaction();
670 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
671 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
672 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
673 "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
676 Introspector relData = loader.introspectorFromName("relationship-data");
677 relData.setValue("relationship-key", "vnfc.vnfc-name");
678 relData.setValue("relationship-value", "a-name");
679 Introspector relationship = loader.introspectorFromName("relationship");
680 relationship.setValue("related-to", "vnfc");
681 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
682 relationship.setValue("relationship-data", relData);
684 assertNotNull(serializer.createEdge(relationship, gvnf));
685 assertTrue(engine.tx().traversal().V(gvnf).both("org.onap.relationships.inventory.BelongsTo").hasNext());
686 assertTrue(engine.tx().traversal().V(vnfc).both("org.onap.relationships.inventory.BelongsTo").hasNext());
691 public void createCousinEdgeThatShouldBeTreeTest()
692 throws AAIException, UnsupportedEncodingException, URISyntaxException {
693 engine.startTransaction();
695 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
696 "/network/generic-vnfs/generic-vnf/myvnf");
697 Vertex vf = engine.tx().addVertex("aai-node-type", "vf-module", "vf-module-id", "vf-id", "aai-uri",
698 "/network/generic-vnfs/generic-vnf/myvnf/vf-modules/vf-module/vf-id");
700 edgeSer.addTreeEdge(engine.tx().traversal(), gvnf, vf);
702 Introspector relationship = loader.introspectorFromName("relationship");
703 relationship.setValue("related-to", "vf-module");
704 relationship.setValue("related-link", serializer.getURIForVertex(vf).toString());
705 Introspector relationshipList = loader.introspectorFromName("relationship-list");
706 relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
708 Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
709 Vertex gvnf2 = serializer.createNewVertex(gvnfObj);
710 gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
711 gvnfObj.setValue("vnf-id", "myvnf-1");
713 QueryParser uriQuery =
714 dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
717 serializer.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
718 } catch (AAIException e) {
719 assertEquals("AAI_6145", e.getCode());
724 public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
725 engine.startTransaction();
727 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
728 "/network/generic-vnfs/generic-vnf/myvnf");
730 // rainy day case, edge to non-existent object
731 Introspector relData = loader.introspectorFromName("relationship-data");
732 relData.setValue("relationship-key", "vnfc.vnfc-name");
733 relData.setValue("relationship-value", "b-name");
734 Introspector relationship = loader.introspectorFromName("relationship");
735 relationship.setValue("related-to", "vnfc");
736 relationship.setValue("related-link", "/network/vnfcs/vnfc/b-name");
737 relationship.setValue("relationship-data", relData);
739 thrown.expect(AAIException.class);
740 thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
741 serializer.createEdge(relationship, gvnf);
746 public void serializeSingleVertexTopLevelTest() throws AAIException, UnsupportedEncodingException {
747 engine.startTransaction();
749 Introspector gvnf = loader.introspectorFromName("generic-vnf");
750 Vertex gvnfVert = serializer.createNewVertex(gvnf);
752 gvnf.setValue("vnf-id", "myvnf");
753 gvnf.setValue("vnf-type", "typo");
754 serializer.serializeSingleVertex(gvnfVert, gvnf, "test");
755 assertTrue(engine.tx().traversal().V().has("aai-node-type", "generic-vnf").has("vnf-id", "myvnf").hasNext());
759 public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException {
760 engine.startTransaction();
762 Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
763 "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
764 Introspector tenIn = loader.introspectorFromName("tenant");
765 Vertex ten = serializer.createNewVertex(tenIn);
766 ten.property("aai-uri", cr.property("aai-uri").value().toString() + "/tenants/tenant/453");
768 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
770 tenIn.setValue("tenant-id", "453");
771 tenIn.setValue("tenant-name", "mytenant");
773 serializer.serializeSingleVertex(ten, tenIn, "test");
775 assertTrue(engine.tx().traversal().V().has("aai-node-type", "tenant").has("tenant-id", "453")
776 .has("tenant-name", "mytenant").hasNext());
781 public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
782 engine.startTransaction();
784 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
785 "/network/generic-vnfs/generic-vnf/vnf-123", "aai-uuid", "a");
786 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
787 "/network/vnfcs/vnfc/vnfc-123", "aai-uuid", "b");
789 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
791 Introspector obj = loader.introspectorFromName("generic-vnf");
792 obj = this.serializer.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
794 assertEquals("edge label between generic-vnf and vnfs is uses", "org.onap.relationships.inventory.BelongsTo",
795 obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0)
796 .getValue("relationship-label"));
801 public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest()
802 throws AAIException, UnsupportedEncodingException {
804 SchemaVersion version = schemaVersions.getAppRootVersion();
805 DBSerializer dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
806 Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
808 engine.startTransaction();
810 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
811 "/network/generic-vnfs/generic-vnf/vnf-123");
812 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
813 "/network/vnfcs/vnfc/vnfc-123");
815 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
817 Introspector obj = loader.introspectorFromName("generic-vnf");
818 obj = dbser.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
820 assertFalse("Relationship does not contain edge-property", obj.getWrappedValue("relationship-list")
821 .getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
826 public void createEdgeWithInvalidLabelTest()
827 throws AAIException, UnsupportedEncodingException, SecurityException, IllegalArgumentException {
829 engine.startTransaction();
831 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
832 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
833 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name",
836 Introspector relData = loader.introspectorFromName("relationship-data");
837 relData.setValue("relationship-key", "vnfc.vnfc-name");
838 relData.setValue("relationship-value", "a-name");
839 Introspector relationship = loader.introspectorFromName("relationship");
840 relationship.setValue("related-to", "vnfc");
841 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
842 relationship.setValue("relationship-data", relData);
843 relationship.setValue("relationship-label", "NA");
845 thrown.expect(AAIException.class);
846 thrown.expectMessage("No rule found");
847 thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
848 serializer.createEdge(relationship, gvnf);
853 public void createEdgeUsingIntrospectorTest()
854 throws AAIException, UnsupportedEncodingException, SecurityException, IllegalArgumentException {
856 engine.startTransaction();
858 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
859 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
860 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name",
863 Introspector relData = loader.introspectorFromName("relationship-data");
864 relData.setValue("relationship-key", "vnfc.vnfc-name");
865 relData.setValue("relationship-value", "a-name");
866 Introspector relationship = loader.introspectorFromName("relationship");
867 relationship.setValue("related-to", "vnfc");
868 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
869 relationship.setValue("relationship-data", relData);
871 assertEquals("/network/vnfcs/vnfc/a-name", relationship.getValue("related-link"));
873 serializer.createEdge(relationship, gvnf);
877 public void addRelatedToPropertyTest() throws AAIException {
878 engine.startTransaction();
880 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myname", "vnf-name", "myname",
881 "aai-uri", "/network/generic-vnfs/generic-vnf/myname");
882 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
883 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
884 Introspector gv = loader.introspectorFromName("generic-vnf");
885 gv.setValue("vnf-name", "myname");
887 Introspector rel = loader.introspectorFromName("relationship");
888 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
889 dbser.addRelatedToProperty(rel, gvnf, "generic-vnf");
890 List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
891 assertThat(relToProps.size(), is(1));
892 Introspector relToProp = relToProps.get(0);
893 assertThat(relToProp.getValue("property-key"), is("generic-vnf.vnf-name"));
894 assertThat(relToProp.getValue("property-value"), is("myname"));
898 public void dbToObjectContainerMismatchTest() throws AAIException, UnsupportedEncodingException {
899 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
900 Graph vertexMaker = TinkerGraph.open();
901 Vertex a = vertexMaker.addVertex(T.id, "0");
902 Vertex b = vertexMaker.addVertex(T.id, "1");
903 List<Vertex> vertices = Arrays.asList(a, b);
905 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
906 Introspector intro = loader.introspectorFromName("image"); // just need any non-container object
908 thrown.expect(AAIException.class);
909 thrown.expectMessage("query object mismatch: this object cannot hold multiple items.");
911 dbser.dbToObject(vertices, intro, Integer.MAX_VALUE, true, "doesn't matter");
915 public void dbToObjectTest() throws AAIException, UnsupportedEncodingException {
916 engine.startTransaction();
918 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
919 Vertex gv1 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
920 Vertex gv2 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id2");
921 List<Vertex> vertices = Arrays.asList(gv1, gv2);
923 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version);
924 Introspector gvContainer = loader.introspectorFromName("generic-vnfs");
926 Introspector res = dbser.dbToObject(vertices, gvContainer, 0, true, "true");
927 List<Introspector> gvs = res.getWrappedListValue("generic-vnf");
928 assertEquals(2, gvs.size());
929 for (Introspector i : gvs) {
930 String vnfId = i.getValue("vnf-id");
931 assertTrue("id1".equals(vnfId) || "id2".equals(vnfId));
937 public void getEdgeBetweenNoLabelTest() throws AAIException {
938 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
939 engine.startTransaction();
940 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
941 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
942 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
944 Edge res = dbser.getEdgeBetween(EdgeType.TREE, gv, lint);
945 assertEquals("org.onap.relationships.inventory.BelongsTo", res.label());
950 public void deleteItemsWithTraversal() throws AAIException {
951 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
952 engine.startTransaction();
953 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", AAIProperties.AAI_URI,
954 "/network/generic-vnfs/generic-vnf/id1", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
955 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
956 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
957 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1",
958 AAIProperties.AAI_URI, "/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1",
959 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
960 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
961 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
963 assertTrue(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
964 assertTrue(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
966 dbser.deleteWithTraversal(gv);
967 dbser.deleteWithTraversal(lint);
969 assertFalse(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
970 assertFalse(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
975 public void serializeToDbWithParentTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
976 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
977 engine.startTransaction();
978 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", "aai-uri",
979 "/network/generic-vnfs/generic-vnf/id1", "aai-uuid", "a", AAIProperties.CREATED_TS, 123L,
980 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
981 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
982 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "aai-uri", "abc", "aai-uuid", "b",
983 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
984 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
985 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
987 Introspector lintIntro = loader.introspectorFromName("l-interface");
988 lintIntro.setValue("interface-name", "name1");
989 lintIntro.setValue("interface-role", "actor");
990 URI lintURI = new URI("/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1");
991 QueryParser uriQuery = engine.getQueryBuilder(gv).createQueryFromURI(lintURI);
992 dbser.serializeToDb(lintIntro, lint, uriQuery, "test-identifier", "AAI-TEST");
994 assertTrue(engine.tx().traversal().V(lint).has("interface-role", "actor").hasNext());
999 public void getLatestVersionViewTest() throws AAIException, UnsupportedEncodingException {
1000 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
1001 engine.startTransaction();
1002 Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo", "speed-value",
1003 "very-fast", "service-provider-bandwidth-up-units", "things");
1005 Introspector res = dbser.getLatestVersionView(phys);
1006 assertEquals("zaldo", res.getValue("link-name"));
1007 assertEquals("very-fast", res.getValue("speed-value"));
1008 assertEquals("things", res.getValue("service-provider-bandwidth-up-units"));
1012 public void cascadeVserverDeleteTest() throws AAIException, UnsupportedEncodingException {
1014 String expected_message = "";
1017 * vserver-->l-interface -->logical-link
1020 Vertex vserver = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id", "vss1").next();
1022 String exceptionMessage = testCascadeDelete(vserver);
1023 assertEquals(expected_message, exceptionMessage);
1028 public void cascadeL3NetworkPreventDeleteTest() throws AAIException, UnsupportedEncodingException {
1030 ArrayList<String> expected_messages = new ArrayList<>();
1031 expected_messages.add(
1032 "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]");
1033 expected_messages.add(
1034 "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]");
1037 * vserver-->l-interface -->logical-link
1041 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v1").next();
1043 String exceptionMessage = testCascadeDelete(l3network);
1044 assertTrue(expected_messages.contains(exceptionMessage));
1049 public void cascadeL3NetworkDeleteTest() throws AAIException, UnsupportedEncodingException {
1051 String expected_message = "";
1054 * vserver-->l-interface -->logical-link
1058 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v2").next();
1060 String exceptionMessage = testCascadeDelete(l3network);
1061 assertEquals(expected_message, exceptionMessage);