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