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.onap.sdnc.config.params.transformer.tosca;
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;
37 public class TestReadArtifact {
39 public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
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");
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(),
55 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
57 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
59 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
62 ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),
65 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(),
75 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
77 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyName(),
79 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyValue(),
82 ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyName(),
85 ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyValue(), "0");
87 ouptPD.getParameters().get(1).getResponseKeys().get(0).getFieldKeyName(), "0");
92 public void testReadArtifactNegetive() throws IOException {
94 String toscaArtifact = getFileContent("tosca/ReadArtifactNegetiveInputTosca.yml");
95 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
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>");
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();
112 while (line != null) {
113 sb.append(line).append("\n");
114 line = buf.readLine();
116 String fileString = sb.toString();