summaryrefslogtreecommitdiffstats
path: root/aai-core/src/test/java
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-01-23 14:40:32 +0100
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-01-25 16:23:33 +0100
commitd749a1072e23073e320ffe78c3f0576da0486279 (patch)
treeeaf13376952ac805219db0a7189311822a97f623 /aai-core/src/test/java
parent948c9f53f6243507e8a8c3e9b562d63e2b8b846a (diff)
Update tinkerpop to 3.2.4
- work around hasStep inlining - add tests that more directly assert traversal state - add TinkerpopUpgradeTests test suite [1] - bump aai-common version to 1.13.2 [1] this allows to run the tests that are likely affected by a tinkerpop upgrade Issue-ID: AAI-3740 Change-Id: I86fb9b0c86802c7c0f74a5aae0976e81bf501eb0 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'aai-core/src/test/java')
-rw-r--r--aai-core/src/test/java/org/onap/aai/TinkerpopUpgrade.java26
-rw-r--r--aai-core/src/test/java/org/onap/aai/TinkerpopUpgradeTests.java43
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java53
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java3
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java99
5 files changed, 223 insertions, 1 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/TinkerpopUpgrade.java b/aai-core/src/test/java/org/onap/aai/TinkerpopUpgrade.java
new file mode 100644
index 00000000..a6aa1e4c
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/TinkerpopUpgrade.java
@@ -0,0 +1,26 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom. 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;
+/**
+ * Marker interface for Junit to annotate tests
+ * that affect the tinkerpop dependency update
+ */
+public interface TinkerpopUpgrade {} \ No newline at end of file
diff --git a/aai-core/src/test/java/org/onap/aai/TinkerpopUpgradeTests.java b/aai-core/src/test/java/org/onap/aai/TinkerpopUpgradeTests.java
new file mode 100644
index 00000000..81c3ed81
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/TinkerpopUpgradeTests.java
@@ -0,0 +1,43 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom. 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;
+
+import org.junit.experimental.categories.Categories;
+import org.junit.experimental.categories.Categories.IncludeCategory;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+import org.onap.aai.introspection.sideeffect.DataLinkTest;
+import org.onap.aai.parsers.query.GraphTraversalTest;
+import org.onap.aai.query.builder.TraversalQueryTest;
+
+/**
+ * Collection of tests that are likely affected by a Tinkerpop update
+ * This is to more targedly run these tests during development:
+ * mvn test -Dcheckstyle.skip -Dtest=TinkerpopUpgradeTests
+ */
+@RunWith(Categories.class)
+@IncludeCategory(TinkerpopUpgrade.class)
+@SuiteClasses({
+ DataLinkTest.class,
+ GraphTraversalTest.class,
+ TraversalQueryTest.class
+})
+public class TinkerpopUpgradeTests {}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
index 2a68e53d..7ccf1305 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
@@ -28,12 +28,18 @@ 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.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
+import javax.ws.rs.core.MultivaluedMap;
+
+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.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -42,24 +48,32 @@ import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.junit.*;
+import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.aai.DataLinkSetup;
+import org.onap.aai.TinkerpopUpgrade;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.edges.enums.EdgeProperty;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderUtil;
import org.onap.aai.introspection.ModelType;
+import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.onap.aai.parsers.query.QueryParser;
+import org.onap.aai.query.builder.QueryBuilder;
+import org.onap.aai.query.builder.TraversalQuery;
+import org.onap.aai.restcore.util.URITools;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
+@Category(TinkerpopUpgrade.class)
@RunWith(value = Parameterized.class)
public class DataLinkTest extends DataLinkSetup {
@@ -81,7 +95,7 @@ public class DataLinkTest extends DataLinkSetup {
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}});
}
@BeforeClass
@@ -204,6 +218,43 @@ public class DataLinkTest extends DataLinkSetup {
}
+ /**
+ * This is more directly testing the modification mechanism (see verifyModificationOfVertex test)
+ */
+ @Test
+ public void linkQuery() throws UnsupportedEncodingException, AAIException, URISyntaxException {
+ Graph g = graph.newTransaction();
+ GraphTraversalSource source = g.traversal();
+ final Loader loader = LoaderUtil.getLatestVersion();
+ URI uri = new URI("/network/vpn-bindings/vpn-binding/modifyKey/route-targets/route-target/modifyTargetKey2/modifyRoleKey2");
+ MultivaluedMap<String, String> map = URITools.getQueryMap(uri);
+ GraphTraversal<Vertex, Vertex> traversal = __.<Vertex>start();
+
+ QueryParser uriQuery = dbEngine.getQueryBuilder(this.queryStyle, loader, source, traversal).createQueryFromURI(uri, map);
+ // assertEquals(6, traversal.asAdmin().getSteps().size());
+ // assertEquals("HasStep([vpn-id.eq(modifyKey)])", traversal.asAdmin().getSteps().get(0).toString());
+ // assertEquals("HasStep([aai-node-type.eq(vpn-binding)])", traversal.asAdmin().getSteps().get(1).toString());
+ // assertEquals("VertexStep(IN,[org.onap.relationships.inventory.BelongsTo],vertex)", traversal.asAdmin().getSteps().get(2).toString());
+ // assertEquals("HasStep([aai-node-type.eq(route-target)])", traversal.asAdmin().getSteps().get(3).toString());
+ // assertEquals("HasStep([global-route-target.eq(modifyTargetKey2)])", traversal.asAdmin().getSteps().get(4).toString());
+ // assertEquals("HasStep([route-target-role.eq(modifyRoleKey2)])", traversal.asAdmin().getSteps().get(5).toString());
+ List<Vertex> results = uriQuery.getQueryBuilder().toList();
+
+ assertEquals(0, results.size());
+ // assertEquals(traversal.asAdmin().getSteps().size(), 6);
+ // assertEquals("HasStep([vpn-id.eq(modifyKey)])", traversal.asAdmin().getSteps().get(0).toString());
+ // assertEquals("HasStep([aai-node-type.eq(vpn-binding)])", traversal.asAdmin().getSteps().get(1).toString());
+ // assertEquals("VertexStep(IN,[org.onap.relationships.inventory.BelongsTo],vertex)", traversal.asAdmin().getSteps().get(2).toString());
+ // assertEquals("HasStep([aai-node-type.eq(route-target)])", traversal.asAdmin().getSteps().get(3).toString());
+ // assertEquals("HasStep([global-route-target.eq(modifyTargetKey2)])", traversal.asAdmin().getSteps().get(4).toString());
+ // assertEquals("HasStep([route-target-role.eq(modifyRoleKey2)])", traversal.asAdmin().getSteps().get(5).toString());
+
+ QueryBuilder<Vertex> queryBuilder = uriQuery.getQueryBuilder().getContainerQuery()
+ .getVerticesByProperty(AAIProperties.LINKED, true);
+ List<Vertex> linkedVertices = queryBuilder.toList();
+ assertEquals(1, linkedVertices.size());
+ }
+
@Test
public void verifyModificationOfVertex()
throws AAIException, UnsupportedEncodingException, IllegalArgumentException, SecurityException {
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
index b038b72a..34b29ceb 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
@@ -43,10 +43,12 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.onap.aai.DataLinkSetup;
+import org.onap.aai.TinkerpopUpgrade;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.ModelType;
@@ -56,6 +58,7 @@ import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.springframework.test.annotation.DirtiesContext;
+@Category(TinkerpopUpgrade.class)
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class GraphTraversalTest extends DataLinkSetup {
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 eca5c54e..df922b08 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2024 DEUTSCHE TELEKOM AG.
+ * ================================================================================
* 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
@@ -30,16 +32,26 @@ import java.util.List;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
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.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphFactory;
import org.junit.Ignore;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.onap.aai.TinkerpopUpgrade;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderUtil;
+import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
+@Category(TinkerpopUpgrade.class)
public class TraversalQueryTest extends QueryBuilderTestAbstraction {
@Override
@@ -258,4 +270,91 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
}
+ @Test
+ public void createDBQueryTest() throws AAIUnknownObjectException {
+ JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ GraphTraversalSource source = graph.newTransaction().traversal();
+ final Loader loader = LoaderUtil.getLatestVersion();
+ GraphTraversal<Vertex, Vertex> traversal = __.<Vertex>start();
+ TraversalQuery traversalQuery = new TraversalQuery<>(loader, source, traversal);
+ Introspector obj = loader.introspectorFromName("vpn-binding");
+ obj.setValue("vpn-id", "modifyKey");
+
+ traversalQuery.createKeyQuery(obj);
+ assertEquals(1, traversal.asAdmin().getSteps().size());
+ assertEquals("HasStep([vpn-id.eq(modifyKey)])", traversal.asAdmin().getSteps().get(0).toString());
+ traversalQuery.createContainerQuery(obj);
+ assertEquals(1, traversal.asAdmin().getSteps().size());
+ assertEquals("HasStep([vpn-id.eq(modifyKey), aai-node-type.eq(vpn-binding)])", traversal.asAdmin().getSteps().get(0).toString());
+ }
+
+ @Test
+ public void removeQueryStepsBetweenTest() throws AAIUnknownObjectException {
+ JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ GraphTraversalSource source = graph.newTransaction().traversal();
+ final Loader loader = LoaderUtil.getLatestVersion();
+ TraversalQuery traversalQuery = new TraversalQuery<>(loader, source);
+ traversalQuery.has("propertyKey", "value");
+
+ QueryBuilder clonedQuery = traversalQuery.removeQueryStepsBetween(0, 1);
+ String query = clonedQuery.getQuery().toString();
+ assertEquals("[HasStep([propertyKey.eq(value)])]", query);
+ }
+
+ @Test
+ public void removeQueryStepsBetweenTest02() throws AAIUnknownObjectException {
+ JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ GraphTraversalSource source = graph.newTransaction().traversal();
+ final Loader loader = LoaderUtil.getLatestVersion();
+ TraversalQuery traversalQuery = new TraversalQuery<>(loader, source);
+ traversalQuery.has("propertyKey", "value");
+
+ QueryBuilder clonedQuery = traversalQuery.removeQueryStepsBetween(0, 2);
+ String query = clonedQuery.getQuery().toString();
+ assertEquals("[]", query);
+ }
+
+ @Test
+ public void removeQueryStepsBetweenTest07() throws AAIUnknownObjectException {
+ JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ GraphTraversalSource source = graph.newTransaction().traversal();
+ final Loader loader = LoaderUtil.getLatestVersion();
+ TraversalQuery traversalQuery = new TraversalQuery<>(loader, source);
+ traversalQuery.limit(1);
+ traversalQuery.has("propertyKey", "value");
+ traversalQuery.has("propertyKey2", "value2");
+ traversalQuery.limit(2);
+ traversalQuery.has("propertyKey3", "value3");
+ traversalQuery.has("propertyKey4", "value4");
+ traversalQuery.has("propertyKey5", "value5");
+ traversalQuery.limit(3);
+ traversalQuery.limit(4);
+
+ QueryBuilder clonedQuery = traversalQuery.removeQueryStepsBetween(0, 7);
+ String query = clonedQuery.getQuery().toString();
+ assertEquals("[HasStep([propertyKey5.eq(value5)]), RangeGlobalStep(0,3), RangeGlobalStep(0,4)]", query);
+ }
+
+ @Test
+ @Ignore("Enable once removeQueryStepsBetween supports a start index > 0")
+ public void removeQueryStepsBetweenTest27() throws AAIUnknownObjectException {
+ JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ GraphTraversalSource source = graph.newTransaction().traversal();
+ final Loader loader = LoaderUtil.getLatestVersion();
+ TraversalQuery traversalQuery = new TraversalQuery<>(loader, source);
+ traversalQuery.limit(1);
+ traversalQuery.has("propertyKey", "value");
+ traversalQuery.has("propertyKey2", "value2");
+ traversalQuery.limit(2);
+ traversalQuery.has("propertyKey3", "value3");
+ traversalQuery.has("propertyKey4", "value4");
+ traversalQuery.has("propertyKey5", "value5");
+ traversalQuery.limit(3);
+ traversalQuery.limit(4);
+
+ QueryBuilder clonedQuery = traversalQuery.removeQueryStepsBetween(2, 7);
+ String query = clonedQuery.getQuery().toString();
+ assertEquals("[RangeGlobalStep(0,1), HasStep([propertyKey.eq(value)]), HasStep([propertyKey5.eq(value5)]), RangeGlobalStep(0,3), RangeGlobalStep(0,4)]", query);
+ }
+
}