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.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
26 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
27 import org.apache.tinkerpop.gremlin.structure.Edge;
28 import org.apache.tinkerpop.gremlin.structure.Graph;
29 import org.apache.tinkerpop.gremlin.structure.T;
30 import org.apache.tinkerpop.gremlin.structure.Vertex;
31 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.onap.aai.AAISetup;
36 import org.onap.aai.db.props.AAIProperties;
37 import org.onap.aai.exceptions.AAIException;
38 import org.onap.aai.serialization.db.exceptions.EdgeMultiplicityException;
39 import org.springframework.beans.factory.annotation.Autowired;
41 public class EdgeSerializerTest extends AAISetup {
46 public ExpectedException thrown = ExpectedException.none();
49 public void addTreeEdgeTest() throws AAIException {
50 Graph graph = TinkerGraph.open();
51 Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "cloud-region");
52 Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
53 GraphTraversalSource g = graph.traversal();
54 rules.addTreeEdge(g, v1, v2);
56 g.V(v1).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "tenant").hasNext());
58 Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "cloud-region");
59 assertEquals(null, rules.addTreeEdgeIfPossible(g, v3, v2));
63 public void addCousinEdgeTest() throws AAIException {
64 Graph graph = TinkerGraph.open();
65 Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "flavor");
66 Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
67 GraphTraversalSource g = graph.traversal();
68 rules.addEdge(g, v1, v2);
70 g.V(v2).out("org.onap.relationships.inventory.Uses").has("aai-node-type", "flavor").hasNext());
72 Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "flavor");
73 assertEquals(null, rules.addEdgeIfPossible(g, v3, v2));
77 public void multiplicityViolationTest() throws AAIException {
78 thrown.expect(EdgeMultiplicityException.class);
80 "multiplicity rule violated: only one edge can exist with label: org.onap.relationships.inventory.Uses between vf-module and volume-group");
82 Graph graph = TinkerGraph.open();
83 Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "vf-module");
84 Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "volume-group");
85 GraphTraversalSource g = graph.traversal();
87 rules.addEdge(g, v2, v1);
88 Vertex v3 = graph.addVertex(T.id, "3", "aai-node-type", "vf-module");
89 rules.addEdge(g, v2, v3);
93 public void addEdgeVerifyAAIUUIDCousinTest() throws AAIException {
94 Graph graph = TinkerGraph.open();
95 Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "flavor");
96 Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
97 GraphTraversalSource g = graph.traversal();
98 Edge e = rules.addEdge(g, v1, v2);
99 assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
100 // assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));
104 public void addEdgeVerifyAAIUUIDTreeTest() throws AAIException {
105 Graph graph = TinkerGraph.open();
106 Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "tenant");
107 Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
108 GraphTraversalSource g = graph.traversal();
109 Edge e = rules.addTreeEdge(g, v1, v2);
110 assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
111 // assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));