From f477ac5eafcfc9e1b074a9fea31e7095bbc75697 Mon Sep 17 00:00:00 2001 From: Igor Dysko Date: Tue, 10 Aug 2021 14:00:45 +0200 Subject: Increase java test coverage Added new tests, removed unused code. Issue-ID: AAI-3278 Signed-off-by: Igor Dysko Change-Id: I046aa25c037850f3aa8a7d3e3d355b88c8f3b3c4 --- src/main/java/org/onap/aai/graphgraph/App.java | 3 +- .../org/onap/aai/graphgraph/ModelExporter.java | 43 ------------------ .../aai/graphgraph/reader/BasicSchemaReader.java | 2 +- src/test/java/org/onap/aai/graphgraph/AppTest.java | 39 ----------------- .../onap/aai/graphgraph/ArgumentParserTest.java | 51 ++++++++++++++++++++++ .../onap/aai/graphgraph/SchemaResourceTest.java | 33 ++++++++++++-- 6 files changed, 83 insertions(+), 88 deletions(-) delete mode 100644 src/test/java/org/onap/aai/graphgraph/AppTest.java create mode 100644 src/test/java/org/onap/aai/graphgraph/ArgumentParserTest.java diff --git a/src/main/java/org/onap/aai/graphgraph/App.java b/src/main/java/org/onap/aai/graphgraph/App.java index 638d3f3..621bd0d 100644 --- a/src/main/java/org/onap/aai/graphgraph/App.java +++ b/src/main/java/org/onap/aai/graphgraph/App.java @@ -52,7 +52,8 @@ public class App { ConfigurableApplicationContext context = app.run(args); if (parser.shouldGenerateUrl()) { ModelExporter modelExporter = context.getBean(ModelExporter.class); - modelExporter.writeExportedModel(modelExporter.exportModel(parser.getSchemaVersion())); + String model = modelExporter.exportModel(parser.getSchemaVersion()); + modelExporter.writeExportedModel(model); SpringApplication.exit(context); } diff --git a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java index f05c39a..745ffa4 100644 --- a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java +++ b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java @@ -20,7 +20,6 @@ package org.onap.aai.graphgraph; import com.google.common.collect.Multimap; -import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; @@ -30,9 +29,6 @@ import org.apache.velocity.tools.generic.EscapeTool; import org.eclipse.jetty.util.StringUtil; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.edges.EdgeRule; -import org.onap.aai.edges.enums.DirectionNotation; -import org.onap.aai.edges.enums.EdgeField; -import org.onap.aai.edges.enums.MultiplicityRule; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; import org.onap.aai.graphgraph.velocity.VelocityAssociation; import org.onap.aai.graphgraph.velocity.VelocityEntity; @@ -50,7 +46,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.*; -import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -61,7 +56,6 @@ public class ModelExporter { private static final String AAIMODEL_UML_FILENAME = "aaimodel.uml"; private static final String VELOCITY_TEMPLATE_FILENAME = "model_export.vm"; - private static final boolean OXM_ENABLED = false; private static final String CAMEL_CASE_REGEX = "(?=[A-Z][a-z])"; private static final String VELOCITY_ASSOCIATION_NAME_FORMAT = "%s - %s (%s)"; @@ -76,10 +70,6 @@ public class ModelExporter { private Multimap getEdgeRules(String schemaVersion) { try { Multimap allRules = edgeIngestor.getAllRules(new SchemaVersion(schemaVersion)); - if (OXM_ENABLED) { - Map allEntities = moxyLoaderRepository.getMoxyLoaders().get(schemaVersion).getAllObjects(); - addOxmRelationships(allRules, allEntities); - } return allRules; } catch (EdgeRuleNotFoundException e) { @@ -89,39 +79,6 @@ public class ModelExporter { return null; } - private void addOxmRelationships( - Multimap allRules, - Map allEntities) { - - for (Entry currentParent : allEntities.entrySet()) { - currentParent.getValue().getProperties().stream() - .filter(allEntities::containsKey) - .filter(v -> !currentParent.getKey().equals(v)) - .forEach(v -> { - String key = currentParent.getKey() + "|" + v; - if (!allRules.containsKey(key)) { - allRules.put(key, createEdgeRule(currentParent.getKey(), v)); - } - }); - } - } - - private EdgeRule createEdgeRule(String parent, String child) { - Map edgeRuleProps = new HashMap<>(); - edgeRuleProps.put(EdgeField.FROM.toString(), child); - edgeRuleProps.put(EdgeField.TO.toString(), parent); - edgeRuleProps.put(EdgeField.DIRECTION.toString(), Direction.OUT.toString()); - edgeRuleProps.put(EdgeField.LABEL.toString(), "OXM Parent-Child"); - edgeRuleProps.put(EdgeField.MULTIPLICITY.toString(), MultiplicityRule.MANY2ONE.toString()); - edgeRuleProps.put(EdgeField.DEFAULT.toString(), Boolean.toString(false)); - edgeRuleProps.put(EdgeField.PRIVATE.toString(), Boolean.toString(false)); - edgeRuleProps.put(EdgeField.DELETE_OTHER_V.toString(), DirectionNotation.DIRECTION.toString()); - edgeRuleProps.put(EdgeField.PREVENT_DELETE.toString(), DirectionNotation.DIRECTION.toString()); - edgeRuleProps.put(EdgeField.CONTAINS.toString(), DirectionNotation.DIRECTION.toString()); - edgeRuleProps.put(EdgeField.DESCRIPTION.toString(), "fake edgerule representing parent-child"); - return new EdgeRule(edgeRuleProps); - } - public String exportModel(String schemaVersion) { Map allObjects = moxyLoaderRepository.getMoxyLoaders().get(schemaVersion).getAllObjects(); Template t = initVelocity(); diff --git a/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java b/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java index 203ef13..0cdbd9c 100644 --- a/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java +++ b/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java @@ -46,7 +46,7 @@ import java.util.stream.Stream; public class BasicSchemaReader implements SchemaReader { - private final static Logger LOGGER = LoggerFactory.getLogger(BasicSchemaReader.class); + private static final Logger LOGGER = LoggerFactory.getLogger(BasicSchemaReader.class); private Map allEntities; private Graph graph = new DefaultDirectedGraph<>(MetadataEdge.class); diff --git a/src/test/java/org/onap/aai/graphgraph/AppTest.java b/src/test/java/org/onap/aai/graphgraph/AppTest.java deleted file mode 100644 index 5393d26..0000000 --- a/src/test/java/org/onap/aai/graphgraph/AppTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - ============LICENSE_START======================================================= - org.onap.aai - ================================================================================ - Copyright © 2019-2020 Orange 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.graphgraph; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } -} diff --git a/src/test/java/org/onap/aai/graphgraph/ArgumentParserTest.java b/src/test/java/org/onap/aai/graphgraph/ArgumentParserTest.java new file mode 100644 index 0000000..bfe7b29 --- /dev/null +++ b/src/test/java/org/onap/aai/graphgraph/ArgumentParserTest.java @@ -0,0 +1,51 @@ +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange 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.graphgraph; + +import org.junit.Assert; +import org.junit.Test; + +public class ArgumentParserTest { + + @Test + public void parsePrintHelpTest() { + ArgumentParser argumentParser = new ArgumentParser(); + argumentParser.parseArguments(new String[] {"-h"}); + Assert.assertTrue(argumentParser.isPrintHelp()); + } + + @Test + public void parseLocalRunTest() { + ArgumentParser argumentParser = new ArgumentParser(); + argumentParser.parseArguments(new String[] {"-d"}); + Assert.assertTrue(argumentParser.isRunLocally()); + Assert.assertFalse(argumentParser.isPrintHelp()); + } + + @Test + public void parseGenerateModelTest() { + ArgumentParser argumentParser = new ArgumentParser(); + argumentParser.parseArguments(new String[] {"-g", "v15"}); + Assert.assertFalse(argumentParser.isRunLocally()); + Assert.assertFalse(argumentParser.isPrintHelp()); + Assert.assertTrue(argumentParser.shouldGenerateUrl()); + Assert.assertEquals("v15", argumentParser.getSchemaVersion()); + } +} diff --git a/src/test/java/org/onap/aai/graphgraph/SchemaResourceTest.java b/src/test/java/org/onap/aai/graphgraph/SchemaResourceTest.java index 84bcf2f..a857d83 100644 --- a/src/test/java/org/onap/aai/graphgraph/SchemaResourceTest.java +++ b/src/test/java/org/onap/aai/graphgraph/SchemaResourceTest.java @@ -23,7 +23,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.graphgraph.dto.Graph; import org.onap.aai.graphgraph.dto.NodeName; import org.onap.aai.graphgraph.dto.NodeProperty; @@ -51,9 +50,6 @@ public class SchemaResourceTest { @Autowired private NodeIngestor nodeIngestor; - @Autowired - private EdgeIngestor edgeIngestor; - @Autowired private MoxyLoaderRepository moxyLoaderRepository; @@ -79,6 +75,20 @@ public class SchemaResourceTest { Assert.assertTrue(containsNodeName(graph.getNodeNames(), "volume-group")); } + @Test + public void loadCloudRegionGraphTest() { + Graph graph = schemaResource.loadGraph("v10", "cloud-region", 1, 1, 1, "Edgerules"); + + Assert.assertNotNull(graph.getEdges()); + Assert.assertEquals(14, graph.getEdges().size()); + Assert.assertEquals(15, graph.getNodeNames().size()); + Assert.assertTrue(containsNodeName(graph.getNodeNames(), "image")); + Assert.assertTrue(containsNodeName(graph.getNodeNames(), "volume-group")); + Assert.assertTrue(containsNodeName(graph.getNodeNames(), "zone")); + Assert.assertTrue(containsNodeName(graph.getNodeNames(), "dvs-switch")); + Assert.assertTrue(containsNodeName(graph.getNodeNames(), "tenant")); + } + @Test public void loadGraphPathsTest() { Graph graph = schemaResource.loadGraphWithPaths("v10", "cloud-region", "image", "Edgerules"); @@ -110,6 +120,21 @@ public class SchemaResourceTest { Assert.assertEquals(844919, schemaExport.length()); } + @Test + public void allVertexNamesTest() { + List nodeNames = schemaResource.loadVertexNames("v10", "Edgerules"); + Assert.assertNotNull(nodeNames); + Assert.assertEquals(74, nodeNames.size()); + Assert.assertTrue(containsNodeName(nodeNames, "connector")); + Assert.assertTrue(containsNodeName(nodeNames, "cvlan-tag")); + Assert.assertTrue(containsNodeName(nodeNames, "element-choice-set")); + Assert.assertTrue(containsNodeName(nodeNames, "image")); + Assert.assertTrue(containsNodeName(nodeNames, "model-constraint")); + Assert.assertTrue(containsNodeName(nodeNames, "pnf")); + Assert.assertTrue(containsNodeName(nodeNames, "service-capability")); + Assert.assertTrue(containsNodeName(nodeNames, "vlan")); + } + private boolean containsNodeProperty(List nodeProperties, String propertyName) { for (NodeProperty nodeProperty : nodeProperties) { -- cgit 1.2.3-korg