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 org.junit.Assert;
28 import org.junit.Test;
29 import org.openecomp.sdnc.config.params.data.PropertyDefinition;
30 import org.openecomp.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
34 public class TestReadArtifact {
36 public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
38 String toscaArtifact = getFileContent("tosca/ReadArtifactPositiveInputTosca.yml");
39 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
40 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
41 Assert.assertEquals(ouptPD.getKind(),"Property Definition");
42 Assert.assertEquals(ouptPD.getVersion(),"V1");
44 Assert.assertEquals(ouptPD.getParameters().get(0).getDefaultValue(),"0.0.0.0");
45 Assert.assertEquals(ouptPD.getParameters().get(0).getName(),"abc");
46 Assert.assertEquals(ouptPD.getParameters().get(0).getSource(),"source");
47 Assert.assertEquals(ouptPD.getParameters().get(0).getRuleType(),"interface-ip-address");
48 Assert.assertEquals(ouptPD.getParameters().get(0).getDescription(),"param_desc");
49 Assert.assertEquals(ouptPD.getParameters().get(0).getType(),"param1_type");
50 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),"address_fqdn");
51 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"0");
52 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),"address_fqdn");
53 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"0");
54 Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),"address-0");
55 Assert.assertEquals(ouptPD.getParameters().get(0).getResponseKeys().get(0).getFieldKeyName(),"0");
57 Assert.assertEquals(ouptPD.getParameters().get(1).getDefaultValue(),"value");
58 Assert.assertEquals(ouptPD.getParameters().get(1).getName(),"param 2");
59 Assert.assertEquals(ouptPD.getParameters().get(1).getSource(),"source");
60 Assert.assertEquals(ouptPD.getParameters().get(1).getRuleType(),"interface-ip-address");
61 Assert.assertEquals(ouptPD.getParameters().get(1).getDescription(),"param2");
62 Assert.assertEquals(ouptPD.getParameters().get(1).getType(),"param2 type");
63 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),"address_fqdn");
64 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),"0");
65 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyName(),"address_type");
66 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyValue(),"v4");
67 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyName(),"address-0");
68 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyValue(),"0");
69 Assert.assertEquals(ouptPD.getParameters().get(1).getResponseKeys().get(0).getFieldKeyName(),"0");
74 public void testReadArtifactNegetive() throws IOException {
76 String toscaArtifact = getFileContent("tosca/ReadArtifactNegetiveInputTosca.yml");
77 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
79 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
80 } catch (ArtifactProcessorException e) {
81 Assert.assertNotNull(e);
82 Assert.assertEquals(e.getMessage(),"Invalid input found <> source1 <reqk1:reqv1 , reqk2:reqv2>");
86 private String getFileContent(String fileName) throws IOException
88 ClassLoader classLoader = new TestReadArtifact().getClass().getClassLoader();
89 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
90 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
91 String line = buf.readLine();
92 StringBuilder sb = new StringBuilder();
94 while (line != null) {
95 sb.append(line).append("\n");
96 line = buf.readLine();
98 String fileString = sb.toString();