2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2018 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.params.transformer.tosca;
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31 import org.apache.commons.io.FileUtils;
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 {
40 public void testReadArtifactPositive() throws ArtifactProcessorException, IOException {
41 String toscaArtifact = FileUtils.readFileToString(
42 new File("src/test/resources/tosca/ReadArtifactPositiveInputTosca.yml"),
43 StandardCharsets.UTF_8);
44 ArtifactProcessorImpl artifact = new ArtifactProcessorImpl();
45 PropertyDefinition ouptPD = artifact.readArtifact(toscaArtifact);
46 Assert.assertEquals(ouptPD.getKind(), "Property Definition");
47 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(), "source");
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(),
56 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
58 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyName(),
60 Assert.assertEquals(ouptPD.getParameters().get(1).getRequestKeys().get(0).getKeyValue(),
63 ouptPD.getParameters().get(0).getResponseKeys().get(0).getUniqueKeyName(),
66 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");
91 public void testReadArtifactNegetive() throws IOException {
92 String toscaArtifact = FileUtils.readFileToString(
93 new File("src/test/resources/tosca/ReadArtifactNegetiveInputTosca.yml"),
94 StandardCharsets.UTF_8);
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>");