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