Add plugin to check coverage
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / parsers / query / GraphTraversalTest.java
index df9d612..02e9efa 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 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.
@@ -16,8 +16,6 @@
  * 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.parsers.query;
 
@@ -29,6 +27,8 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 import org.onap.aai.AAISetup;
 import org.onap.aai.db.props.AAIProperties;
 import org.onap.aai.exceptions.AAIException;
@@ -46,6 +46,8 @@ import javax.ws.rs.core.UriBuilder;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 
 import static org.hamcrest.CoreMatchers.containsString;
@@ -53,13 +55,23 @@ import static org.hamcrest.Matchers.hasProperty;
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
 
+@RunWith(value = Parameterized.class)
 public class GraphTraversalTest extends AAISetup {
 
        private TransactionalGraphEngine dbEngine;
        private TransactionalGraphEngine dbEnginev9;
-       
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
+
+       @Parameterized.Parameter(value = 0)
+       public QueryStyle queryStyle;
+
+       @Parameterized.Parameters(name = "QueryStyle.{0}")
+       public static Collection<Object[]> data() {
+               return Arrays.asList(new Object[][]{
+                               {QueryStyle.TRAVERSAL}
+               });
+       }
+
+       @Rule public ExpectedException thrown = ExpectedException.none();
        
        /**
         * Configure.
@@ -70,12 +82,12 @@ public class GraphTraversalTest extends AAISetup {
        @Before
        public void configure() throws Exception {
                dbEngine =
-                               new TitanDBEngine(QueryStyle.TRAVERSAL, 
+                               new TitanDBEngine(queryStyle,
                                        LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST),
                                        false);
                
                dbEnginev9 = 
-                               new TitanDBEngine(QueryStyle.TRAVERSAL, 
+                               new TitanDBEngine(queryStyle,
                                        LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v9),
                                        false);
        }
@@ -126,7 +138,7 @@ public class GraphTraversalTest extends AAISetup {
                QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("physical-location-id", "key1").has("aai-node-type", "complex")
-                               .out("hasCtagPool")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "ctag-pool")
                                .has("target-pe", "key2").has("availability-zone-name", "key3");
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
@@ -164,14 +176,14 @@ public class GraphTraversalTest extends AAISetup {
                QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("vnf-id", "key1").has("aai-node-type", "vce")
-                               .out("hasPortGroup")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "port-group")
-                               .has("interface-id", "key2").out("hasCTag")
+                               .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "cvlan-tag")
                                .has("cvlan-tag", 655);
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("vnf-id", "key1").has("aai-node-type", "vce")
-                               .out("hasPortGroup")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "port-group")
                                .has("interface-id", "key2");
                assertEquals(
@@ -212,13 +224,13 @@ public class GraphTraversalTest extends AAISetup {
                QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("vnf-id", "key1").has("aai-node-type", "vce")
-                               .out("hasPortGroup")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "port-group")
-                               .has("interface-id", "key2").out("hasCTag")
+                               .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "cvlan-tag");
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("vnf-id", "key1").has("aai-node-type", "vce")
-                               .out("hasPortGroup")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "port-group")
                                .has("interface-id", "key2");
                assertEquals(
@@ -296,7 +308,7 @@ public class GraphTraversalTest extends AAISetup {
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
                                .has("aai-node-type", "cloud-region")
-                               .out("has")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "tenant")
                                .has("tenant-name", "Tenant1");
 
@@ -340,7 +352,7 @@ public class GraphTraversalTest extends AAISetup {
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
                                .has("aai-node-type", "cloud-region")
-                               .out("has")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "tenant")
                                .has("tenant-name", P.within(values));
 
@@ -432,14 +444,14 @@ public class GraphTraversalTest extends AAISetup {
                
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("vnf-id", "key1").has("aai-node-type", "vce")
-                               .out("hasPortGroup")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "port-group")
-                               .has("interface-id", "key2").out("hasCTag")
+                               .has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "cvlan-tag")
                                .has("cvlan-tag", 333);
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("vnf-id", "key1").has("aai-node-type", "vce")
-                               .out("hasPortGroup")
+                               .in("org.onap.relationships.inventory.BelongsTo")
                                .has("aai-node-type", "port-group")
                                .has("interface-id", "key2");
                assertEquals(
@@ -527,7 +539,7 @@ public class GraphTraversalTest extends AAISetup {
                
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
-                               .union(__.out("has").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2");
+                               .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2");
                
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
@@ -621,15 +633,15 @@ public class GraphTraversalTest extends AAISetup {
        
        @Test
        public void dbAliasedSearch() throws UnsupportedEncodingException, AAIException {
-               URI uri = UriBuilder.fromPath("network/test-objects").build();
+               URI uri = UriBuilder.fromPath("network/generic-vnfs").build();
                MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
                map.putSingle("persona-model-customization-id", "key2");
                QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
-                               .has("aai-node-type", "test-object")
+                               .has("aai-node-type", "generic-vnf")
                                .has("model-customization-id", "key2");
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
-                               .has("aai-node-type", "test-object");
+                               .has("aai-node-type", "generic-vnf");
                
                assertEquals(
                                "gremlin query should be " + expected.toString(),
@@ -642,7 +654,7 @@ public class GraphTraversalTest extends AAISetup {
                
                assertEquals(
                                "result type should be",
-                               "test-object",
+                               "generic-vnf",
                                query.getResultType());
                assertEquals(
                                "result type should be empty",
@@ -661,7 +673,7 @@ public class GraphTraversalTest extends AAISetup {
                QueryParser query = dbEnginev9.getQueryBuilder().createQueryFromURI(uri, map);
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("aai-node-type", "vpn-binding")
-                               .where(__.out("has").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2"));
+                               .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2"));
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("aai-node-type", "vpn-binding");
                
@@ -693,7 +705,7 @@ public class GraphTraversalTest extends AAISetup {
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("physical-location-id", "key1")
                                .has("aai-node-type", "complex")
-                               .in("locatedIn").has("aai-node-type", "pserver");
+                               .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver");
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("physical-location-id", "key1")
                                .has("aai-node-type", "complex");
@@ -727,7 +739,7 @@ public class GraphTraversalTest extends AAISetup {
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("physical-location-id", "key1")
                                .has("aai-node-type", "complex")
-                               .in("locatedIn").has("aai-node-type", "pserver")
+                               .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
                                .has("hostname", "key2");
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("physical-location-id", "key1")
@@ -762,14 +774,14 @@ public class GraphTraversalTest extends AAISetup {
                GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
                                .has("physical-location-id", "key1")
                                .has("aai-node-type", "complex")
-                               .in("locatedIn").has("aai-node-type", "pserver")
+                               .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
                                .has("hostname", "key2")
-                               .in("runsOnPserver").has("aai-node-type", "vserver")
+                               .in("tosca.relationships.HostedOn").has("aai-node-type", "vserver")
                                .has("vserver-id", "key3");
                GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
                                .has("physical-location-id", "key1")
                                .has("aai-node-type", "complex")
-                               .in("locatedIn").has("aai-node-type", "pserver")
+                               .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
                                .has("hostname", "key2");
 
                assertEquals(