summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-heat-lib/src/test/java
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2017-12-27 12:59:05 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2017-12-27 14:42:02 +0000
commitb220096e336b0e2bff63f596db3b65878dcd5fe1 (patch)
tree84b5f4d456cc3fc561ec6dbd426e3eef0ed077e5 /openecomp-be/lib/openecomp-heat-lib/src/test/java
parent549b96f3b8da259ed482bc76be7097aea70b7147 (diff)
Add tests
Add unit tests for ToscaTreeManager Change-Id: I772b63799cd34b687e6c81cb235c1c9a36ad34a2 Issue-ID: SDC-802 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src/test/java')
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManagerTest.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManagerTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManagerTest.java
new file mode 100644
index 0000000000..0cfac52318
--- /dev/null
+++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManagerTest.java
@@ -0,0 +1,86 @@
+package org.openecomp.sdc.heat.services.tree;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.regex.Pattern;
+
+public class ToscaTreeManagerTest {
+ private static final String BASE_DIR = "/mock/toscaTree/";
+ private static final String IN = "in";
+ private static final String OUT = "out";
+ private static final String EXPECTED_TREE_FILE = "/expectedTree.json";
+ private ToscaTreeManager toscaTreeManager = new ToscaTreeManager();
+
+ @Test
+ public void testTreeWithDiffFileNames() throws IOException {
+ String inputDirectory = BASE_DIR + "diffFileNames/" + IN;
+ String outputFileName = BASE_DIR + "diffFileNames/" + OUT + EXPECTED_TREE_FILE;
+
+ testTreeManager(inputDirectory, outputFileName);
+ }
+
+ @Test
+ public void testDirectoriesWithSimilarNameUnderDifferentRoots() throws IOException {
+ String inputDirectory = BASE_DIR + "similarDirectoryName/" + IN;
+ String outputFileName = BASE_DIR + "similarDirectoryName/" + OUT + EXPECTED_TREE_FILE;
+
+ testTreeManager(inputDirectory, outputFileName);
+ }
+
+ @Test
+ public void testTwoFilesUnderSameDirectory() throws IOException {
+ String inputDirectory = BASE_DIR + "twoFilesUnderSameDirectory/" + IN;
+ String outputFileName = BASE_DIR + "twoFilesUnderSameDirectory/" + OUT + EXPECTED_TREE_FILE;
+
+ testTreeManager(inputDirectory, outputFileName);
+ }
+
+ private void testTreeManager(String inputDirectory, String outputFileName) throws IOException {
+ initTreeManager(inputDirectory);
+ toscaTreeManager.createTree();
+ HeatStructureTree tree = toscaTreeManager.getTree();
+
+ validateToscaTree(outputFileName, tree);
+ }
+
+ private void validateToscaTree(String outputFileName, HeatStructureTree tree) throws IOException {
+ String actualTree = JsonUtil.object2Json(tree);
+ File expectedTreeFile = new File(this.getClass().getResource(outputFileName).getFile());
+
+ String expectedTree;
+ try(FileInputStream fis = new FileInputStream(expectedTreeFile)) {
+ expectedTree = new String(FileUtils.toByteArray(fis));
+ }
+ Assert.assertNotNull(expectedTree);
+ expectedTree = expectedTree.trim().replace("\r", "");
+ Assert.assertEquals(expectedTree, actualTree);
+ }
+
+ private void initTreeManager(String inputDir) throws IOException {
+ String fileName = inputDir.replace("/", File.separator);
+ File directory = new File(this.getClass().getResource(inputDir).getFile());
+
+ addFilesToTreeManager(fileName, directory.listFiles());
+ }
+
+ private void addFilesToTreeManager(String baseDir, File[] listFiles) throws IOException {
+ for (File file : listFiles) {
+ if (file.isDirectory()) {
+ addFilesToTreeManager(baseDir, file.listFiles());
+ } else {
+ toscaTreeManager.addFile(getFileNameWithoutTestDirectory(baseDir, file.getPath()), new byte[2]);
+ }
+ }
+ }
+
+ private String getFileNameWithoutTestDirectory(String baseDir, String fileName) {
+ return fileName.split(Pattern.quote(baseDir) + Pattern.quote(File.separator))[1];
+ }
+} \ No newline at end of file