diff options
Diffstat (limited to 'aai-core')
4 files changed, 311 insertions, 4 deletions
diff --git a/aai-core/src/test/java/org/openecomp/aai/serialization/db/DbSerializerTest.java b/aai-core/src/test/java/org/openecomp/aai/serialization/db/DbSerializerTest.java index 3c3ec789..35894259 100644 --- a/aai-core/src/test/java/org/openecomp/aai/serialization/db/DbSerializerTest.java +++ b/aai-core/src/test/java/org/openecomp/aai/serialization/db/DbSerializerTest.java @@ -22,14 +22,20 @@ package org.openecomp.aai.serialization.db; import com.thinkaurelius.titan.core.TitanFactory; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.openecomp.aai.AAISetup; +import org.openecomp.aai.db.props.AAIProperties; import org.openecomp.aai.dbmap.DBConnectionType; import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.introspection.Introspector; import org.openecomp.aai.introspection.Loader; import org.openecomp.aai.introspection.LoaderFactory; import org.openecomp.aai.introspection.ModelType; @@ -38,11 +44,23 @@ import org.openecomp.aai.serialization.engines.QueryStyle; import org.openecomp.aai.serialization.engines.TitanDBEngine; import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class DbSerializerTest extends AAISetup { + + //to use, set thrown.expect to whatever your test needs + //this line establishes default of expecting no exception to be thrown + @Rule + public ExpectedException thrown = ExpectedException.none(); protected Graph graph; protected final EdgeRules rules = EdgeRules.getInstance(); @@ -53,6 +71,8 @@ public class DbSerializerTest extends AAISetup { private final DBConnectionType type = DBConnectionType.REALTIME; private Loader loader; private TransactionalGraphEngine dbEngine; + private TransactionalGraphEngine engine; //for tests that aren't mocking the engine + private DBSerializer dbser; TransactionalGraphEngine spy; TransactionalGraphEngine.Admin adminSpy; @@ -65,6 +85,9 @@ public class DbSerializerTest extends AAISetup { adminSpy = spy(dbEngine.asAdmin()); createGraph(); + + engine = new TitanDBEngine(queryStyle, type, loader); + dbser = new DBSerializer(Version.getLatest(), engine, introspectorFactoryType, "AAI-TEST"); } public void createGraph() throws AAIException { @@ -156,5 +179,258 @@ public class DbSerializerTest extends AAISetup { return exceptionMessage; } + + @Test + public void createNewVertexTest() throws AAIException { + engine.startTransaction(); + + Introspector testObj = loader.introspectorFromName("generic-vnf"); + + Vertex testVertex = dbser.createNewVertex(testObj); + Vertex fromGraph = engine.tx().traversal().V().has("aai-node-type","generic-vnf").toList().get(0); + assertEquals(testVertex.id(), fromGraph.id()); + assertEquals("AAI-TEST", fromGraph.property(AAIProperties.SOURCE_OF_TRUTH.toString()).value()); + engine.rollback(); + } + + @Test + public void touchStandardVertexPropertiesTest() throws AAIException { + engine.startTransaction(); + DBSerializer dbser2 = new DBSerializer(Version.getLatest(), engine, introspectorFactoryType, "AAI-TEST-2"); + + Graph graph = TinkerGraph.open(); + Vertex vert = graph.addVertex("aai-node-type", "generic-vnf"); + + dbser.touchStandardVertexProperties(vert, true); + String resverStart = (String)vert.property(AAIProperties.RESOURCE_VERSION.toString()).value(); + String lastModTimeStart = (String)vert.property(AAIProperties.LAST_MOD_TS.toString()).value(); + + dbser2.touchStandardVertexProperties(vert, false); + assertFalse(resverStart.equals((String)vert.property(AAIProperties.RESOURCE_VERSION.toString()).value())); + assertFalse(lastModTimeStart.equals((String)vert.property(AAIProperties.LAST_MOD_TS.toString()).value())); + assertEquals("AAI-TEST-2", (String)vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH.toString()).value()); + engine.rollback(); + } + + @Test + public void verifyResourceVersion_SunnyDayTest() throws AAIException { + engine.startTransaction(); + + assertTrue(dbser.verifyResourceVersion("delete", "vnfc", "abc", "abc", "vnfcs/vnfc/vnfcId")); + engine.rollback(); + } + + @Test + public void verifyResourceVersion_CreateWithRVTest() throws AAIException { + engine.startTransaction(); + + thrown.expect(AAIException.class); + thrown.expectMessage("resource-version passed for create of generic-vnfs/generic-vnf/myid"); + try { + dbser.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid"); + } finally { + engine.rollback(); + } + } + + @Test + public void verifyResourceVersion_MissingRVTest() throws AAIException { + engine.startTransaction(); + + thrown.expect(AAIException.class); + thrown.expectMessage("resource-version not passed for update of generic-vnfs/generic-vnf/myid"); + try { + dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid"); + } finally { + engine.rollback(); + } + } + + @Test + public void verifyResourceVersion_MismatchRVTest() throws AAIException { + engine.startTransaction(); + + thrown.expect(AAIException.class); + thrown.expectMessage("resource-version MISMATCH for update of generic-vnfs/generic-vnf/myid"); + try { + dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver", "generic-vnfs/generic-vnf/myid"); + } finally { + engine.rollback(); + } + } + + @Test + public void trimClassNameTest() throws AAIException { + assertEquals("GenericVnf", dbser.trimClassName("GenericVnf")); + assertEquals("GenericVnf", dbser.trimClassName("org.onap.aai.GenericVnf")); + } + + @Test + public void getURIForVertexTest() throws AAIException, URISyntaxException, UnsupportedEncodingException { + engine.startTransaction(); + + Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123"); + Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453"); + EdgeRules rules = EdgeRules.getInstance(); + rules.addTreeEdge(engine.tx().traversal(), cr, ten); + + URI compare = new URI("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453"); + assertEquals(compare, dbser.getURIForVertex(ten)); + + cr.property("aai-node-type").remove(); + URI compareFailure = new URI("/unknown-uri"); + assertEquals(compareFailure, dbser.getURIForVertex(ten)); + engine.rollback(); + } + + @Test + public void getVertexPropertiesTest() throws AAIException, UnsupportedEncodingException { + engine.startTransaction(); + + Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123"); + + Introspector crIntro = dbser.getVertexProperties(cr); + assertEquals("cloud-region", crIntro.getDbName()); + assertEquals("me", crIntro.getValue("cloud-owner")); + assertEquals("123", crIntro.getValue("cloud-region-id")); + engine.rollback(); + } + + @Test + public void setCachedURIsTest() throws AAIException, UnsupportedEncodingException, URISyntaxException { + engine.startTransaction(); + + Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123"); + Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453"); + Vertex vs = engine.tx().addVertex("aai-node-type", "vserver", "vserver-id", "vs1", + AAIProperties.AAI_URI.toString(), + "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vs1"); + EdgeRules rules = EdgeRules.getInstance(); + rules.addTreeEdge(engine.tx().traversal(), cr, ten); + rules.addTreeEdge(engine.tx().traversal(), ten, vs); + + List<Vertex> vertices = new ArrayList<Vertex>(Arrays.asList(cr, ten, vs)); + Introspector crIn = dbser.getVertexProperties(cr); + Introspector tenIn = dbser.getVertexProperties(ten); + Introspector vsIn = dbser.getVertexProperties(vs); + List<Introspector> intros = new ArrayList<Introspector>(Arrays.asList(crIn, tenIn, vsIn)); + + dbser.setCachedURIs(vertices, intros); + + assertEquals("/cloud-infrastructure/cloud-regions/cloud-region/me/123", + (String)cr.property(AAIProperties.AAI_URI.toString()).value()); + assertEquals("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453", + (String)ten.property(AAIProperties.AAI_URI.toString()).value()); + assertEquals("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vs1", + (String)vs.property(AAIProperties.AAI_URI.toString()).value()); + engine.rollback(); + } + + @Test + public void getEdgeBetweenTest() throws AAIException { + engine.startTransaction(); + + Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123"); + Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453"); + EdgeRules rules = EdgeRules.getInstance(); + rules.addTreeEdge(engine.tx().traversal(), cr, ten); + + Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr); + assertEquals("has", e.label()); + engine.rollback(); + } + + @Test + public void deleteEdgeTest() throws AAIException, UnsupportedEncodingException { + engine.startTransaction(); + + Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf"); + Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name"); + EdgeRules rules = EdgeRules.getInstance(); + rules.addEdge(engine.tx().traversal(), gvnf, vnfc); + + Introspector relData = loader.introspectorFromName("relationship-data"); + relData.setValue("relationship-key", "vnfc.vnfc-name"); + relData.setValue("relationship-value", "a-name"); + Introspector relationship = loader.introspectorFromName("relationship"); + relationship.setValue("related-to", "vnfc"); + relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name"); + relationship.setValue("relationship-data",relData); + + assertTrue(dbser.deleteEdge(relationship, gvnf)); + + assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext()); + assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext()); + engine.rollback(); + } + + @Test + public void createEdgeTest() throws AAIException, UnsupportedEncodingException { + engine.startTransaction(); + + Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf"); + Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name"); + + //sunny day case + Introspector relData = loader.introspectorFromName("relationship-data"); + relData.setValue("relationship-key", "vnfc.vnfc-name"); + relData.setValue("relationship-value", "a-name"); + Introspector relationship = loader.introspectorFromName("relationship"); + relationship.setValue("related-to", "vnfc"); + relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name"); + relationship.setValue("relationship-data",relData); + + assertTrue(dbser.createEdge(relationship, gvnf)); + assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext()); + assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext()); + + //rainy day case, edge to nonexistant object + Introspector relData2 = loader.introspectorFromName("relationship-data"); + relData2.setValue("relationship-key", "vnfc.vnfc-name"); + relData2.setValue("relationship-value", "b-name"); + Introspector relationship2 = loader.introspectorFromName("relationship"); + relationship2.setValue("related-to", "vnfc"); + relationship2.setValue("related-link", "/network/vnfcs/vnfc/b-name"); + relationship2.setValue("relationship-data",relData2); + + thrown.expect(AAIException.class); + thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name"); + try { + dbser.createEdge(relationship2, gvnf); + } finally { + engine.rollback(); + } + } + + @Test + public void serializeSingleVertexTopLevelTest() throws AAIException, UnsupportedEncodingException { + engine.startTransaction(); + + Introspector gvnf = loader.introspectorFromName("generic-vnf"); + Vertex gvnfVert = dbser.createNewVertex(gvnf); + + gvnf.setValue("vnf-id", "myvnf"); + dbser.serializeSingleVertex(gvnfVert, gvnf, "test"); + assertTrue(engine.tx().traversal().V().has("aai-node-type","generic-vnf").has("vnf-id","myvnf").hasNext()); + engine.rollback(); + } + + @Test + public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException { + engine.startTransaction(); + + Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123"); + Introspector tenIn = loader.introspectorFromName("tenant"); + Vertex ten = dbser.createNewVertex(tenIn); + EdgeRules rules = EdgeRules.getInstance(); + rules.addTreeEdge(engine.tx().traversal(), cr, ten); + + tenIn.setValue("tenant-id", "453"); + tenIn.setValue("tenant-name", "mytenant"); -} + dbser.serializeSingleVertex(ten, tenIn, "test"); + + assertTrue(engine.tx().traversal().V().has("aai-node-type","tenant").has("tenant-id","453").has("tenant-name","mytenant").hasNext()); + engine.rollback(); + } +}
\ No newline at end of file diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/appprops/titan-cached.properties b/aai-core/src/test/resources/bundleconfig-local/etc/appprops/titan-cached.properties new file mode 100644 index 00000000..2afe2234 --- /dev/null +++ b/aai-core/src/test/resources/bundleconfig-local/etc/appprops/titan-cached.properties @@ -0,0 +1,17 @@ +query.fast-property=true +# the following parameters are not reloaded automatically and require a manual bounce +storage.backend=inmemory +storage.hostname=mtanjv9aads01.nvp.cip.att.com,mtanjv9aads02.nvp.cip.att.com,mtanjv9aads03.nvp.cip.att.com + +#schema.default=none +storage.lock.wait-time=300 +storage.hbase.table=aaigraph-dev1.dev +storage.hbase.ext.zookeeper.znode.parent=/hbase-unsecure +#caching on +cache.db-cache = true +cache.db-cache-clean-wait = 20 +cache.db-cache-time = 180000 +cache.db-cache-size = 0.3 + +#load graphson file on startup +load.snapshot.file=false
\ No newline at end of file diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/appprops/titan-realtime.properties b/aai-core/src/test/resources/bundleconfig-local/etc/appprops/titan-realtime.properties new file mode 100644 index 00000000..9c5c0299 --- /dev/null +++ b/aai-core/src/test/resources/bundleconfig-local/etc/appprops/titan-realtime.properties @@ -0,0 +1,14 @@ +query.fast-property=true +# the following parameters are not reloaded automatically and require a manual bounce +storage.backend=inmemory +storage.hostname=mtanjv9aads01.nvp.cip.att.com,mtanjv9aads02.nvp.cip.att.com,mtanjv9aads03.nvp.cip.att.com + +#schema.default=none +storage.lock.wait-time=300 +storage.hbase.table=aaigraph-dev1.dev +storage.hbase.ext.zookeeper.znode.parent=/hbase-unsecure +# Setting db-cache to false ensure the fastest propagation of changes across servers +cache.db-cache = false + +#load graphson file on startup +load.snapshot.file=false
\ No newline at end of file diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v11.xml b/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v11.xml index 3822a54b..7daf12ab 100644 --- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v11.xml +++ b/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v11.xml @@ -4497,8 +4497,8 @@ <xml-element java-attribute="isParent" name="isParent" type="java.lang.Boolean" /> <xml-element java-attribute="usesResource" name="usesResource" type="java.lang.Boolean" /> <xml-element java-attribute="hasDelTarget" name="hasDelTarget" type="java.lang.Boolean" /> - <xml-element java-attribute="SVC-INFRA" name="SVC-INFRA" type="java.lang.String" /> - <xml-element java-attribute="SVC-INFRA-REV" name="SVC-INFRA-REV" type="java.lang.String" /> + <xml-element java-attribute="svcInfra" name="svcInfra" type="java.lang.String" /> + <xml-element java-attribute="svcInfraRev" name="svcInfraRev" type="java.lang.String" /> </java-attributes> </java-type> |