aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/test/java/org
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2020-03-13 16:40:27 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-03-19 16:05:02 +0000
commit9c49e4b01ef5300026b62afa4e5b6cc591469dc1 (patch)
tree35fac34e9f564b53513d5ce64bfbcca2211f929b /asdctool/src/test/java/org
parentb3e9914ce32f3e1b11396f88b3af9ae00c76479d (diff)
Added new unit tests
Added new unit tests to GraphMLConverter class. Fixed the Sonar issue. Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I985a860012c0c2b0b6524c0a2346415cb113d83c
Diffstat (limited to 'asdctool/src/test/java/org')
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java271
1 files changed, 122 insertions, 149 deletions
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java
index 87eb40d10b..96369e045d 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,156 +20,129 @@
package org.openecomp.sdc.asdctool.impl;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.tinkerpop.gremlin.structure.Element;
import org.janusgraph.core.JanusGraph;
import org.junit.Test;
-import java.util.List;
-import java.util.Map;
+import java.io.File;
+import java.util.Collections;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
public class GraphMLConverterTest {
-
- public GraphMLConverter createTestSubject() {
- return new GraphMLConverter();
- }
-
- @Test
- public void testImportGraph() throws Exception {
- GraphMLConverter testSubject;
- String[] args = new String[] { "" };
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.importGraph(args);
- }
-
- @Test
- public void testExportGraph() throws Exception {
- GraphMLConverter testSubject;
- String[] args = new String[] { "" };
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.exportGraph(args);
- }
-
- @Test
- public void testExportGraphMl() throws Exception {
- GraphMLConverter testSubject;
- String[] args = new String[] { "" };
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.exportGraphMl(args);
- }
-
- @Test
- public void testFindErrorInJsonGraph() throws Exception {
- GraphMLConverter testSubject;
- String[] args = new String[] { "" };
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.findErrorInJsonGraph(args);
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void testOpenGraph() throws Exception {
- GraphMLConverter testSubject;
- String janusGraphFileLocation = "";
- JanusGraph result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.openGraph("src/main/resources/config/janusgraph.properties");
- }
-
- @Test(expected=NullPointerException.class)
- public void testExportJsonGraph() throws Exception {
- GraphMLConverter testSubject;
- JanusGraph graph = null;
- String outputDirectory = "";
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.exportJsonGraph(graph, outputDirectory);
- }
-
- @Test(expected=NullPointerException.class)
- public void testExportGraphMl_1() throws Exception {
- GraphMLConverter testSubject;
- JanusGraph graph = null;
- String outputDirectory = "";
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.exportGraphMl(graph, outputDirectory);
- }
-
- @Test
- public void testImportJsonGraph() throws Exception {
- GraphMLConverter testSubject;
- JanusGraph graph = null;
- String graphJsonFile = "";
- List<ImmutablePair<String, String>> propertiesCriteriaToDelete = null;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.importJsonGraph(graph, graphJsonFile, propertiesCriteriaToDelete);
- }
-
- @Test(expected=NullPointerException.class)
- public void testFindErrorInJsonGraph_1() throws Exception {
- GraphMLConverter testSubject;
- JanusGraph graph = null;
- String outputDirectory = "";
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.findErrorInJsonGraph(graph, outputDirectory);
- }
-
-
- @Test(expected=NullPointerException.class)
- public void testExportUsers() throws Exception {
- GraphMLConverter testSubject;
- JanusGraph graph = null;
- String outputDirectory = "";
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.exportUsers(graph, outputDirectory);
- }
-
- @Test(expected=NullPointerException.class)
- public void testGetProperties() throws Exception {
- GraphMLConverter testSubject;
- Element element = null;
- Map<String, Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getProperties(element);
- }
-
- @Test
- public void testExportUsers_1() throws Exception {
- GraphMLConverter testSubject;
- String[] args = new String[] { "" };
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.exportUsers(args);
- }
+
+ @Test
+ public void testImportGraph() {
+ String[] args = getInputArgs();
+ GraphMLConverter testSubject = new GraphMLConverter();
+ assertTrue(testSubject.importGraph(args));
+ }
+
+ @Test
+ public void testExportGraph() {
+ String[] args = getOutputArgs();
+ GraphMLConverter testSubject = new GraphMLConverter();
+ assertTrue(testSubject.exportGraph(args));
+ }
+
+ @Test
+ public void testExportGraphMl() {
+ String[] args = getOutputArgs();
+ GraphMLConverter testSubject = new GraphMLConverter();
+
+ String result = testSubject.exportGraphMl(args);
+ assertNotNull(result);
+ assertTrue(result.startsWith(args[2]));
+ }
+
+ @Test
+ public void testFindErrorInJsonGraph() {
+ String[] args = getOutputArgs();
+ GraphMLConverter testSubject = new GraphMLConverter();
+ assertTrue(testSubject.findErrorInJsonGraph(args));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testOpenGraphWithBadPath() {
+
+ GraphMLConverter testSubject = new GraphMLConverter();
+ testSubject.openGraph("badPath");
+ }
+
+ @Test
+ public void testExportJsonGraphWithBadOutputDir() {
+
+ GraphMLConverter testSubject = new GraphMLConverter();
+ JanusGraph graph = testSubject.openGraph(getJanusGraphConfig());
+ assertNull(testSubject.exportJsonGraph(graph, "badOutputDir"));
+ }
+
+ @Test
+ public void testImportJsonGraph() {
+ GraphMLConverter testSubject = new GraphMLConverter();
+ JanusGraph graph = testSubject.openGraph(getJanusGraphConfig());
+
+ assertTrue(testSubject.importJsonGraph(graph, getGraphSON(), Collections.emptyList()));
+ }
+
+ @Test
+ public void testImportJsonGraphNoGraphSONFile() {
+ GraphMLConverter testSubject = new GraphMLConverter();
+ JanusGraph graph = testSubject.openGraph(getJanusGraphConfig());
+
+ assertFalse(testSubject.importJsonGraph(graph, "noFile", Collections.emptyList()));
+ }
+
+
+ @Test
+ public void testExportUsers() {
+ GraphMLConverter testSubject = new GraphMLConverter();
+
+ JanusGraph graph = testSubject.openGraph(getJanusGraphConfig());
+ String outputDirectory = getOutputJanusGraph();
+
+ String result = testSubject.exportUsers(graph, outputDirectory);
+ assertNotNull(result);
+ assertTrue(result.startsWith(outputDirectory));
+ }
+
+ @Test
+ public void testExportUsersWithBadOutputDir() {
+ GraphMLConverter testSubject = new GraphMLConverter();
+
+ JanusGraph graph = testSubject.openGraph(getJanusGraphConfig());
+ assertNull(testSubject.exportUsers(graph, "badOutputDir"));
+ }
+
+ @Test
+ public void testExportUsersFromArgs() {
+ String[] args = getOutputArgs();
+ GraphMLConverter testSubject = new GraphMLConverter();
+ assertTrue(testSubject.exportUsers(args));
+ }
+
+ private String getJanusGraphConfig() {
+ return getClass().getClassLoader().getResource("config/janusgraph.properties").getPath();
+ }
+
+ private String getOutputJanusGraph() {
+ return new File(getClass().getClassLoader().getResource("graphSON.json").getFile())
+ .getAbsolutePath()
+ .replace(File.separator + "graphSON.json", "");
+ }
+
+ private String getGraphSON() {
+ return getClass().getClassLoader().getResource("graphSON.json").getPath();
+ }
+
+ private String[] getOutputArgs() {
+ return new String[]{"", getJanusGraphConfig(), getOutputJanusGraph()};
+ }
+
+ private String[] getInputArgs() {
+ return new String[]{"", getJanusGraphConfig(), getGraphSON()};
+ }
}