1 package org.openecomp.sdc.be.tosca;
3 import org.junit.Assert;
4 import org.junit.Before;
6 import org.openecomp.sdc.be.datatypes.elements.Annotation;
7 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
8 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
9 import org.openecomp.sdc.be.model.DataTypeDefinition;
10 import org.openecomp.sdc.be.model.InputDefinition;
11 import org.openecomp.sdc.be.model.PropertyDefinition;
12 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
13 import org.openecomp.sdc.be.tosca.model.ToscaInput;
14 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
15 import org.openecomp.sdc.be.tosca.utils.InputConverter;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
25 public class InputAnnotationConvertToToscaTest {
26 private InputConverter inputConverter;
27 private PropertyDefinition property , property1 , property2,property3;
28 private InputDefinition inputDefinition;
29 Map<String, DataTypeDefinition> dataTypes;
33 property = new PropertyDefinition();
34 property.setName("myProperty");
35 property.setType(ToscaPropertyType.STRING.getType());
36 property.setValue("this is property string");
37 property.setDescription("propertyDescription");
38 SchemaDefinition schemaDefinition = new SchemaDefinition();
39 schemaDefinition.setProperty(property);
42 property1 = new PropertyDefinition();
43 property1.setName("otherProperty");
44 property1.setType(ToscaPropertyType.INTEGER.getType());
45 property1.setValue("2");
47 property1.setSchema(schemaDefinition);
50 property2 = new PropertyDefinition();
51 property2.setName("annotationProperty");
52 property2.setType(ToscaPropertyType.FLOAT.getType());
53 property2.setValue("3.14");
55 property3 = new PropertyDefinition();
56 property3.setName("anotherAnnotationProperty");
57 property3.setType(ToscaPropertyType.BOOLEAN.getType());
58 property3.setValue("True");
60 dataTypes = new HashMap();
61 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
63 List<PropertyDefinition> properties = new ArrayList();
64 properties.add(property1);
66 dataTypeDefinition.setProperties(properties);
67 dataTypes.put("nameProperty", dataTypeDefinition);
69 List<Annotation> annotationList = new ArrayList<>();
70 Annotation annotation = new Annotation();
71 annotation.setName("Annotation1");
72 annotation.setDescription("description1");
74 List<PropertyDataDefinition> propertiesAnnotation = new ArrayList();
75 propertiesAnnotation.add(property2);
76 propertiesAnnotation.add(property3);
77 annotation.setProperties(propertiesAnnotation);
78 annotationList.add(annotation);
79 inputDefinition = new InputDefinition();
80 inputDefinition.setName("inputName1");
81 inputDefinition.setSchema(schemaDefinition);
82 inputDefinition.setAnnotations(annotationList);
86 public void ConvertAnnotationParseOneInput(){
88 ArrayList<InputDefinition> inputDefList = new ArrayList<> ();
89 inputDefList.add(inputDefinition);
90 inputConverter = new InputConverter();
91 Map<String, ToscaProperty> resultInputs ;
92 resultInputs = inputConverter.convertInputs(inputDefList,dataTypes);
93 //verify one Input only
94 assertEquals(1,resultInputs.size());
95 ToscaInput toscaInput =(ToscaInput) resultInputs.get("inputName1");
96 Map<String, Object> propertyMap = toscaInput.getAnnotations().get("Annotation1").getProperties();
97 assertEquals(2,propertyMap.size());
98 double pi = (double)propertyMap.get("annotationProperty");
99 Assert.assertEquals(3.14,pi,0.01);
100 boolean annotationVal = (boolean)propertyMap.get("anotherAnnotationProperty");
101 assertTrue(annotationVal);
102 assertEquals("propertyDescription", toscaInput.getEntry_schema().getDescription());
103 assertEquals("string", toscaInput.getEntry_schema().getType() );