2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.config.params.transformer.tosca;
26 import java.io.BufferedReader;
27 import java.io.ByteArrayOutputStream;
29 import java.io.FileInputStream;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.InputStream;
33 import java.io.InputStreamReader;
34 import java.io.OutputStream;
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 TestArtifactProcessor {
43 public TemporaryFolder temporaryFolder = new TemporaryFolder();
46 public void testArtifactProcessor() throws IOException, ArtifactProcessorException {
48 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
50 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
51 OutputStream outstream = null;
53 File tempFile = temporaryFolder.newFile("TestTosca.yml");
54 outstream = new FileOutputStream(tempFile);
55 arp.generateArtifact(pdString, outstream);
59 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
60 String toscaString = getFileContent(tempFile);
61 Assert.assertEquals(expectedTosca, toscaString);
65 public void testArtifactProcessorWithStringOutput()
66 throws IOException, ArtifactProcessorException {
68 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
70 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
71 OutputStream outstream = null;
73 outstream = new ByteArrayOutputStream();
74 arp.generateArtifact(pdString, outstream);
78 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
79 String toscaString = outstream.toString();
82 private String getFileContent(String fileName) throws IOException {
83 ClassLoader classLoader = new TestArtifactProcessor().getClass().getClassLoader();
84 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
85 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
86 String line = buf.readLine();
87 StringBuilder sb = new StringBuilder();
89 while (line != null) {
90 sb.append(line).append("\n");
91 line = buf.readLine();
93 String fileString = sb.toString();
98 private String getFileContent(File file) throws IOException {
99 InputStream is = new FileInputStream(file);
100 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
101 String line = buf.readLine();
102 StringBuilder sb = new StringBuilder();
104 while (line != null) {
105 sb.append(line).append("\n");
106 line = buf.readLine();
108 String fileString = sb.toString();