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;
37 * Created by pranavdi on 3/21/2017.
39 public class TestGenerateArtifactString{
42 public TemporaryFolder temporaryFolder = new TemporaryFolder();
45 public void testStringArtifactGenerator() throws IOException, ArtifactProcessorException {
47 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
48 OutputStream outstream=null;
50 File tempFile = temporaryFolder.newFile("TestTosca.yml");
51 outstream = new FileOutputStream(tempFile);
52 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
53 arp.generateArtifact(pdString,outstream);
57 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
58 String toscaString = getFileContent(tempFile);
59 Assert.assertEquals(expectedTosca,toscaString);
64 public void testArtifactGeneratorWithParameterNameBlank() throws IOException, ArtifactProcessorException {
66 String pdString = getFileContent("tosca/ExamplePropertyDefinition2.yml");
67 OutputStream outstream=null;
68 String expectedMsg ="Parameter name is empty,null or contains whitespace";
70 File tempFile = temporaryFolder.newFile("TestTosca.yml");
71 outstream = new FileOutputStream(tempFile);
72 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
74 arp.generateArtifact(pdString, outstream);
76 catch (ArtifactProcessorException e)
78 Assert.assertEquals(expectedMsg,e.getMessage());
85 public void testArtifactGeneratorWithParameterNameNull() throws IOException, ArtifactProcessorException {
87 String pdString = getFileContent("tosca/ExamplePropertyDefinition3.yml");
88 OutputStream outstream=null;
89 String expectedMsg ="Parameter name is empty,null or contains whitespace";
91 File tempFile = temporaryFolder.newFile("TestTosca.yml");
92 outstream = new FileOutputStream(tempFile);
93 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
95 arp.generateArtifact(pdString, outstream);
97 catch (ArtifactProcessorException e)
99 Assert.assertEquals(expectedMsg,e.getMessage());
106 public void testArtifactGeneratorWithKindNull() throws IOException, ArtifactProcessorException {
108 String pdString = getFileContent("tosca/ExamplePropertyDefinition4.yml");
109 OutputStream outstream=null;
110 String expectedMsg ="Kind in PropertyDefinition is blank or null";
112 File tempFile = temporaryFolder.newFile("TestTosca.yml");
113 outstream = new FileOutputStream(tempFile);
114 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
116 arp.generateArtifact(pdString, outstream);
118 catch (ArtifactProcessorException e)
120 Assert.assertEquals(expectedMsg,e.getMessage());
126 private String getFileContent(String fileName) throws IOException
128 ClassLoader classLoader = new TestGenerateArtifactString().getClass().getClassLoader();
129 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
130 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
131 String line = buf.readLine();
132 StringBuilder sb = new StringBuilder();
134 while (line != null) {
135 sb.append(line).append("\n");
136 line = buf.readLine();
138 String fileString = sb.toString();
143 private String getFileContent(File file) throws IOException
145 InputStream is = new FileInputStream(file);
146 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
147 String line = buf.readLine();
148 StringBuilder sb = new StringBuilder();
150 while (line != null) {
151 sb.append(line).append("\n");
152 line = buf.readLine();
154 String fileString = sb.toString();