Search in sources :

Example 41 with TransactionalGraphEngine

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

the class HttpEntryTest method test8FailedGetOnPserver.

@Test
public void test8FailedGetOnPserver() throws UnsupportedEncodingException, AAIException {
    traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
    // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
    Loader loader = traversalHttpEntry.getLoader();
    TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
    String uri = "/cloud-infrastructure/pservers/pserver/junit-test2";
    String content = "";
    Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
    dbEngine.commit();
    assertEquals("Expected the pserver to be deleted", 404, response.getStatus());
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) Loader(org.onap.aai.introspection.Loader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 42 with TransactionalGraphEngine

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

the class HttpEntryTest method getRelationshipListTest.

@Test
public void getRelationshipListTest() throws UnsupportedEncodingException, AAIException {
    traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
    Loader loader = traversalHttpEntry.getLoader();
    TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
    // Put pserver
    String uri = "/cloud-infrastructure/pservers/pserver/httpEntryTest-pserver-01";
    String content = "{\"hostname\":\"httpEntryTest-pserver-01\"}";
    doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
    // Put complex
    uri = "/cloud-infrastructure/complexes/complex/httpEntryTest-complex-01";
    content = "{\"physical-location-id\":\"httpEntryTest-complex-01\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
    doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
    // Put Relationship
    uri = "/cloud-infrastructure/pservers/pserver/httpEntryTest-pserver-01/relationship-list/relationship";
    content = "{\"related-to\":\"complex\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/complexes/complex/httpEntryTest-complex-01\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}" + "\"relationship-daasSta\":[{" + "\"relationship-key\":\"complex.physical-location-id\"," + "\"relationship-value\":\"httpEntryTest-complex-01\"" + "}]";
    Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
    assertEquals("Expected the pserver relationship to be created", 200, response.getStatus());
    // Get Relationship
    uri = "/cloud-infrastructure/pservers/pserver/httpEntryTest-pserver-01";
    content = "";
    response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET_RELATIONSHIP, uri, content);
    String expected = "{\"relationship\":[{\"related-to\":\"complex\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\",\"related-link\":\"/aai/v14/cloud-infrastructure/complexes/complex/httpEntryTest-complex-01\",\"relationship-data\":[{\"relationship-key\":\"complex.physical-location-id\",\"relationship-value\":\"httpEntryTest-complex-01\"}]}]}";
    Assert.assertEquals(expected, response.getEntity().toString());
    dbEngine.rollback();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) Loader(org.onap.aai.introspection.Loader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 43 with TransactionalGraphEngine

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

the class DbAliasTest method checkOnWrite.

@Test
public void checkOnWrite() throws AAIException, UnsupportedEncodingException, URISyntaxException, SecurityException, IllegalArgumentException {
    final String property = "persona-model-customization-id";
    String dbPropertyName = property;
    TransactionalGraphEngine spy = spy(this.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(version, spy, introspectorFactoryType, "AAI_TEST");
    QueryParser uriQuery = spy.getQueryBuilder().createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1"));
    Introspector obj = loader.introspectorFromName("generic-vnf");
    Vertex v = g.addVertex();
    v.property("aai-uri", "abc");
    v.property("aai-uuid", "b");
    v.property(AAIProperties.CREATED_TS, 123L);
    v.property(AAIProperties.SOURCE_OF_TRUTH, "sot");
    v.property(AAIProperties.RESOURCE_VERSION, "123");
    v.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, "lmsot");
    v.property(AAIProperties.LAST_MOD_TS, 123L);
    Object id = v.id();
    obj.setValue("vnf-id", "key1");
    obj.setValue(property, "hello");
    serializer.serializeToDb(obj, v, uriQuery, "", "");
    g.tx().commit();
    v = graph.traversal().V(id).next();
    Map<PropertyMetadata, String> map = obj.getPropertyMetadata(property);
    if (map.containsKey(PropertyMetadata.DB_ALIAS)) {
        dbPropertyName = map.get(PropertyMetadata.DB_ALIAS);
    }
    assertEquals("dbAlias is ", "model-customization-id", dbPropertyName);
    assertEquals("dbAlias property exists", "hello", v.property(dbPropertyName).orElse(""));
    assertEquals("model property does not", "missing", v.property(property).orElse("missing"));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Introspector(org.onap.aai.introspection.Introspector) URI(java.net.URI) TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) QueryParser(org.onap.aai.parsers.query.QueryParser) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) PropertyMetadata(org.onap.aai.schema.enums.PropertyMetadata) Test(org.junit.Test)

Example 44 with TransactionalGraphEngine

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

the class DbAliasTest method checkOnRead.

@Test
public void checkOnRead() throws AAIException, UnsupportedEncodingException, SecurityException, IllegalArgumentException {
    final String property = "persona-model-customization-id";
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Vertex v = graph.traversal().addV().property("vnf-id", "key1").property("model-customization-id", "hello").next();
    graph.tx().commit();
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
    Introspector obj = loader.introspectorFromName("generic-vnf");
    serializer.dbToObject(Collections.singletonList(v), obj, 0, true, "false");
    assertEquals("dbAlias property exists", "hello", obj.getValue(property));
}
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) Introspector(org.onap.aai.introspection.Introspector) Test(org.junit.Test)

Example 45 with TransactionalGraphEngine

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

the class DataLinkTest method verifyModificationOfVertex.

@Test
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("vpn-id", "modifyKey");
    obj.setValue("global-route-target", "modifyTargetKey2");
    obj.setValue("route-target-role", "modifyRoleKey2");
    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);
    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").hasNext(), is(true));
    assertThat("new route-target vertex found", traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2").has("linked", true).hasNext(), is(true));
    assertThat("previous link removed", traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").has("linked").hasNext(), is(not(true)));
    assertThat("previous vertex still exists", traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").hasNext(), is(true));
    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)

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