aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool/src/test')
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java271
-rw-r--r--asdctool/src/test/resources/config/janusgraph.properties1
-rw-r--r--asdctool/src/test/resources/graphSON.json1
3 files changed, 124 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()};
+ }
}
diff --git a/asdctool/src/test/resources/config/janusgraph.properties b/asdctool/src/test/resources/config/janusgraph.properties
new file mode 100644
index 0000000000..4f8d3ad79c
--- /dev/null
+++ b/asdctool/src/test/resources/config/janusgraph.properties
@@ -0,0 +1 @@
+storage.backend=inmemory
diff --git a/asdctool/src/test/resources/graphSON.json b/asdctool/src/test/resources/graphSON.json
new file mode 100644
index 0000000000..726c20af09
--- /dev/null
+++ b/asdctool/src/test/resources/graphSON.json
@@ -0,0 +1 @@
+{"id":0,"label":"node","outE":{"relation_is":[{"id":0,"inV":1,"properties":{"value":1}}]},"properties":{"node0":[{"id":0,"value":"node0"}],"node1":[{"id":1,"value":"node1"}]}} \ No newline at end of file