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