Search in sources :

Example 36 with TransactionalGraphEngine

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

the class HttpEntryTest method relatedToTest.

@Test
public void relatedToTest() throws UnsupportedEncodingException, AAIException {
    traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
    Loader loader = traversalHttpEntry.getLoader();
    TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
    // Put pserver
    String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
    String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
    doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
    // Put complex
    uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
    content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"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);
    // PutEdge
    uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
    content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
    doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
    // getRelatedTo
    uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/related-to/pservers";
    content = "";
    Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
    String respBody = response.getEntity().toString();
    dbEngine.rollback();
    assertEquals("Expected the pserver to be created", 200, response.getStatus());
    assertThat("Related to pserver is returned.", respBody, containsString("\"hostname\":\"junit-edge-test-pserver\""));
}
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 37 with TransactionalGraphEngine

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

the class HttpEntryTest method getRelationshipListTestWithFormatSimple.

@Test
public void getRelationshipListTestWithFormatSimple() 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 complex
    uri = "/cloud-infrastructure/pservers/pserver/httpEntryTest-pserver-01";
    content = "";
    response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
    // Get Relationship
    uri = "/cloud-infrastructure/pservers/pserver/httpEntryTest-pserver-01";
    queryParameters.add("format", "resource");
    content = "";
    response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET_RELATIONSHIP, uri, content);
    String responsePayload = response.getEntity().toString();
    JSONObject responseJsonObject = new JSONObject(responsePayload);
    JSONArray responseResultsArray = responseJsonObject.getJSONArray("results");
    String responseResults = responseResultsArray.get(0).toString();
    JSONObject pserverResponseObject = new JSONObject(responseResults);
    String pserverResponse = pserverResponseObject.get("pserver").toString();
    JSONObject pserverResponseFields = new JSONObject(pserverResponse);
    String pserverResponseRelationshipList = pserverResponseFields.get("relationship-list").toString();
    String expected = "{\"relationship\":[{\"related-to\":\"complex\",\"relationship-data\":[{\"relationship-value\":\"httpEntryTest-complex-01\",\"relationship-key\":\"complex.physical-location-id\"}],\"related-link\":\"/aai/v14/cloud-infrastructure/complexes/complex/httpEntryTest-complex-01\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}]}";
    assertEquals(expected, pserverResponseRelationshipList);
    // Assert.assertEquals(expected, response.getEntity().toString());
    queryParameters.remove("format");
    dbEngine.rollback();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Loader(org.onap.aai.introspection.Loader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 38 with TransactionalGraphEngine

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

the class HttpEntryTest method test4GetOnPserver.

@Test
public void test4GetOnPserver() throws UnsupportedEncodingException, AAIException {
    traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
    Loader loader = traversalHttpEntry.getLoader();
    TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
    String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
    String content = "{\"hostname\":\"junit-test1\", \"equip-type\":\"junit-equip-type\"}";
    Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
    dbEngine.commit();
    assertEquals("Expected the pserver to be returned", 200, 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 39 with TransactionalGraphEngine

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

the class HttpEntryTest method putEdgeWrongLabelTest.

@Test
public void putEdgeWrongLabelTest() 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();
    // Put pserver
    String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
    String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
    doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
    // Put complex
    uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
    content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"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);
    // PutEdge
    uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
    content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"junk\"}";
    Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
    dbEngine.rollback();
    String msg = response.getEntity().toString();
    assertEquals("Expected the pserver to be created", 400, response.getStatus());
    assertThat(msg, containsString("ERR.5.4.6107"));
    assertThat(msg, containsString("Required Edge-property not found in input data:org.onap.aai.edges.exceptions.EdgeRuleNotFoundException: No rule found for EdgeRuleQuery with filter params node type: complex, node type: pserver, label: junk, type: COUSIN, isPrivate: false"));
}
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 40 with TransactionalGraphEngine

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

the class HttpEntryTest method test7DeleteOnPserverNoPinterface.

@Test
public void test7DeleteOnPserverNoPinterface() 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();
    String msg = response.getEntity().toString();
    JsonObject jsonObj = new JsonParser().parse(msg).getAsJsonObject();
    String resourceVersion = "";
    if (jsonObj.isJsonObject()) {
        resourceVersion = jsonObj.get("resource-version").getAsString();
    }
    assertEquals("Expected the pserver to be deleted", 204, doDelete(resourceVersion, "/cloud-infrastructure/pservers/pserver/junit-test2", "pserver"));
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) Loader(org.onap.aai.introspection.Loader) JsonObject(com.google.gson.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonParser(com.google.gson.JsonParser) 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