2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.sdnc.config.params.transformer.tosca;
27 import org.junit.Assert;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.TemporaryFolder;
31 import org.openecomp.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
36 public class TestGenerateArtifactString{
39 public TemporaryFolder temporaryFolder = new TemporaryFolder();
42 public void testStringArtifactGenerator() throws IOException, ArtifactProcessorException {
44 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
45 OutputStream outstream=null;
47 File tempFile = temporaryFolder.newFile("TestTosca.yml");
48 outstream = new FileOutputStream(tempFile);
49 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
50 arp.generateArtifact(pdString,outstream);
54 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
55 String toscaString = getFileContent(tempFile);
56 Assert.assertEquals(expectedTosca,toscaString);
61 public void testArtifactGeneratorWithParameterNameBlank() throws IOException, ArtifactProcessorException {
63 String pdString = getFileContent("tosca/ExamplePropertyDefinition2.yml");
64 OutputStream outstream=null;
65 String expectedMsg ="Parameter name is empty,null or contains whitespace";
67 File tempFile = temporaryFolder.newFile("TestTosca.yml");
68 outstream = new FileOutputStream(tempFile);
69 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
71 arp.generateArtifact(pdString, outstream);
73 catch (ArtifactProcessorException e)
75 Assert.assertEquals(expectedMsg,e.getMessage());
82 public void testArtifactGeneratorWithParameterNameNull() throws IOException, ArtifactProcessorException {
84 String pdString = getFileContent("tosca/ExamplePropertyDefinition3.yml");
85 OutputStream outstream=null;
86 String expectedMsg ="Parameter name is empty,null or contains whitespace";
88 File tempFile = temporaryFolder.newFile("TestTosca.yml");
89 outstream = new FileOutputStream(tempFile);
90 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
92 arp.generateArtifact(pdString, outstream);
94 catch (ArtifactProcessorException e)
96 Assert.assertEquals(expectedMsg,e.getMessage());
103 public void testArtifactGeneratorWithKindNull() throws IOException, ArtifactProcessorException {
105 String pdString = getFileContent("tosca/ExamplePropertyDefinition4.yml");
106 OutputStream outstream=null;
107 String expectedMsg ="Kind in PropertyDefinition is blank or null";
109 File tempFile = temporaryFolder.newFile("TestTosca.yml");
110 outstream = new FileOutputStream(tempFile);
111 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
113 arp.generateArtifact(pdString, outstream);
115 catch (ArtifactProcessorException e)
117 Assert.assertEquals(expectedMsg,e.getMessage());
123 private String getFileContent(String fileName) throws IOException
125 ClassLoader classLoader = new TestGenerateArtifactString().getClass().getClassLoader();
126 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
127 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
128 String line = buf.readLine();
129 StringBuilder sb = new StringBuilder();
131 while (line != null) {
132 sb.append(line).append("\n");
133 line = buf.readLine();
135 String fileString = sb.toString();
140 private String getFileContent(File file) throws IOException
142 InputStream is = new FileInputStream(file);
143 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
144 String line = buf.readLine();
145 StringBuilder sb = new StringBuilder();
147 while (line != null) {
148 sb.append(line).append("\n");
149 line = buf.readLine();
151 String fileString = sb.toString();