aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java')
-rw-r--r--appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java73
1 files changed, 20 insertions, 53 deletions
diff --git a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java
index d9b31e4bb..df2147c33 100644
--- a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java
+++ b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.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,21 +25,18 @@
package org.onap.sdnc.config.params.transformer.tosca;
-import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
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;
import org.junit.rules.TemporaryFolder;
-import org.onap.sdnc.config.params.data.PropertyDefinition;
-import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
public class TestArtifactProcessor {
@@ -46,10 +45,10 @@ public class TestArtifactProcessor {
@Test
public void testArtifactProcessor() throws IOException, ArtifactProcessorException {
-
ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
-
- 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");
@@ -58,9 +57,11 @@ public class TestArtifactProcessor {
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"));
}
@Test
@@ -69,7 +70,9 @@ public class TestArtifactProcessor {
ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
- String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
+ String pdString = FileUtils.readFileToString(
+ new File("src/test/resources/tosca/ExamplePropertyDefinition.yml"),
+ Charset.defaultCharset());
OutputStream outstream = null;
outstream = new ByteArrayOutputStream();
@@ -77,46 +80,10 @@ public class TestArtifactProcessor {
outstream.flush();
outstream.close();
- String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
+ String expectedTosca = FileUtils.readFileToString(
+ new File("src/test/resources/tosca/ExpectedTosca.yml"),
+ Charset.defaultCharset());
String toscaString = outstream.toString();
- }
-
- @Test
- public void testReadArtifact() throws IOException, ArtifactProcessorException {
- ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
- String pdString = getFileContent("tosca/ExpectedTosca.yml");
- PropertyDefinition propertyDefinitionObj = arp.readArtifact(pdString);
- Assert.assertEquals(7, propertyDefinitionObj.getParameters().size());
- }
-
- private String getFileContent(String fileName) throws IOException {
- ClassLoader classLoader = new TestArtifactProcessor().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;
+ Assert.assertEquals(expectedTosca.replaceAll("\\r\\n", "\n"), toscaString.replaceAll("\\r\\n", "\n"));
}
}