2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.config.params.transformer.tosca;
26 import java.io.BufferedReader;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.onap.sdnc.config.params.data.PropertyDefinition;
34 import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException;
36 public class TestReadArtifact {
38 public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
40 String toscaArtifact = getFileContent("tosca/ReadArtifactPositiveInputTosca.yml");
41 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
42 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
43 Assert.assertEquals(ouptPD.getKind(), "Property Definition");
44 Assert.assertEquals(ouptPD.getVersion(), "V1");
46 Assert.assertEquals(ouptPD.getParameters().get(0).getDefaultValue(), "0.0.0.0");
47 Assert.assertEquals(ouptPD.getParameters().get(0).getName(), "abc");
48 Assert.assertEquals(ouptPD.getParameters().get(0).getSource(), "source");
49 Assert.assertEquals(ouptPD.getParameters().get(0).getRuleType(), "interface-ip-address");
50 Assert.assertEquals(ouptPD.getParameters().get(0).getDescription(), "param_desc");
51 Assert.assertEquals(ouptPD.getParameters().get(0).getType(), "param1_type");
52 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
54 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
56 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
58 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
61 ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),
64 ouptPD.getParameters().get(0).getResponseKeys().get(0).getFieldKeyName(), "0");
66 Assert.assertEquals(ouptPD.getParameters().get(1).getDefaultValue(), "value");
67 Assert.assertEquals(ouptPD.getParameters().get(1).getName(), "param 2");
68 Assert.assertEquals(ouptPD.getParameters().get(1).getSource(), "source");
69 Assert.assertEquals(ouptPD.getParameters().get(1).getRuleType(), "interface-ip-address");
70 Assert.assertEquals(ouptPD.getParameters().get(1).getDescription(), "param2");
71 Assert.assertEquals(ouptPD.getParameters().get(1).getType(), "param2 type");
72 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
74 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
76 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyName(),
78 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(1).getKeyValue(),
81 ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyName(),
84 ouptPD.getParameters().get(1).getResponseKeys().get(0).getUniqueKeyValue(), "0");
86 ouptPD.getParameters().get(1).getResponseKeys().get(0).getFieldKeyName(), "0");
91 public void testReadArtifactNegetive() throws IOException {
93 String toscaArtifact = getFileContent("tosca/ReadArtifactNegetiveInputTosca.yml");
94 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
96 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
97 } catch (ArtifactProcessorException e) {
98 Assert.assertNotNull(e);
99 Assert.assertEquals(e.getMessage(),
100 "Invalid input found <> source1 <reqk1:reqv1 , reqk2:reqv2>");
104 private String getFileContent(String fileName) throws IOException {
105 ClassLoader classLoader = new TestReadArtifact().getClass().getClassLoader();
106 InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile());
107 BufferedReader buf = new BufferedReader(new InputStreamReader(is));
108 String line = buf.readLine();
109 StringBuilder sb = new StringBuilder();
111 while (line != null) {
112 sb.append(line).append("\n");
113 line = buf.readLine();
115 String fileString = sb.toString();