2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.openecomp.sdnc.config.params.transformer.tosca;
25 import org.junit.Assert;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.TemporaryFolder;
29 import org.openecomp.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
33 public class TestArtifactProcessor{
35 public TemporaryFolder temporaryFolder = new TemporaryFolder();
38 public void testArtifactProcessor() throws IOException, ArtifactProcessorException {
40 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
42 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
43 OutputStream outstream=null;
45 File tempFile = temporaryFolder.newFile("TestTosca.yml");
46 outstream = new FileOutputStream(tempFile);
47 arp.generateArtifact(pdString,outstream);
51 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
52 String toscaString = getFileContent(tempFile);
53 Assert.assertEquals(expectedTosca,toscaString);
57 public void testArtifactProcessorWithStringOutput() throws IOException, ArtifactProcessorException {
59 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
61 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
62 OutputStream outstream=null;
64 outstream = new ByteArrayOutputStream();
65 arp.generateArtifact(pdString,outstream);
69 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
70 String toscaString = outstream.toString();
71 Assert.assertEquals(expectedTosca,toscaString);
74 private String getFileContent(String fileName) throws IOException{
75 ClassLoader classLoader = new TestArtifactProcessor().getClass().getClassLoader();
76 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
77 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
78 String line = buf.readLine();
79 StringBuilder sb = new StringBuilder();
81 while (line != null) {
82 sb.append(line).append("\n");
83 line = buf.readLine();
85 String fileString = sb.toString();
90 private String getFileContent(File file) throws IOException{
91 InputStream is = new FileInputStream(file);
92 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
93 String line = buf.readLine();
94 StringBuilder sb = new StringBuilder();
96 while (line != null) {
97 sb.append(line).append("\n");
98 line = buf.readLine();
100 String fileString = sb.toString();