2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.sdnc.config.params.transformer.tosca;
27 //import static org.junit.Assert;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.openecomp.sdnc.config.params.data.PropertyDefinition;
31 import org.openecomp.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
38 * @since March 23,2017
40 public class TestReadArtifact {
42 public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
44 String toscaArtifact = getFileContent("tosca/ReadArtifactPositiveInputTosca.yml");
45 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
46 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
47 Assert.assertEquals(ouptPD.getKind(),"Property Definition");
48 Assert.assertEquals(ouptPD.getVersion(),"V1");
50 Assert.assertEquals(ouptPD.getParameters().get(0).getDefaultValue(),"0.0.0.0");
51 Assert.assertEquals(ouptPD.getParameters().get(0).getName(),"abc");
52 Assert.assertEquals(ouptPD.getParameters().get(0).getSource(),"INSTAR");
53 Assert.assertEquals(ouptPD.getParameters().get(0).getRuleType(),"interface-ip-address");
54 Assert.assertEquals(ouptPD.getParameters().get(0).getDescription(),"param_desc");
55 Assert.assertEquals(ouptPD.getParameters().get(0).getType(),"param1_type");
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(1).getRequestKeys().get(0).getKeyName(),"address_fqdn");
59 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"000000000");
60 Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),"address-fqdn");
61 //Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyValue(),"000000000");
62 Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getFieldKeyName(),"ipaddress-v4");
64 Assert.assertEquals(ouptPD.getParameters().get(1).getDefaultValue(),"0:0:0:0:0:0:0:0");
65 Assert.assertEquals(ouptPD.getParameters().get(1).getName(),"param 2");
66 Assert.assertEquals(ouptPD.getParameters().get(1).getSource(),"INSTAR");
67 Assert.assertEquals(ouptPD.getParameters().get(1).getRuleType(),"interface-ip-address");
68 Assert.assertEquals(ouptPD.getParameters().get(1).getDescription(),"param2");
69 Assert.assertEquals(ouptPD.getParameters().get(1).getType(),"param2 type");
70 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),"address_fqdn");
71 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"000000000");
72 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyName(),"address_type");
73 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyValue(),"v4");
74 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyName(),"address-fqdn");
75 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyValue(),"000000000");
76 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getFieldKeyName(),"ipaddress-v4");
80 public void testReadArtifactNegetive() throws IOException {
82 String toscaArtifact = getFileContent("tosca/ReadArtifactNegetiveInputTosca.yml");
83 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
85 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
86 } catch (ArtifactProcessorException e) {
87 Assert.assertNotNull(e);
88 Assert.assertEquals(e.getMessage(),"Invalid input found <> source1 <reqk1:reqv1 , reqk2:reqv2>");
92 private String getFileContent(String fileName) throws IOException
94 ClassLoader classLoader = new TestReadArtifact().getClass().getClassLoader();
95 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
96 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
97 String line = buf.readLine();
98 StringBuilder sb = new StringBuilder();
100 while (line != null) {
101 sb.append(line).append("\n");
102 line = buf.readLine();
104 String fileString = sb.toString();