package org.onap.aai.introspection.sideeffect;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.janusgraph.core.Cardinality;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
+import org.janusgraph.core.schema.JanusGraphManagement;
import org.junit.*;
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.AAISetup;
import org.onap.aai.DataLinkSetup;
import org.onap.aai.db.props.AAIProperties;
-import org.onap.aai.dbmap.DBConnectionType;
import org.onap.aai.edges.enums.EdgeProperty;
import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.*;
+import org.onap.aai.introspection.Introspector;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.ModelType;
import org.onap.aai.parsers.query.QueryParser;
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;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
@RunWith(value = Parameterized.class)
public class DataLinkTest extends DataLinkSetup {
private static JanusGraph graph;
private final static ModelType introspectorFactoryType = ModelType.MOXY;
- private final static DBConnectionType type = DBConnectionType.REALTIME;
private static Loader loader;
private static TransactionalGraphEngine dbEngine;
@Mock
@Rule
public ExpectedException thrown = ExpectedException.none();
- @Parameterized.Parameter(value = 0)
+ @Parameterized.Parameter
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
}
@BeforeClass
- public static void setup() throws NoSuchFieldException, SecurityException, Exception {
+ public static void setup() {
graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ JanusGraphManagement graphMgt = graph.openManagement();
+ graphMgt.makePropertyKey(AAIProperties.CREATED_TS).dataType(Long.class).cardinality(Cardinality.SINGLE)
+ .make();
+ graphMgt.makePropertyKey(AAIProperties.LAST_MOD_TS).dataType(Long.class).cardinality(Cardinality.SINGLE)
+ .make();
+ graphMgt.commit();
graph.traversal()
- .addV("aai-node-type", "vpn-binding", "vpn-id", "addKey", AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/addKey")
- .as("v1")
- .addV("aai-node-type", "vpn-binding", "vpn-id", "modifyKey", AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/modifyKey")
- .as("v2")
- .addV("aai-node-type", "route-target", "global-route-target", "modifyTargetKey", "route-target-role",
- "modifyRoleKey", "linked", true, AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/modifyKey/route-targets/route-target/modifyTargetKey/modifyRoleKey")
- .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true)
- .addV("aai-node-type", "vpn-binding", "vpn-id", "deleteKey", AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/deleteKey")
- .as("v3")
- .addV("aai-node-type", "route-target", "global-route-target", "deleteTargetKey", "route-target-role",
- "deleteRoleKey", "linked", true, AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/deleteKey/route-targets/route-target/deleteTargetKey/deleteRoleKey")
- .addOutE("org.onap.relationships.inventory.BelongsTo", "v3", EdgeProperty.CONTAINS.toString(), true)
- .addV("aai-node-type", "vpn-binding", "vpn-id", "getKey", AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/getKey")
- .as("v4")
- .addV("aai-node-type", "route-target", "global-route-target", "getTargetKey", "route-target-role",
- "getRoleKey", "linked", true, AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/getKey/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
- .addOutE("org.onap.relationships.inventory.BelongsTo", "v4", EdgeProperty.CONTAINS.toString(), true)
- .addV("aai-node-type", "vpn-binding", "vpn-id", "getKeyNoLink", AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/getKeyNoLink")
- .as("v5")
- .addV("aai-node-type", "route-target", "global-route-target", "getTargetKeyNoLink", "route-target-role",
- "getRoleKeyNoLink", AAIProperties.AAI_URI,
- "/network/vpn-bindings/vpn-binding/getKeyNoLink/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
- .addOutE("org.onap.relationships.inventory.BelongsTo", "v5", EdgeProperty.CONTAINS.toString(), true)
+ .addV()
+ .property("aai-node-type", "vpn-binding")
+ .property("vpn-id", "addKey")
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/addKey")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v1")
+ .addV()
+ .property("aai-node-type", "vpn-binding")
+ .property("vpn-id", "modifyKey")
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v2")
+ .addV()
+ .property("aai-node-type", "route-target")
+ .property("global-route-target", "modifyTargetKey")
+ .property("route-target-role", "modifyRoleKey")
+ .property("linked", true)
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey/route-targets/route-target/modifyTargetKey/modifyRoleKey")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v3")
+ .addE("org.onap.relationships.inventory.BelongsTo").to("v2").from("v3")
+ .property(EdgeProperty.CONTAINS.toString(), true)
+ .addV()
+ .property("aai-node-type", "vpn-binding")
+ .property("vpn-id", "deleteKey")
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v4")
+ .addV()
+ .property("aai-node-type", "route-target")
+ .property("global-route-target", "deleteTargetKey")
+ .property("route-target-role", "deleteRoleKey")
+ .property("linked", true)
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey/route-targets/route-target/deleteTargetKey/deleteRoleKey")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v5")
+ .addE("org.onap.relationships.inventory.BelongsTo").to("v4").from("v5")
+ .property(EdgeProperty.CONTAINS.toString(), true)
+ .addV()
+ .property("aai-node-type", "vpn-binding")
+ .property("vpn-id", "getKey")
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v6")
+ .addV()
+ .property("aai-node-type", "route-target")
+ .property("global-route-target", "getTargetKey")
+ .property("route-target-role", "getRoleKey")
+ .property("linked", true)
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v7")
+ .addE("org.onap.relationships.inventory.BelongsTo").to("v6").from("v7")
+ .property(EdgeProperty.CONTAINS.toString(), true)
+ .addV()
+ .property("aai-node-type", "vpn-binding")
+ .property("vpn-id", "getKeyNoLink")
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v8")
+ .addV()
+ .property("aai-node-type", "route-target")
+ .property("global-route-target", "getTargetKeyNoLink")
+ .property("route-target-role", "getRoleKeyNoLink")
+ .property(AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
+ .property(AAIProperties.AAI_UUID, UUID.randomUUID().toString())
+ .property(AAIProperties.CREATED_TS, 123)
+ .property(AAIProperties.SOURCE_OF_TRUTH, "sot")
+ .property(AAIProperties.RESOURCE_VERSION, "123")
+ .property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot")
+ .property(AAIProperties.LAST_MOD_TS, 333)
+ .as("v9")
+ .addE("org.onap.relationships.inventory.BelongsTo").to("v8").from("v9")
+ .property(EdgeProperty.CONTAINS.toString(), true)
.next();
graph.tx().commit();
- /*
- * Commented for SysOut issues
- */
- // graph.traversal().V().has("aai-uri","/network/vpn-bindings/vpn-binding/deleteKey").properties().forEachRemaining(p->System.out.println(p.key()
- // +" : " + p.value()));
-
}
@AfterClass
public void initMock() {
loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
MockitoAnnotations.initMocks(this);
- dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
+ dbEngine = new JanusGraphDBEngine(queryStyle, loader);
}
@Test
- public void verifyCreationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException,
- IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
- InstantiationException, NoSuchMethodException, MalformedURLException {
+ public void verifyCreationOfVertex() throws AAIException, UnsupportedEncodingException,
+ IllegalArgumentException, SecurityException {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
Graph g = graph.newTransaction();
GraphTraversalSource traversal = g.traversal();
- // Graph g = graph.newTransaction();
- // GraphTraversalSource traversal = g;
- // System.out.println("Begin method inventory:");
- Iterator<Vertex> vertexItr = traversal.V();
- while (vertexItr != null && vertexItr.hasNext()) {
- Vertex v = vertexItr.next();
- // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for (String key : v.keys()) {
- // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+";id= "+v.id());
- }
- Direction d = null;
- Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while (edgeItr != null && edgeItr.hasNext()) {
- Edge e = edgeItr.next();
- // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
- // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
- }
- }
- // System.out.println("End method inventory:");
when(spy.asAdmin()).thenReturn(adminSpy);
when(adminSpy.getTraversalSource()).thenReturn(traversal);
when(spy.tx()).thenReturn(g);
runner.execute(obj, self);
- assertEquals("route-target vertex found", true, traversal.V().has(AAIProperties.NODE_TYPE, "route-target")
- .has("global-route-target", "key1").has("route-target-role", "key2").has("linked", true).hasNext());
+ assertTrue("route-target vertex found", traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key1").has("route-target-role", "key2").has("linked", true).hasNext());
g.tx().rollback();
}
@Test
- public void verifyModificationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException,
- IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
- InstantiationException, NoSuchMethodException, MalformedURLException {
+ public void verifyModificationOfVertex() throws AAIException, UnsupportedEncodingException,
+ IllegalArgumentException, SecurityException {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
obj.setValue("route-target-role", "modifyRoleKey2");
TransactionalGraphEngine spy = spy(dbEngine);
TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
- // Graph g = graph.newTransaction();
- // GraphTraversalSource traversal = g;
Graph g = graph.newTransaction();
GraphTraversalSource traversal = g.traversal();
- Iterator<Vertex> vertexItr = traversal.V();
- while (vertexItr != null && vertexItr.hasNext()) {
- Vertex v = vertexItr.next();
- // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for (String key : v.keys()) {
- // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
- }
- Direction d = null;
- Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while (edgeItr != null && edgeItr.hasNext()) {
- Edge e = edgeItr.next();
- // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
- // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
- }
- }
- // System.out.println("End method inventory:");
when(spy.asAdmin()).thenReturn(adminSpy);
when(adminSpy.getTraversalSource()).thenReturn(traversal);
- // when(spy.tx()).thenReturn(graph);
when(spy.tx()).thenReturn(g);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
SideEffectRunner runner =
new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
- // System.out.println("Traversal Source: "+traversal.toString());
- vertexItr = traversal.V();
- // System.out.println("Begin method inventory:");
- while (vertexItr != null && vertexItr.hasNext()) {
- Vertex v = vertexItr.next();
- // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for (String key : v.keys()) {
- // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
- }
- Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while (edgeItr != null && edgeItr.hasNext()) {
- Edge e = edgeItr.next();
- // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
- // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
- }
- }
- // System.out.println("End method inventory:");
- try {
- runner.execute(obj, self);
- } catch (Exception e) {
-
- }
- // runner.execute(obj, self);
- // System.out.println("=================\n");
- vertexItr = traversal.V();
- while (vertexItr != null && vertexItr.hasNext()) {
- Vertex v = vertexItr.next();
- // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for (String key : v.keys()) {
- // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
- }
- Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while (edgeItr != null && edgeItr.hasNext()) {
- Edge e = edgeItr.next();
- // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
- // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
- }
- }
+ runner.execute(obj, self);
+
assertThat("new route-target vertex found with/or without link",
traversal.V().has(AAIProperties.NODE_TYPE, "route-target")
.has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2")
}
@Test
- public void verifyDeleteOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException,
- IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
- InstantiationException, NoSuchMethodException, MalformedURLException {
+ public void verifyDeleteOfVertex() throws Exception {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
runner.execute(obj, self);
- assertEquals("route-target vertex not found", false,
- traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "deleteTargetKey")
- .has("route-target-role", "deleteRoleKey").has("linked", true).hasNext());
+ assertFalse("route-target vertex not found", traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "deleteTargetKey").has("route-target-role", "deleteRoleKey").has("linked", true).hasNext());
g.tx().rollback();
}
@Test
- public void verifyPropertyPopulation() throws URISyntaxException, AAIException, UnsupportedEncodingException,
- IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
- InstantiationException, NoSuchMethodException, MalformedURLException {
+ public void verifyPropertyPopulation() throws Exception {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
runner.execute(obj, self);
- assertEquals("both properties have been populated in target object", true,
- obj.getValue("global-route-target").equals("getTargetKey")
- && obj.getValue("route-target-role").equals("getRoleKey"));
+ assertTrue("both properties have been populated in target object", obj.getValue("global-route-target").equals("getTargetKey") && obj.getValue("route-target-role").equals("getRoleKey"));
g.tx().rollback();
}
@Test
- public void verifyPropertyPopulationWithV10OnlyPut() throws URISyntaxException, AAIException,
- UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
- SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
+ public void verifyPropertyPopulationWithV10OnlyPut() throws AAIException,
+ UnsupportedEncodingException, IllegalArgumentException, SecurityException {
final Introspector obj = loader.introspectorFromName("vpn-binding");
obj.setValue("vpn-id", "getKeyNoLink");
final Introspector routeTargets = loader.introspectorFromName("route-targets");