diff options
Diffstat (limited to 'aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java')
-rw-r--r-- | aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java | 1279 |
1 files changed, 455 insertions, 824 deletions
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 624bf19..406d122 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 @@ -21,891 +21,522 @@ */ package org.onap.aai.dbgraphgen; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Map.Entry; +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.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.tinkergraph.structure.TinkerGraph; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +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.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.Version; +import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; 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.EdgeRules; +import org.onap.aai.serialization.db.EdgeType; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.TitanDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; +import java.util.*; +@RunWith(MockitoJUnitRunner.class) public class ModelBasedProcessingTest { - 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; + @Mock private static TransactionalGraphEngine dbEngine; private static Loader loader; - EdgeRules rules; - - ModelBasedProcessing modelBasedProcessor; - - GraphTraversalSource source; - - Graph graph; - - Vertex model; - Vertex modelVersion; - Vertex modelElement; - Vertex constrainedElementSet; - Vertex namedQueryElement; - Vertex linkagePoints; - Vertex namedQuery; - + @Mock private static DBSerializer serializer; + @Mock private static TransactionalGraphEngine.Admin admin; + ModelBasedProcessing mockProcessor; + @Mock + private DbMethHelper dbMethHelper; + @BeforeClass public static void configure() throws Exception { System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); + loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST); + + } - + @Before - public void init() throws AAIException { + public void init() { + mockProcessor = new ModelBasedProcessing(loader, dbEngine, serializer); + MockitoAnnotations.initMocks(this); - rules = EdgeRules.getInstance(); - loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, AAIProperties.LATEST); - TransactionalGraphEngine newDbEngine = new TitanDBEngine(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 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); - } - - @Test - public void testGetStartNodesAndModVersionIds_ModelInId() 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.getStartNodesAndModVersionIds(TRANSACTION_ID, FROM_APP_ID,passedModelVersion,MODEL_INVARIANT_ID_VALUE, passedModelName, - AAI_NODE_TYPE, startNodeFilterArrayOfHashes, API_VERSION); } @Test - public void testGetStartNodesAndModVersionIds_ModelName() throws AAIException { - List<Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<>(); - 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); + 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); } - - @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 { + + @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"); + + 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); + + Map<String,String> result1=processor.getStartNodesAndModVersionIds("9999","postmen","vnf-id-1","vnf-id-1", + "vnf-id","generic-vnf",startNodeFilterArrayOfHashes,""); } - - @Test(expected=AAIException.class) - public void testQueryByModel_Timed() throws AAIException { + + + @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"); + + 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 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 testShowResultSet_NullVertex() { - ResultSet rs = getResultSet(); - rs.setVert(null); - modelBasedProcessor.showResultSet(rs, 1); - } - - @Test - public void testShowResultSet_NonEmptyOverrideHash() { - ResultSet rs = getResultSet(); - modelBasedProcessor.showResultSet(rs, 2); - } - - @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; - } - - @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<>()); - } - - @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 - 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); - } - - @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); - } - - @Test - public void testMakeSureItsAnArrayList() { - String listString = getArrayListAsString(); - modelBasedProcessor.makeSureItsAnArrayList(listString); - } - - private String getArrayListAsString() { - List<String> strList = new ArrayList<>(); - strList.add("1"); - strList.add("2"); - strList.add("3"); - String listString = strList.toString(); - return listString; + Map<String,String> result1=processor.getStartNodesAndModVersionIds("9999","postmen","vnf-id-1","vnf-id-1", + "vnf-id","generic-vnf",startNodeFilterArrayOfHashes,""); } @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 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 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 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 testGetNextStepElementsFromSet_NullVertex() throws AAIException{ - modelBasedProcessor.getNextStepElementsFromSet(null); - } - - @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 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 - 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 testNamedQueryConstraintSaysStop_NullNamedQueryVertex() throws AAIException { - modelBasedProcessor.namedQueryConstraintSaysStop(TRANSACTION_ID, FROM_APP_ID, null, model, API_VERSION); - } - - @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); + 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); } - + @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"); + 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); } - @Test(expected=AAIException.class) - public void testCheck4EdgeRule_InvalidNodeB() throws AAIException { - modelBasedProcessor.check4EdgeRule("model-ver", "model-version1"); + @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(expected=AAIException.class) - public void testCheck4EdgeRule_InvalidEdge() throws AAIException { - modelBasedProcessor.check4EdgeRule("model-ver", "named-query"); + + //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 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); + + //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 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"); + + //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 testGetModelThatNqElementRepresents() throws AAIException { - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); - modelBasedProcessor.getModelThatNqElementRepresents(namedQueryElement, ""); + + @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 testGetModelVerThatElementRepresents() throws AAIException{ - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); - modelBasedProcessor.getModelVerThatElementRepresents(modelElement, ""); + + //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 testGetModelTypeFromModel() throws AAIException { - Mockito.when(dbEngine.asAdmin()).thenReturn(admin); - Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(source); - modelBasedProcessor.getModelTypeFromModel(model, ""); + + //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 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(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); + + } - - @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 = 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(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(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 - public void testSecondConstructor() { - ModelBasedProcessing mdp = new ModelBasedProcessing(); + + @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=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 = 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=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 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 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 = 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(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 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 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 = 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(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 getNamedQueryExtraDataLookupTest() throws AAIException{ + ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); + + Map<String,Object> re=processor.getNamedQueryExtraDataLookup("","",null,vertex, + ""); } - - @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(expected = AAIException.class) + public void getNamedQueryExtraDataLookupTest1() throws AAIException{ + ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); + + Map<String,Object> re=processor.getNamedQueryExtraDataLookup("","",vertex,null, + ""); } - - @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); + + @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); + } - } |