use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.
the class HttpTestUtil method doDelete.
public Response doDelete(Map<String, Pair<String, String>> deletes) {
this.init();
Response response = null;
boolean success = true;
TransactionalGraphEngine dbEngine = null;
try {
List<DBRequest> dbRequestList = new ArrayList<>();
for (Map.Entry<String, Pair<String, String>> delete : deletes.entrySet()) {
String uri = delete.getKey();
String resourceVersion = delete.getValue().getValue0();
String content = delete.getValue().getValue1();
uri = uri.replaceAll("/aai/", "");
logger.info("Starting the delete request for the uri {} with resource version {}", uri, resourceVersion);
String[] arr = uri.split("/");
SchemaVersion version = null;
if (arr.length > 1) {
if (arr[0].matches("^v\\d+")) {
version = new SchemaVersion(arr[0]);
uri = uri.replaceAll("^v\\d+", "");
}
}
if (version == null) {
version = schemaVersions.getDefaultVersion();
}
Mockito.when(uriInfo.getPath()).thenReturn(uri);
if (notification != null) {
traversalHttpEntry.setHttpEntryProperties(version, notification, notificationDepth);
} else {
traversalHttpEntry.setHttpEntryProperties(version);
}
Loader loader = traversalHttpEntry.getLoader();
dbEngine = traversalHttpEntry.getDbEngine();
URI uriObject = UriBuilder.fromPath(uri).build();
URIToObject uriToObject = new URIToObject(loader, uriObject);
String objType = uriToObject.getEntityName();
queryParameters.add("resource-version", resourceVersion);
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject, queryParameters);
logger.info("Unmarshalling the payload to this {}", objType);
Introspector obj;
HttpMethod httpMethod;
if (uri.contains("/relationship-list/relationship")) {
httpMethod = HttpMethod.DELETE_EDGE;
obj = loader.unmarshal("relationship", content, org.onap.aai.restcore.MediaType.getEnum("application/json"));
} else {
obj = loader.introspectorFromName(objType);
httpMethod = HttpMethod.DELETE;
}
DBRequest dbRequest = new DBRequest.Builder(httpMethod, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION").build();
dbRequestList.add(dbRequest);
}
Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalHttpEntry.process(dbRequestList, "JUNIT");
response = responsesTuple.getValue1().get(0).getValue1();
} catch (AAIException e) {
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.DELETE, e);
success = false;
} catch (Exception e) {
AAIException ex = new AAIException("AAI_4000", e);
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.DELETE, ex);
success = false;
} finally {
if (success) {
if (response != null) {
if ((response.getStatus() / 100) == 2) {
logger.info("Successfully completed the DELETE request with status {} and committing it to DB", response.getStatus());
} else {
logFailure(HttpMethod.DELETE, response);
}
}
dbEngine.commit();
} else {
logFailure(HttpMethod.DELETE, response);
dbEngine.rollback();
}
}
return response;
}
use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.
the class DataCopyTest method verifyNestedSideEffect.
@Test
public void verifyNestedSideEffect() throws AAIException, IllegalArgumentException, SecurityException, IOException {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
final Introspector obj = loader.unmarshal("customer", this.getJsonString("nested-case.json"));
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);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
when(uriQuery.isDependent()).thenReturn(false);
DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
Vertex v = serializer.createNewVertex(obj);
serializer.serializeToDb(obj, v, uriQuery, obj.getURI(), "test");
assertEquals("nested value populated", "testValue", g.traversal().V().has("service-instance-id", "nested-instance-key").next().property("persona-model-version").orElse(""));
g.tx().rollback();
}
use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.
the class DataCopyTest method expectedMissingPropertyExceptionInURI.
@Test
public void expectedMissingPropertyExceptionInURI() throws AAIException, UnsupportedEncodingException {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
obj.setValue("model-invariant-id", "key1");
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(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(DataCopy.class).build();
thrown.expect(AAIMissingRequiredPropertyException.class);
runner.execute(obj, self);
}
use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.
the class DataCopyTest method expectNoProcessingWithNoProperties.
@Test
public void expectNoProcessingWithNoProperties() throws AAIException, UnsupportedEncodingException {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
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(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(DataCopy.class).build();
runner.execute(obj, self);
assertNull("no model-version-id", obj.getValue("model-version-id"));
assertNull("no model-invariant-id", obj.getValue("model-invariant-id"));
}
use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.
the class HttpEntryTest method getAbstractTest.
@Test
public void getAbstractTest() throws UnsupportedEncodingException, AAIException {
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
// Put generic-vnf
String uri = "/network/generic-vnfs/generic-vnf/junit-abstract-test-generic-vnf";
String content = "{\"vnf-id\":\"junit-abstract-test-generic-vnf\",\"vnf-name\":\"junit-generic-vnf-name\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
// Put pserver
uri = "/cloud-infrastructure/pservers/pserver/junit-abstract-test-pserver";
content = "{\"hostname\":\"junit-abstract-test-pserver\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
// PutEdge
uri = "/cloud-infrastructure/pservers/pserver/junit-abstract-test-pserver/relationship-list/relationship";
content = "{\"related-to\":\"vnf\",\"relationship-data\":[{\"relationship-key\":\"vnf.vnf-id\",\"relationship-value\":\"junit-abstract-test-generic-vnf\"}]}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
// getRelatedTo
uri = "/network/generic-vnfs/generic-vnf/junit-abstract-test-generic-vnf/related-to/pservers";
content = "";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
String respBody = response.getEntity().toString();
dbEngine.rollback();
assertThat("Related to pserver is returned.", respBody, containsString("\"hostname\":\"junit-abstract-test-pserver\""));
}
Aggregations