X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fserialization%2Fdb%2FVersionedScenariosTest.java;h=1dcdccbf5852e5c2e87fcc368e39acccd13fe17d;hb=fbb02159b84435cf37221ae8ae5e0045167be15a;hp=8e77c5499509ee089496fa4d182b3b8694774324;hpb=58f0fd2f6ef58de52e1f9a73540c1bb895c0d6e6;p=aai%2Faai-common.git diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/VersionedScenariosTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/VersionedScenariosTest.java index 8e77c549..1dcdccbf 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/db/VersionedScenariosTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/db/VersionedScenariosTest.java @@ -20,6 +20,18 @@ package org.onap.aai.serialization.db; +import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraphFactory; @@ -40,18 +52,6 @@ import org.onap.aai.setup.SchemaVersion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class VersionedScenariosTest extends AAISetup { @@ -108,8 +108,8 @@ public class VersionedScenariosTest extends AAISetup { */ private void initData() throws UnsupportedEncodingException, AAIException, URISyntaxException { engine.startTransaction(); - DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); - + DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); Introspector gvnf = loader.introspectorFromName("generic-vnf"); gvnf.setValue("vnf-id", "gvnf" + SOURCE_OF_TRUTH); @@ -132,27 +132,20 @@ public class VersionedScenariosTest extends AAISetup { QueryParser uriQuery = engine.getQueryBuilder().createQueryFromURI(new URI(gvnfUri)); serializer.serializeToDb(gvnf, gvnfV, uriQuery, "generic-vnf", gvnf.marshal(false)); - assertTrue("generic-vnf created", engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, gvnfUri) - .hasNext()); - assertTrue("source created", engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, lintSourceUri) - .hasNext()); - assertTrue("destination created", engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, lintDestinationUri) - .hasNext()); - - + assertTrue("generic-vnf created", engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfUri).hasNext()); + assertTrue("source created", engine.tx().traversal().V().has(AAIProperties.AAI_URI, lintSourceUri).hasNext()); + assertTrue("destination created", + engine.tx().traversal().V().has(AAIProperties.AAI_URI, lintDestinationUri).hasNext()); Introspector llDefault = loader.introspectorFromName("logical-link"); llDefault.setValue("link-name", "llDefault"); List relList = new ArrayList<>(); Introspector relationship = loader.introspectorFromName("relationship"); - //relationship.setValue("related-to", "l-interface"); + // relationship.setValue("related-to", "l-interface"); relationship.setValue("related-link", lintSourceUri); relList.add(relationship.getUnderlyingObject()); relationship = loader.introspectorFromName("relationship"); - //relationship.setValue("related-to", "l-interface"); + // relationship.setValue("related-to", "l-interface"); relationship.setValue("related-link", lintDestinationUri); relList.add(relationship.getUnderlyingObject()); Introspector relationshipList = loader.introspectorFromName("relationship-list"); @@ -163,20 +156,13 @@ public class VersionedScenariosTest extends AAISetup { uriQuery = engine.getQueryBuilder().createQueryFromURI(new URI(llDefaultUri)); serializer.serializeToDb(llDefault, llDefaultV, uriQuery, "logical-link", llDefault.marshal(false)); - assertTrue("logical-link created", engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, llDefaultUri) - .hasNext()); - assertTrue("default source relationship created",engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, llDefaultUri) - .both() - .has(AAIProperties.AAI_URI, lintSourceUri) - .hasNext()); - assertTrue("default destination relationship created", engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, llDefaultUri) - .both() - .has(AAIProperties.AAI_URI, lintDestinationUri) - .hasNext()); - + assertTrue("logical-link created", + engine.tx().traversal().V().has(AAIProperties.AAI_URI, llDefaultUri).hasNext()); + assertTrue("default source relationship created", engine.tx().traversal().V() + .has(AAIProperties.AAI_URI, llDefaultUri).both().has(AAIProperties.AAI_URI, lintSourceUri).hasNext()); + assertTrue("default destination relationship created", + engine.tx().traversal().V().has(AAIProperties.AAI_URI, llDefaultUri).both() + .has(AAIProperties.AAI_URI, lintDestinationUri).hasNext()); Introspector llLabeled = loader.introspectorFromName("logical-link"); llLabeled.setValue("link-name", "llLabeled"); @@ -199,179 +185,122 @@ public class VersionedScenariosTest extends AAISetup { uriQuery = engine.getQueryBuilder().createQueryFromURI(new URI(llLabeledUri)); serializer.serializeToDb(llLabeled, llLabeledV, uriQuery, "logical-link", llLabeled.marshal(false)); - assertTrue("logical-link created", engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, llLabeledUri) - .hasNext()); - assertTrue("labeled source relationship created",engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, llLabeledUri) - .both("org.onap.relationships.inventory.Source") - .has(AAIProperties.AAI_URI, lintSourceUri) - .hasNext()); - assertTrue("labeled destination relationship created", engine.tx().traversal().V() - .has(AAIProperties.AAI_URI, llLabeledUri) - .both("org.onap.relationships.inventory.Destination") - .has(AAIProperties.AAI_URI, lintDestinationUri) - .hasNext()); + assertTrue("logical-link created", + engine.tx().traversal().V().has(AAIProperties.AAI_URI, llLabeledUri).hasNext()); + assertTrue("labeled source relationship created", + engine.tx().traversal().V().has(AAIProperties.AAI_URI, llLabeledUri) + .both("org.onap.relationships.inventory.Source").has(AAIProperties.AAI_URI, lintSourceUri) + .hasNext()); + assertTrue("labeled destination relationship created", + engine.tx().traversal().V().has(AAIProperties.AAI_URI, llLabeledUri) + .both("org.onap.relationships.inventory.Destination") + .has(AAIProperties.AAI_URI, lintDestinationUri).hasNext()); } - @Test public void verifyRelsOfLatestViewOfGenericVnf() throws AAIException, UnsupportedEncodingException { - DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); + DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); - String gvnfLatestView = serializer.getLatestVersionView( - engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfUri).next()).marshal(false); + String gvnfLatestView = + serializer.getLatestVersionView(engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfUri).next()) + .marshal(false); assertThat(gvnfLatestView, - hasJsonPath( - "$.l-interfaces.l-interface[*].relationship-list.relationship[*]", - hasSize(4) - )); + hasJsonPath("$.l-interfaces.l-interface[*].relationship-list.relationship[*]", hasSize(4))); assertThat(gvnfLatestView, - hasJsonPath( - "$.l-interfaces.l-interface[*].relationship-list.relationship[*].related-link", - containsInAnyOrder( - "/aai/" + schemaVersions.getDefaultVersion() + llDefaultUri, - "/aai/" + schemaVersions.getDefaultVersion() + llDefaultUri, - "/aai/" + schemaVersions.getDefaultVersion() + llLabeledUri, - "/aai/" + schemaVersions.getDefaultVersion() + llLabeledUri - ) - )); + hasJsonPath("$.l-interfaces.l-interface[*].relationship-list.relationship[*].related-link", + containsInAnyOrder("/aai/" + schemaVersions.getDefaultVersion() + llDefaultUri, + "/aai/" + schemaVersions.getDefaultVersion() + llDefaultUri, + "/aai/" + schemaVersions.getDefaultVersion() + llLabeledUri, + "/aai/" + schemaVersions.getDefaultVersion() + llLabeledUri))); assertThat(gvnfLatestView, - hasJsonPath( - "$.l-interfaces.l-interface[*].relationship-list.relationship[*].relationship-label", - containsInAnyOrder( - "tosca.relationships.network.LinksTo", - "tosca.relationships.network.LinksTo", - "org.onap.relationships.inventory.Source", - "org.onap.relationships.inventory.Destination") - )); + hasJsonPath("$.l-interfaces.l-interface[*].relationship-list.relationship[*].relationship-label", + containsInAnyOrder("tosca.relationships.network.LinksTo", "tosca.relationships.network.LinksTo", + "org.onap.relationships.inventory.Source", + "org.onap.relationships.inventory.Destination"))); } @Test public void verifyRelsOfLatestViewOfLLDefault() throws AAIException, UnsupportedEncodingException { - DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); + DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); - String llDefaultLatestView = serializer.getLatestVersionView( - engine.tx().traversal().V().has(AAIProperties.AAI_URI, llDefaultUri).next()).marshal(false); - assertThat(llDefaultLatestView, - hasJsonPath( - "$.relationship-list.relationship[*]", - hasSize(2) - )); - assertThat(llDefaultLatestView, - hasJsonPath( - "$.relationship-list.relationship[*].related-link", - containsInAnyOrder( - "/aai/" + schemaVersions.getDefaultVersion() + lintSourceUri, - "/aai/" + schemaVersions.getDefaultVersion() + lintDestinationUri - ) - )); + String llDefaultLatestView = serializer + .getLatestVersionView(engine.tx().traversal().V().has(AAIProperties.AAI_URI, llDefaultUri).next()) + .marshal(false); + assertThat(llDefaultLatestView, hasJsonPath("$.relationship-list.relationship[*]", hasSize(2))); assertThat(llDefaultLatestView, - hasJsonPath( - "$.relationship-list.relationship[*].relationship-label", - containsInAnyOrder("tosca.relationships.network.LinksTo","tosca.relationships.network.LinksTo") - )); - assertThat(llDefaultLatestView, - hasJsonPath( - "$.relationship-list.relationship[*].relationship-label", - not(contains("org.onap.relationships.inventory.Source", "org.onap.relationships.inventory.Destination")) - )); + hasJsonPath("$.relationship-list.relationship[*].related-link", + containsInAnyOrder("/aai/" + schemaVersions.getDefaultVersion() + lintSourceUri, + "/aai/" + schemaVersions.getDefaultVersion() + lintDestinationUri))); + assertThat(llDefaultLatestView, hasJsonPath("$.relationship-list.relationship[*].relationship-label", + containsInAnyOrder("tosca.relationships.network.LinksTo", "tosca.relationships.network.LinksTo"))); + assertThat(llDefaultLatestView, hasJsonPath("$.relationship-list.relationship[*].relationship-label", not( + contains("org.onap.relationships.inventory.Source", "org.onap.relationships.inventory.Destination")))); } @Test public void verifyRelsOfLatestViewOfLLLabeled() throws AAIException, UnsupportedEncodingException { - DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); + DBSerializer serializer = new DBSerializer(version, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); - String llLabeledLatestView = serializer.getLatestVersionView( - engine.tx().traversal().V().has(AAIProperties.AAI_URI, llLabeledUri).next()).marshal(false); - assertThat(llLabeledLatestView, - hasJsonPath( - "$.relationship-list.relationship[*]", - hasSize(2) - )); + String llLabeledLatestView = serializer + .getLatestVersionView(engine.tx().traversal().V().has(AAIProperties.AAI_URI, llLabeledUri).next()) + .marshal(false); + assertThat(llLabeledLatestView, hasJsonPath("$.relationship-list.relationship[*]", hasSize(2))); assertThat(llLabeledLatestView, - hasJsonPath( - "$.relationship-list.relationship[*].related-link", - containsInAnyOrder( - "/aai/" + schemaVersions.getDefaultVersion() + lintSourceUri, - "/aai/" + schemaVersions.getDefaultVersion() + lintDestinationUri - ) - )); - assertThat(llLabeledLatestView, - hasJsonPath( - "$.relationship-list.relationship[*].relationship-label", - not(containsInAnyOrder("tosca.relationships.network.LinksTo","tosca.relationships.network.LinksTo")) - )); - assertThat(llLabeledLatestView, - hasJsonPath( - "$.relationship-list.relationship[*].relationship-label", - contains("org.onap.relationships.inventory.Source", "org.onap.relationships.inventory.Destination") - )); + hasJsonPath("$.relationship-list.relationship[*].related-link", + containsInAnyOrder("/aai/" + schemaVersions.getDefaultVersion() + lintSourceUri, + "/aai/" + schemaVersions.getDefaultVersion() + lintDestinationUri))); + assertThat(llLabeledLatestView, hasJsonPath("$.relationship-list.relationship[*].relationship-label", + not(containsInAnyOrder("tosca.relationships.network.LinksTo", "tosca.relationships.network.LinksTo")))); + assertThat(llLabeledLatestView, hasJsonPath("$.relationship-list.relationship[*].relationship-label", + contains("org.onap.relationships.inventory.Source", "org.onap.relationships.inventory.Destination"))); } - @Test public void verifyRelsOfOldViewOfGenericVnf() throws AAIException, UnsupportedEncodingException { SchemaVersion oldVersion = new SchemaVersion("v11"); Loader oldLoader = loaderFactory.getLoaderStrategy(introspectorFactoryType, oldVersion); - DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); - - String gvnfOldView = oldSerializer.dbToObject( - Collections.singletonList(engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfUri).next()), - oldLoader.introspectorFromName("generic-vnf"), - AAIProperties.MAXIMUM_DEPTH, false, "false") - .marshal(false); + DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); + + String gvnfOldView = oldSerializer + .dbToObject( + Collections + .singletonList(engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfUri).next()), + oldLoader.introspectorFromName("generic-vnf"), AAIProperties.MAXIMUM_DEPTH, false, "false") + .marshal(false); assertThat(gvnfOldView, - hasJsonPath( - "$.l-interfaces.l-interface[*].relationship-list.relationship[*]", - hasSize(2) - )); + hasJsonPath("$.l-interfaces.l-interface[*].relationship-list.relationship[*]", hasSize(2))); assertThat(gvnfOldView, - hasJsonPath( - "$.l-interfaces.l-interface[*].relationship-list.relationship[*].relationship-label", - emptyCollectionOf(String.class) - )); + hasJsonPath("$.l-interfaces.l-interface[*].relationship-list.relationship[*].relationship-label", + emptyCollectionOf(String.class))); assertThat(gvnfOldView, - hasJsonPath( - "$.l-interfaces.l-interface[*].relationship-list.relationship[*].related-link", - containsInAnyOrder( - "/aai/" + oldVersion + llDefaultUri, - "/aai/" + oldVersion + llDefaultUri - ) - )); + hasJsonPath("$.l-interfaces.l-interface[*].relationship-list.relationship[*].related-link", + containsInAnyOrder("/aai/" + oldVersion + llDefaultUri, "/aai/" + oldVersion + llDefaultUri))); } @Test public void verifyRelsOfOldViewOfLLDefault() throws AAIException, UnsupportedEncodingException { SchemaVersion oldVersion = new SchemaVersion("v11"); Loader oldLoader = loaderFactory.getLoaderStrategy(introspectorFactoryType, oldVersion); - DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); - - String llDefaultOldView = oldSerializer.dbToObject( - Collections.singletonList(engine.tx().traversal().V().has(AAIProperties.AAI_URI, llDefaultUri).next()), - oldLoader.introspectorFromName("logical-link"), - AAIProperties.MAXIMUM_DEPTH, false, "false") - .marshal(false); - assertThat(llDefaultOldView, - hasJsonPath( - "$.relationship-list.relationship[*]", - hasSize(2) - )); + DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); + + String llDefaultOldView = oldSerializer + .dbToObject( + Collections.singletonList( + engine.tx().traversal().V().has(AAIProperties.AAI_URI, llDefaultUri).next()), + oldLoader.introspectorFromName("logical-link"), AAIProperties.MAXIMUM_DEPTH, false, "false") + .marshal(false); + assertThat(llDefaultOldView, hasJsonPath("$.relationship-list.relationship[*]", hasSize(2))); assertThat(llDefaultOldView, - hasJsonPath( - "$.relationship-list.relationship[*].relationship-label", - emptyCollectionOf(String.class) - )); - assertThat(llDefaultOldView, - hasJsonPath( - "$.relationship-list.relationship[*].related-link", - containsInAnyOrder( - "/aai/" + oldVersion + lintSourceUri, - "/aai/" + oldVersion + lintDestinationUri - ) - )); + hasJsonPath("$.relationship-list.relationship[*].relationship-label", emptyCollectionOf(String.class))); + assertThat(llDefaultOldView, hasJsonPath("$.relationship-list.relationship[*].related-link", + containsInAnyOrder("/aai/" + oldVersion + lintSourceUri, "/aai/" + oldVersion + lintDestinationUri))); } @@ -379,39 +308,32 @@ public class VersionedScenariosTest extends AAISetup { public void verifyRelsOfOldViewOfLLLabeled() throws AAIException, UnsupportedEncodingException { SchemaVersion oldVersion = new SchemaVersion("v11"); Loader oldLoader = loaderFactory.getLoaderStrategy(introspectorFactoryType, oldVersion); - DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); - - String llLabeledtOldView = oldSerializer.dbToObject( - Collections.singletonList(engine.tx().traversal().V().has(AAIProperties.AAI_URI, llLabeledUri).next()), - oldLoader.introspectorFromName("logical-link"), - AAIProperties.MAXIMUM_DEPTH, false, "false") - .marshal(false); - assertThat(llLabeledtOldView, - not(hasJsonPath( - "$.relationship-list.relationship[*]" - ))); + DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); + + String llLabeledtOldView = oldSerializer + .dbToObject( + Collections.singletonList( + engine.tx().traversal().V().has(AAIProperties.AAI_URI, llLabeledUri).next()), + oldLoader.introspectorFromName("logical-link"), AAIProperties.MAXIMUM_DEPTH, false, "false") + .marshal(false); + assertThat(llLabeledtOldView, not(hasJsonPath("$.relationship-list.relationship[*]"))); } - @Test - public void useOldVersionToUpdatedGenericVnfAndVerifyLatestVersionRels() throws AAIException, UnsupportedEncodingException, URISyntaxException { + public void useOldVersionToUpdatedGenericVnfAndVerifyLatestVersionRels() + throws AAIException, UnsupportedEncodingException, URISyntaxException { SchemaVersion oldVersion = new SchemaVersion("v11"); Loader oldLoader = loaderFactory.getLoaderStrategy(introspectorFactoryType, oldVersion); - DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, AAIProperties.MINIMUM_DEPTH); + DBSerializer oldSerializer = new DBSerializer(oldVersion, engine, introspectorFactoryType, SOURCE_OF_TRUTH, + AAIProperties.MINIMUM_DEPTH); Vertex oldGvnfV = engine.tx().traversal().V().has(AAIProperties.AAI_URI, gvnfUri).next(); - Introspector oldGvnf = oldSerializer.dbToObject( - Collections.singletonList(oldGvnfV), - oldLoader.introspectorFromName("generic-vnf"), - AAIProperties.MAXIMUM_DEPTH, false, "false"); + Introspector oldGvnf = oldSerializer.dbToObject(Collections.singletonList(oldGvnfV), + oldLoader.introspectorFromName("generic-vnf"), AAIProperties.MAXIMUM_DEPTH, false, "false"); assertThat(oldGvnf.marshal(false), - hasJsonPath( - "$.l-interfaces.l-interface[*].relationship-list.relationship[*].related-link", - containsInAnyOrder( - "/aai/" + oldVersion + llDefaultUri, - "/aai/" + oldVersion + llDefaultUri - ) - )); + hasJsonPath("$.l-interfaces.l-interface[*].relationship-list.relationship[*].related-link", + containsInAnyOrder("/aai/" + oldVersion + llDefaultUri, "/aai/" + oldVersion + llDefaultUri))); oldGvnf.setValue("in-maint", true); QueryParser uriQuery = engine.getQueryBuilder().createQueryFromURI(new URI(gvnfUri)); oldSerializer.serializeToDb(oldGvnf, oldGvnfV, uriQuery, "generic-vnf", oldGvnf.marshal(false)); @@ -420,7 +342,4 @@ public class VersionedScenariosTest extends AAISetup { verifyRelsOfOldViewOfGenericVnf(); } - - - }