diff options
author | Kajur, Harish (vk250x) <vk250x@att.com> | 2018-03-21 19:51:39 -0400 |
---|---|---|
committer | Kajur, Harish (vk250x) <vk250x@att.com> | 2018-03-28 16:02:27 -0400 |
commit | 6da2faa2bbf183f43365ddad786a5aa945d5ed98 (patch) | |
tree | 7b02f35f0b5932e418ae45aaffacd15d737dd432 | |
parent | 248c5f89fdf9505c2e81129ad7d95c0ee86de517 (diff) |
Update the titan code to janus graph code
Issue-ID: AAI-949
Change-Id: Iabb282fb808742d2cc09791a189a5372a01f5be2
Signed-off-by: Kajur, Harish (vk250x) <vk250x@att.com>
23 files changed, 963 insertions, 545 deletions
diff --git a/aai-traversal/pom.xml b/aai-traversal/pom.xml index 73e4137..e6d7dbd 100644 --- a/aai-traversal/pom.xml +++ b/aai-traversal/pom.xml @@ -80,8 +80,8 @@ <hamcrest.junit.version>2.0.0.0</hamcrest.junit.version> <janino.version>2.7.8</janino.version> <google.guava.version>16.0</google.guava.version> - <titan.version>1.0.0</titan.version> - <gremlin.driver.version>3.0.1-incubating</gremlin.driver.version> + <janusgraph.version>0.2.0</janusgraph.version> + <gremlin.version>3.2.2</gremlin.version> <hbase.version>1.0.2</hbase.version> <smack.version>3.0.4</smack.version> <json.simple.version>1.1.1</json.simple.version> @@ -119,7 +119,7 @@ <!-- Location where assembly of our scripts, resources and main jar will be held - Check the aai-traversal/src/main/assembly/descriptor.xml for more info + Check the aai-traversal/src/main/assembly/descriptor.xml for more info --> <aai.build.directory>${project.build.directory}/${project.artifactId}-${project.version}-build/ </aai.build.directory> @@ -152,6 +152,8 @@ <antlr4.visitor>true</antlr4.visitor> <antlr4.listener>true</antlr4.listener> <antlr.version>4.7</antlr.version> + + <jacoco.line.coverage.limit>0.66</jacoco.line.coverage.limit> </properties> <profiles> <!-- Docker profile to be used for building docker image and pushing to nexus --> @@ -387,9 +389,9 @@ <version>${google.guava.version}</version> </dependency> <dependency> - <groupId>com.thinkaurelius.titan</groupId> - <artifactId>titan-core</artifactId> - <version>${titan.version}</version> + <groupId>org.janusgraph</groupId> + <artifactId>janusgraph-core</artifactId> + <version>${janusgraph.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> @@ -398,9 +400,9 @@ </exclusions> </dependency> <dependency> - <groupId>com.thinkaurelius.titan</groupId> - <artifactId>titan-cassandra</artifactId> - <version>${titan.version}</version> + <groupId>org.janusgraph</groupId> + <artifactId>janusgraph-cassandra</artifactId> + <version>${janusgraph.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> @@ -409,9 +411,9 @@ </exclusions> </dependency> <dependency> - <groupId>com.thinkaurelius.titan</groupId> - <artifactId>titan-hbase</artifactId> - <version>${titan.version}</version> + <groupId>org.janusgraph</groupId> + <artifactId>janusgraph-hbase</artifactId> + <version>${janusgraph.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> @@ -419,11 +421,10 @@ </exclusion> </exclusions> </dependency> - <dependency> <groupId>org.apache.tinkerpop</groupId> <artifactId>gremlin-driver</artifactId> - <version>${gremlin.driver.version}</version> + <version>${gremlin.version}</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> @@ -716,6 +717,10 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>log4j-over-slf4j</artifactId> + </exclusion> </exclusions> </dependency> <dependency> @@ -765,7 +770,27 @@ </exclusion> </exclusions> </dependency> - + <dependency> + <groupId>org.apache.tinkerpop</groupId> + <artifactId>gremlin-core</artifactId> + <version>${gremlin.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.tinkerpop</groupId> + <artifactId>tinkergraph-gremlin</artifactId> + <version>${gremlin.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tinkerpop</groupId> + <artifactId>gremlin-groovy</artifactId> + <version>${gremlin.version}</version> + </dependency> </dependencies> <build> <resources> @@ -796,8 +821,8 @@ <resource> <directory>${project.basedir}/src/main/resources/etc/appprops/</directory> <includes> - <include>titan-realtime.properties</include> - <include>titan-cached.properties</include> + <include>janusgraph-realtime.properties</include> + <include>janusgraph-cached.properties</include> <include>aaiconfig.properties</include> </includes> <targetPath>${project.build.directory}/swm/package/nix/dist_files/opt/app/aai-traversal/appconfig @@ -841,32 +866,25 @@ <version>2.8</version> <executions> <execution> - <id>copy-agent</id> - <phase>process-test-classes</phase> - <goals> - <goal>copy</goal> - </goals> - </execution> - <execution> <id>unpack-schema-dependency</id> <phase>initialize</phase> <goals> <goal>unpack</goal> </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>org.onap.aai.aai-common</groupId> + <artifactId>aai-schema</artifactId> + <version>${aai.core.version}</version> + <outputDirectory>${project.basedir}/src/main/resources/etc/</outputDirectory> + <includes>oxm/*.xml</includes> + </artifactItem> + </artifactItems> + <!-- other configurations here --> + </configuration> </execution> </executions> - <configuration> - <artifactItems> - <artifactItem> - <groupId>org.onap.aai.aai-common</groupId> - <artifactId>aai-schema</artifactId> - <version>${aai.core.version}</version> - <outputDirectory>${project.basedir}/src/main/resources/etc</outputDirectory> - <includes>oxm/*.xml</includes> - </artifactItem> - </artifactItems> - <!-- other configurations here --> - </configuration> </plugin> <plugin> <groupId>org.codehaus.groovy.maven</groupId> @@ -992,6 +1010,28 @@ <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory> </configuration> </execution> + <execution> + <id>default-check</id> + <goals> + <goal>check</goal> + </goals> + <configuration> + <dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile> + <rules> + <!-- implementation is needed only for Maven 2 --> + <rule implementation="org.jacoco.maven.RuleConfiguration"> + <element>BUNDLE</element> + <limits> + <limit implementation="org.jacoco.report.check.Limit"> + <counter>LINE</counter> + <value>COVEREDRATIO</value> + <minimum>${jacoco.line.coverage.limit}</minimum> + </limit> + </limits> + </rule> + </rules> + </configuration> + </execution> </executions> </plugin> <plugin> diff --git a/aai-traversal/src/main/assembly/descriptor.xml b/aai-traversal/src/main/assembly/descriptor.xml index c0dc10e..08e253f 100644 --- a/aai-traversal/src/main/assembly/descriptor.xml +++ b/aai-traversal/src/main/assembly/descriptor.xml @@ -9,21 +9,21 @@ <fileSets> <fileSet> <directory>${project.basedir}/src/main/resources</directory> - <outputDirectory>/resources</outputDirectory> + <outputDirectory>./resources</outputDirectory> <includes> <include>**/*</include> </includes> </fileSet> <fileSet> <directory>${project.basedir}/src/main/scripts</directory> - <outputDirectory>/bin</outputDirectory> + <outputDirectory>./bin</outputDirectory> <includes> <include>**/*</include> </includes> </fileSet> <fileSet> <directory>${project.build.directory}</directory> - <outputDirectory>/lib</outputDirectory> + <outputDirectory>./lib</outputDirectory> <includes> <include>${project.artifactId}-${project.version}.jar</include> </includes> diff --git a/aai-traversal/src/main/docker/docker-entrypoint.sh b/aai-traversal/src/main/docker/docker-entrypoint.sh index efaba95..8e52f0b 100644 --- a/aai-traversal/src/main/docker/docker-entrypoint.sh +++ b/aai-traversal/src/main/docker/docker-entrypoint.sh @@ -35,10 +35,6 @@ USER_ID=${LOCAL_USER_ID:-9001} GROUP_ID=${LOCAL_GROUP_ID:-9001} if [ $(cat /etc/passwd | grep aaiadmin | wc -l) -eq 0 ]; then - - ln -s bin scripts - ln -s /opt/aai/logroot/AAI-GQ logs - groupadd aaiadmin -g ${GROUP_ID} || { echo "Unable to create the group id for ${GROUP_ID}"; exit 1; @@ -53,7 +49,12 @@ chown -R aaiadmin:aaiadmin /opt/app /opt/aai/logroot /var/chef find /opt/app/ -name "*.sh" -exec chmod +x {} + if [ -f ${APP_HOME}/aai.sh ]; then + + gosu aaiadmin ln -s bin scripts + gosu aaiadmin ln -s /opt/aai/logroot/AAI-GQ logs + mv ${APP_HOME}/aai.sh /etc/profile.d/aai.sh + chmod 755 /etc/profile.d/aai.sh fi; @@ -114,6 +115,6 @@ JAVA_OPTS="${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom"; JAVA_OPTS="${JAVA_OPTS} -Dloader.path=$APP_HOME/resources"; JAVA_OPTS="${JAVA_OPTS} ${POST_JAVA_OPTS}"; -JAVA_MAIN_JAR=$(ls lib/aai-traversal-*SNAPSHOT.jar); +JAVA_MAIN_JAR=$(ls lib/aai-traversal*.jar); ${JAVA_CMD} ${JVM_OPTS} ${JAVA_OPTS} -jar ${JAVA_MAIN_JAR}; diff --git a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java index c986aa4..419743b 100644 --- a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java +++ b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java @@ -67,7 +67,7 @@ import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.db.EdgeRule; import org.onap.aai.serialization.db.EdgeRules; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; @@ -521,7 +521,7 @@ public class SearchGraph { MoxyLoader loader = (MoxyLoader)LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST); DynamicJAXBContext jaxbContext = loader.getJAXBContext(); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( QueryStyle.TRAVERSAL, connectionType, loader); @@ -641,7 +641,7 @@ public class SearchGraph { MoxyLoader loader = (MoxyLoader) LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST); DynamicJAXBContext jaxbContext = loader.getJAXBContext(); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( QueryStyle.TRAVERSAL, connectionType, loader); diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java index 73f6f50..e1d4400 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java @@ -53,7 +53,7 @@ import org.onap.aai.restcore.HttpMethod; import org.onap.aai.restcore.RESTAPI; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; import org.onap.aai.util.AAIConstants; @@ -153,7 +153,7 @@ public class SearchProvider extends RESTAPI { } final ModelType factoryType = ModelType.MOXY; Loader loader = LoaderFactory.createLoaderForVersion(factoryType, version); - TransactionalGraphEngine dbEngine = new TitanDBEngine( + TransactionalGraphEngine dbEngine = new JanusGraphDBEngine( QueryStyle.TRAVERSAL, type, loader); @@ -287,7 +287,7 @@ public class SearchProvider extends RESTAPI { } final ModelType factoryType = ModelType.MOXY; Loader loader = LoaderFactory.createLoaderForVersion(factoryType, version); - TransactionalGraphEngine dbEngine = new TitanDBEngine( + TransactionalGraphEngine dbEngine = new JanusGraphDBEngine( QueryStyle.TRAVERSAL, type, loader); diff --git a/aai-traversal/src/main/resources/etc/appprops/error.properties b/aai-traversal/src/main/resources/etc/appprops/error.properties index ba71275..d25a2bf 100644 --- a/aai-traversal/src/main/resources/etc/appprops/error.properties +++ b/aai-traversal/src/main/resources/etc/appprops/error.properties @@ -67,7 +67,7 @@ AAI_5107=5:2:WARN:5107:400:3000:Required information missing AAI_5108=5:2:WARN:5108:200:0:Unexpected information in request being ignored #--- aaidbgen: 6101-6199 -AAI_6101=5:4:ERROR:6101:500:3002:null TitanGraph object passed +AAI_6101=5:4:ERROR:6101:500:3002:null JanusGraph object passed AAI_6102=5:4:WARN:6102:400:3000:Passed-in property is not valid for this nodeType AAI_6103=5:4:WARN:6103:400:3000:Required Node-property not found in input data AAI_6104=5:4:WARN:6104:400:3000:Required Node-property was passed with no data diff --git a/aai-traversal/src/main/resources/etc/appprops/titan-cached.properties b/aai-traversal/src/main/resources/etc/appprops/janusgraph-cached.properties index 0106788..aecea7c 100644 --- a/aai-traversal/src/main/resources/etc/appprops/titan-cached.properties +++ b/aai-traversal/src/main/resources/etc/appprops/janusgraph-cached.properties @@ -21,11 +21,15 @@ # query.fast-property=true +query.smart-limit=false # the following parameters are not reloaded automatically and require a manual bounce #storage.backend=inmemory storage.backend=inmemory storage.hostname=localhost +#explicit Titan version in use - added for JanusGraph migration +#graph.titan-version=1.0.0 + #schema.default=none storage.lock.wait-time=300 storage.hbase.table=aaigraph-dev02 diff --git a/aai-traversal/src/main/resources/etc/appprops/titan-realtime.properties b/aai-traversal/src/main/resources/etc/appprops/janusgraph-realtime.properties index ace08b3..9e64ac2 100644 --- a/aai-traversal/src/main/resources/etc/appprops/titan-realtime.properties +++ b/aai-traversal/src/main/resources/etc/appprops/janusgraph-realtime.properties @@ -21,11 +21,15 @@ # query.fast-property=true +query.smart-limit=false # the following parameters are not reloaded automatically and require a manual bounce #storage.backend=inmemory storage.backend=inmemory storage.hostname=localhost +#explicit Titan version in use - added for JanusGraph migration +#graph.titan-version=1.0.0 + #schema.default=none storage.lock.wait-time=300 storage.hbase.table=aaigraph-dev02 diff --git a/aai-traversal/src/main/resources/etc/query/stored-queries.json b/aai-traversal/src/main/resources/etc/query/stored-queries.json index 8d18fd7..6c61246 100644 --- a/aai-traversal/src/main/resources/etc/query/stored-queries.json +++ b/aai-traversal/src/main/resources/etc/query/stored-queries.json @@ -31,7 +31,7 @@ } },{ "pnf-topology":{ - "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'pnf', 'p-interface').where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link')).as('item').store('x').createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link').store('x').createEdgeTraversal(EdgeType.COUSIN, 'physical-link', 'p-interface').where(builder.newInstance().not(builder.newInstance().cap('item'))).store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pnf').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pnf', 'complex').store('x')).cap('x').unfold().dedup()" + "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'pnf', 'p-interface').where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link')).as('item').store('x').createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link').store('x').createEdgeTraversal(EdgeType.COUSIN, 'physical-link', 'p-interface').store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pserver').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pnf').store('x')),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pnf', 'complex').store('x')).cap('x').unfold().dedup()" } },{ "so-request-vfModule":{ @@ -185,7 +185,7 @@ } },{ "ucpe-topology":{ - "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'pserver', 'p-interface').where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link')).as('item').store('x').createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link').store('x').createEdgeTraversal(EdgeType.COUSIN, 'physical-link', 'p-interface').where(builder.newInstance().not(builder.newInstance().cap('item'))).store('x').createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'generic-vnf').store('x').as('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnf-image').store('x').select('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'complex').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'vserver').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').as('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnf-image').store('x').select('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x')).cap('x').unfold().dedup()" + "stored-query":"builder.store('x').union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'pserver', 'p-interface').where(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link')).as('item').store('x').createEdgeTraversal(EdgeType.COUSIN, 'p-interface', 'physical-link').store('x').createEdgeTraversal(EdgeType.COUSIN, 'physical-link', 'p-interface').store('x').createEdgeTraversal(EdgeType.TREE, 'p-interface', 'pnf').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'generic-vnf').store('x').as('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnf-image').store('x').select('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'complex').store('x'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'pserver', 'vserver').createEdgeTraversal(EdgeType.COUSIN, 'vserver', 'generic-vnf').store('x').as('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vnf-image').store('x').select('vnf').createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'service-instance').store('x').createEdgeTraversal(EdgeType.TREE, 'service-instance', 'service-subscription').store('x').createEdgeTraversal(EdgeType.TREE, 'service-subscription', 'customer').store('x')).cap('x').unfold().dedup()" } },{ "topology-summary":{ diff --git a/aai-traversal/src/main/resources/logback.xml b/aai-traversal/src/main/resources/logback.xml index 4bdc015..7947f8f 100644 --- a/aai-traversal/src/main/resources/logback.xml +++ b/aai-traversal/src/main/resources/logback.xml @@ -373,7 +373,7 @@ <logger name="org.apache" level="WARN" /> <logger name="org.zookeeper" level="WARN" /> - <logger name="com.thinkaurelius" level="WARN" /> + <logger name="org.janusgraph" level="WARN" /> <logger name="com.att.aft.dme2" level="WARN" /> <!-- ============================================================================ --> diff --git a/aai-traversal/src/main/swm/package/nix/dist_files/opt/app/aai-traversal/docker-compose.template.yaml b/aai-traversal/src/main/swm/package/nix/dist_files/opt/app/aai-traversal/docker-compose.template.yaml index 74ae555..7d31b8b 100644 --- a/aai-traversal/src/main/swm/package/nix/dist_files/opt/app/aai-traversal/docker-compose.template.yaml +++ b/aai-traversal/src/main/swm/package/nix/dist_files/opt/app/aai-traversal/docker-compose.template.yaml @@ -42,8 +42,8 @@ services: - /opt/app/aai-traversal/appconfig/dme2.properties:/opt/app/aai-traversal/resources/dme2.properties - /opt/app/aai-traversal/appconfig/localhost-access-logback.xml:/opt/app/aai-traversal/resources/localhost-access-logback.xml - /opt/app/aai-traversal/appconfig/logback.xml:/opt/app/aai-traversal/resources/logback.xml - - /opt/app/aai-traversal/appconfig/titan-cached.properties:/opt/app/aai-traversal/resources/etc/appprops/titan-cached.properties - - /opt/app/aai-traversal/appconfig/titan-realtime.properties:/opt/app/aai-traversal/resources/etc/appprops/titan-realtime.properties + - /opt/app/aai-traversal/appconfig/janusgraph-cached.properties:/opt/app/aai-traversal/resources/etc/appprops/janusgraph-cached.properties + - /opt/app/aai-traversal/appconfig/janusgraph-realtime.properties:/opt/app/aai-traversal/resources/etc/appprops/janusgraph-realtime.properties logging: driver: "json-file" options: diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java index d0e8725..62bc7ce 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java @@ -29,12 +29,12 @@ import com.bazaarvoice.jolt.modifier.DataType; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; -import com.thinkaurelius.titan.graphdb.olap.computer.VertexMapJob; -import com.thinkaurelius.titan.graphdb.types.VertexLabelVertex; -import com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel; -import com.thinkaurelius.titan.graphdb.types.system.EmptyVertex; -import com.thinkaurelius.titan.graphdb.types.vertices.EdgeLabelVertex; -import com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex; +import org.janusgraph.graphdb.olap.computer.VertexMapJob; +import org.janusgraph.graphdb.types.VertexLabelVertex; +import org.janusgraph.graphdb.types.system.BaseVertexLabel; +import org.janusgraph.graphdb.types.system.EmptyVertex; +import org.janusgraph.graphdb.types.vertices.EdgeLabelVertex; +import org.janusgraph.graphdb.types.vertices.PropertyKeyVertex; import org.apache.commons.lang.ObjectUtils; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.T; diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java index ca7e1a2..afb9b17 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,524 +16,891 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.dbgraphgen; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import com.bazaarvoice.jolt.modifier.DataType; +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.*; -import org.mockito.internal.exceptions.MockitoLimitations; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.aai.db.DbMethHelper; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.onap.aai.db.props.AAIProperties; +import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; +import org.onap.aai.introspection.Version; import org.onap.aai.parsers.exceptions.AAIIdentityMapParseException; -import org.onap.aai.query.builder.GraphTraversalBuilder; -import org.onap.aai.query.builder.QueryBuilder; -import org.onap.aai.query.builder.TraversalQuery; -import org.onap.aai.schema.enums.PropertyMetadata; import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.db.EdgeType; +import org.onap.aai.serialization.db.EdgeRules; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import org.powermock.modules.junit4.PowerMockRunner; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -@RunWith(MockitoJUnitRunner.class) public class ModelBasedProcessingTest { - @Mock private static TransactionalGraphEngine dbEngine; + private static final Version version = Version.getLatest(); + private static final ModelType introspectorFactoryType = ModelType.MOXY; + private static final QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private static final DBConnectionType type = DBConnectionType.REALTIME; + + private static final String TRANSACTION_ID = "transaction-1"; + private static final String FROM_APP_ID = "JUNIT"; + private static final String API_VERSION = "1.0"; + private static final String AAI_NODE_TYPE = "aai-node-type"; + + private static final String MODEL_VESION_NODE_VALUE = "model-ver"; + private static final String MODEL_VERSION_ID_KEY = "model-version-id"; + private static final String MODEL_VERSION_ID_VALUE = "model-version-id-1"; + + private static final String MODEL_INVARIANT_ID_NODE_VALUE = "model-invariant-id-local"; + private static final String MODEL_INVARIANT_ID_KEY = "model-invariant-id-local"; + private static final String MODEL_INVARIANT_ID_VALUE = "model-invariant-id-1"; + + private static final String MODEL_NAME_NODE_VALUE = "model-name"; + private static final String MODEL_NAME_ID_KEY = "model-name"; + private static final String MODEL_NAME_ID_VALUE = "generic-vnf"; + + + private static TransactionalGraphEngine dbEngine; + private static TransactionalGraphEngine.Admin admin; + DBSerializer serializer; private static Loader loader; - @Mock private static DBSerializer serializer; - @Mock private static TransactionalGraphEngine.Admin admin; - ModelBasedProcessing mockProcessor; - @Mock - private DbMethHelper dbMethHelper; - + EdgeRules rules; + + ModelBasedProcessing modelBasedProcessor; + + GraphTraversalSource source; + + Graph graph; + + Vertex model; + Vertex modelVersion; + Vertex modelElement; + Vertex constrainedElementSet; + Vertex namedQueryElement; + Vertex linkagePoints; + Vertex namedQuery; + @BeforeClass public static void configure() throws Exception { System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST); - } - + @Before - public void init() { - mockProcessor = new ModelBasedProcessing(loader, dbEngine, serializer); - + public void init() throws AAIException { MockitoAnnotations.initMocks(this); + rules = EdgeRules.getInstance(); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, AAIProperties.LATEST); + TransactionalGraphEngine newDbEngine = new JanusGraphDBEngine(queryStyle, type, loader); + dbEngine = Mockito.spy(newDbEngine); + serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); + admin = Mockito.spy(dbEngine.asAdmin()); + modelBasedProcessor = new ModelBasedProcessing(loader, dbEngine, serializer); + graph = TinkerGraph.open(); + source = createGraph(); } - + + private GraphTraversalSource createGraph() throws AAIException { + model = graph.addVertex(T.label, "model", T.id, "0", AAI_NODE_TYPE, "model", "model-invariant-id", "model-invariant-id-1", "model-type", "widget"); + modelVersion = graph.addVertex(T.label, MODEL_VESION_NODE_VALUE, T.id, "1", AAI_NODE_TYPE, MODEL_VESION_NODE_VALUE, MODEL_VERSION_ID_KEY, + MODEL_VERSION_ID_VALUE,MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE, "model-version", "model-version-1"); + graph.addVertex(T.label, MODEL_INVARIANT_ID_NODE_VALUE, T.id, "2", MODEL_INVARIANT_ID_KEY, MODEL_INVARIANT_ID_VALUE, "model-version-id-local", MODEL_VERSION_ID_VALUE); + namedQuery = graph.addVertex(T.label, "named-query", T.id, "3","aai-node-type", "named-query", "named-query-uuid", "named-query-uuid-1"); + graph.addVertex(T.label, MODEL_NAME_NODE_VALUE, T.id, "4", AAI_NODE_TYPE, MODEL_NAME_NODE_VALUE, MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE); + modelElement = graph.addVertex(T.label, "model-element", T.id, "5", AAI_NODE_TYPE, "model-element"); + Vertex modelConstraint = graph.addVertex(T.label, "model-constraint", T.id, "6", AAI_NODE_TYPE, "model-constraint","constrained-element-set-uuid-2-replace","cesu2r-1"); + constrainedElementSet = graph.addVertex(T.label, "constrained-element-set", T.id, "7", AAI_NODE_TYPE, "constrained-element-set"); + Vertex elementChoiceSet = graph.addVertex(T.label, "element-choice-set", T.id, "8", AAI_NODE_TYPE, "element-choice-set"); + namedQueryElement = graph.addVertex(T.label, "named-query-element", T.id, "9","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + linkagePoints = graph.addVertex(T.label, "linkage-points", T.id, "10", AAI_NODE_TYPE, "linkage-points", "linkage-points", getArrayListAsString(), + "new-data-del-flag", "F"); + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, model, modelVersion); + rules.addTreeEdge(g, modelElement, modelConstraint); + rules.addTreeEdge(g, constrainedElementSet, modelConstraint); + rules.addTreeEdge(g, modelVersion, modelElement); + rules.addTreeEdge(g, modelElement, constrainedElementSet); + rules.addTreeEdge(g, constrainedElementSet, elementChoiceSet); + rules.addTreeEdge(g, modelElement, elementChoiceSet); + rules.addTreeEdge(g, namedQuery, namedQueryElement); + rules.addTreeEdge(g, namedQueryElement, namedQueryElement); + rules.addEdge(g, modelVersion, modelElement); + rules.addEdge(g, model, namedQueryElement); + return g; + } + + @Test(expected=AAIException.class) + public void testGetStartNodesAndModVersionIds_NullId_ExpectException() throws AAIException { + List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); + String passedModelVerId = null; + String passedModelInvId = null; + String passedModelName = null; + modelBasedProcessor.getStartNodesAndModVersionIds("9999","postmen",passedModelVerId,passedModelInvId, + passedModelName,"generic-vnf",startNodeFilterArrayOfHashes,""); + } + @Test - public void testPropNameChange1() throws AAIUnknownObjectException { - String result; - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - result = processor.getPropNameWithAliasIfNeeded("generic-vnf", "model-invariant-id"); - assertEquals("result has -local tacked on the end as it should", "model-invariant-id" + AAIProperties.DB_ALIAS_SUFFIX, result); - result = processor.getPropNameWithAliasIfNeeded("generic-vnf", "vnf-id"); - assertEquals("result does NOT have -local tacked on the end as it should", "vnf-id", result); - result = processor.getPropNameWithAliasIfNeeded("generic-vnf", "model-invariant-id" + AAIProperties.DB_ALIAS_SUFFIX); - assertEquals("property not modified because it already includes the right suffix", "model-invariant-id" + AAIProperties.DB_ALIAS_SUFFIX, result); + public void testGetStartNodesAndModVersionIds_ModelVersion() throws AAIException { + + List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); + String passedModelInvId = null; + String passedModelName = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID, MODEL_VERSION_ID_VALUE, passedModelInvId, passedModelName, + AAI_NODE_TYPE, startNodeFilterArrayOfHashes, API_VERSION); } - - @Mock - GraphTraversal<Vertex, Vertex> v; - @Mock - GraphTraversal<Vertex, Vertex> graphTraversal; - @Mock - GraphTraversalSource graphTraversalSource; - @Mock Iterable <?> uniqVerts; - List<Vertex> vertexList=new ArrayList<>(); - @Mock Vertex vertex; - @Mock Vertex vertex1; - @Mock - QueryBuilder<Vertex> queryBuilder; - - EdgeType treeType; - @Test(expected = NullPointerException.class) - public void getStartNodesAndModVersionIds() throws AAIException{ - - vertex.property("model-ver","model-version-id"); - vertex1.property(AAIProperties.NODE_TYPE,"model-ver"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"model-ver")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("model-ver","model-version-id")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - //this.engine.getQueryBuilder(startV).createEdgeTraversal(treeType, startV, loader.introspectorFromName(connectedNodeType)); - - queryBuilder.toList().add(vertex); - Mockito.when(dbEngine.getQueryBuilder(vertex)).thenReturn(queryBuilder); - - Introspector obj=loader.introspectorFromName("model-ver"); - - Mockito.when(queryBuilder.createEdgeTraversal(EdgeType.TREE,vertex,obj)).thenReturn(queryBuilder); - //Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","model-ver","model-version-id","vnf-id-1"); - - + + @Test + public void testGetStartNodesAndModVersionIds_ModelInId() throws AAIException { List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); - - Map<String,String> result1=processor.getStartNodesAndModVersionIds("9999","postmen","vnf-id-1","vnf-id-1", - "vnf-id","generic-vnf",startNodeFilterArrayOfHashes,""); + String passedModelVersion = null; + String passedModelName = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID,passedModelVersion,MODEL_INVARIANT_ID_VALUE, passedModelName, + AAI_NODE_TYPE, startNodeFilterArrayOfHashes, API_VERSION); } - - @Test(expected = AAIException.class) - public void getStartNodesAndModVersionIds1() throws AAIException{ - - vertex.property("model-version-id","vnf-id-1"); - vertex1.property(AAIProperties.NODE_TYPE,"model-ver"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"model-ver")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("model-version-id","vnf-id-1")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - //this.engine.getQueryBuilder(startV).createEdgeTraversal(treeType, startV, loader.introspectorFromName(connectedNodeType)); - - queryBuilder.toList().add(vertex); - Mockito.when(dbEngine.getQueryBuilder(vertex)).thenReturn(queryBuilder); - - Introspector obj=loader.introspectorFromName("generic-vnf"); - Mockito.when(queryBuilder.createEdgeTraversal(EdgeType.TREE,vertex,obj)).thenReturn(queryBuilder); - //Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","model-ver","model-version-id","vnf-id-1"); - - + @Test + public void testGetStartNodesAndModVersionIds_ModelName() throws AAIException { List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); - - Map<String,String> result1=processor.getStartNodesAndModVersionIds("9999","postmen","vnf-id-1","vnf-id-1", - "vnf-id","generic-vnf",startNodeFilterArrayOfHashes,""); + String passedModelVersion = null; + String passedModelInvId = null; + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID,passedModelVersion,passedModelInvId, MODEL_NAME_ID_VALUE, + AAI_NODE_TYPE, startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testGetStartNodesAndModVersionIds_NonEmptyHashMap_ModelVersion() throws AAIException { + Map<String, Object> map = new HashMap<>(); + map.put("model-ver.model-name", "model-name"); + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<>(); + startNodeFilterArrayOfHashes.add(map); + String passedModelInvId = null; + String passedModelName = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID, MODEL_VERSION_ID_VALUE, passedModelInvId, passedModelName, + MODEL_NAME_ID_VALUE, startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testGetStartNodesAndModVersionIds_NonEmptyHashMap_ModelInvId() throws AAIException { + Map<String, Object> map = new HashMap<>(); + map.put("model-ver.model-name", "model-name"); + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<>(); + startNodeFilterArrayOfHashes.add(map); + String passedModelVersion = null; + String passedModelName = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID,passedModelVersion,MODEL_INVARIANT_ID_VALUE, passedModelName, + MODEL_NAME_ID_VALUE, startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testGetStartNodesAndModVersionIds_NonEmptyHashMap_ModelName() throws AAIException { + Map<String, Object> map = new HashMap<>(); + map.put("model-ver.model-name", "model-name"); + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<>(); + startNodeFilterArrayOfHashes.add(map); + String passedModelVersion = null; + String passedModelInvId = null; + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID,passedModelVersion,passedModelInvId, MODEL_NAME_ID_VALUE, + MODEL_NAME_ID_VALUE, startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testQueryByModel() throws AAIException { + List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); + String passedModelInvId = null; + String passedModelName = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.queryByModel(TRANSACTION_ID, FROM_APP_ID, MODEL_VERSION_ID_VALUE, passedModelInvId, passedModelName, + AAI_NODE_TYPE, startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testQueryByModel_Timed() throws AAIException { + List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); + String passedModelVersion = null; + String passedModelName = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.queryByModel_Timed(TRANSACTION_ID, FROM_APP_ID,passedModelVersion,MODEL_INVARIANT_ID_VALUE, passedModelName, + MODEL_NAME_ID_VALUE, startNodeFilterArrayOfHashes, API_VERSION); } + @Test(expected=AAIException.class) + public void testgetModelTypeFromModelVer_NullVertexArg() throws AAIException { + Vertex nullVertex = null; + modelBasedProcessor.getModelVerTopWidgetType(nullVertex, ""); + } + @Test - public void getNodeUsingUniqueIdTest() throws AAIException{ - vertex.property("vnf-id","vnf-id-1"); - vertex1.property(AAIProperties.NODE_TYPE,"generic-vnf"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"generic-vnf")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("vnf-id","vnf-id-1")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","vnf-id","vnf-id-1"); - - assertNotNull(result); + public void testValidateNamedQuery_FoundQuery() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + + modelBasedProcessor.validateNamedQuery("9999", "JUNIT", "named-query-uuid-1", "1.0"); } - + + @Test(expected=AAIException.class) + public void testValidateNamedQuery_NotFoundQuery() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + + modelBasedProcessor.validateNamedQuery("9999", "JUNIT", "named-query-uuid", "1.0"); + } + + @Test(expected=AAIException.class) + public void testGetNodeUsingUniqueId_NullUniqueId() throws AAIException { + modelBasedProcessor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","vnf-id",""); + modelBasedProcessor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","vnf-id",null); + } + + @Test(expected=AAIException.class) + public void testGetNodeUsingUniqueId_NullPropertyName() throws AAIException { + modelBasedProcessor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","","vnf-id-1"); + modelBasedProcessor.getNodeUsingUniqueId("9999", "postmen","generic-vnf",null,"vnf-id-1"); + } + + @Test(expected=AAIException.class) + public void testGetNodeUsingUniqueId_NullNodeType() throws AAIException { + modelBasedProcessor.getNodeUsingUniqueId("9999", "postmen","","vnf-id","vnf-id-1"); + modelBasedProcessor.getNodeUsingUniqueId("9999", "postmen",null,"vnf-id","vnf-id-1"); + } + + @Test(expected=AAIException.class) + public void testValidateModel() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.validateModel("9999", "JUNIT", MODEL_VERSION_ID_VALUE, "1.0"); + } + @Test - public void getNodeUsingUniqueIdTest1() throws AAIException{ - vertex.property("named-query-uui","vnf-id-1"); - vertex1.property(AAIProperties.NODE_TYPE,"named-query"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"named-query")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("named-query-uui","vnf-id-1")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","named-query","named-query-uui","vnf-id-1"); - - assertNotNull(result); + public void testShowResultSet_NullVertex() { + ResultSet rs = getResultSet(); + rs.setVert(null); + modelBasedProcessor.showResultSet(rs, 1); } - - @Test(expected = AAIException.class) - public void getModelVersUsingNameTest() throws AAIException{ - - vertex.property(AAIProperties.NODE_TYPE,"generic-vnf"); - vertex1.property("generic-vnf","generic-vnf"); - graphTraversal.addV(vertex1); - v.addV(vertex1); - vertexList.add(vertex); - vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"model-ver")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("model-name","generic-vnf")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - //Mockito.when(vertexList.listIterator().hasNext()).thenReturn(true); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - List<Vertex> result=processor.getModelVersUsingName("9999","postment","generic-vnf"); - - assertTrue(result.size()>0); + + @Test + public void testShowResultSet_NonEmptyOverrideHash() { + ResultSet rs = getResultSet(); + modelBasedProcessor.showResultSet(rs, 2); } - - //uniqueIdVal Null Expecting AAI Excpetion - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdTestNull() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","vnf-id",""); - - + + @Test + public void testShowResultSet_EmptyOverrideHash() { + ResultSet rs = getResultSet(); + rs.setPropertyOverRideHash(new HashMap<String, Object>()); + modelBasedProcessor.showResultSet(rs, 2); + } + + private ResultSet getResultSet() { + ResultSet rs = new ResultSet(); + rs.setVert(model); + rs.setLocationInModelSubGraph("2"); + Map<String,Object> overrideHash = new HashMap<String, Object>(); + rs.setPropertyOverRideHash(overrideHash); + overrideHash.put("key1", "value1"); + overrideHash.put("key2", "value2"); + overrideHash.put("key3", "value3"); + overrideHash.put("key4", "value4"); + + Map<String,Object> extraHash = new HashMap<String, Object>(); + rs.setExtraPropertyHash(extraHash); + extraHash.put("key1", "value1"); + extraHash.put("key2", "value2"); + extraHash.put("key3", "value3"); + extraHash.put("key4", "value4"); + + return rs; } - - //idPropertyName Null Expecting AAI Excpetion - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdTestNull1() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","","vnf-id-1"); - - + + @Test + public void testPruneResultSet_NotCutPointType() throws AAIException { + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + + ResultSet rs = getResultSet(); + List<ResultSet> subResultSet = new ArrayList<>(); + subResultSet.add(getResultSet()); + rs.setSubResultSet(subResultSet); + modelBasedProcessor.pruneResultSet(rs, "mdl", new HashMap<>()); } - - //idPropertyName Null Expecting AAI Excpetion - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdTestNull2() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","","vnf-id","vnf-id-1"); - - + + @Test + public void testPruneResultSet_CutPointType() throws AAIException { + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + + ResultSet rs = getResultSet(); + Map<String, Object> startNodeFilterHash = new HashMap<>(); + startNodeFilterHash.put("model.model_type","widget"); + startNodeFilterHash.put("named_query.named-query-uuid","named-query-uuid-1"); + modelBasedProcessor.pruneResultSet(rs, "model", startNodeFilterHash); } - - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdTestTwoVertex() throws AAIException{ - vertex.property("vnf-id","vnf-id-1"); - vertex1.property(AAIProperties.NODE_TYPE,"generic-vnf"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"generic-vnf")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("vnf-id","vnf-id-1")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","vnf-id","vnf-id-1"); - - assertNotNull(result); + + @Test + public void testCollapseForDoNotOutput_FlagTrue() throws AAIException { + + ResultSet rs = getResultSet(); + List<ResultSet> subResultSet = new ArrayList<>(); + subResultSet.add(getResultSet()); + rs.setSubResultSet(subResultSet); + rs.setDoNotOutputFlag("true"); + modelBasedProcessor.collapseForDoNotOutput(rs); } - - //uniqVerts Null Expection AAI Exception - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdTestVertexNull() throws AAIException{ - vertex.property("vnf-id","vnf-id-1"); - vertex1.property(AAIProperties.NODE_TYPE,"generic-vnf"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"generic-vnf")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("vnf-id","vnf-id-1")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(null); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","vnf-id","vnf-id-1"); - - assertNotNull(result); + + @Test + public void testCollapseForDoNotOutput_FlagFalse() throws AAIException { + + ResultSet rs = getResultSet(); + List<ResultSet> subResultSet = new ArrayList<>(); + subResultSet.add(getResultSet()); + rs.setSubResultSet(subResultSet); + rs.setDoNotOutputFlag("false"); + modelBasedProcessor.collapseForDoNotOutput(rs); } - - //uniqVerts Null Expection AAI Exception - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdTestVertexHasNot() throws AAIException{ - vertex.property("vnf-id","vnf-id-1"); - vertex1.property(AAIProperties.NODE_TYPE,"generic-vnf"); - graphTraversal.addV(vertex); - v.addV(vertex1); - //vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"generic-vnf")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("vnf-id","vnf-id-1")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Vertex result=processor.getNodeUsingUniqueId("9999", "postmen","generic-vnf","vnf-id","vnf-id-1"); - - assertNotNull(result); + + @Test + public void testMakeSureItsAnArrayList() { + String listString = getArrayListAsString(); + modelBasedProcessor.makeSureItsAnArrayList(listString); } - - @Test(expected = AAIIdentityMapParseException.class) - public void runDeleteByModelTest() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - Optional<Vertex> vertex=Optional.empty(); - Map<String,Object> startNodeFilterHash=new HashMap<>(); - startNodeFilterHash.put("related-link.data","relationshipdata"); - startNodeFilterHash.put("generic-vnf.d","relationshipdata"); - Mockito.when(dbMethHelper.searchVertexByIdentityMap("relationship-data",startNodeFilterHash)).thenReturn(vertex); - Map<String,String> re =processor.runDeleteByModel("9999","postmen","","relationship-data",startNodeFilterHash,"vnf-id","vnf-id"); - assertNotNull(re); - - + + private String getArrayListAsString() { + List<String> strList = new ArrayList<>(); + strList.add("1"); + strList.add("2"); + strList.add("3"); + String listString = strList.toString(); + return listString; } - @Test(expected = AAIException.class) - public void getModelGivenModelVerTest() throws AAIException{ - vertex.property("named-query-uuid","vnf-id-1"); - vertex1.property(AAIProperties.NODE_TYPE,"named-query"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"named-query")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("named-query-uuid","vnf-id-1")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - - QueryBuilder qub=Mockito.mock(QueryBuilder.class); - qub.toList().addAll(vertexList); - Mockito.when(dbEngine.getQueryBuilder(Mockito.any(Vertex.class))).thenReturn(queryBuilder); - - Mockito.when(queryBuilder.createEdgeTraversal(Mockito.any(EdgeType.class),Mockito.any(Vertex.class),Mockito.any(Introspector.class))).thenReturn(qub); - - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Vertex result=processor.getModelGivenModelVer(vertex,""); - assertNotNull(result); - + @Test + public void testGetModConstraintHash() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getModConstraintHash(modelElement, new HashMap<>()); } - - @Test(expected = AAIException.class) - public void queryByNamedQuery_TimedTest() throws AAIException{ - vertex.property("named-query-uuid","named-query-element"); - vertex1.property(AAIProperties.NODE_TYPE,"named-query"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - //vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"named-query")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("named-query-uuid","named-query-element")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - - QueryBuilder qub=Mockito.mock(QueryBuilder.class); - qub.toList().addAll(vertexList); - Mockito.when(dbEngine.getQueryBuilder(Mockito.any(Vertex.class))).thenReturn(queryBuilder); - - Mockito.when(queryBuilder.createEdgeTraversal(Mockito.any(EdgeType.class),Mockito.any(Vertex.class),Mockito.any(Introspector.class))).thenReturn(qub); - - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); - Map<String,Object> secondaryFilterHash=new HashMap<>(); - - List<ResultSet> res=processor.queryByNamedQuery_Timed("99999","postmen","named-query-element",startNodeFilterArrayOfHashes,"vnf","vnf", - secondaryFilterHash); - - + + @Test(expected=AAIException.class) + public void testGenTopoMap4ModelVer_WidgetType() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.genTopoMap4ModelVer(TRANSACTION_ID, FROM_APP_ID, modelVersion, MODEL_VERSION_ID_VALUE); } - - @Test(expected = AAIException.class) - public void genTopoMap4NamedQTest() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - vertex.property("named-query-uuid","named-query-element"); - vertex1.property(AAIProperties.NODE_TYPE,"named-query-element"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - QueryBuilder qub=Mockito.mock(QueryBuilder.class); - qub.toList().addAll(vertexList); - Mockito.when(dbEngine.getQueryBuilder(Mockito.any(Vertex.class))).thenReturn(queryBuilder); - - Mockito.when(queryBuilder.createEdgeTraversal(Mockito.any(EdgeType.class),Mockito.any(Vertex.class),Mockito.any(Introspector.class))).thenReturn(qub); - - Multimap<String, String> map =processor.genTopoMap4NamedQ("9999","postmen",vertex,"named-query-element"); + + @Test(expected=AAIException.class) + public void testGenTopoMap4ModelVer_ServiceType() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex modelV = serviceGraph.addVertex(T.label, "model", T.id, "20", AAI_NODE_TYPE, "model", "model-invariant-id", "model-invariant-id-1", "model-type", "service"); + Vertex modelVerV = serviceGraph.addVertex(T.label, MODEL_VESION_NODE_VALUE, T.id, "21", AAI_NODE_TYPE, MODEL_VESION_NODE_VALUE, + MODEL_VERSION_ID_KEY, MODEL_VERSION_ID_VALUE,MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE, "model-version", "model-version-1"); + Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "22", AAI_NODE_TYPE, "model-element"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, modelV, modelVerV); + rules4Service.addTreeEdge(gts, modelElementV, modelVerV); + rules4Service.addEdge(gts, modelElementV, modelVerV); + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.genTopoMap4ModelVer(TRANSACTION_ID, FROM_APP_ID, modelVerV, MODEL_VERSION_ID_VALUE); } - - @Test(expected = AAIException.class) - public void genTopoMap4NamedQTest1() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - vertex.property("named-query-uuid","named-query-element"); - vertex1.property(AAIProperties.NODE_TYPE,"named-query-element"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - QueryBuilder qub=Mockito.mock(QueryBuilder.class); - qub.toList().addAll(vertexList); - Mockito.when(dbEngine.getQueryBuilder(Mockito.any(Vertex.class))).thenReturn(queryBuilder); - - Mockito.when(queryBuilder.createEdgeTraversal(Mockito.any(EdgeType.class),Mockito.any(Vertex.class),Mockito.any(Introspector.class))).thenReturn(qub); - - Multimap<String, String> map =processor.genTopoMap4NamedQ("9999","postmen",null,"named-query-element"); + + @Test(expected=AAIException.class) + public void testCollectTopology4ModelVer() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + + Multimap<String, String> initialEmptyMap = ArrayListMultimap.create(); + List<String> vidsTraversed = new ArrayList<>(); + modelBasedProcessor.collectTopology4ModelVer(TRANSACTION_ID, FROM_APP_ID, modelElement, "", initialEmptyMap, vidsTraversed, + 0, null, MODEL_INVARIANT_ID_VALUE, MODEL_VERSION_ID_VALUE); } - - @Test(expected = AAIException.class) - public void getModelThatNqElementRepresentsTest() throws AAIException{ - vertex.property("model-ver","named-query-element"); - vertex1.property(AAIProperties.NODE_TYPE,"named-query-element"); - graphTraversal.addV(vertex); - v.addV(vertex1); - vertexList.add(vertex); - QueryBuilder qub=Mockito.mock(QueryBuilder.class); - qub.toList().addAll(vertexList); - Mockito.when(dbEngine.getQueryBuilder(Mockito.any(Vertex.class))).thenReturn(queryBuilder); - - Mockito.when(queryBuilder.createEdgeTraversal(Mockito.any(EdgeType.class),Mockito.any(Vertex.class),Mockito.any(Introspector.class))).thenReturn(qub); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - Vertex v=processor.getModelThatNqElementRepresents(vertex,"g"); + + @Test(expected=AAIException.class) + public void testGetNextStepElementsFromSet_NullVertex() throws AAIException { + modelBasedProcessor.getNextStepElementsFromSet(null); } - - @Test(expected = NullPointerException.class) - public void getModelTypeFromModel() throws AAIException{ - Vertex vt=Mockito.mock(Vertex.class); - vt.property("model-type","named-query-element"); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - String v=processor.getModelTypeFromModel(vt,"g"); + + @Test + public void testRundeleteAsNeededFromResultSet() throws AAIException { + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + + ResultSet rs = getResultSet(); + rs.setNewDataDelFlag("T"); + modelBasedProcessor.deleteAsNeededFromResultSet(TRANSACTION_ID, FROM_APP_ID, rs, + "", API_VERSION, API_VERSION, new HashMap<>()); } - - @Test(expected = AAIException.class) - public void getModelTypeFromModel1() throws AAIException{ - Vertex vt=Mockito.mock(Vertex.class); - vt.property("model-type","named-query-element"); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - String v=processor.getModelTypeFromModel(null,"g"); + + @Test(expected=AAIException.class) + public void testQueryByNamedQuery() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.queryByNamedQuery(TRANSACTION_ID, FROM_APP_ID, "named-query-uuid-1", new ArrayList<>(), API_VERSION); } - - @Test(expected = NullPointerException.class) - public void getModVersUsingModelInvId() throws AAIException{ - - vertex.property(AAIProperties.NODE_TYPE,"model-invariant-id"); - vertex1.property("model","model-invariant-id"); - graphTraversal.addV(vertex1); - v.addV(vertex1); - vertexList.add(vertex); - vertexList.add(vertex1); - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(graphTraversalSource); - Mockito.when(graphTraversalSource.V()).thenReturn(v); - Mockito.when(v.has(AAIProperties.NODE_TYPE,"model-invariant-id")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.has("model","model-invariant-id")).thenReturn(graphTraversal); - Mockito.when(graphTraversal.toList()).thenReturn(vertexList); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Iterator<Vertex> result=processor.getModVersUsingModelInvId("9999","postment","model"); + + @Test + public void testCollectInstanceData() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + Multimap<String, String> validNextStepMap = ArrayListMultimap.create(); + validNextStepMap.put("named-query-element-uuid-1", "named-query-element-uuid-1"); + List<String> vidsTraversed=new ArrayList<>(); + vidsTraversed.add("named-query-element-uuid-1"); + Map<String,String> namedQueryElementHash = new HashMap<>(); + namedQueryElementHash.put("named-query-element-uuid-1", "named-query-element-uuid-1"); + modelBasedProcessor.collectInstanceData(TRANSACTION_ID, FROM_APP_ID, modelElement, "named-query-element-uuid-1", + validNextStepMap, vidsTraversed, 0, new HashMap<>(), namedQueryElementHash, API_VERSION); } - - @Test(expected = AAIException.class) - public void getNamedQueryExtraDataLookupTest() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Map<String,Object> re=processor.getNamedQueryExtraDataLookup("","",null,vertex, - ""); + + @Test(expected=AAIException.class) + public void testNamedQueryConstraintSaysStop_NullNamedQueryVertex() throws AAIException { + modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, null, model, API_VERSION); } - - @Test(expected = AAIException.class) - public void getNamedQueryExtraDataLookupTest1() throws AAIException{ - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - Map<String,Object> re=processor.getNamedQueryExtraDataLookup("","",vertex,null, - ""); + + @Test(expected=AAIException.class) + public void testNamedQueryConstraintSaysStop_NullInstanceVertex() throws AAIException { + modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, model, null, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testNamedQueryConstraintSaysStop_NullContraintType() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "30","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex propertyContraintV = graph.addVertex(T.label, "property-constraint", T.id, "31", AAI_NODE_TYPE, "property-constraint"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "32", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testNamedQueryConstraintSaysStop_NullPropertyName() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "33","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex propertyContraintV = graph.addVertex(T.label, "property-constraint", T.id, "34", AAI_NODE_TYPE, "property-constraint", "constraint-type", "EQUALS"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "35", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testNamedQueryConstraintSaysStop_NullPropertyValue() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "36","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex propertyContraintV = graph.addVertex(T.label, "property-constraint", T.id, "37", AAI_NODE_TYPE, "property-constraint", + "constraint-type", "EQUALS", "property-name", "property-name"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "38", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test + public void testNamedQueryConstraintSaysStop_ConstraintTypeEquals() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "39","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex propertyContraintV = graph.addVertex(T.label, "property-constraint", T.id, "40", AAI_NODE_TYPE, "property-constraint", + "constraint-type", "EQUALS", "property-name", "property-name", "property-value", "property-value"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "41", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test + public void testNamedQueryConstraintSaysStop_ConstraintTypeNotEquals() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "42","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex propertyContraintV = graph.addVertex(T.label, "property-constraint", T.id, "43", AAI_NODE_TYPE, "property-constraint", + "constraint-type", "NOT-EQUALS", "property-name", "property-name", "property-value", "property-value"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "44", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testGetNamedQueryExtraDataLookup_TargetNodeTypeNull() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "45","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex relatedLookUpV = graph.addVertex(T.label, "related-lookup", T.id, "46", AAI_NODE_TYPE, "related-lookup", + "source-node-property", "source-node-property", "source-node-type", "generic-vnf"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "47", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); + GraphTraversalSource gts = serviceGraph.traversal(); + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.getNamedQueryExtraDataLookup(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test + public void testGetNamedQueryExtraDataLookup_InvalidSourceProperty() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "51","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex relatedLookUpV = graph.addVertex(T.label, "related-lookup", T.id, "52", AAI_NODE_TYPE, "related-lookup", + "source-node-property", "source-node-property", "source-node-type", "generic-vnf", "target-node-type", "generic-vnf", + "target-node-property", "generic-vnf", "property-collect-list", "property-collect-list"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "53", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); + GraphTraversalSource gts = serviceGraph.traversal(); + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.getNamedQueryExtraDataLookup(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test(expected=IllegalArgumentException.class) + public void testGetNamedQueryExtraDataLookup_ValidSourceProperty() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex namedQueryElementV = graph.addVertex(T.label, "named-query-element", T.id, "54","aai-node-type", "named-query-element", + "property-limit-desc", "show-all", "do-not-output", "true", "named-query-element-uuid", "named-query-element-uuid-1", + "property-collect-list", "property-collect-list-1"); + Vertex relatedLookUpV = graph.addVertex(T.label, "related-lookup", T.id, "55", AAI_NODE_TYPE, "related-lookup", + "source-node-property", "source-node-property", "source-node-type", "generic-vnf", "target-node-type", "generic-vnf", "target-node-property", "generic-vnf"); + Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "56", AAI_NODE_TYPE, "instance-vertex", "source-node-property", "source-node-property"); + GraphTraversalSource gts = serviceGraph.traversal(); + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.getNamedQueryExtraDataLookup(TRANSACTION_ID, FROM_APP_ID, namedQueryElementV, instanceVertexV, API_VERSION); + } + + @Test + public void testCollectNQElementHash() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.collectNQElementHash(TRANSACTION_ID, FROM_APP_ID, namedQueryElement, "", new HashMap<>(), new ArrayList<>(), 0); + } + + @Test + public void testCollectDeleteKeyHash() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.collectDeleteKeyHash(TRANSACTION_ID, FROM_APP_ID, linkagePoints, "", new HashMap<>(), new ArrayList<>(), + 0, new HashMap<>(), "model-version-1", "model-version-id-local"); + } + + @Test(expected=AAIException.class) + public void testCheck4EdgeRule_InvalidNodeA() throws AAIException { + modelBasedProcessor.check4EdgeRule("model-version1", "model-ver"); } - @Test(expected = NullPointerException.class) - public void showResultSet() throws AAIException{ - vertex.property("model-ver","model-versionId"); - vertex.property("aai","model-versionId"); - - - ResultSet rs= Mockito.mock(ResultSet.class); - Mockito.when(rs.getVert()).thenReturn(vertex); - - List<VertexProperty<String>> vb=new ArrayList<>(); - VertexProperty<String> v=Mockito.mock(VertexProperty.class); - v.property("model-ver","1"); - vb.add(v); - v.property("aai","5"); - vb.add(v); - v.property("source-of-truth","6"); - vb.add(v); - - vertex.properties("model-ver","aai"); - Mockito.when(vertex.<String>property(AAIProperties.NODE_TYPE)).thenReturn(v); - //Mockito.when(vertex.properties()).thenReturn(Mockito.any()); - ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - processor.showResultSet(rs,8); - + @Test(expected=AAIException.class) + public void testCheck4EdgeRule_InvalidNodeB() throws AAIException { + modelBasedProcessor.check4EdgeRule("model-ver", "model-version1"); + } + + @Test(expected=AAIException.class) + public void testCheck4EdgeRule_InvalidEdge() throws AAIException { + modelBasedProcessor.check4EdgeRule("model-ver", "named-query"); + } + + @Test + public void testCollectTopology4LinkagePoint() throws AAIException { + String linkagePointStrVal = new String("model-ver|model"); + String incomingTrail = new String("model|model-ver"); + Multimap<String, String> currentMap = ArrayListMultimap.create(); + modelBasedProcessor.collectTopology4LinkagePoint(TRANSACTION_ID, FROM_APP_ID, linkagePointStrVal, incomingTrail, currentMap); + } + + @Test + public void testGenTopoMap4NamedQ() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.genTopoMap4NamedQ(TRANSACTION_ID, FROM_APP_ID, namedQuery, "named-query-uuid-1"); + } + + @Test + public void testGetModelThatNqElementRepresents() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getModelThatNqElementRepresents(namedQueryElement, ""); + } + + @Test + public void testGetModelVerThatElementRepresents() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getModelVerThatElementRepresents(modelElement, ""); + } + + @Test + public void testGetModelTypeFromModel() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getModelTypeFromModel(model, ""); + } + + @Test + public void testGetModelVerTopWidgetType() throws AAIException { + Graph serviceGraph = TinkerGraph.open(); + Vertex modelV = serviceGraph.addVertex(T.label, "model", T.id, "57", AAI_NODE_TYPE, "model", "model-invariant-id", "model-invariant-id-1", "model-type", "service"); + Vertex modelVerV = serviceGraph.addVertex(T.label, MODEL_VESION_NODE_VALUE, T.id, "58", AAI_NODE_TYPE, MODEL_VESION_NODE_VALUE, + MODEL_VERSION_ID_KEY, MODEL_VERSION_ID_VALUE,MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE, "model-version", "model-version-1"); + Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "59", AAI_NODE_TYPE, "model-element"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, modelV, modelVerV); + rules4Service.addTreeEdge(gts, modelElementV, modelVerV); + rules4Service.addEdge(gts, modelElementV, modelVerV); + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.getModelVerTopWidgetType(modelVerV, ""); + } + + @Test + public void testGetModelElementStepName() throws AAIException { + Graph serviceGraph = TinkerGraph.open(); + Vertex modelV = serviceGraph.addVertex(T.label, "model", T.id, "60", AAI_NODE_TYPE, "model", "model-invariant-id", "model-invariant-id-1", "model-type", "service"); + Vertex modelVerV = serviceGraph.addVertex(T.label, MODEL_VESION_NODE_VALUE, T.id, "61", AAI_NODE_TYPE, MODEL_VESION_NODE_VALUE, + MODEL_VERSION_ID_KEY, MODEL_VERSION_ID_VALUE,MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE, "model-version", "model-version-1"); + Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "62", AAI_NODE_TYPE, "model-element"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, modelV, modelVerV); + rules4Service.addTreeEdge(gts, modelElementV, modelVerV); + rules4Service.addEdge(gts, modelElementV, modelVerV); + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.getModelElementStepName(modelElementV, ""); + } + + @Test(expected=IllegalArgumentException.class) + public void testRunDeleteByModel() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + Map<String, Object> map = new HashMap<>(); + map.put("generic-vnf.d","relationshipdata"); + + modelBasedProcessor.runDeleteByModel(TRANSACTION_ID, FROM_APP_ID, MODEL_VERSION_ID_VALUE, "model-ver", map, API_VERSION, API_VERSION); + } + + @Test + public void testSecondConstructor() { + ModelBasedProcessing mdp = new ModelBasedProcessing(); + } + + @Test(expected=AAIIdentityMapParseException.class) + public void testQueryByNamedQuery_NonEmptyMap() throws AAIException { + Map<String, Object> map = new HashMap<>(); + map.put("model-ver.model-name", "model-name"); + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<>(); + startNodeFilterArrayOfHashes.add(map); + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + + modelBasedProcessor.queryByNamedQuery(TRANSACTION_ID, FROM_APP_ID, "named-query-uuid-1", startNodeFilterArrayOfHashes, API_VERSION, null, null); + + } + + @Test(expected=AAIIdentityMapParseException.class) + public void testRunDeleteByModel_Service() throws AAIException { + Graph serviceGraph = TinkerGraph.open(); + Vertex modelV = serviceGraph.addVertex(T.label, "model", T.id, "63", AAI_NODE_TYPE, "model", "model-invariant-id", "model-invariant-id-1", "model-type", "service"); + Vertex modelVerV = serviceGraph.addVertex(T.label, MODEL_VESION_NODE_VALUE, T.id, "64", AAI_NODE_TYPE, MODEL_VESION_NODE_VALUE, + MODEL_VERSION_ID_KEY, MODEL_VERSION_ID_VALUE,MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE, "model-version", "model-version-1"); + Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "65", AAI_NODE_TYPE, "model-element"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, modelV, modelVerV); + rules4Service.addTreeEdge(gts, modelElementV, modelVerV); + rules4Service.addEdge(gts, modelElementV, modelVerV); + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + + Map<String, Object> map = new HashMap<>(); + map.put("generic-vnf.d","relationshipdata"); + + modelBasedProcessor.runDeleteByModel(TRANSACTION_ID, FROM_APP_ID, MODEL_VERSION_ID_VALUE, "model-ver", map, API_VERSION, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testGetStartNodesAndModVersionIds_NonEmptyHashMap_AllEmpty() throws AAIException { + Map<String, Object> map = new HashMap<>(); + map.put("model-ver.model-name", "model-name"); + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<>(); + startNodeFilterArrayOfHashes.add(map); + String passedModelInvId = null; + String passedModelName = null; + String passedModelVerId = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID, passedModelVerId, passedModelInvId, passedModelName, + "", startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testGetStartNodesAndModVersionIds_NonEmptyHashMap_ModelTypeNonNull() throws AAIException { + Map<String, Object> map = new HashMap<>(); + map.put("model-ver.model-name", "model-name"); + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<>(); + startNodeFilterArrayOfHashes.add(map); + String passedModelInvId = null; + String passedModelName = null; + String passedModelVerId = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID, passedModelVerId, passedModelInvId, passedModelName, + MODEL_NAME_ID_VALUE, startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testQueryByModel_Timed_NonEmptyHash() throws AAIException { + Map<String, Object> map = new HashMap<>(); + map.put("model-ver.model-name", "model-name"); + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<>(); + startNodeFilterArrayOfHashes.add(map); + String passedModelVersion = null; + String passedModelName = null; + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + modelBasedProcessor.queryByModel_Timed(TRANSACTION_ID, FROM_APP_ID,passedModelVersion,MODEL_INVARIANT_ID_VALUE, passedModelName, + MODEL_NAME_ID_VALUE, startNodeFilterArrayOfHashes, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testRunDeleteByModel_NullVersionAndNode() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + Map<String, Object> map = new HashMap<>(); + map.put("generic-vnf.d","relationshipdata"); + + modelBasedProcessor.runDeleteByModel(TRANSACTION_ID, FROM_APP_ID, "", "", map, API_VERSION, API_VERSION); + } + + @Test(expected=AAIException.class) + public void testRunDeleteByModel_NullVersion() throws AAIException { + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); + Map<String, Object> map = new HashMap<>(); + map.put("generic-vnf.d","relationshipdata"); + + modelBasedProcessor.runDeleteByModel(TRANSACTION_ID, FROM_APP_ID, "", "model-ver", map, API_VERSION, API_VERSION); + } + + @Test + public void testGenTopoMap4ModelVer_WidgetType_Map() throws AAIException { + + Graph serviceGraph = TinkerGraph.open(); + Vertex modelV = serviceGraph.addVertex(T.label, "model", T.id, "66", AAI_NODE_TYPE, "model", "model-invariant-id", "model-invariant-id-1", "model-type", "widget"); + Vertex modelVerV = serviceGraph.addVertex(T.label, MODEL_VESION_NODE_VALUE, T.id, "67", AAI_NODE_TYPE, MODEL_VESION_NODE_VALUE, + MODEL_VERSION_ID_KEY, MODEL_VERSION_ID_VALUE,MODEL_NAME_ID_KEY, MODEL_NAME_ID_VALUE, "model-version", "model-version-1"); + //Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "68", AAI_NODE_TYPE, "model-element"); + GraphTraversalSource gts = serviceGraph.traversal(); + + EdgeRules rules4Service = EdgeRules.getInstance(); + rules4Service.addTreeEdge(gts, modelV, modelVerV); + //rules4Service.addTreeEdge(gts, modelElementV, modelVerV); + //rules4Service.addEdge(gts, modelElementV, modelVerV); + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + + Mockito.when(dbEngine.asAdmin()).thenReturn(admin); + Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); + modelBasedProcessor.genTopoMap4ModelVer(TRANSACTION_ID, FROM_APP_ID, modelVerV, MODEL_VERSION_ID_VALUE); } + } diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java index fae4222..87ebb8f 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java @@ -19,8 +19,8 @@ */ package org.onap.aai.dbgraphmap; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.graphdb.types.system.EmptyVertex; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.graphdb.types.system.EmptyVertex; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -40,7 +40,7 @@ import org.onap.aai.introspection.*; import org.onap.aai.parsers.relationship.RelationshipToURI; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; @@ -86,7 +86,7 @@ public class SearchGraphTest { private List<MediaType> outputMediaTypes; private Loader loader; - private TitanGraph graph; + private JanusGraph graph; private Graph tx; @@ -135,7 +135,7 @@ public class SearchGraphTest { when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java index 3ce971a..d5b695a 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java @@ -22,8 +22,8 @@ package org.onap.aai.rest; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.jayway.jsonpath.JsonPath; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanTransaction; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.junit.After; import org.junit.Before; @@ -258,8 +258,8 @@ public class GfpVserverDataStoredQueryTest { private void removeVertexes(){ - TitanGraph titanGraph = AAIGraph.getInstance().getGraph(); - TitanTransaction transaction = titanGraph.newTransaction(); + JanusGraph JanusGraph = AAIGraph.getInstance().getGraph(); + JanusGraphTransaction transaction = JanusGraph.newTransaction(); boolean success = true; @@ -282,8 +282,8 @@ public class GfpVserverDataStoredQueryTest { private void addVservers(int vserversCount){ - TitanGraph titanGraph = AAIGraph.getInstance().getGraph(); - TitanTransaction transaction = titanGraph.newTransaction(); + JanusGraph JanusGraph = AAIGraph.getInstance().getGraph(); + JanusGraphTransaction transaction = JanusGraph.newTransaction(); boolean success = true; diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java index 767b761..1391bbf 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java @@ -19,7 +19,7 @@ */ package org.onap.aai.rest.search; -import com.thinkaurelius.titan.core.TitanGraph; +import org.janusgraph.core.JanusGraph; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; @@ -36,7 +36,7 @@ import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.Version; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.SubGraphStyle; @@ -80,7 +80,7 @@ public class GremlinServerImplTest { private List<MediaType> outputMediaTypes; private Loader loader; - private TitanGraph graph; + private JanusGraph graph; private Graph tx; @@ -126,7 +126,7 @@ public class GremlinServerImplTest { when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java index 9296a7f..0bbb04f 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java @@ -19,7 +19,7 @@ */ package org.onap.aai.rest.search; -import com.thinkaurelius.titan.core.TitanGraph; +import org.janusgraph.core.JanusGraph; import groovy.lang.MissingPropertyException; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; @@ -36,7 +36,7 @@ import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.Version; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.SubGraphStyle; @@ -80,7 +80,7 @@ public class GroovyShellImplTest { private List<MediaType> outputMediaTypes; private Loader loader; - private TitanGraph graph; + private JanusGraph graph; private Graph tx; @@ -126,7 +126,7 @@ public class GroovyShellImplTest { when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java index 5a224ac..793723e 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java @@ -32,7 +32,7 @@ import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; @@ -126,7 +126,7 @@ public class ModelAndNamedQueryRestProviderTest { when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/PnfTopologyQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/PnfTopologyQueryTest.java index c086259..21da962 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/PnfTopologyQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/PnfTopologyQueryTest.java @@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Ignore; import org.junit.Test; import org.onap.aai.exceptions.AAIException; diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java index 023dd64..08cce81 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java @@ -31,7 +31,7 @@ import org.onap.aai.introspection.ModelType; import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; @@ -122,7 +122,7 @@ public class SearchProviderTest { when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new TitanDBEngine( + dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java index 823d1ad..531437f 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java @@ -44,7 +44,7 @@ import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.db.EdgeRules; import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.RawFormat; import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException; @@ -97,7 +97,7 @@ public class SimpleFormatTest { final ModelType factoryType = ModelType.MOXY; Loader loader = LoaderFactory.createLoaderForVersion(factoryType, Version.v10); - dbEngine = spy(new TitanDBEngine( + dbEngine = spy(new JanusGraphDBEngine( QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader)); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java index 91b9804..d4eac58 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java @@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Ignore; import org.junit.Test; import org.onap.aai.exceptions.AAIException; diff --git a/aai-traversal/src/test/resources/logback.xml b/aai-traversal/src/test/resources/logback.xml index f79a189..f8a5925 100644 --- a/aai-traversal/src/test/resources/logback.xml +++ b/aai-traversal/src/test/resources/logback.xml @@ -373,7 +373,7 @@ <logger name="org.apache" level="WARN" /> <logger name="org.zookeeper" level="WARN" /> - <logger name="com.thinkaurelius" level="WARN" /> + <logger name="org.janusgraph" level="WARN" /> <logger name="com.att.aft.dme2" level="WARN" /> <!-- ============================================================================ --> |