Search in sources :

Example 46 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.

the class DataLinkTest method verifyCreationOfVertex.

@Test
public void verifyCreationOfVertex() throws AAIException, UnsupportedEncodingException, IllegalArgumentException, SecurityException {
    final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
    final Introspector obj = loader.introspectorFromName("vpn-binding");
    obj.setValue("vpn-id", "addKey");
    obj.setValue("global-route-target", "key1");
    obj.setValue("route-target-role", "key2");
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    when(spy.tx()).thenReturn(g);
    when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
    when(prop.orElse(null)).thenReturn(obj.getURI());
    DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
    SideEffectRunner runner = new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
    runner.execute(obj, self);
    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();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) DBSerializer(org.onap.aai.serialization.db.DBSerializer) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector)

Example 47 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.

the class DataLinkTest method verifyDeleteOfVertex.

@Test
public void verifyDeleteOfVertex() throws Exception {
    final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
    final Introspector obj = loader.introspectorFromName("vpn-binding");
    obj.setValue("vpn-id", "deleteKey");
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
    when(spy.tx()).thenReturn(g);
    when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
    when(prop.orElse(null)).thenReturn(obj.getURI());
    DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
    SideEffectRunner runner = new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
    runner.execute(obj, self);
    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();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) DBSerializer(org.onap.aai.serialization.db.DBSerializer) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector)

Example 48 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.

the class OwnerCheckTest method shouldPassIfGroupsIsEmpty.

@Test
public void shouldPassIfGroupsIsEmpty() throws Exception {
    final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
    final Introspector obj = loader.introspectorFromName("pnf");
    obj.setValue("pnf-name", "my-pnf");
    obj.setValue("model-invariant-id", "key1");
    obj.setValue("model-version-id", "key2");
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
    Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
    OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
    assertNotNull(ownerCheck);
    ownerCheck.execute();
    g.tx().rollback();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) DBSerializer(org.onap.aai.serialization.db.DBSerializer) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector) Test(org.junit.Test)

Example 49 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.

the class OwnerCheckTest method shouldFailIfGroupsNotContainsDataOwner.

@Test
public void shouldFailIfGroupsNotContainsDataOwner() throws Exception {
    final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
    final Introspector obj = loader.introspectorFromName("pnf");
    obj.setValue("pnf-name", "my-pnf");
    obj.setValue("model-invariant-id", "key1");
    obj.setValue("model-version-id", "key2");
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST", new HashSet<>(Arrays.asList("OperatorI", "OperatorII")));
    Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
    OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
    thrown.expect(AAIException.class);
    thrown.expectMessage("Group(s) :[OperatorII, OperatorI] not authorized to perform function");
    ownerCheck.execute();
    g.tx().rollback();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) DBSerializer(org.onap.aai.serialization.db.DBSerializer) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector) Test(org.junit.Test)

Example 50 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.

the class OwnerCheckTest method shouldPassIfGroupsContainsDataOwner.

@Test
public void shouldPassIfGroupsContainsDataOwner() throws Exception {
    final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
    final Introspector obj = loader.introspectorFromName("pnf");
    obj.setValue("pnf-name", "my-pnf");
    obj.setValue("model-invariant-id", "key1");
    obj.setValue("model-version-id", "key2");
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.tx()).thenReturn(g);
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    Vertex selfV = g.traversal().V().has("aai-node-type", "pnf").next();
    DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST", new HashSet<>(Arrays.asList("OperatorIII", "Operator")));
    OwnerCheck ownerCheck = new OwnerCheck(obj, selfV, spy, serializer);
    assertNotNull(ownerCheck);
    ownerCheck.execute();
    g.tx().rollback();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) DBSerializer(org.onap.aai.serialization.db.DBSerializer) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector) Test(org.junit.Test)

Aggregations

TransactionalGraphEngine (org.onap.aai.serialization.engines.TransactionalGraphEngine)86 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)60 JanusGraphDBEngine (org.onap.aai.serialization.engines.JanusGraphDBEngine)45 Loader (org.onap.aai.introspection.Loader)42 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)33 Before (org.junit.Before)31 Test (org.junit.Test)24 Introspector (org.onap.aai.introspection.Introspector)23 Graph (org.apache.tinkerpop.gremlin.structure.Graph)18 Matchers.containsString (org.hamcrest.Matchers.containsString)18 JanusGraph (org.janusgraph.core.JanusGraph)18 DBSerializer (org.onap.aai.serialization.db.DBSerializer)18 AAIException (org.onap.aai.exceptions.AAIException)9 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)8 SchemaVersion (org.onap.aai.setup.SchemaVersion)8 URI (java.net.URI)6 QueryParser (org.onap.aai.parsers.query.QueryParser)6 JsonObject (com.google.gson.JsonObject)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 URIToObject (org.onap.aai.parsers.uri.URIToObject)4