summaryrefslogtreecommitdiffstats
path: root/aai-core/src/test
diff options
context:
space:
mode:
authorMaharajh, Robby (rx2202) <rx2202@att.com>2017-12-01 10:41:41 -0500
committerMaharajh, Robby (rx2202) <rx2202@att.com>2017-12-01 10:45:31 -0500
commit2e4f21dea97049f4de34fcfd789f461882e24602 (patch)
tree72696b56796bd32990bb9b3f241036d20e6ed550 /aai-core/src/test
parent8dcb9900cae95a17ca6d029a665d512b3e7b11a2 (diff)
Added support for Multiple Edges
Issue-ID: AAI-524 Change-Id: I33dd31315992e2efb2d6d390ffc523655b55a84c Signed-off-by: Maharajh, Robby (rx2202) <rx2202@att.com>
Diffstat (limited to 'aai-core/src/test')
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java50
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java635
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java193
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java633
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java117
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/util/VersionCheckerTest.java41
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java141
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java75
-rw-r--r--aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml5
-rw-r--r--aai-core/src/test/resources/dbedgerules/DbEdgeRules_TraversalQueryTest.json145
-rw-r--r--aai-core/src/test/resources/dbedgerules/DbEdgeRules_test.json92
12 files changed, 2065 insertions, 64 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
index 7dbf2392..4a870995 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
@@ -162,7 +162,7 @@ public class DataCopyTest {
final Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
final Introspector obj = loader.unmarshal("customer", this.getJsonString("nested-case.json"));
- System.out.println(obj.marshal(true));
+ //System.out.println(obj.marshal(true));
TransactionalGraphEngine spy = spy(dbEngine);
TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
Graph g = graph.newTransaction();
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java
new file mode 100644
index 00000000..02486b61
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java
@@ -0,0 +1,50 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.query.builder;
+
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+public class GremlinTraversalTest extends QueryBuilderTestAbstraction {
+
+ @Override
+ protected QueryBuilder<Edge> getNewEdgeTraversal(Vertex v) {
+ return new GremlinTraversal<>(loader, g, v, testEdgeRules);
+ }
+
+ @Override
+ protected QueryBuilder<Edge> getNewEdgeTraversal() {
+ return new GremlinTraversal<>(loader, g, testEdgeRules);
+ }
+
+ @Override
+ protected QueryBuilder<Vertex> getNewVertexTraversal(Vertex v) {
+ return new GremlinTraversal<>(loader, g, v, testEdgeRules);
+ }
+
+ @Override
+ protected QueryBuilder<Vertex> getNewVertexTraversal() {
+ return new GremlinTraversal<>(loader, g, testEdgeRules);
+ }
+
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
new file mode 100644
index 00000000..d478d608
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
@@ -0,0 +1,635 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.query.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.AAISetup;
+import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderFactory;
+import org.onap.aai.introspection.ModelType;
+import org.onap.aai.serialization.db.EdgeRules;
+import org.onap.aai.serialization.db.EdgeType;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
+
+public abstract class QueryBuilderTestAbstraction extends AAISetup {
+
+ protected Loader loader;
+ protected Graph graph;
+ protected GraphTraversalSource g;
+
+ protected EdgeRules testEdgeRules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_TraversalQueryTest.json");
+
+ @Before
+ public void configure() throws Exception {
+ loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
+ graph = TitanFactory.build().set("storage.backend", "inmemory").open();
+ g = graph.traversal();
+ }
+
+
+ @Test
+ public void createEdgeGVnfToVnfcTraversal() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","myvnf").next();
+ Vertex vnfc = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ testEdgeRules.addEdge(g, gvnf, vnfc, "uses");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "vnfc");
+
+ assertEquals(vnfc, tQ.next());
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void createEdgeLinterfaceToLogicalLinkTraversal() throws AAIException {
+
+ Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ testEdgeRules.addEdge(g, lInterface, logicalLink, "sourceLInterface");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(lInterface);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "l-interface", "logical-link");
+
+ Vertex next = tQ.next();
+
+ assertEquals(logicalLink, next);
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void createEdgeLinterfaceToLogicalLinkIntrospectorTraversal() throws AAIException {
+
+ Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ testEdgeRules.addEdge(g, lInterface, logicalLink, "sourceLInterface");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(lInterface);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, loader.introspectorFromName("l-interface"), loader.introspectorFromName("logical-link"));
+
+ Vertex next = tQ.next();
+
+ assertEquals(logicalLink, next);
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void createEdgeLinterfaceToLogicalLinkVertexToIntrospectorTraversal() throws AAIException {
+
+ Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ testEdgeRules.addEdge(g, lInterface, logicalLink, "sourceLInterface");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(lInterface);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, lInterface, loader.introspectorFromName("logical-link"));
+
+ Vertex next = tQ.next();
+
+ assertEquals(logicalLink, next);
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeToVertexTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, vnfc1);
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "vnfc");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 1 vertexes ", 1, list.size());
+ assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeToVertexTraversalSingleOutRuleTest() throws AAIException {
+
+ Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+
+ testEdgeRules.addEdge(g, vce, vnfc1);
+
+ QueryBuilder<Vertex> tQ1 = getNewVertexTraversal(vce);
+ tQ1.createEdgeTraversal(EdgeType.COUSIN, "vce", "vnfc");
+
+ QueryBuilder<Vertex> tQ2 = getNewVertexTraversal(vnfc1);
+ tQ2.createEdgeTraversal(EdgeType.COUSIN, "vnfc", "vce");
+
+ List<Vertex> list1 = tQ1.toList();
+ List<Vertex> list2 = tQ2.toList();
+
+ assertEquals("1 - Has 1 vertexes ", 1, list1.size());
+ assertTrue("1 - traversal results in vnfc ", list1.contains(vnfc1));
+ assertEquals("2 - Has 1 vertexes ", 1, list2.size());
+ assertTrue("2 - traversal results in vce ", list2.contains(vce));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeToVertexTraversalSingleInRuleTest() throws AAIException {
+
+ Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ testEdgeRules.addEdge(g, vce, pserver);
+
+ QueryBuilder<Vertex> tQ1 = getNewVertexTraversal(vce);
+ tQ1.createEdgeTraversal(EdgeType.COUSIN, "vce", "pserver");
+
+ List<Vertex> list = tQ1.toList();
+
+ assertEquals("1 - Has 1 vertexes ", 1, list.size());
+ assertTrue("1 - traversal results in vnfc ", list.contains(pserver));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeToVertexMultiRuleTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, vnfc1);
+ testEdgeRules.addEdge(g, gvnf, vnfc2, "re-uses");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "vnfc");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+ assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
+ assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeToVertexMultiLabelTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, vnfc1);
+ testEdgeRules.addEdge(g, pserver, vnfc1);
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(vnfc1);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "vnfc", "generic-vnf");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 1 vertexes ", 1, list.size());
+ assertTrue("Only returns the generic vnf vertex", list.contains(gvnf));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void limitTraversalTest() throws AAIException {
+
+ g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+
+ QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
+ tQ.getVerticesByProperty("aai-node-type","vnfc").limit(1);
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 1 vertexes ", 1, list.size());
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void getVertexesByPropertiesTraversalTest() throws AAIException {
+
+ g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+
+ QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
+ tQ.getVerticesByProperty("vnfc-name", Arrays.asList("a-name", "b-name"));
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void getVertexesByIndexedPropertyTraversalTest() throws AAIException {
+
+ g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+
+ QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
+ tQ.getVerticesByIndexedProperty("aai-node-type","vnfc");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void dedupTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, pserver);
+ testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver").dedup();
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 1, list.size());
+ assertTrue("result has pserver ", list.contains(pserver));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void storeCapTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, pserver);
+ testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ GremlinTraversal<BulkSet<Vertex>> tQ = new GremlinTraversal<>(loader, g, gvnf, testEdgeRules);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver").store("x").cap("x");
+
+ List<BulkSet<Vertex>> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 1, list.size());
+ assertEquals("result has pserver ",pserver, list.get(0).iterator().next());
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void storeCapUnfoldTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, pserver);
+ testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver").store("x").cap("x").unfold();
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+ assertTrue("result has pserver ", list.contains(pserver));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void nextAndHasNextTraversalTest() throws AAIException {
+
+ Vertex v1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex v2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+
+ QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g, testEdgeRules);
+ tQ.getVerticesByProperty("aai-node-type","vnfc");
+
+ List<Vertex> list = new ArrayList<>();
+
+ assertTrue("Has next 1 ",tQ.hasNext());
+ list.add(tQ.next());
+ assertTrue("Has next 2 ",tQ.hasNext());
+ list.add(tQ.next());
+ assertFalse("Has next 3 ",tQ.hasNext());
+ assertTrue("Has all the vertexes", list.contains(v1) && list.remove(v2));
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeToVertexMultiRuleOutTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, pserver);
+ testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "pserver");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+ assertTrue("result has pserver ", list.contains(pserver));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeToVertexMultiRuleInTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, complex);
+ testEdgeRules.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "generic-vnf", "complex");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+ assertTrue("result has pserver ", list.contains(complex));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeTraversalSingleInRuleTest() throws AAIException {
+
+ Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e = testEdgeRules.addEdge(g, vce, pserver);
+
+ QueryBuilder<Edge> tQ1 = getNewEdgeTraversal(vce);
+ tQ1.getEdgesBetween(EdgeType.COUSIN, "vce", "pserver");
+
+ List<Edge> list = tQ1.toList();
+
+ assertEquals("1 - Has 1 edge ", 1, list.size());
+ assertTrue("1 - traversal results in edge ", list.contains(e));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeTraversalSingleOutRuleTest() throws AAIException {
+
+ Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+
+ Edge e = testEdgeRules.addEdge(g, vce, vnfc1);
+
+ QueryBuilder<Edge> tQ1 = getNewEdgeTraversal(vce);
+ tQ1.getEdgesBetween(EdgeType.COUSIN, "vce", "vnfc");
+
+ List<Edge> list1 = tQ1.toList();
+
+ assertEquals("1 - Has 1 edge ", 1, list1.size());
+ assertTrue("1 - traversal results in edge ", list1.contains(e));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeTraversalMultiRuleOutTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetween(EdgeType.COUSIN, "generic-vnf", "pserver");
+
+ List<Edge> list = tQ.toList();
+
+ assertEquals("Has 2 edges ", 2, list.size());
+ assertTrue("result has default edge ", list.contains(e1));
+ assertTrue("result has other edge ", list.contains(e2));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeTraversalMultiRuleInTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, complex);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetween(EdgeType.COUSIN, "generic-vnf", "complex");
+
+ List<Edge> list = tQ.toList();
+
+ assertEquals("Has 2 edges ", 2, list.size());
+ assertTrue("result has default edge ", list.contains(e1));
+ assertTrue("result has other edge ", list.contains(e2));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void edgeTraversalMultiRuleTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, vnfc1);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, vnfc2, "re-uses");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetween(EdgeType.COUSIN, "generic-vnf", "vnfc");
+
+ List<Edge> list = tQ.toList();
+
+ assertEquals("Has 2 edges ", 2, list.size());
+ assertTrue("result has default edge ", list.contains(e1));
+ assertTrue("result has other edge ", list.contains(e2));
+
+ g.tx().rollback();
+ }
+
+ @Test (expected = NoEdgeRuleFoundException.class)
+ public void getEdgesBetweenWithLabelsEmptyListTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.emptyList());
+ g.tx().rollback();
+ }
+
+ @Test
+ public void getEdgesBetweenWithLabelsSingleItemTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.singletonList("generic-vnf-pserver-B"));
+
+ List<Edge> list = tQ.toList();
+
+ assertEquals("Has 1 edges ", 1, list.size());
+ assertFalse("result does not have default edge ", list.contains(e1));
+ assertTrue("result has other edge ", list.contains(e2));
+ g.tx().rollback();
+ }
+
+ @Test
+ public void getEdgesBetweenWithLabelsMultipleItemTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
+
+ List<Edge> list = tQ.toList();
+
+ assertEquals("Has 2 edges ", 2, list.size());
+ assertTrue("result has generic-vnf-pserver-A edge ", list.contains(e1));
+ assertTrue("result has generic-vnf-pserver-B edge ", list.contains(e2));
+ g.tx().rollback();
+ }
+
+ @Test (expected = NoEdgeRuleFoundException.class)
+ public void createEdgeTraversalWithLabelsEmptyListTest() throws AAIException {
+
+ Vertex gvnf = getVertex();
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.emptyList());
+
+ List<Edge> list = tQ.toList();
+
+ g.tx().rollback();
+ }
+
+ private Vertex getVertex() throws AAIException {
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+ return gvnf;
+ }
+
+ @Test
+ public void createEdgeTraversalWithLabelsSingleItemTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.singletonList("generic-vnf-pserver-B"));
+
+ List<Edge> list = tQ.toList();
+
+ assertEquals("Has 1 edges ", 1, list.size());
+ assertFalse("result does not have default edge ", list.contains(e1));
+ assertTrue("result has other edge ", list.contains(e2));
+ g.tx().rollback();
+ }
+
+ @Test
+ public void createEdgeTraversalWithLabelsMultipleItemTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ Edge e1 = testEdgeRules.addEdge(g, gvnf, pserver);
+ Edge e2 = testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Edge> tQ = getNewEdgeTraversal(gvnf);
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
+
+ List<Edge> list = tQ.toList();
+
+ assertEquals("Has 2 edges ", 2, list.size());
+ assertTrue("result has generic-vnf-pserver-A edge ", list.contains(e1));
+ assertTrue("result has generic-vnf-pserver-B edge ", list.contains(e2));
+ g.tx().rollback();
+ }
+
+ protected abstract QueryBuilder<Edge> getNewEdgeTraversal(Vertex v);
+
+ protected abstract QueryBuilder<Edge> getNewEdgeTraversal();
+
+ protected abstract QueryBuilder<Vertex> getNewVertexTraversal(Vertex v);
+
+ protected abstract QueryBuilder<Vertex> getNewVertexTraversal();
+
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
index fa06e17f..41daf17f 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
@@ -21,44 +21,51 @@
*/
package org.onap.aai.query.builder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
-import org.mockito.Mock;
-import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.Loader;
-import org.onap.aai.introspection.LoaderFactory;
-import org.onap.aai.introspection.ModelType;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import static org.junit.Assert.assertEquals;
-
-public class TraversalQueryTest extends AAISetup {
-
- private Loader loader;
+import org.onap.aai.serialization.db.EdgeType;
- @Mock
- private GraphTraversalSource g;
+public class TraversalQueryTest extends QueryBuilderTestAbstraction {
- @Before
- public void configure() throws Exception {
- loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
+
+ @Override
+ protected QueryBuilder<Edge> getNewEdgeTraversal(Vertex v) {
+ return new TraversalQuery<>(loader, g, v, testEdgeRules);
+ }
+
+ @Override
+ protected QueryBuilder<Edge> getNewEdgeTraversal() {
+ return new TraversalQuery<>(loader, g, testEdgeRules);
+ }
+
+ @Override
+ protected QueryBuilder<Vertex> getNewVertexTraversal(Vertex v) {
+ return new TraversalQuery<>(loader, g, v, testEdgeRules);
+ }
+
+ @Override
+ protected QueryBuilder<Vertex> getNewVertexTraversal() {
+ return new TraversalQuery<>(loader, g, testEdgeRules);
}
@Test
public void unionQuery() {
- TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g);
- TraversalQuery<Vertex> tQ2 = new TraversalQuery<>(loader, g);
- TraversalQuery<Vertex> tQ3 = new TraversalQuery<>(loader, g);
+ QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g);
+ QueryBuilder<Vertex> tQ2 = new TraversalQuery<>(loader, g);
+ QueryBuilder<Vertex> tQ3 = new TraversalQuery<>(loader, g);
tQ.union(
tQ2.getVerticesByProperty("test1", "value1"),
tQ3.getVerticesByIndexedProperty("test2", "value2"));
@@ -68,12 +75,12 @@ public class TraversalQueryTest extends AAISetup {
assertEquals("they are equal", expected, tQ.getQuery());
+ g.tx().rollback();
}
- @Ignore
@Test
public void traversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
- TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g);
+ QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g);
QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/test-objects/test-object/key1")).getQueryBuilder();
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "test-object");
GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("aai-node-type", "test-object");
@@ -81,13 +88,13 @@ public class TraversalQueryTest extends AAISetup {
assertEquals("query object", expected.toString(), builder.getQuery().toString());
assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
+ g.tx().rollback();
}
- @Ignore
@Test
public void nestedTraversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
- TraversalQuery<Vertex> tQ = new TraversalQuery<>(loader, g);
+ QueryBuilder<Vertex> tQ = new TraversalQuery<>(loader, g);
QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2")).getQueryBuilder();
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface").has("interface-name", "key2");
GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface");
@@ -95,6 +102,132 @@ public class TraversalQueryTest extends AAISetup {
assertEquals("query object", expected.toString(), builder.getQuery().toString());
assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
+ g.tx().rollback();
+ }
+
+ @Test
+ public void abstractEdgeToVertexTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, vnfc1);
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 1 vertexes ", 1, list.size());
+ assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void abstractEdgeToVertexTraversalSingleOutRuleTest() throws AAIException {
+
+ Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+
+ testEdgeRules.addEdge(g, vce, vnfc1);
+
+ QueryBuilder<Vertex> tQ1 = new TraversalQuery<>(loader, g, vce, testEdgeRules);
+ tQ1.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc");
+
+ QueryBuilder<Vertex> tQ2 = new TraversalQuery<>(loader, g, vnfc1, testEdgeRules);
+ tQ2.createEdgeTraversal(EdgeType.COUSIN, "vnfc", "vnf");
+
+ List<Vertex> list1 = tQ1.toList();
+ List<Vertex> list2 = tQ2.toList();
+
+ assertEquals("1 - Has 1 vertexes ", 1, list1.size());
+ assertTrue("1 - traversal results in vnfc ", list1.contains(vnfc1));
+ assertEquals("2 - Has 1 vertexes ", 1, list2.size());
+ assertTrue("2 - traversal results in vce ", list2.contains(vce));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void abstractEdgeToVertexTraversalSingleInRuleTest() throws AAIException {
+
+ Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ testEdgeRules.addEdge(g, vce, pserver);
+
+ QueryBuilder<Vertex> tQ1 = new TraversalQuery<>(loader, g, vce, testEdgeRules);
+ tQ1.createEdgeTraversal(EdgeType.COUSIN, "vnf", "pserver");
+
+ List<Vertex> list = tQ1.toList();
+
+ assertEquals("1 - Has 1 vertexes ", 1, list.size());
+ assertTrue("1 - traversal results in vnfc ", list.contains(pserver));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void abstractEdgeToVertexMultiRuleTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, vnfc1);
+ testEdgeRules.addEdge(g, gvnf, vnfc2, "re-uses");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+ assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
+ assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void abstractEdgeToVertexMultiRuleOutTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, pserver);
+ testEdgeRules.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "pserver");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+ assertTrue("result has pserver ", list.contains(pserver));
+
+ g.tx().rollback();
+ }
+
+ @Test
+ public void abstractEdgeToVertexMultiRuleInTraversalTest() throws AAIException {
+
+ Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
+ Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
+
+ testEdgeRules.addEdge(g, gvnf, complex);
+ testEdgeRules.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
+
+ QueryBuilder<Vertex> tQ = getNewVertexTraversal(gvnf);
+ tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "complex");
+
+ List<Vertex> list = tQ.toList();
+
+ assertEquals("Has 2 vertexes ", 2, list.size());
+ assertTrue("result has pserver ", list.contains(complex));
+
+ g.tx().rollback();
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
index c89150b6..4d46c021 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
@@ -1,27 +1,40 @@
-/**
+/*-
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
+
package org.onap.aai.serialization.db;
-import com.thinkaurelius.titan.core.TitanFactory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -41,20 +54,12 @@ import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.introspection.Version;
+import org.onap.aai.parsers.query.QueryParser;
import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TitanDBEngine;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import com.thinkaurelius.titan.core.TitanFactory;
public class DbSerializerTest extends AAISetup {
@@ -76,7 +81,7 @@ public class DbSerializerTest extends AAISetup {
private DBSerializer dbser;
TransactionalGraphEngine spy;
TransactionalGraphEngine.Admin adminSpy;
-
+
@Before
public void setup() throws Exception {
graph = TitanFactory.build().set("storage.backend", "inmemory").open();
@@ -84,11 +89,11 @@ public class DbSerializerTest extends AAISetup {
dbEngine = new TitanDBEngine(queryStyle, type, loader);
spy = spy(dbEngine);
adminSpy = spy(dbEngine.asAdmin());
-
+
createGraph();
engine = new TitanDBEngine(queryStyle, type, loader);
- dbser = new DBSerializer(Version.getLatest(), engine, introspectorFactoryType, "AAI-TEST");
+ dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
}
public void createGraph() throws AAIException {
@@ -340,7 +345,7 @@ public class DbSerializerTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance();
rules.addTreeEdge(engine.tx().traversal(), cr, ten);
- Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr);
+ Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr, null);
assertEquals("has", e.label());
engine.rollback();
}
@@ -388,20 +393,61 @@ public class DbSerializerTest extends AAISetup {
assertTrue(dbser.createEdge(relationship, gvnf));
assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ engine.rollback();
+ }
+
+ @Test
+ public void createCousinEdgeThatShouldBeTreeTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
+ engine.startTransaction();
- //rainy day case, edge to nonexistant object
- Introspector relData2 = loader.introspectorFromName("relationship-data");
- relData2.setValue("relationship-key", "vnfc.vnfc-name");
- relData2.setValue("relationship-value", "b-name");
- Introspector relationship2 = loader.introspectorFromName("relationship");
- relationship2.setValue("related-to", "vnfc");
- relationship2.setValue("related-link", "/network/vnfcs/vnfc/b-name");
- relationship2.setValue("relationship-data",relData2);
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vf = engine.tx().addVertex("aai-node-type","vf-module","vf-module-id","vf-id");
+
+ EdgeRules.getInstance().addTreeEdge(engine.tx().traversal(), gvnf, vf);
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vf-module");
+ relationship.setValue("related-link", dbser.getURIForVertex(vf).toString());
+ //relationship.setValue("relationship-label", "");
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf2 = dbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf-1");
+
+ QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
+
+ try {
+ dbser.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
+ } catch (AAIException e) {
+ assertEquals("AAI_6145", e.getCode());
+ }
+ finally {
+ engine.rollback();
+ }
+ }
+
+ @Test
+ public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+
+ //rainy day case, edge to non-existent object
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "b-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/b-name");
+ relationship.setValue("relationship-data",relData);
thrown.expect(AAIException.class);
thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
try {
- dbser.createEdge(relationship2, gvnf);
+ dbser.createEdge(relationship, gvnf);
} finally {
engine.rollback();
}
@@ -438,4 +484,529 @@ public class DbSerializerTest extends AAISetup {
assertTrue(engine.tx().traversal().V().has("aai-node-type","tenant").has("tenant-id","453").has("tenant-name","mytenant").hasNext());
engine.rollback();
}
+
+
+ @Test
+ public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123");
+ EdgeRules rules = EdgeRules.getInstance();
+ rules.addEdge(engine.tx().traversal(), gvnf, vnfc);
+
+ Introspector obj = loader.introspectorFromName("generic-vnf");
+ obj = this.dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
+
+ assertEquals("edge label between generic-vnf and vnfs is uses", "uses", obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0).getValue("relationship-label"));
+
+ engine.rollback();
+ }
+
+ @Test
+ public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest() throws AAIException, UnsupportedEncodingException {
+
+ Version version = Version.v11;
+ DBSerializer dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
+ Loader loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123");
+ EdgeRules rules = EdgeRules.getInstance();
+ rules.addEdge(engine.tx().traversal(), gvnf, vnfc);
+
+ Introspector obj = loader.introspectorFromName("generic-vnf");
+ obj = dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
+
+ assertEquals("Relationship does not contain edge-property", false, obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
+
+ engine.rollback();
+ }
+
+ @Test
+ public void createEdgeWithValidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ //sunny day case
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+ relationship.setValue("relationship-label", "over-uses");
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
+ engine.rollback();
+ }
+
+ @Test
+ public void createEdgeWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+ relationship.setValue("relationship-label", "NA");
+
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("no COUSIN edge rule between generic-vnf and vnfc with label NA");
+ try {
+ dbser.createEdge(relationship, gvnf);
+ } finally {
+ engine.rollback();
+ }
+ }
+
+ @Test
+ public void createEdgeWithValidLabelWhenSameEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+ relationship.setValue("relationship-label", "re-uses");
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(vnfc).both().count().next());
+ engine.rollback();
+ }
+
+ @Test
+ public void createEdgeWithValidLabelWhenDiffEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+ relationship.setValue("relationship-label", "uses");
+ localDbser.createEdge(relationship, gvnf);
+
+ relationship.setValue("relationship-label", "re-uses");
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
+ engine.rollback();
+ }
+
+ @Test
+ public void createEdgeWithNoLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+ localDbser.createEdge(relationship, gvnf);
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(gvnf).both().count().next());
+
+ engine.rollback();
+ }
+
+ @Test
+ public void deleteEdgeWithNoLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+
+ assertTrue(localDbser.deleteEdge(relationship, gvnf));
+ assertFalse("generic-vnf has no edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertFalse("vnfc has no edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
+ engine.rollback();
+ }
+
+ @Test
+ public void deleteEdgeWithValidLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+ relationship.setValue("relationship-label", "re-uses");
+
+ assertTrue(localDbser.deleteEdge(relationship, gvnf));
+ assertTrue("generic-vnf has edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertTrue("vnfc has edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
+ engine.rollback();
+ }
+
+ @Test
+ public void deleteEdgeWithValidInvalidLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+ ers.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data",relData);
+ relationship.setValue("relationship-label", "NA");
+
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("no COUSIN edge rule between generic-vnf and vnfc with label NA");
+ try {
+ localDbser.deleteEdge(relationship, gvnf);
+ } finally {
+ engine.rollback();
+ }
+ }
+
+ @Test
+ public void serializeToDbWithLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "re-uses");
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf");
+
+ QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+ engine.rollback();
+ }
+
+ @Test
+ public void serializeToDbWithoutLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf");
+
+ QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertTrue("vnfc has edge uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge over-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+ engine.rollback();
+ }
+
+ @Test
+ public void serializeToDbWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+
+ engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "NA");
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf");
+
+ QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("No EdgeRule found for passed nodeTypes: generic-vnf, vnfc with label NA.");
+ try {
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+ } finally {
+ engine.rollback();
+ }
+ engine.rollback();
+ }
+
+ @Test
+ public void serializeToDbWithLabelAndEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+ engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ Introspector relationship;
+ Introspector relationshipList;
+ List<Object> relList = new ArrayList<>();
+
+ // create generic-vnf
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("vnf-id", "myvnf");
+ QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ // create relationship to vnfc
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relList.add(relationship.getUnderlyingObject());
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ // add gvnf to graph
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ // add second relationship
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "re-uses");
+ relList.add(relationship.getUnderlyingObject());
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertTrue("vnfc has edge uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge over-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+ engine.rollback();
+ }
+
+ @Test
+ public void serializeToDbWithLabelDroppingRelationshipTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ EdgeRules ers = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules(ers);
+
+ engine.startTransaction();
+ engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name");
+
+ Introspector relationship;
+ Introspector relationshipList;
+ List<Object> relList = new ArrayList<>();
+
+ // create generic-vnf
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("vnf-id", "myvnf");
+ QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ // create relationship to vnfc
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relList.add(relationship.getUnderlyingObject());
+ // add second relationship
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "re-uses");
+ relList.add(relationship.getUnderlyingObject());
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ // add gvnf to graph
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ // drop second relationship
+ relList.remove(1);
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertTrue("vnfc has edge uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertFalse("generic-vnf no longer has edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertFalse("vnfc no longer has edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge over-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+ engine.rollback();
+ }
+
+ private DBSerializer getDBSerializerWithSpecificEdgeRules(EdgeRules ers)
+ throws NoSuchFieldException, AAIException, IllegalAccessException {
+ // reflection to set the edge rules to the test one for DBSerializer
+ Field reader = DBSerializer.class.getDeclaredField("edgeRules");
+ reader.setAccessible(true);
+ DBSerializer localDbser = new DBSerializer(Version.getLatest(), engine, introspectorFactoryType, "AAI-TEST");
+ reader.set(localDbser, ers);
+ return localDbser;
+ }
+
} \ No newline at end of file
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
index e007f027..bc6a721f 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
@@ -26,7 +26,10 @@ import org.apache.tinkerpop.gremlin.structure.Direction;
import org.junit.Test;
import org.onap.aai.AAISetup;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -41,6 +44,7 @@ import org.junit.rules.ExpectedException;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Version;
import org.onap.aai.serialization.db.exceptions.EdgeMultiplicityException;
+import org.onap.aai.serialization.db.exceptions.MultipleEdgeRuleFoundException;
import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
import com.google.common.collect.Multimap;
@@ -106,6 +110,35 @@ public class EdgeRulesTest extends AAISetup {
}
@Test
+ public void hasEdgeRuleTest() {
+ assertEquals("true: cloud-region | tenant", true, EdgeRules.getInstance().hasEdgeRule("cloud-region", "tenant"));
+ assertEquals("true: tenant | cloud-region", true, EdgeRules.getInstance().hasEdgeRule("tenant", "cloud-region"));
+ assertEquals("true: pserver | complex", true, EdgeRules.getInstance().hasEdgeRule("pserver", "complex"));
+ assertEquals("false: pserver | service", false, EdgeRules.getInstance().hasEdgeRule("pserver", "service"));
+ }
+
+ @Test
+ public void hasTreeEdgeRuleTest() {
+ assertEquals("true: cloud-region | tenant", true, EdgeRules.getInstance().hasTreeEdgeRule("cloud-region", "tenant"));
+ assertEquals("true: tenant | cloud-region", true, EdgeRules.getInstance().hasTreeEdgeRule("tenant", "cloud-region"));
+ assertEquals("false: pserver | complex", false, EdgeRules.getInstance().hasTreeEdgeRule("pserver", "complex"));
+ assertEquals("true: service-instance | allotted-resource", true, EdgeRules.getInstance().hasTreeEdgeRule("service-instance", "allotted-resource"));
+
+ }
+
+ @Test
+ public void hasCousinEdgeRuleTest() {
+ assertEquals("false: cloud-region | tenant", false, EdgeRules.getInstance().hasCousinEdgeRule("cloud-region", "tenant", null));
+ assertEquals("false: tenant | cloud-region", false, EdgeRules.getInstance().hasCousinEdgeRule("tenant", "cloud-region", null));
+ assertEquals("true: pserver | complex", true, EdgeRules.getInstance().hasCousinEdgeRule("pserver", "complex", null));
+ assertEquals("true: service-instance | allotted-resource", true, EdgeRules.getInstance().hasCousinEdgeRule("service-instance", "allotted-resource", null));
+ assertEquals("true: logical-link | l-interface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", null));
+ assertEquals("true: logical-link | l-interface : sourceLInterface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "sourceLInterface"));
+ assertEquals("true: logical-link | l-interface : targetLInterface", true, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "targetLInterface"));
+ assertEquals("false: logical-link | l-interface : blah", false, EdgeRules.getInstance().hasCousinEdgeRule("logical-link", "l-interface", "blah"));
+ }
+
+ @Test
public void hasEdgeRuleVertexTest() {
Graph graph = TinkerGraph.open();
Vertex v1 = graph.addVertex("aai-node-type", "cloud-region");
@@ -192,7 +225,7 @@ public class EdgeRulesTest extends AAISetup {
public void getAllRulesTest() {
EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
Multimap<String, EdgeRule> allRules = rules.getAllRules();
- assertEquals(6, allRules.size());
+ assertEquals(14, allRules.size());
assertEquals(true, allRules.containsKey("foo|bar"));
assertEquals(true, allRules.containsKey("foo|bar"));
assertEquals(true, allRules.containsKey("quux|foo"));
@@ -221,7 +254,6 @@ public class EdgeRulesTest extends AAISetup {
EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test_broken.json");
thrown.expect(RuntimeException.class);
- thrown.expectMessage("org.onap.aai.exceptions.AAIException: Rule between quux and foo is missing property SVC-INFRA.");
rules.getEdgeRules("foo", "quux");
}
@@ -235,4 +267,85 @@ public class EdgeRulesTest extends AAISetup {
rules.getAllRules();
}
}
+
+ @Test(expected = NoEdgeRuleFoundException.class)
+ public void noEdgeRuleFoundTest() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance();
+ rules.getEdgeRule(EdgeType.TREE, "a", "b");
+ }
+
+ @Test
+ public void verifyOutDirectionUsingLabel() throws AAIException, NoEdgeRuleFoundException {
+ EdgeRules rules = EdgeRules.getInstance();
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "generic-vnf", "l3-network", "usesL3Network");
+
+ assertEquals("out direction", rule.getDirection(), Direction.OUT);
+ }
+
+ @Test
+ public void verifyOutDirectionLinterfaceToLinterfaceUsingLabel() throws AAIException, NoEdgeRuleFoundException {
+ EdgeRules rules = EdgeRules.getInstance();
+ EdgeRule rule = rules.getEdgeRule(EdgeType.TREE, "l-interface", "l-interface");
+
+ assertEquals("out direction", rule.getDirection(), Direction.OUT);
+ }
+
+ @Test
+ public void verifyOutFlippedDirectionUsingLabel() throws AAIException, NoEdgeRuleFoundException {
+ EdgeRules rules = EdgeRules.getInstance();
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l3-network", "generic-vnf", "usesL3Network");
+
+ assertEquals("in direction", rule.getDirection(), Direction.IN);
+ }
+
+ @Test(expected = MultipleEdgeRuleFoundException.class)
+ public void multipleEdgeRulesVerifyMultipleEdgeRuleException() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ rules.getEdgeRule(EdgeType.COUSIN, "foo", "bar");
+ }
+
+ @Test
+ public void multipleEdgeRulesVerifyGetRuleWithLabel() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "foo", "bar", "eatz");
+ assertEquals("in direction", rule.getDirection(), Direction.IN);
+ }
+
+ @Test
+ public void multipleEdgeRulesVerifyGetRuleWithOutLabelDefaults() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "a", "b");
+ assertEquals("in direction", rule.getLabel(), "d");
+ }
+
+ @Test
+ public void multipleEdgeRulesRevVerifyGetRuleWithOutLabelDefaults() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "z", "y");
+ assertEquals("in direction", rule.getLabel(), "w");
+ }
+
+ @Test
+ public void multipleEdgeRulesRevRevVerifyGetRuleWithOutLabelDefaults() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "y", "z");
+ assertEquals("in direction", rule.getLabel(), "w");
+ }
+
+ @Test
+ public void getEdgeRulesWithLabelsTest() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ List<String> labels = Arrays.asList("uses","re-uses","over-uses");
+ Map<String, EdgeRule> edgeRules = rules.getEdgeRulesWithLabels(EdgeType.COUSIN, "generic-vnf", "vnfc", labels);
+ assertEquals("Found 3 edge rules", 3, edgeRules.size());
+ assertTrue("Rules for each edge label found", edgeRules.keySet().containsAll(labels));
+ }
+
+ @Test(expected = NoEdgeRuleFoundException.class)
+ public void getEdgeRulesWithLabelsBadLabelTest() throws AAIException {
+ EdgeRules rules = EdgeRules.getInstance("/dbedgerules/DbEdgeRules_test.json");
+ List<String> labels = Arrays.asList("bad","re-uses","over-uses");
+ Map<String, EdgeRule> edgeRules = rules.getEdgeRulesWithLabels(EdgeType.COUSIN, "generic-vnf", "vnfc", labels);
+ }
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/util/VersionCheckerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/util/VersionCheckerTest.java
new file mode 100644
index 00000000..093be695
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/util/VersionCheckerTest.java
@@ -0,0 +1,41 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.serialization.db.util;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.onap.aai.introspection.Version;
+
+public class VersionCheckerTest {
+
+ @Test
+ public void apiVersionNeedsEdgeLabelTrueTest() {
+ assertTrue(VersionChecker.apiVersionNeedsEdgeLabel(Version.v12));
+ }
+
+ @Test
+ public void apiVersionNeedsEdgeLabelFalseTest() {
+ assertFalse(VersionChecker.apiVersionNeedsEdgeLabel(Version.v10));
+ }
+
+}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
new file mode 100644
index 00000000..37a2a4f0
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
@@ -0,0 +1,141 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.serialization.queryformats;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.AAISetup;
+import org.onap.aai.dbmap.DBConnectionType;
+import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderFactory;
+import org.onap.aai.introspection.ModelType;
+import org.onap.aai.introspection.Version;
+import org.onap.aai.serialization.db.DBSerializer;
+import org.onap.aai.serialization.db.EdgeRules;
+import org.onap.aai.serialization.engines.QueryStyle;
+import org.onap.aai.serialization.engines.TitanDBEngine;
+import org.onap.aai.serialization.engines.TransactionalGraphEngine;
+import org.onap.aai.serialization.queryformats.RawFormat.Builder;
+import org.onap.aai.serialization.queryformats.exceptions.AAIFormatQueryResultFormatNotSupported;
+import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
+import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+public class RawFormatTest extends AAISetup {
+
+ @Mock
+ private UrlBuilder urlBuilder;
+
+ private Graph graph;
+ private TransactionalGraphEngine dbEngine;
+ private Loader loader;
+ private RawFormat rawFormat;
+ private final ModelType factoryType = ModelType.MOXY;
+ private final EdgeRules rules = EdgeRules.getInstance();
+ private Version version = Version.getLatest();
+ private Vertex pserver;
+ private Vertex complex;
+
+ private DBSerializer serializer;
+
+ @Before
+ public void setUp() throws Exception {
+
+ MockitoAnnotations.initMocks(this);
+
+ graph = TinkerGraph.open();
+
+ Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname",
+ "hostname-1");
+ Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex",
+ "physical-location-id", "physical-location-id-1", "country", "US");
+
+ GraphTraversalSource g = graph.traversal();
+ rules.addEdge(g, pserver1, complex1);
+
+ pserver = pserver1;
+ complex = complex1;
+
+ createLoaderEngineSetup();
+
+ }
+
+ @Test
+ public void verifyPserverRelatedToHasEdgeLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("locatedIn"));
+ }
+
+ @Test
+ public void verifyPserverRelatedToComplexLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("node-type").getAsString().equals("complex"));
+ }
+
+ @Test
+ public void verifyComplexRelatedToHasEdgeLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("locatedIn"));
+ }
+
+ @Test
+ public void verifyComplexRelatedToPserverLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("node-type").getAsString().equals("pserver"));
+ }
+
+ public void createLoaderEngineSetup() throws AAIException {
+
+ if (loader == null) {
+ loader = LoaderFactory.createLoaderForVersion(factoryType, version);
+ dbEngine = spy(new TitanDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
+ serializer = new DBSerializer(version, dbEngine, factoryType, "Junit");
+ rawFormat = new RawFormat.Builder(loader, serializer, urlBuilder).build();
+
+ TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
+
+ when(dbEngine.tx()).thenReturn(graph);
+ when(dbEngine.asAdmin()).thenReturn(spyAdmin);
+
+ when(spyAdmin.getReadOnlyTraversalSource())
+ .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
+ when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
+ }
+ }
+}
diff --git a/aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java b/aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java
new file mode 100644
index 00000000..6635f252
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.util;
+
+
+import java.time.zone.ZoneRulesException;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore
+public class FormatDateTest {
+
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testExceptionThrownWhenInvalidPatternIsPassed()
+ {
+ FormatDate formatDate = new FormatDate("XX/TT/GGGG");
+ formatDate.getDateTime();
+ }
+
+ @Test
+ public void correctPattern()
+ {
+ FormatDate formatDate = new FormatDate("dd/mm/yyyy");
+ Assert.assertNotNull(formatDate.getDateTime());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void invalidPattern()
+ {
+ FormatDate formatDate = new FormatDate("XX/TT/GGGG","GMT");
+ formatDate.getDateTime();
+ }
+
+ @Test(expected=ZoneRulesException.class)
+ public void invalidZone()
+ {
+ FormatDate formatDate = new FormatDate("dd/mm/yyyy","IST");
+ formatDate.getDateTime();
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testExceptionThrownWhenInvalidPatternAndZoneIsPassed()
+ {
+ FormatDate formatDate = new FormatDate("XX/TT/GGGG","IST");
+ formatDate.getDateTime();
+ }
+
+ @Test
+ public void correctPatternAndZone()
+ {
+ FormatDate formatDate = new FormatDate("dd/mm/yyyy","GMT");
+ Assert.assertNotNull(formatDate.getDateTime());
+ }
+}
diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml b/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml
index 270d96a7..30fe6b6f 100644
--- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml
+++ b/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml
@@ -668,6 +668,11 @@
<xml-property name="description" value="A keyword provided by A&amp;AI to indicate type of node." />
</xml-properties>
</xml-element>
+ <xml-element java-attribute="relationshipLabel" name="relationship-label" type="java.lang.String">
+ <xml-properties>
+ <xml-property name="description" value="The edge lable for this relationship." />
+ </xml-properties>
+ </xml-element>
<xml-element java-attribute="relatedLink" name="related-link" type="java.lang.String">
<xml-properties>
<xml-property name="description" value="URL to the object in A&amp;AI." />
diff --git a/aai-core/src/test/resources/dbedgerules/DbEdgeRules_TraversalQueryTest.json b/aai-core/src/test/resources/dbedgerules/DbEdgeRules_TraversalQueryTest.json
new file mode 100644
index 00000000..0b79192a
--- /dev/null
+++ b/aai-core/src/test/resources/dbedgerules/DbEdgeRules_TraversalQueryTest.json
@@ -0,0 +1,145 @@
+{
+ "rules": [
+ {
+ "from": "generic-vnf",
+ "to": "vnfc",
+ "label": "uses",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ },
+ {
+ "from": "vnfc",
+ "to": "generic-vnf",
+ "label": "re-uses",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE"
+ },
+ {
+ "from": "vce",
+ "to": "vnfc",
+ "label": "vce-vnfc",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ },
+ {
+ "from": "pserver",
+ "to": "vce",
+ "label": "pserver-vce",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ },
+ {
+ "from": "generic-vnf",
+ "to": "pserver",
+ "label": "generic-vnf-pserver-A",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ },
+ {
+ "from": "generic-vnf",
+ "to": "pserver",
+ "label": "generic-vnf-pserver-B",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE"
+ },
+ {
+ "from": "complex",
+ "to": "generic-vnf",
+ "label": "complex-generic-vnf-A",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ },
+ {
+ "from": "complex",
+ "to": "generic-vnf",
+ "label": "complex-generic-vnf-B",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE"
+ },
+ {
+ "from": "l-interface",
+ "to": "logical-link",
+ "label": "usesLogicalLink",
+ "direction": "OUT",
+ "multiplicity": "MANY2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ },
+ {
+ "from": "l-interface",
+ "to": "logical-link",
+ "label": "sourceLInterface",
+ "direction": "OUT",
+ "multiplicity": "MANY2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "false"
+ },
+ {
+ "from": "l-interface",
+ "to": "logical-link",
+ "label": "targetLInterface",
+ "direction": "OUT",
+ "multiplicity": "MANY2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "false"
+ },
+ {
+ "from": "pserver",
+ "to": "vnfc",
+ "label": "uses",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ }
+ ]
+}
diff --git a/aai-core/src/test/resources/dbedgerules/DbEdgeRules_test.json b/aai-core/src/test/resources/dbedgerules/DbEdgeRules_test.json
index 957129b2..76059ed6 100644
--- a/aai-core/src/test/resources/dbedgerules/DbEdgeRules_test.json
+++ b/aai-core/src/test/resources/dbedgerules/DbEdgeRules_test.json
@@ -13,6 +13,17 @@
},
{
"from": "foo",
+ "to": "bar",
+ "label": "eatz",
+ "direction": "IN",
+ "multiplicity": "One2Many",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "NONE",
+ "prevent-delete": "NONE"
+ },
+ {
+ "from": "foo",
"to": "baz",
"label": "isVeryHappyAbout",
"direction": "OUT",
@@ -65,6 +76,87 @@
"delete-other-v": "${direction}",
"SVC-INFRA": "NONE",
"prevent-delete": "NONE"
+ },
+ {
+ "from": "a",
+ "to": "b",
+ "label": "c",
+ "direction": "OUT",
+ "multiplicity": "One2Many",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "NONE",
+ "prevent-delete": "NONE",
+ "default": "false"
+ },
+ {
+ "from": "a",
+ "to": "b",
+ "label": "d",
+ "direction": "IN",
+ "multiplicity": "One2Many",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "NONE",
+ "prevent-delete": "NONE",
+ "default" : "true"
+ },
+ {
+ "from": "z",
+ "to": "y",
+ "label": "x",
+ "direction": "OUT",
+ "multiplicity": "One2Many",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "NONE",
+ "prevent-delete": "NONE"
+ },
+ {
+ "from": "y",
+ "to": "z",
+ "label": "w",
+ "direction": "IN",
+ "multiplicity": "One2Many",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "NONE",
+ "prevent-delete": "NONE",
+ "default" : "true"
+ },
+ {
+ "from": "generic-vnf",
+ "to": "vnfc",
+ "label": "uses",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE",
+ "default": "true"
+ },
+ {
+ "from": "generic-vnf",
+ "to": "vnfc",
+ "label": "re-uses",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE"
+ },
+ {
+ "from": "generic-vnf",
+ "to": "vnfc",
+ "label": "over-uses",
+ "direction": "OUT",
+ "multiplicity": "ONE2MANY",
+ "contains-other-v": "NONE",
+ "delete-other-v": "${direction}",
+ "SVC-INFRA": "${direction}",
+ "prevent-delete": "NONE"
}
]
} \ No newline at end of file