2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.tosca;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openecomp.sdc.be.datatypes.elements.Annotation;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
28 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
29 import org.openecomp.sdc.be.model.DataTypeDefinition;
30 import org.openecomp.sdc.be.model.InputDefinition;
31 import org.openecomp.sdc.be.model.PropertyDefinition;
32 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
33 import org.openecomp.sdc.be.tosca.model.ToscaInput;
34 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
35 import org.openecomp.sdc.be.tosca.utils.InputConverter;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
42 import static org.junit.Assert.assertEquals;
43 import static org.junit.Assert.assertTrue;
45 public class InputAnnotationConvertToToscaTest {
46 private InputConverter inputConverter;
47 private PropertyDefinition property , property1 , property2,property3;
48 private InputDefinition inputDefinition;
49 Map<String, DataTypeDefinition> dataTypes;
53 property = new PropertyDefinition();
54 property.setName("myProperty");
55 property.setType(ToscaPropertyType.STRING.getType());
56 property.setValue("this is property string");
57 property.setDescription("propertyDescription");
58 SchemaDefinition schemaDefinition = new SchemaDefinition();
59 schemaDefinition.setProperty(property);
62 property1 = new PropertyDefinition();
63 property1.setName("otherProperty");
64 property1.setType(ToscaPropertyType.INTEGER.getType());
65 property1.setValue("2");
67 property1.setSchema(schemaDefinition);
70 property2 = new PropertyDefinition();
71 property2.setName("annotationProperty");
72 property2.setType(ToscaPropertyType.FLOAT.getType());
73 property2.setValue("3.14");
75 property3 = new PropertyDefinition();
76 property3.setName("anotherAnnotationProperty");
77 property3.setType(ToscaPropertyType.BOOLEAN.getType());
78 property3.setValue("True");
80 dataTypes = new HashMap();
81 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
83 List<PropertyDefinition> properties = new ArrayList();
84 properties.add(property1);
86 dataTypeDefinition.setProperties(properties);
87 dataTypes.put("nameProperty", dataTypeDefinition);
89 List<Annotation> annotationList = new ArrayList<>();
90 Annotation annotation = new Annotation();
91 annotation.setName("Annotation1");
92 annotation.setDescription("description1");
94 List<PropertyDataDefinition> propertiesAnnotation = new ArrayList();
95 propertiesAnnotation.add(property2);
96 propertiesAnnotation.add(property3);
97 annotation.setProperties(propertiesAnnotation);
98 annotationList.add(annotation);
99 inputDefinition = new InputDefinition();
100 inputDefinition.setName("inputName1");
101 inputDefinition.setSchema(schemaDefinition);
102 inputDefinition.setAnnotations(annotationList);
106 public void ConvertAnnotationParseOneInput(){
108 ArrayList<InputDefinition> inputDefList = new ArrayList<> ();
109 inputDefList.add(inputDefinition);
110 inputConverter = new InputConverter();
111 Map<String, ToscaProperty> resultInputs ;
112 resultInputs = inputConverter.convertInputs(inputDefList,dataTypes);
113 //verify one Input only
114 assertEquals(1,resultInputs.size());
115 ToscaInput toscaInput =(ToscaInput) resultInputs.get("inputName1");
116 Map<String, Object> propertyMap = toscaInput.getAnnotations().get("Annotation1").getProperties();
117 assertEquals(2,propertyMap.size());
118 double pi = (double)propertyMap.get("annotationProperty");
119 Assert.assertEquals(3.14,pi,0.01);
120 boolean annotationVal = (boolean)propertyMap.get("anotherAnnotationProperty");
121 assertTrue(annotationVal);
122 assertEquals("propertyDescription", toscaInput.getEntry_schema().getDescription());
123 assertEquals("string", toscaInput.getEntry_schema().getType() );