Add unit tests for dupeTool, datasnapshot 23/67523/2
authorKajur, Harish (vk250x) <vk250x@att.com>
Tue, 18 Sep 2018 22:57:39 +0000 (18:57 -0400)
committerKajur, Harish (vk250x) <vk250x@att.com>
Tue, 18 Sep 2018 23:40:01 +0000 (19:40 -0400)
and also for the audit oxm

Issue-ID: AAI-1633
Change-Id: If5ead46eaa9e7d012054713268009957d0103477
Signed-off-by: Kajur, Harish (vk250x) <vk250x@att.com>
src/main/java/org/onap/aai/db/schema/AuditOXM.java
src/main/java/org/onap/aai/db/schema/AuditorFactory.java
src/main/java/org/onap/aai/db/schema/ManageJanusGraphSchema.java
src/main/java/org/onap/aai/db/schema/ScriptDriver.java
src/test/java/org/onap/aai/datasnapshot/DataSnapshotTest.java
src/test/java/org/onap/aai/db/schema/AuditOXMTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/dbgen/DupeToolTest.java
src/test/java/org/onap/aai/schema/db/ManageSchemaTest.java
src/test/resources/pserver2.graphson.P0
src/test/resources/pserver2.graphson.P1

index 417824c..d7f7314 100644 (file)
@@ -53,10 +53,12 @@ public class AuditOXM extends Auditor {
         *
         * @param version the version
         */
-       public AuditOXM(LoaderFactory loaderFactory, SchemaVersion version) {
+       public AuditOXM(LoaderFactory loaderFactory, SchemaVersion version, EdgeIngestor ingestor) {
                
                Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version);
                Set<String> objectNames = getAllObjects(loader);
+               this.ingestor = ingestor;
+
                allObjects = new HashSet<>();
                for (String key : objectNames) {
                        try {
@@ -220,8 +222,4 @@ public class AuditOXM extends Auditor {
        public Set<Introspector> getAllIntrospectors() {
                return this.allObjects;
        }
-
-       public void setEdgeIngestor(EdgeIngestor ingestor){
-               this.ingestor = ingestor;
-       }
 }
index 6d96f29..40dd047 100644 (file)
@@ -20,6 +20,7 @@
 package org.onap.aai.db.schema;
 
 import org.janusgraph.core.JanusGraph;
+import org.onap.aai.edges.EdgeIngestor;
 import org.onap.aai.introspection.LoaderFactory;
 import org.onap.aai.setup.SchemaVersions;
 import org.onap.aai.setup.SchemaVersion;
@@ -37,8 +38,8 @@ public class AuditorFactory {
         * @param v the v
         * @return the OXM auditor
         */
-       public Auditor getOXMAuditor (SchemaVersion v) {
-               return new AuditOXM(loaderFactory, v);
+       public Auditor getOXMAuditor (SchemaVersion v, EdgeIngestor ingestor) {
+               return new AuditOXM(loaderFactory, v, ingestor);
        }
        
        /**
index dccc141..24aac9f 100644 (file)
@@ -26,6 +26,7 @@ import org.janusgraph.core.schema.JanusGraphIndex;
 import org.janusgraph.core.schema.JanusGraphManagement;
 import org.janusgraph.core.schema.JanusGraphManagement.IndexBuilder;
 import org.janusgraph.core.schema.SchemaStatus;
+import org.onap.aai.edges.EdgeIngestor;
 import org.onap.aai.setup.SchemaVersions;
 import org.onap.aai.setup.SchemaVersion;
 
@@ -49,9 +50,9 @@ public class ManageJanusGraphSchema {
         *
         * @param graph the graph
         */
-       public ManageJanusGraphSchema(final JanusGraph graph, AuditorFactory auditorFactory, SchemaVersions schemaVersions) {
+       public ManageJanusGraphSchema(final JanusGraph graph, AuditorFactory auditorFactory, SchemaVersions schemaVersions, EdgeIngestor edgeIngestor) {
                this.graph = graph;
-               oxmInfo = auditorFactory.getOXMAuditor(schemaVersions.getDefaultVersion());
+               oxmInfo = auditorFactory.getOXMAuditor(schemaVersions.getDefaultVersion(), edgeIngestor);
                graphInfo = auditorFactory.getGraphAuditor(graph);
        }
 
index dca8e83..ebef01d 100644 (file)
@@ -27,9 +27,9 @@ import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;\r
 import org.codehaus.jackson.JsonGenerationException;\r
 import org.onap.aai.dbmap.AAIGraphConfig;\r
+import org.onap.aai.edges.EdgeIngestor;\r
 import org.onap.aai.exceptions.AAIException;\r
 import org.onap.aai.setup.SchemaVersions;\r
-import org.onap.aai.setup.SchemaVersion;\r
 import org.onap.aai.logging.LoggingContext;\r
 import org.onap.aai.logging.LoggingContext.StatusCode;\r
 import org.onap.aai.util.AAIConfig;\r
@@ -47,7 +47,6 @@ public class ScriptDriver {
         * @param args the arguments\r
         * @throws AAIException the AAI exception\r
         * @throws JsonGenerationException the json generation exception\r
-        * @throws JsonMappingException the json mapping exception\r
         * @throws IOException Signals that an I/O exception has occurred.\r
         */\r
        public static void main (String[] args) throws AAIException, IOException, ConfigurationException {\r
@@ -76,6 +75,7 @@ public class ScriptDriver {
 \r
                AuditorFactory auditorFactory = ctx.getBean(AuditorFactory.class);\r
                SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);\r
+               EdgeIngestor edgeIngestor     = ctx.getBean(EdgeIngestor.class);\r
 \r
                String config = cArgs.config;\r
                AAIConfig.init();\r
@@ -94,7 +94,7 @@ public class ScriptDriver {
 \r
                        AuditDoc doc = null;\r
                        if ("oxm".equals(cArgs.type)) {\r
-                               doc = auditorFactory.getOXMAuditor(schemaVersions.getDefaultVersion()).getAuditDoc();\r
+                               doc = auditorFactory.getOXMAuditor(schemaVersions.getDefaultVersion(), edgeIngestor).getAuditDoc();\r
                        } else if ("graph".equals(cArgs.type)) {\r
                                doc = auditorFactory.getGraphAuditor(graph).getAuditDoc();\r
                        }\r
index 35e8aa2..63fd1fa 100644 (file)
@@ -31,6 +31,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.onap.aai.AAISetup;
 import org.onap.aai.dbmap.AAIGraph;
+import org.onap.aai.exceptions.AAIException;
 import org.springframework.boot.test.rule.OutputCapture;
 
 import java.io.File;
@@ -59,7 +60,7 @@ public class DataSnapshotTest extends AAISetup {
     public OutputCapture outputCapture = new OutputCapture();
 
     @Before
-    public void setup(){
+    public void setup() throws AAIException {
         JanusGraph graph = AAIGraph.getInstance().getGraph();
         currentTransaction = graph.newTransaction();
         g = currentTransaction.traversal();
@@ -347,7 +348,7 @@ public class DataSnapshotTest extends AAISetup {
         DataSnapshot.main(args);
     }
 
-    private List<Vertex> setupPserverData(GraphTraversalSource g){
+    private List<Vertex> setupPserverData(GraphTraversalSource g) throws AAIException {
         Vertex v1 = g.addV().property("aai-node-type", "pserver")
             .property("hostname", "somerandomhostname")
             .next();
@@ -356,6 +357,13 @@ public class DataSnapshotTest extends AAISetup {
         Vertex v2 = g.addV().property("aai-node-type", "pserver")
             .property("hostname", "somerandomhostname2")
             .next();
+        Vertex pinterface = g.addV()
+                .property("aai-node-type", "p-interface")
+                .property("interface-name", "p-interface-name")
+                .property("in-maint", false)
+                .property("source-of-truth", "JUNIT")
+                .next();
+        edgeSerializer.addTreeEdge(g, v2, pinterface);
         list.add(v2);
         return list;
     }
diff --git a/src/test/java/org/onap/aai/db/schema/AuditOXMTest.java b/src/test/java/org/onap/aai/db/schema/AuditOXMTest.java
new file mode 100644 (file)
index 0000000..cba202a
--- /dev/null
@@ -0,0 +1,60 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 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.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.db.schema;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.AAISetup;
+import org.onap.aai.introspection.Loader;
+import org.onap.aai.introspection.LoaderFactory;
+import org.onap.aai.introspection.ModelType;
+import org.onap.aai.setup.SchemaVersion;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.AdditionalMatchers.not;
+
+public class AuditOXMTest extends AAISetup {
+
+    private AuditOXM auditOXM;
+
+    @Before
+    public void setUp() {
+    }
+
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @Test
+    public void getAllIntrospectors() {
+        auditOXM = new AuditOXM(loaderFactory, schemaVersions.getDefaultVersion(), edgeIngestor);
+        assertTrue(auditOXM.getAllIntrospectors().size() > 0);
+    }
+
+    @Test
+    public void setEdgeIngestor() {
+    }
+}
\ No newline at end of file
index 392ce97..1d3228e 100644 (file)
@@ -100,7 +100,7 @@ public class DupeToolTest extends AAISetup {
     }
 
     @Test
-    public void testDupeTool(){
+    public void testDupeToolForPInterface(){
         //TODO: test does not find duplicates
         String[] args = {
                 "-userId", "testuser",
index ddaad21..6d62098 100644 (file)
@@ -98,7 +98,7 @@ public class ManageSchemaTest extends AAISetup {
                                "    } ]\r\n" + 
                                "  }";
                DBIndex index = mapper.readValue(content, DBIndex.class);
-               ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph, auditorFactory, schemaVersions);
+               ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph, auditorFactory, schemaVersions, edgeIngestor);
                JanusGraphManagement mgmt = graph.openManagement();
                Set<String> instances = mgmt.getOpenInstances();
                System.out.println(instances);
index 8c89c1c..59c9a7d 100644 (file)
@@ -1 +1 @@
-{"id":4176,"label":"vertex","properties":{"hostname":[{"id":"sq-380-c3d1","value":"somerandomhostname"}],"aai-node-type":[{"id":"16y-380-5xc5","value":"pserver"}]}}
+{"id":4240,"label":"vertex","properties":{"hostname":[{"id":"sy-39s-c3d1","value":"somerandomhostname"}],"aai-node-type":[{"id":"176-39s-5xc5","value":"pserver"}]}}
index cbc864b..5a0ece5 100644 (file)
@@ -1 +1,2 @@
-{"id":4296,"label":"vertex","properties":{"hostname":[{"id":"t5-3bc-c3d1","value":"somerandomhostname2"}],"aai-node-type":[{"id":"17d-3bc-5xc5","value":"pserver"}]}}
+{"id":8336,"label":"vertex","inE":{"tosca.relationships.network.BindsTo":[{"id":"4r6-9lc-f11-6fk","outV":12432,"properties":{"private":false,"aai-uuid":"42904b97-7d39-485d-8ac4-6a8022d714f2","prevent-delete":"NONE","delete-other-v":"IN","contains-other-v":"IN"}}]},"properties":{"hostname":[{"id":"1zm-6fk-c3d1","value":"somerandomhostname2"}],"aai-node-type":[{"id":"2du-6fk-5xc5","value":"pserver"}]}}
+{"id":12432,"label":"vertex","outE":{"tosca.relationships.network.BindsTo":[{"id":"4r6-9lc-f11-6fk","inV":8336,"properties":{"private":false,"aai-uuid":"42904b97-7d39-485d-8ac4-6a8022d714f2","prevent-delete":"NONE","delete-other-v":"IN","contains-other-v":"IN"}}]},"properties":{"in-maint":[{"id":"36a-9lc-2685","value":false}],"interface-name":[{"id":"3ki-9lc-3u9x","value":"p-interface-name"}],"source-of-truth":[{"id":"3yq-9lc-622t","value":"JUNIT"}],"aai-node-type":[{"id":"4cy-9lc-5xc5","value":"p-interface"}]}}