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.onap.sdnc.config.params.transformer.tosca;
27 import java.io.BufferedReader;
28 import java.io.ByteArrayOutputStream;
30 import java.io.FileInputStream;
31 import java.io.FileOutputStream;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.InputStreamReader;
35 import java.io.OutputStream;
36 import org.junit.Assert;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.TemporaryFolder;
40 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
42 public class TestArtifactProcessor {
44 public TemporaryFolder temporaryFolder = new TemporaryFolder();
47 public void testArtifactProcessor() throws IOException, ArtifactProcessorException {
49 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
51 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
52 OutputStream outstream = null;
54 File tempFile = temporaryFolder.newFile("TestTosca.yml");
55 outstream = new FileOutputStream(tempFile);
56 arp.generateArtifact(pdString, outstream);
60 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
61 String toscaString = getFileContent(tempFile);
62 Assert.assertEquals(expectedTosca, toscaString);
66 public void testArtifactProcessorWithStringOutput()
67 throws IOException, ArtifactProcessorException {
69 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
71 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
72 OutputStream outstream = null;
74 outstream = new ByteArrayOutputStream();
75 arp.generateArtifact(pdString, outstream);
79 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
80 String toscaString = outstream.toString();
83 private String getFileContent(String fileName) throws IOException {
84 ClassLoader classLoader = new TestArtifactProcessor().getClass().getClassLoader();
85 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
86 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
87 String line = buf.readLine();
88 StringBuilder sb = new StringBuilder();
90 while (line != null) {
91 sb.append(line).append("\n");
92 line = buf.readLine();
94 String fileString = sb.toString();
99 private String getFileContent(File file) throws IOException {
100 InputStream is = new FileInputStream(file);
101 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
102 String line = buf.readLine();
103 StringBuilder sb = new StringBuilder();
105 while (line != null) {
106 sb.append(line).append("\n");
107 line = buf.readLine();
109 String fileString = sb.toString();