More license header updates to appc-config files
[appc.git] / appc-config / appc-config-params / provider / src / test / java / org / onap / sdnc / config / params / transformer / tosca / TestReadArtifact.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  * 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.sdnc.config.params.transformer.tosca;
25
26 import java.io.BufferedReader;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.onap.sdnc.config.params.data.PropertyDefinition;
34 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
35
36 public class TestReadArtifact {
37     @Test
38     public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
39
40         String toscaArtifact = getFileContent("tosca/ReadArtifactPositiveInputTosca.yml");
41         ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
42         PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
43         Assert.assertEquals(ouptPD.getKind(), "Property Definition");
44         Assert.assertEquals(ouptPD.getVersion(), "V1");
45
46         Assert.assertEquals(ouptPD.getParameters().get(0).getDefaultValue(), "0.0.0.0");
47         Assert.assertEquals(ouptPD.getParameters().get(0).getName(), "abc");
48         Assert.assertEquals(ouptPD.getParameters().get(0).getSource(), "source");
49         Assert.assertEquals(ouptPD.getParameters().get(0).getRuleType(), "interface-ip-address");
50         Assert.assertEquals(ouptPD.getParameters().get(0).getDescription(), "param_desc");
51         Assert.assertEquals(ouptPD.getParameters().get(0).getType(), "param1_type");
52         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
53                 "address_fqdn");
54         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
55                 "0");
56         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
57                 "address_fqdn");
58         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
59                 "0");
60         Assert.assertEquals(
61                 ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),
62                 "address-0");
63         Assert.assertEquals(
64                 ouptPD.getParameters().get(0).getResponseKeys().get(0).getFieldKeyName(), "0");
65
66         Assert.assertEquals(ouptPD.getParameters().get(1).getDefaultValue(), "value");
67         Assert.assertEquals(ouptPD.getParameters().get(1).getName(), "param 2");
68         Assert.assertEquals(ouptPD.getParameters().get(1).getSource(), "source");
69         Assert.assertEquals(ouptPD.getParameters().get(1).getRuleType(), "interface-ip-address");
70         Assert.assertEquals(ouptPD.getParameters().get(1).getDescription(), "param2");
71         Assert.assertEquals(ouptPD.getParameters().get(1).getType(), "param2 type");
72         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
73                 "address_fqdn");
74         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
75                 "0");
76         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyName(),
77                 "address_type");
78         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyValue(),
79                 "v4");
80         Assert.assertEquals(
81                 ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyName(),
82                 "address-0");
83         Assert.assertEquals(
84                 ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyValue(), "0");
85         Assert.assertEquals(
86                 ouptPD.getParameters().get(1).getResponseKeys().get(0).getFieldKeyName(), "0");
87
88     }
89
90     @Test
91     public void testReadArtifactNegetive() throws IOException {
92
93         String toscaArtifact = getFileContent("tosca/ReadArtifactNegetiveInputTosca.yml");
94         ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
95         try {
96             PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
97         } catch (ArtifactProcessorException e) {
98             Assert.assertNotNull(e);
99             Assert.assertEquals(e.getMessage(),
100                     "Invalid input found <> source1 <reqk1:reqv1 , reqk2:reqv2>");
101         }
102     }
103
104     private String getFileContent(String fileName) throws IOException {
105         ClassLoader classLoader = new TestReadArtifact().getClass().getClassLoader();
106         InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
107         BufferedReader buf = new BufferedReader(new InputStreamReader(is));
108         String line = buf.readLine();
109         StringBuilder sb = new StringBuilder();
110
111         while (line != null) {
112             sb.append(line).append("\n");
113             line = buf.readLine();
114         }
115         String fileString = sb.toString();
116         is.close();
117         return fileString;
118     }
119
120 }