* ============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.
* 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;
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;
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;
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.
@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);
}
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()
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(
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(
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");
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));
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(
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"));
@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(),
assertEquals(
"result type should be",
- "test-object",
+ "generic-vnf",
query.getResultType());
assertEquals(
"result type should be empty",
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");
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");
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")
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(