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.*;
25 import static org.mockito.Mockito.spy;
26 import static org.mockito.Mockito.when;
28 import java.io.UnsupportedEncodingException;
30 import java.net.URISyntaxException;
33 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
34 import org.apache.tinkerpop.gremlin.structure.Edge;
35 import org.apache.tinkerpop.gremlin.structure.Graph;
36 import org.apache.tinkerpop.gremlin.structure.T;
37 import org.apache.tinkerpop.gremlin.structure.Vertex;
38 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
39 import org.janusgraph.core.JanusGraphFactory;
41 import org.junit.rules.ExpectedException;
42 import org.junit.runner.RunWith;
43 import org.junit.runners.Parameterized;
44 import org.onap.aai.AAISetup;
45 import org.onap.aai.db.props.AAIProperties;
46 import org.onap.aai.edges.EdgeIngestor;
47 import org.onap.aai.edges.enums.EdgeType;
48 import org.onap.aai.exceptions.AAIException;
49 import org.onap.aai.introspection.Introspector;
50 import org.onap.aai.introspection.Loader;
51 import org.onap.aai.introspection.ModelType;
52 import org.onap.aai.parsers.query.QueryParser;
53 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
54 import org.onap.aai.serialization.engines.QueryStyle;
55 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
56 import org.onap.aai.setup.SchemaVersion;
57 import org.onap.aai.util.AAIConstants;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.test.annotation.DirtiesContext;
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", AAIProperties.AAI_UUID,
169 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
170 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
171 AAIProperties.LAST_MOD_TS, 333L);
172 Vertex subnet_2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-2", AAIProperties.AAI_UUID,
173 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
174 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
175 AAIProperties.LAST_MOD_TS, 333L);
176 Vertex l3interipv6addresslist_3 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
177 "l3-interface-ipv6-address", "l3-interface-ipv6-address-3", AAIProperties.AAI_UUID,
178 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
179 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
180 AAIProperties.LAST_MOD_TS, 333L);
181 Vertex subnet_4 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-4", AAIProperties.AAI_UUID,
182 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
183 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
184 AAIProperties.LAST_MOD_TS, 333L);
185 Vertex subnet_5 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-5", AAIProperties.AAI_UUID,
186 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
187 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
188 AAIProperties.LAST_MOD_TS, 333L);
189 Vertex l3network_6 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-6",
190 "network-name", "network-name-6", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
191 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
192 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
194 GraphTraversalSource g = graph.traversal();
195 edgeSer.addEdge(g, l3interipv4addresslist_1, subnet_2);
196 edgeSer.addEdge(g, l3interipv6addresslist_3, subnet_4);
197 edgeSer.addTreeEdge(g, subnet_5, l3network_6);
199 l3interipv4addresslist_1.property(AAIProperties.AAI_URI,
200 dbser.getURIForVertex(l3interipv4addresslist_1).toString());
201 subnet_2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet_2).toString());
202 l3interipv6addresslist_3.property(AAIProperties.AAI_URI,
203 dbser.getURIForVertex(l3interipv6addresslist_3).toString());
204 subnet_4.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet_4).toString());
205 subnet_5.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet_5).toString());
206 l3network_6.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3network_6).toString());
210 private void l3NetworkSetup() throws AAIException, UnsupportedEncodingException {
212 * This setus up the test graph, For future junits , add more vertices
216 Vertex l3network1 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v1",
217 "network-name", "network-name-v1", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
218 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
219 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
220 Vertex l3network2 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v2",
221 "network-name", "network-name-v2", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
222 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
223 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
224 Vertex subnet1 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v1", AAIProperties.AAI_UUID,
225 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
226 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
227 AAIProperties.LAST_MOD_TS, 333L);
228 Vertex subnet2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v2", AAIProperties.AAI_UUID,
229 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
230 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
231 AAIProperties.LAST_MOD_TS, 333L);
233 Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
234 "l3-interface-ipv4-address", "l3-intr-v1", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
235 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
236 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
237 Vertex l3interipv6addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
238 "l3-interface-ipv6-address", "l3-interface-ipv6-v1", AAIProperties.AAI_UUID,
239 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
240 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
241 AAIProperties.LAST_MOD_TS, 333L);
243 GraphTraversalSource g = graph.traversal();
244 edgeSer.addTreeEdge(g, subnet1, l3network1);
245 edgeSer.addEdge(g, l3interipv4addresslist_1, subnet1);
246 edgeSer.addEdge(g, l3interipv6addresslist_1, subnet1);
248 edgeSer.addTreeEdge(g, subnet2, l3network2);
250 subnet1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet1).toString());
251 l3interipv4addresslist_1.property(AAIProperties.AAI_URI,
252 dbser.getURIForVertex(l3interipv4addresslist_1).toString());
253 l3network1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3network1).toString());
254 subnet2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(subnet2).toString());
255 l3network2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(l3network2).toString());
259 private void vserverSetup() throws AAIException, UnsupportedEncodingException {
261 * This setus up the test graph, For future junits , add more vertices
265 Vertex vserver1 = graph.addVertex("aai-node-type", "vserver", "vserver-id", "vss1", AAIProperties.AAI_URI,
266 "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vss1",
267 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
268 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
269 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
271 Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr1",
272 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
273 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
274 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
275 Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr2",
276 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
277 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
278 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
280 Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink1",
281 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
282 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
283 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
284 Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink2",
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 l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
290 "l3-interface-ipv4-address", "l3-intr-ipv4-address-1", AAIProperties.AAI_UUID,
291 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
292 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
293 AAIProperties.LAST_MOD_TS, 333L);
294 Vertex l3interipv6addresslist_2 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
295 "l3-interface-ipv4-address", "l3-intr-ipv6-address-1", AAIProperties.AAI_UUID,
296 UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot",
297 AAIProperties.RESOURCE_VERSION, "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot",
298 AAIProperties.LAST_MOD_TS, 333L);
300 GraphTraversalSource g = graph.traversal();
302 edgeSer.addTreeEdge(g, lInterface1, vserver1);
303 edgeSer.addTreeEdge(g, lInterface2, vserver1);
304 edgeSer.addTreeEdge(g, l3interipv4addresslist_1, lInterface1);
305 edgeSer.addTreeEdge(g, l3interipv6addresslist_2, lInterface2);
307 edgeSer.addEdge(g, lInterface1, logicalLink1);
308 edgeSer.addEdge(g, lInterface2, logicalLink2);
310 vserver1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(vserver1).toString());
311 lInterface1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(lInterface1).toString());
312 lInterface2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(lInterface2).toString());
313 l3interipv4addresslist_1.property(AAIProperties.AAI_URI,
314 dbser.getURIForVertex(l3interipv4addresslist_1).toString());
315 l3interipv6addresslist_2.property(AAIProperties.AAI_URI,
316 dbser.getURIForVertex(l3interipv6addresslist_2).toString());
317 logicalLink1.property(AAIProperties.AAI_URI, dbser.getURIForVertex(logicalLink1).toString());
318 logicalLink2.property(AAIProperties.AAI_URI, dbser.getURIForVertex(logicalLink2).toString());
322 public void subnetDelWithInEdgesIpv4Test() throws AAIException, UnsupportedEncodingException {
324 String expected_message =
325 "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]";
328 * This subnet has in-edges with l3-ipv4 and NOT ok to delete
330 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-2").next();
332 String exceptionMessage = testCascadeDelete(subnet);
333 assertEquals(expected_message, exceptionMessage);
338 public void subnetDelWithInEdgesIpv6Test() throws AAIException, UnsupportedEncodingException {
340 String expected_message =
341 "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]";
344 * This subnet has in-edges with l3-ipv6 and NOT ok to delete
346 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-4").next();
347 String exceptionMessage = testCascadeDelete(subnet);
348 assertEquals(expected_message, exceptionMessage);
353 public void subnetDelWithInEdgesL3network() throws AAIException, UnsupportedEncodingException {
355 String expected_message = "";
358 * This subnet has in-edges with l3-network and ok to delete
360 Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-5").next();
362 String exceptionMessage = testCascadeDelete(subnet);
363 assertEquals(expected_message, exceptionMessage);
367 private String testCascadeDelete(Vertex v) throws AAIException {
369 GraphTraversalSource traversal = graph.traversal();
370 when(spy.asAdmin()).thenReturn(adminSpy);
371 when(adminSpy.getTraversalSource()).thenReturn(traversal);
372 when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
374 String exceptionMessage = "";
375 DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
376 List<Vertex> deletableVertices = spy.getQueryEngine().findDeletable(v);
379 serializer.delete(v, deletableVertices, "resourceVersion", false);
380 } catch (AAIException exception) {
381 exception.printStackTrace();
382 exceptionMessage = exception.getMessage();
384 return exceptionMessage;
389 public void createNewVertexTest() throws AAIException {
390 engine.startTransaction();
392 Introspector testObj = loader.introspectorFromName("generic-vnf");
394 Vertex testVertex = dbser.createNewVertex(testObj);
395 Vertex fromGraph = engine.tx().traversal().V().has("aai-node-type", "generic-vnf").toList().get(0);
396 assertEquals(testVertex.id(), fromGraph.id());
397 assertEquals("AAI-TEST", fromGraph.property(AAIProperties.SOURCE_OF_TRUTH).value());
402 public void touchStandardVertexPropertiesTest() throws AAIException, InterruptedException {
403 engine.startTransaction();
405 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
408 DBSerializer dbser2 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-2");
409 Vertex vert = graph.addVertex("aai-node-type", "generic-vnf", "aai-uri", "a");
411 // Upon first creation of the Vertex and the DBSerializer
412 // the source of truth and created-ts should be the same as their modified counterparts
413 dbser2.touchStandardVertexProperties(vert, true);
414 String createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
415 String modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
416 String sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
417 String lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
418 assertEquals(createTS, modTS);
419 assertEquals(sot, lastModSOT);
421 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
425 // Not new vertex && new DBSerializer (A new serializer since a new one will be created per transaction)
426 // Here the vertex will be modified by a different source of truth
427 DBSerializer dbser3 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-3");
428 dbser3.touchStandardVertexProperties(vert, false);
429 createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
430 modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
431 sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
432 lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
433 assertNotEquals(createTS, modTS);
434 assertNotEquals(sot, lastModSOT);
436 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
440 // The currentTimeMillis used for the created-ts and modified-ts is created at DBSerializer instantiation
441 // Every REST transaction should create a new DBSerializer - thus a new currentTimeMillis is used at the time of
443 // Using an existing vertex, but treating it as new && using an older DBSerializer
444 dbser.touchStandardVertexProperties(vert, true);
445 String resverStart = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
446 String lastModTimeStart = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
447 createTS = String.valueOf(vert.property(AAIProperties.CREATED_TS).value());
448 modTS = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
449 assertEquals(createTS, modTS);
450 assertEquals("AAI-TEST", vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value());
452 // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
456 dbser2.touchStandardVertexProperties(vert, false);
457 String resourceVer = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
458 String lastModTs = String.valueOf(vert.property(AAIProperties.LAST_MOD_TS).value());
459 String lastModSoT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
461 assertNotEquals(resverStart, resourceVer);
462 assertNotEquals(lastModTimeStart, lastModTs);
463 assertEquals("AAI-TEST-2", lastModSoT);
467 public void touchStandardVertexPropertiesAAIUUIDTest() {
468 engine.startTransaction();
470 Graph graph = TinkerGraph.open();
471 Vertex v = graph.addVertex("aai-node-type", "generic-vnf");
473 dbser.touchStandardVertexProperties(v, true);
475 assertTrue(v.property(AAIProperties.AAI_UUID).isPresent());
477 UUID.fromString((String) v.property(AAIProperties.AAI_UUID).value());
478 } catch (IllegalArgumentException e) {
479 fail("Vertex uuid is not valid uuid");
484 public void verifyResourceVersion_SunnyDayTest() throws AAIException {
485 engine.startTransaction();
487 assertTrue(dbser.verifyResourceVersion("delete", "vnfc", "abc", "abc", "vnfcs/vnfc/vnfcId"));
492 public void verifyResourceVersion_CreateWithRVTest() throws AAIException {
493 engine.startTransaction();
495 thrown.expect(AAIException.class);
496 thrown.expectMessage("resource-version passed for create of generic-vnfs/generic-vnf/myid");
497 dbser.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid");
502 public void verifyResourceVersion_MissingRVTest() throws AAIException {
503 engine.startTransaction();
505 thrown.expect(AAIException.class);
506 thrown.expectMessage("resource-version not passed for update of generic-vnfs/generic-vnf/myid");
507 dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid");
512 public void verifyResourceVersion_MismatchRVTest() throws AAIException {
513 engine.startTransaction();
515 thrown.expect(AAIException.class);
516 thrown.expectMessage("resource-version MISMATCH for update of generic-vnfs/generic-vnf/myid");
517 dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver",
518 "generic-vnfs/generic-vnf/myid");
523 public void verifyResourceVersion_DeleteTest() throws AAIException {
524 engine.startTransaction();
526 assertTrue(dbser.verifyResourceVersion("delete", "generic-vnf", "current-res-ver",
527 AAIConstants.AAI_RESVERSION_DISABLED_UUID_DEFAULT, "generic-vnfs/generic-vnf/myid"));
532 public void trimClassNameTest() {
533 assertEquals("GenericVnf", dbser.trimClassName("GenericVnf"));
534 assertEquals("GenericVnf", dbser.trimClassName("org.onap.aai.GenericVnf"));
538 public void getURIForVertexTest() throws AAIException, URISyntaxException, UnsupportedEncodingException {
539 engine.startTransaction();
541 Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
542 "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
543 Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
545 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
547 ten.property("aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
549 URI compare = new URI("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
550 assertEquals(compare, dbser.getURIForVertex(ten));
552 URI compareFailure = new URI("/unknown-uri");
553 ten.property("aai-uri").remove();
554 assertEquals(compareFailure, dbser.getURIForVertex(ten));
559 public void getVertexPropertiesTest() throws AAIException, UnsupportedEncodingException {
560 engine.startTransaction();
562 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
563 "/network/generic-vnfs/generic-vnf/myvnf", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
564 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
565 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
566 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
567 "/network/vnfcs/vnfc/a-name", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
568 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
569 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
571 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
573 Introspector vnf = dbser.getVertexProperties(gvnf);
574 assertEquals("generic-vnf", vnf.getDbName());
575 assertEquals("myvnf", vnf.getValue("vnf-id"));
577 assertFalse(vnf.marshal(false).contains("relationship-list"));
582 public void getEdgeBetweenTest() throws AAIException {
583 engine.startTransaction();
586 engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
587 Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
589 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
591 Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr, null);
592 assertEquals("org.onap.relationships.inventory.BelongsTo", e.label());
597 public void deleteEdgeTest() throws AAIException, UnsupportedEncodingException {
598 engine.startTransaction();
600 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
601 "/network/generic-vnfs/generic-vnf/myvnf", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
602 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
603 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
604 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
605 "/network/vnfcs/vnfc/a-name", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
606 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
607 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
609 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
611 Introspector relData = loader.introspectorFromName("relationship-data");
612 relData.setValue("relationship-key", "vnfc.vnfc-name");
613 relData.setValue("relationship-value", "a-name");
614 Introspector relationship = loader.introspectorFromName("relationship");
615 relationship.setValue("related-to", "vnfc");
616 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
617 relationship.setValue("relationship-data", relData);
619 assertTrue(dbser.deleteEdge(relationship, gvnf).isPresent());
621 assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext());
622 assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext());
627 public void createEdgeTest() throws AAIException, UnsupportedEncodingException {
628 engine.startTransaction();
630 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
631 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
632 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
633 "/network/vnfcs/vnfc/a-name", "aai-uuid", "b");
636 Introspector relData = loader.introspectorFromName("relationship-data");
637 relData.setValue("relationship-key", "vnfc.vnfc-name");
638 relData.setValue("relationship-value", "a-name");
639 Introspector relationship = loader.introspectorFromName("relationship");
640 relationship.setValue("related-to", "vnfc");
641 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
642 relationship.setValue("relationship-data", relData);
644 assertNotNull(dbser.createEdge(relationship, gvnf));
645 assertTrue(engine.tx().traversal().V(gvnf).both("org.onap.relationships.inventory.BelongsTo").hasNext());
646 assertTrue(engine.tx().traversal().V(vnfc).both("org.onap.relationships.inventory.BelongsTo").hasNext());
651 public void createCousinEdgeThatShouldBeTreeTest()
652 throws AAIException, UnsupportedEncodingException, URISyntaxException {
653 engine.startTransaction();
655 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
656 "/network/generic-vnfs/generic-vnf/myvnf");
657 Vertex vf = engine.tx().addVertex("aai-node-type", "vf-module", "vf-module-id", "vf-id", "aai-uri",
658 "/network/generic-vnfs/generic-vnf/myvnf/vf-modules/vf-module/vf-id");
660 edgeSer.addTreeEdge(engine.tx().traversal(), gvnf, vf);
662 Introspector relationship = loader.introspectorFromName("relationship");
663 relationship.setValue("related-to", "vf-module");
664 relationship.setValue("related-link", dbser.getURIForVertex(vf).toString());
665 Introspector relationshipList = loader.introspectorFromName("relationship-list");
666 relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
668 Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
669 Vertex gvnf2 = dbser.createNewVertex(gvnfObj);
670 gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
671 gvnfObj.setValue("vnf-id", "myvnf-1");
673 QueryParser uriQuery =
674 dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
677 dbser.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
678 } catch (AAIException e) {
679 assertEquals("AAI_6145", e.getCode());
684 public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
685 engine.startTransaction();
687 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
688 "/network/generic-vnfs/generic-vnf/myvnf");
690 // rainy day case, edge to non-existent object
691 Introspector relData = loader.introspectorFromName("relationship-data");
692 relData.setValue("relationship-key", "vnfc.vnfc-name");
693 relData.setValue("relationship-value", "b-name");
694 Introspector relationship = loader.introspectorFromName("relationship");
695 relationship.setValue("related-to", "vnfc");
696 relationship.setValue("related-link", "/network/vnfcs/vnfc/b-name");
697 relationship.setValue("relationship-data", relData);
699 thrown.expect(AAIException.class);
700 thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
701 dbser.createEdge(relationship, gvnf);
706 public void serializeSingleVertexTopLevelTest() throws AAIException, UnsupportedEncodingException {
707 engine.startTransaction();
709 Introspector gvnf = loader.introspectorFromName("generic-vnf");
710 Vertex gvnfVert = dbser.createNewVertex(gvnf);
712 gvnf.setValue("vnf-id", "myvnf");
713 gvnf.setValue("vnf-type", "typo");
714 dbser.serializeSingleVertex(gvnfVert, gvnf, "test");
715 assertTrue(engine.tx().traversal().V().has("aai-node-type", "generic-vnf").has("vnf-id", "myvnf").hasNext());
719 public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException {
720 engine.startTransaction();
722 Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
723 "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
724 Introspector tenIn = loader.introspectorFromName("tenant");
725 Vertex ten = dbser.createNewVertex(tenIn);
726 ten.property("aai-uri", cr.property("aai-uri").value().toString() + "/tenants/tenant/453");
728 edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
730 tenIn.setValue("tenant-id", "453");
731 tenIn.setValue("tenant-name", "mytenant");
733 dbser.serializeSingleVertex(ten, tenIn, "test");
735 assertTrue(engine.tx().traversal().V().has("aai-node-type", "tenant").has("tenant-id", "453")
736 .has("tenant-name", "mytenant").hasNext());
741 public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
742 engine.startTransaction();
744 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
745 "/network/generic-vnfs/generic-vnf/vnf-123", "aai-uuid", "a");
746 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
747 "/network/vnfcs/vnfc/vnfc-123", "aai-uuid", "b");
749 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
751 Introspector obj = loader.introspectorFromName("generic-vnf");
752 obj = this.dbser.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
754 assertEquals("edge label between generic-vnf and vnfs is uses", "org.onap.relationships.inventory.BelongsTo",
755 obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0)
756 .getValue("relationship-label"));
761 public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest()
762 throws AAIException, UnsupportedEncodingException {
764 SchemaVersion version = schemaVersions.getAppRootVersion();
765 DBSerializer dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
766 Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
768 engine.startTransaction();
770 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
771 "/network/generic-vnfs/generic-vnf/vnf-123");
772 Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
773 "/network/vnfcs/vnfc/vnfc-123");
775 edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
777 Introspector obj = loader.introspectorFromName("generic-vnf");
778 obj = dbser.dbToObject(Collections.singletonList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
780 assertFalse("Relationship does not contain edge-property", obj.getWrappedValue("relationship-list")
781 .getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
786 public void createEdgeWithInvalidLabelTest()
787 throws AAIException, UnsupportedEncodingException, SecurityException, IllegalArgumentException {
789 engine.startTransaction();
791 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
792 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
793 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name",
796 Introspector relData = loader.introspectorFromName("relationship-data");
797 relData.setValue("relationship-key", "vnfc.vnfc-name");
798 relData.setValue("relationship-value", "a-name");
799 Introspector relationship = loader.introspectorFromName("relationship");
800 relationship.setValue("related-to", "vnfc");
801 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
802 relationship.setValue("relationship-data", relData);
803 relationship.setValue("relationship-label", "NA");
805 thrown.expect(AAIException.class);
806 thrown.expectMessage("No rule found");
807 thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
808 dbser.createEdge(relationship, gvnf);
813 public void createEdgeUsingIntrospectorTest()
814 throws AAIException, UnsupportedEncodingException, SecurityException, IllegalArgumentException {
816 engine.startTransaction();
818 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
819 "/network/generic-vnfs/generic-vnf/myvnf", "aai-uuid", "a");
820 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name",
823 Introspector relData = loader.introspectorFromName("relationship-data");
824 relData.setValue("relationship-key", "vnfc.vnfc-name");
825 relData.setValue("relationship-value", "a-name");
826 Introspector relationship = loader.introspectorFromName("relationship");
827 relationship.setValue("related-to", "vnfc");
828 relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
829 relationship.setValue("relationship-data", relData);
831 assertEquals("/network/vnfcs/vnfc/a-name", relationship.getValue("related-link"));
833 dbser.createEdge(relationship, gvnf);
837 public void addRelatedToPropertyTest() throws AAIException {
838 engine.startTransaction();
840 Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myname", "vnf-name", "myname",
841 "aai-uri", "/network/generic-vnfs/generic-vnf/myname");
842 engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
843 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
844 Introspector gv = loader.introspectorFromName("generic-vnf");
845 gv.setValue("vnf-name", "myname");
847 Introspector rel = loader.introspectorFromName("relationship");
848 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
849 dbser.addRelatedToProperty(rel, gvnf, "generic-vnf");
850 List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
851 assertThat(relToProps.size(), is(1));
852 Introspector relToProp = relToProps.get(0);
853 assertThat(relToProp.getValue("property-key"), is("generic-vnf.vnf-name"));
854 assertThat(relToProp.getValue("property-value"), is("myname"));
858 public void dbToObjectContainerMismatchTest() throws AAIException, UnsupportedEncodingException {
859 DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
860 Graph vertexMaker = TinkerGraph.open();
861 Vertex a = vertexMaker.addVertex(T.id, "0");
862 Vertex b = vertexMaker.addVertex(T.id, "1");
863 List<Vertex> vertices = Arrays.asList(a, b);
865 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
866 Introspector intro = loader.introspectorFromName("image"); // just need any non-container object
868 thrown.expect(AAIException.class);
869 thrown.expectMessage("query object mismatch: this object cannot hold multiple items.");
871 dbser.dbToObject(vertices, intro, Integer.MAX_VALUE, true, "doesn't matter");
875 public void dbToObjectTest() throws AAIException, UnsupportedEncodingException {
876 engine.startTransaction();
878 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
879 Vertex gv1 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
880 Vertex gv2 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id2");
881 List<Vertex> vertices = Arrays.asList(gv1, gv2);
883 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version);
884 Introspector gvContainer = loader.introspectorFromName("generic-vnfs");
886 Introspector res = dbser.dbToObject(vertices, gvContainer, 0, true, "true");
887 List<Introspector> gvs = res.getWrappedListValue("generic-vnf");
888 assertEquals(2, gvs.size());
889 for (Introspector i : gvs) {
890 String vnfId = i.getValue("vnf-id");
891 assertTrue("id1".equals(vnfId) || "id2".equals(vnfId));
897 public void getEdgeBetweenNoLabelTest() throws AAIException {
898 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
899 engine.startTransaction();
900 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
901 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
902 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
904 Edge res = dbser.getEdgeBetween(EdgeType.TREE, gv, lint);
905 assertEquals("org.onap.relationships.inventory.BelongsTo", res.label());
910 public void deleteItemsWithTraversal() throws AAIException {
911 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
912 engine.startTransaction();
913 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", AAIProperties.AAI_URI,
914 "/network/generic-vnfs/generic-vnf/id1", AAIProperties.AAI_UUID, UUID.randomUUID().toString(),
915 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
916 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
917 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1",
918 AAIProperties.AAI_URI, "/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1",
919 AAIProperties.AAI_UUID, UUID.randomUUID().toString(), AAIProperties.CREATED_TS, 123L,
920 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
921 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
923 assertTrue(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
924 assertTrue(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
926 dbser.deleteWithTraversal(gv);
927 dbser.deleteWithTraversal(lint);
929 assertFalse(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
930 assertFalse(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
935 public void serializeToDbWithParentTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
936 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
937 engine.startTransaction();
938 Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", "aai-uri",
939 "/network/generic-vnfs/generic-vnf/id1", "aai-uuid", "a", AAIProperties.CREATED_TS, 123L,
940 AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION, "123",
941 AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
942 Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "aai-uri", "abc", "aai-uuid", "b",
943 AAIProperties.CREATED_TS, 123L, AAIProperties.SOURCE_OF_TRUTH, "sot", AAIProperties.RESOURCE_VERSION,
944 "123", AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot", AAIProperties.LAST_MOD_TS, 333L);
945 edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
947 Introspector lintIntro = loader.introspectorFromName("l-interface");
948 lintIntro.setValue("interface-name", "name1");
949 lintIntro.setValue("interface-role", "actor");
950 URI lintURI = new URI("/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1");
951 QueryParser uriQuery = engine.getQueryBuilder(gv).createQueryFromURI(lintURI);
952 dbser.serializeToDb(lintIntro, lint, uriQuery, "test-identifier", "AAI-TEST");
954 assertTrue(engine.tx().traversal().V(lint).has("interface-role", "actor").hasNext());
959 public void getLatestVersionViewTest() throws AAIException, UnsupportedEncodingException {
960 DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
961 engine.startTransaction();
962 Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo", "speed-value",
963 "very-fast", "service-provider-bandwidth-up-units", "things");
965 Introspector res = dbser.getLatestVersionView(phys);
966 assertEquals("zaldo", res.getValue("link-name"));
967 assertEquals("very-fast", res.getValue("speed-value"));
968 assertEquals("things", res.getValue("service-provider-bandwidth-up-units"));
972 public void cascadeVserverDeleteTest() throws AAIException, UnsupportedEncodingException {
974 String expected_message = "";
977 * vserver-->l-interface -->logical-link
980 Vertex vserver = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id", "vss1").next();
982 String exceptionMessage = testCascadeDelete(vserver);
983 assertEquals(expected_message, exceptionMessage);
988 public void cascadeL3NetworkPreventDeleteTest() throws AAIException, UnsupportedEncodingException {
990 ArrayList expected_messages = new ArrayList<String>();
991 expected_messages.add(
992 "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]");
993 expected_messages.add(
994 "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]");
997 * vserver-->l-interface -->logical-link
1001 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v1").next();
1003 String exceptionMessage = testCascadeDelete(l3network);
1004 assertTrue(expected_messages.contains(exceptionMessage));
1009 public void cascadeL3NetworkDeleteTest() throws AAIException, UnsupportedEncodingException {
1011 String expected_message = "";
1014 * vserver-->l-interface -->logical-link
1018 graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v2").next();
1020 String exceptionMessage = testCascadeDelete(l3network);
1021 assertEquals(expected_message, exceptionMessage);