2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2018 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.params.transformer.tosca;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.io.OutputStream;
32 import java.nio.charset.Charset;
33 import java.nio.charset.StandardCharsets;
34 import org.apache.commons.io.FileUtils;
35 import org.junit.Assert;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.rules.TemporaryFolder;
39 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
41 public class TestGenerateArtifactString {
44 public TemporaryFolder temporaryFolder = new TemporaryFolder();
47 public void testStringArtifactGenerator() throws IOException, ArtifactProcessorException {
49 String pdString = FileUtils.readFileToString(
50 new File("src/test/resources/tosca/ExamplePropertyDefinition.yml"),
51 Charset.defaultCharset());
52 OutputStream outstream = null;
54 File tempFile = temporaryFolder.newFile("TestTosca.yml");
55 outstream = new FileOutputStream(tempFile);
56 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
57 arp.generateArtifact(pdString, outstream);
61 String expectedTosca = FileUtils.readFileToString(
62 new File("src/test/resources/tosca/ExpectedTosca.yml"),
63 StandardCharsets.UTF_8);
64 String toscaString = FileUtils.readFileToString(tempFile, StandardCharsets.UTF_8);
65 Assert.assertEquals(expectedTosca.replaceAll("\\r\\n", "\n"), toscaString.replaceAll("\\r\\n", "\n"));
70 public void testArtifactGeneratorWithParameterNameBlank()
71 throws IOException, ArtifactProcessorException {
73 String pdString = FileUtils.readFileToString(
74 new File("src/test/resources/tosca/ExamplePropertyDefinition2.yml"),
75 Charset.defaultCharset());
76 OutputStream outstream = null;
77 String expectedMsg = "Parameter name is empty,null or contains whitespace";
79 File tempFile = temporaryFolder.newFile("TestTosca.yml");
80 outstream = new FileOutputStream(tempFile);
81 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
83 arp.generateArtifact(pdString, outstream);
84 } catch (ArtifactProcessorException e) {
85 Assert.assertEquals(expectedMsg, e.getMessage());
92 public void testArtifactGeneratorWithParameterNameNull()
93 throws IOException, ArtifactProcessorException {
95 String pdString = FileUtils.readFileToString(
96 new File("src/test/resources/tosca/ExamplePropertyDefinition3.yml"),
97 Charset.defaultCharset());
98 OutputStream outstream = null;
99 String expectedMsg = "Parameter name is empty,null or contains whitespace";
101 File tempFile = temporaryFolder.newFile("TestTosca.yml");
102 outstream = new FileOutputStream(tempFile);
103 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
105 arp.generateArtifact(pdString, outstream);
106 } catch (ArtifactProcessorException e) {
107 Assert.assertEquals(expectedMsg, e.getMessage());
114 public void testArtifactGeneratorWithKindNull() throws IOException, ArtifactProcessorException {
115 String pdString = FileUtils.readFileToString(
116 new File("src/test/resources/tosca/ExamplePropertyDefinition4.yml"),
117 Charset.defaultCharset());
118 OutputStream outstream = null;
119 String expectedMsg = "Kind in PropertyDefinition is blank or null";
121 File tempFile = temporaryFolder.newFile("TestTosca.yml");
122 outstream = new FileOutputStream(tempFile);
123 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
125 arp.generateArtifact(pdString, outstream);
126 } catch (ArtifactProcessorException e) {
127 Assert.assertEquals(expectedMsg, e.getMessage());