aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-params/provider/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-config-params/provider/src/test/java/org')
-rw-r--r--appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/TestArtifactTransformer.java48
-rw-r--r--appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestArtifactProcessor.java73
-rw-r--r--appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactObject.java39
-rw-r--r--appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactString.java65
-rw-r--r--appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestReadArtifact.java39
5 files changed, 109 insertions, 155 deletions
diff --git a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/TestArtifactTransformer.java b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/TestArtifactTransformer.java
new file mode 100644
index 000000000..003f7e87f
--- /dev/null
+++ b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/TestArtifactTransformer.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdnc.config.params.transformer;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import org.apache.commons.io.FileUtils;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
+
+public class TestArtifactTransformer {
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Test
+ public void testArtifactTransformerYAMLtoJSON() throws IOException {
+ ArtificatTransformer transformer = new ArtificatTransformer();
+ String pdString = FileUtils.readFileToString(
+ new File("src/test/resources/tosca/ExamplePropertyDefinition.yml"),
+ Charset.defaultCharset());
+ String output = transformer.transformYamlToJson(pdString);
+ Assert.assertThat(output, CoreMatchers.containsString("response-keys"));
+ }
+}
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"));
}
}
diff --git a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactObject.java b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactObject.java
index f570b4b8c..766f0d986 100644
--- a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactObject.java
+++ b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestGenerateArtifactObject.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,16 +25,14 @@
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.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
@@ -77,7 +77,7 @@ public class TestGenerateArtifactObject {
outstream.flush();
outstream.close();
- String toscaString = getFileContent(toscaFile);
+ String toscaString = FileUtils.readFileToString(toscaFile, StandardCharsets.UTF_8);
Assert.assertEquals(expectedTosca, toscaString);
}
@@ -102,7 +102,8 @@ public class TestGenerateArtifactObject {
outstream.flush();
outstream.close();
- String toscaString = getFileContent(toscaFile);
+ String toscaString = FileUtils.readFileToString(toscaFile, StandardCharsets.UTF_8);
+
Assert.assertEquals(expectedTosca, toscaString);
}
@@ -194,17 +195,6 @@ public class TestGenerateArtifactObject {
return responseKeyList;
}
- private Parameter createParameter() {
- Parameter singleParameter1 = new Parameter();
- singleParameter1.setName("LOCAL_ACCESS_IP_ADDR");
- singleParameter1.setRequired(false);
- singleParameter1.setSource("source");
- singleParameter1.setDefaultValue("0.0.0.0");
- singleParameter1.setRequestKeys(createRequestKeys());
- singleParameter1.setResponseKeys(createResponseKeys());
- return singleParameter1;
- }
-
@Test(expected = Exception.class)
public void testPDnull() throws IOException, ArtifactProcessorException {
PropertyDefinition pd = null;
@@ -216,19 +206,4 @@ public class TestGenerateArtifactObject {
outstream.flush();
outstream.close();
}
-
- 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;
- }
}
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;
- }
}
diff --git a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestReadArtifact.java b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestReadArtifact.java
index 97a2458ed..697b90b07 100644
--- a/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestReadArtifact.java
+++ b/appc-config/appc-config-params/provider/src/test/java/org/onap/sdnc/config/params/transformer/tosca/TestReadArtifact.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,26 +25,26 @@
package org.onap.sdnc.config.params.transformer.tosca;
-import java.io.BufferedReader;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import org.onap.sdnc.config.params.data.PropertyDefinition;
import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
public class TestReadArtifact {
+
@Test
public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
-
- String toscaArtifact = getFileContent("tosca/ReadArtifactPositiveInputTosca.yml");
+ String toscaArtifact = FileUtils.readFileToString(
+ new File("src/test/resources/tosca/ReadArtifactPositiveInputTosca.yml"),
+ StandardCharsets.UTF_8);
ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
Assert.assertEquals(ouptPD.getKind(), "Property Definition");
Assert.assertEquals(ouptPD.getVersion(), "V1");
-
Assert.assertEquals(ouptPD.getParameters().get(0).getDefaultValue(), "0.0.0.0");
Assert.assertEquals(ouptPD.getParameters().get(0).getName(), "abc");
Assert.assertEquals(ouptPD.getParameters().get(0).getSource(), "source");
@@ -62,7 +64,6 @@ public class TestReadArtifact {
"address-0");
Assert.assertEquals(
ouptPD.getParameters().get(0).getResponseKeys().get(0).getFieldKeyName(), "0");
-
Assert.assertEquals(ouptPD.getParameters().get(1).getDefaultValue(), "value");
Assert.assertEquals(ouptPD.getParameters().get(1).getName(), "param 2");
Assert.assertEquals(ouptPD.getParameters().get(1).getSource(), "source");
@@ -84,13 +85,13 @@ public class TestReadArtifact {
ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyValue(), "0");
Assert.assertEquals(
ouptPD.getParameters().get(1).getResponseKeys().get(0).getFieldKeyName(), "0");
-
}
@Test
public void testReadArtifactNegetive() throws IOException {
-
- String toscaArtifact = getFileContent("tosca/ReadArtifactNegetiveInputTosca.yml");
+ String toscaArtifact = FileUtils.readFileToString(
+ new File("src/test/resources/tosca/ReadArtifactNegetiveInputTosca.yml"),
+ StandardCharsets.UTF_8);
ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
try {
PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
@@ -101,20 +102,4 @@ public class TestReadArtifact {
}
}
- private String getFileContent(String fileName) throws IOException {
- ClassLoader classLoader = new TestReadArtifact().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;
- }
-
}