Changed to unmaintained
[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  * 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.IOException;
30 import java.nio.charset.StandardCharsets;
31 import org.apache.commons.io.FileUtils;
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
39     @Test
40     public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
41         String toscaArtifact = FileUtils.readFileToString(
42                 new File("src/test/resources/tosca/ReadArtifactPositiveInputTosca.yml"),
43                 StandardCharsets.UTF_8);
44         ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
45         PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
46         Assert.assertEquals(ouptPD.getKind(), "Property Definition");
47         Assert.assertEquals(ouptPD.getVersion(), "V1");
48         Assert.assertEquals(ouptPD.getParameters().get(0).getDefaultValue(), "0.0.0.0");
49         Assert.assertEquals(ouptPD.getParameters().get(0).getName(), "abc");
50         Assert.assertEquals(ouptPD.getParameters().get(0).getSource(), "source");
51         Assert.assertEquals(ouptPD.getParameters().get(0).getRuleType(), "interface-ip-address");
52         Assert.assertEquals(ouptPD.getParameters().get(0).getDescription(), "param_desc");
53         Assert.assertEquals(ouptPD.getParameters().get(0).getType(), "param1_type");
54         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
55                 "address_fqdn");
56         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
57                 "0");
58         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
59                 "address_fqdn");
60         Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
61                 "0");
62         Assert.assertEquals(
63                 ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),
64                 "address-0");
65         Assert.assertEquals(
66                 ouptPD.getParameters().get(0).getResponseKeys().get(0).getFieldKeyName(), "0");
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     @Test
91     public void testReadArtifactNegetive() throws IOException {
92         String toscaArtifact = FileUtils.readFileToString(
93                 new File("src/test/resources/tosca/ReadArtifactNegetiveInputTosca.yml"),
94                 StandardCharsets.UTF_8);
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 }