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