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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations