Changed to unmaintained
[appc.git] / appc-config / appc-config-params / provider / src / test / java / org / onap / sdnc / config / params / transformer / tosca / TestGenerateArtifactString.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.File;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.io.OutputStream;
32 import java.nio.charset.Charset;
33 import java.nio.charset.StandardCharsets;
34 import org.apache.commons.io.FileUtils;
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;
40
41 public class TestGenerateArtifactString {
42
43     @Rule
44     public TemporaryFolder temporaryFolder = new TemporaryFolder();
45
46     @Test
47     public void testStringArtifactGenerator() throws IOException, ArtifactProcessorException {
48
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         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
57         arp.generateArtifact(pdString, outstream);
58         outstream.flush();
59         outstream.close();
60
61         String expectedTosca = FileUtils.readFileToString(
62                 new File("src/test/resources/tosca/ExpectedTosca.yml"),
63                 StandardCharsets.UTF_8);
64         String toscaString = FileUtils.readFileToString(tempFile, StandardCharsets.UTF_8);
65         Assert.assertEquals(expectedTosca.replaceAll("\\r\\n", "\n"), toscaString.replaceAll("\\r\\n", "\n"));
66
67     }
68
69     @Test
70     public void testArtifactGeneratorWithParameterNameBlank()
71             throws IOException, ArtifactProcessorException {
72
73         String pdString = FileUtils.readFileToString(
74                 new File("src/test/resources/tosca/ExamplePropertyDefinition2.yml"),
75                 Charset.defaultCharset());
76         OutputStream outstream = null;
77         String expectedMsg = "Parameter name is empty,null or contains whitespace";
78
79         File tempFile = temporaryFolder.newFile("TestTosca.yml");
80         outstream = new FileOutputStream(tempFile);
81         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
82         try {
83             arp.generateArtifact(pdString, outstream);
84         } catch (ArtifactProcessorException e) {
85             Assert.assertEquals(expectedMsg, e.getMessage());
86         }
87         outstream.flush();
88         outstream.close();
89     }
90
91     @Test
92     public void testArtifactGeneratorWithParameterNameNull()
93             throws IOException, ArtifactProcessorException {
94
95         String pdString = FileUtils.readFileToString(
96                 new File("src/test/resources/tosca/ExamplePropertyDefinition3.yml"),
97                 Charset.defaultCharset());
98         OutputStream outstream = null;
99         String expectedMsg = "Parameter name is empty,null or contains whitespace";
100
101         File tempFile = temporaryFolder.newFile("TestTosca.yml");
102         outstream = new FileOutputStream(tempFile);
103         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
104         try {
105             arp.generateArtifact(pdString, outstream);
106         } catch (ArtifactProcessorException e) {
107             Assert.assertEquals(expectedMsg, e.getMessage());
108         }
109         outstream.flush();
110         outstream.close();
111     }
112
113     @Test
114     public void testArtifactGeneratorWithKindNull() throws IOException, ArtifactProcessorException {
115         String pdString = FileUtils.readFileToString(
116                 new File("src/test/resources/tosca/ExamplePropertyDefinition4.yml"),
117                 Charset.defaultCharset());
118         OutputStream outstream = null;
119         String expectedMsg = "Kind in PropertyDefinition is blank or null";
120
121         File tempFile = temporaryFolder.newFile("TestTosca.yml");
122         outstream = new FileOutputStream(tempFile);
123         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
124         try {
125             arp.generateArtifact(pdString, outstream);
126         } catch (ArtifactProcessorException e) {
127             Assert.assertEquals(expectedMsg, e.getMessage());
128         }
129         outstream.flush();
130         outstream.close();
131     }
132 }