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.data.PropertyDefinition;
40 import org.onap.sdnc.config.params.transformer.ArtificatTransformer;
41 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
43 public class TestArtifactProcessor {
45 public TemporaryFolder temporaryFolder = new TemporaryFolder();
48 public void testArtifactProcessor() throws IOException, ArtifactProcessorException {
50 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
52 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
53 OutputStream outstream = null;
55 File tempFile = temporaryFolder.newFile("TestTosca.yml");
56 outstream = new FileOutputStream(tempFile);
57 arp.generateArtifact(pdString, outstream);
61 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
62 String toscaString = getFileContent(tempFile);
63 Assert.assertEquals(expectedTosca, toscaString);
67 public void testArtifactProcessorWithStringOutput()
68 throws IOException, ArtifactProcessorException {
70 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
72 String pdString = getFileContent("tosca/ExamplePropertyDefinition.yml");
73 OutputStream outstream = null;
75 outstream = new ByteArrayOutputStream();
76 arp.generateArtifact(pdString, outstream);
80 String expectedTosca = getFileContent("tosca/ExpectedTosca.yml");
81 String toscaString = outstream.toString();
85 public void testReadArtifact() throws IOException, ArtifactProcessorException {
86 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
87 String pdString = getFileContent("tosca/ExpectedTosca.yml");
88 PropertyDefinition propertyDefinitionObj = arp.readArtifact(pdString);
89 Assert.assertEquals(7, propertyDefinitionObj.getParameters().size());
92 private String getFileContent(String fileName) throws IOException {
93 ClassLoader classLoader = new TestArtifactProcessor().getClass().getClassLoader();
94 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
95 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
96 String line = buf.readLine();
97 StringBuilder sb = new StringBuilder();
99 while (line != null) {
100 sb.append(line).append("\n");
101 line = buf.readLine();
103 String fileString = sb.toString();
108 private String getFileContent(File file) throws IOException {
109 InputStream is = new FileInputStream(file);
110 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
111 String line = buf.readLine();
112 StringBuilder sb = new StringBuilder();
114 while (line != null) {
115 sb.append(line).append("\n");
116 line = buf.readLine();
118 String fileString = sb.toString();