2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.openecomp.sdnc.config.params.transformer.tosca;
25 //import static org.junit.Assert;
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.openecomp.sdnc.config.params.data.PropertyDefinition;
29 import org.openecomp.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
36 * @since March 23,2017
38 public class TestReadArtifact {
40 public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
42 String toscaArtifact = getFileContent("tosca/ReadArtifactPositiveInputTosca.yml");
43 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
44 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
45 Assert.assertEquals(ouptPD.getKind(),"Property Definition");
46 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(),"INSTAR");
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(),"address_fqdn");
55 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"000000000");
56 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),"address_fqdn");
57 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"000000000");
58 Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),"address-fqdn");
59 //Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyValue(),"000000000");
60 Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getFieldKeyName(),"ipaddress-v4");
62 Assert.assertEquals(ouptPD.getParameters().get(1).getDefaultValue(),"0:0:0:0:0:0:0:0");
63 Assert.assertEquals(ouptPD.getParameters().get(1).getName(),"param 2");
64 Assert.assertEquals(ouptPD.getParameters().get(1).getSource(),"INSTAR");
65 Assert.assertEquals(ouptPD.getParameters().get(1).getRuleType(),"interface-ip-address");
66 Assert.assertEquals(ouptPD.getParameters().get(1).getDescription(),"param2");
67 Assert.assertEquals(ouptPD.getParameters().get(1).getType(),"param2 type");
68 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),"address_fqdn");
69 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"000000000");
70 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyName(),"address_type");
71 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyValue(),"v4");
72 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyName(),"address-fqdn");
73 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyValue(),"000000000");
74 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getFieldKeyName(),"ipaddress-v4");
78 public void testReadArtifactNegetive() throws IOException {
80 String toscaArtifact = getFileContent("tosca/ReadArtifactNegetiveInputTosca.yml");
81 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
83 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
84 } catch (ArtifactProcessorException e) {
85 Assert.assertNotNull(e);
86 Assert.assertEquals(e.getMessage(),"Invalid input found <> source1 <reqk1:reqv1 , reqk2:reqv2>");
90 private String getFileContent(String fileName) throws IOException
92 ClassLoader classLoader = new TestReadArtifact().getClass().getClassLoader();
93 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
94 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
95 String line = buf.readLine();
96 StringBuilder sb = new StringBuilder();
98 while (line != null) {
99 sb.append(line).append("\n");
100 line = buf.readLine();
102 String fileString = sb.toString();