Fix for APPC-1263
[appc.git] / appc-config / appc-config-params / provider / src / test / java / org / onap / sdnc / config / params / transformer / tosca / TestArtifactProcessor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
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.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.sdnc.config.params.transformer.tosca;
27
28 import java.io.ByteArrayOutputStream;
29 import java.io.File;
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;
41
42 public class TestArtifactProcessor {
43     @Rule
44     public TemporaryFolder temporaryFolder = new TemporaryFolder();
45
46     @Test
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;
53
54         File tempFile = temporaryFolder.newFile("TestTosca.yml");
55         outstream = new FileOutputStream(tempFile);
56         arp.generateArtifact(pdString, outstream);
57         outstream.flush();
58         outstream.close();
59
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"));
65     }
66
67     @Test
68     public void testArtifactProcessorWithStringOutput()
69             throws IOException, ArtifactProcessorException {
70
71         ArtifactProcessor arp = ArtifactProcessorFactory.getArtifactProcessor();
72
73         String pdString = FileUtils.readFileToString(
74                 new File("src/test/resources/tosca/ExamplePropertyDefinition.yml"),
75                 Charset.defaultCharset());
76         OutputStream outstream = null;
77
78         outstream = new ByteArrayOutputStream();
79         arp.generateArtifact(pdString, outstream);
80         outstream.flush();
81         outstream.close();
82
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"));
88     }
89 }