2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2018 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.params.transformer.tosca;
28 import java.io.ByteArrayOutputStream;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.OutputStream;
33 import java.nio.charset.Charset;
34 import java.nio.charset.StandardCharsets;
35 import org.apache.commons.io.FileUtils;
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 {
48 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
49 String pdString = FileUtils.readFileToString(
50 new File("src/test/resources/tosca/ExamplePropertyDefinition.yml"),
51 Charset.defaultCharset());
52 OutputStream outstream = null;
54 File tempFile = temporaryFolder.newFile("TestTosca.yml");
55 outstream = new FileOutputStream(tempFile);
56 arp.generateArtifact(pdString, outstream);
60 String expectedTosca = FileUtils.readFileToString(
61 new File("src/test/resources/tosca/ExpectedTosca.yml"),
62 StandardCharsets.UTF_8);
63 String toscaString = FileUtils.readFileToString(tempFile, StandardCharsets.UTF_8);
64 Assert.assertEquals(expectedTosca.replaceAll("\\r\\n", "\n"), toscaString.replaceAll("\\r\\n", "\n"));
68 public void testArtifactProcessorWithStringOutput()
69 throws IOException, ArtifactProcessorException {
71 ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
73 String pdString = FileUtils.readFileToString(
74 new File("src/test/resources/tosca/ExamplePropertyDefinition.yml"),
75 Charset.defaultCharset());
76 OutputStream outstream = null;
78 outstream = new ByteArrayOutputStream();
79 arp.generateArtifact(pdString, outstream);
83 String expectedTosca = FileUtils.readFileToString(
84 new File("src/test/resources/tosca/ExpectedTosca.yml"),
85 Charset.defaultCharset());
86 String toscaString = outstream.toString();
87 Assert.assertEquals(expectedTosca.replaceAll("\\r\\n", "\n"), toscaString.replaceAll("\\r\\n", "\n"));