diff options
Diffstat (limited to 'appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactString.java')
-rw-r--r-- | appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactString.java | 65 |
1 files changed, 22 insertions, 43 deletions
diff --git a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactString.java b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactString.java index 76eddb056..79e9daca7 100644 --- a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactString.java +++ b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactString.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2018 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,14 +25,13 @@ package org.onap.sdnc.config.params.transformer.tosca; -import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -45,7 +46,9 @@ public class TestGenerateArtifactString { @Test public void testStringArtifactGenerator() throws IOException, ArtifactProcessorException { - String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml"); + String pdString = FileUtils.readFileToString( + new File("src/test/resources/tosca/ExamplePropertyDefinition.yml"), + Charset.defaultCharset()); OutputStream outstream = null; File tempFile = temporaryFolder.newFile("TestTosca.yml"); @@ -55,9 +58,11 @@ public class TestGenerateArtifactString { outstream.flush(); outstream.close(); - String expectedTosca = getFileContent("tosca/ExpectedTosca.yml"); - String toscaString = getFileContent(tempFile); - Assert.assertEquals(expectedTosca, toscaString); + String expectedTosca = FileUtils.readFileToString( + new File("src/test/resources/tosca/ExpectedTosca.yml"), + StandardCharsets.UTF_8); + String toscaString = FileUtils.readFileToString(tempFile, StandardCharsets.UTF_8); + Assert.assertEquals(expectedTosca.replaceAll("\\r\\n", "\n"), toscaString.replaceAll("\\r\\n", "\n")); } @@ -65,7 +70,9 @@ public class TestGenerateArtifactString { public void testArtifactGeneratorWithParameterNameBlank() throws IOException, ArtifactProcessorException { - String pdString = getFileContent("tosca/ExamplePropertyDefinition2.yml"); + String pdString = FileUtils.readFileToString( + new File("src/test/resources/tosca/ExamplePropertyDefinition2.yml"), + Charset.defaultCharset()); OutputStream outstream = null; String expectedMsg = "Parameter name is empty,null or contains whitespace"; @@ -85,7 +92,9 @@ public class TestGenerateArtifactString { public void testArtifactGeneratorWithParameterNameNull() throws IOException, ArtifactProcessorException { - String pdString = getFileContent("tosca/ExamplePropertyDefinition3.yml"); + String pdString = FileUtils.readFileToString( + new File("src/test/resources/tosca/ExamplePropertyDefinition3.yml"), + Charset.defaultCharset()); OutputStream outstream = null; String expectedMsg = "Parameter name is empty,null or contains whitespace"; @@ -103,8 +112,9 @@ public class TestGenerateArtifactString { @Test public void testArtifactGeneratorWithKindNull() throws IOException, ArtifactProcessorException { - - String pdString = getFileContent("tosca/ExamplePropertyDefinition4.yml"); + String pdString = FileUtils.readFileToString( + new File("src/test/resources/tosca/ExamplePropertyDefinition4.yml"), + Charset.defaultCharset()); OutputStream outstream = null; String expectedMsg = "Kind in PropertyDefinition is blank or null"; @@ -119,35 +129,4 @@ public class TestGenerateArtifactString { outstream.flush(); outstream.close(); } - - private String getFileContent(String fileName) throws IOException { - ClassLoader classLoader = new TestGenerateArtifactString().getClass().getClassLoader(); - InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile()); - BufferedReader buf = new BufferedReader(new InputStreamReader(is)); - String line = buf.readLine(); - StringBuilder sb = new StringBuilder(); - - while (line != null) { - sb.append(line).append("\n"); - line = buf.readLine(); - } - String fileString = sb.toString(); - is.close(); - return fileString; - } - - private String getFileContent(File file) throws IOException { - InputStream is = new FileInputStream(file); - BufferedReader buf = new BufferedReader(new InputStreamReader(is)); - String line = buf.readLine(); - StringBuilder sb = new StringBuilder(); - - while (line != null) { - sb.append(line).append("\n"); - line = buf.readLine(); - } - String fileString = sb.toString(); - is.close(); - return fileString; - } } |