* 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.
package org.onap.sdnc.config.params.transformer;
import java.io.IOException;
-import java.util.List;
import org.apache.commons.lang3.StringUtils;
-import org.onap.sdnc.config.params.data.Parameter;
import org.onap.sdnc.config.params.data.PropertyDefinition;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
}
return propertyDefinition;
}
-
- public String convertYAMLToParams(String pdContent)
- throws JsonParseException, JsonMappingException, IOException {
- String paramJson = null;
- if (StringUtils.isNotBlank(pdContent)) {
- paramJson = convertPdToParams(convertYAMLToPD(pdContent));
- }
- return paramJson;
- }
-
- public String convertPdToParams(PropertyDefinition propertyDefinition)
- throws JsonParseException, JsonMappingException, IOException {
- String paramJson = null;
- if (propertyDefinition != null && propertyDefinition.getParameters() != null) {
- List<Parameter> parameters = propertyDefinition.getParameters();
-
- }
- return paramJson;
- }
}
--- /dev/null
+/*-
+ * ============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"));
+ }
+}
* 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.
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 {
@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");
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
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();
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"));
}
}
* 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.
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;
outstream.flush();
outstream.close();
- String toscaString = getFileContent(toscaFile);
+ String toscaString = FileUtils.readFileToString(toscaFile, StandardCharsets.UTF_8);
Assert.assertEquals(expectedTosca, toscaString);
}
outstream.flush();
outstream.close();
- String toscaString = getFileContent(toscaFile);
+ String toscaString = FileUtils.readFileToString(toscaFile, StandardCharsets.UTF_8);
+
Assert.assertEquals(expectedTosca, toscaString);
}
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;
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;
- }
}
* 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.
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;
@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");
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"));
}
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";
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";
@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";
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;
- }
}
* 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.
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");
"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");
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);
}
}
- 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;
- }
-
}