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
|
package org.openecomp.sdc.be.tosca;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import fj.data.Either;
public class PropertyConvertorTest {
private PropertyDefinition property;
Map<String, DataTypeDefinition> dataTypes;
@Before
public void setUp(){
property = new PropertyDefinition();
property.setName("myProperty");
property.setType(ToscaPropertyType.INTEGER.getType());
dataTypes = new HashMap<String, DataTypeDefinition>();
dataTypes.put(property.getName(), new DataTypeDefinition());
}
@Test
public void convertPropertyWhenValueAndDefaultNull() {
assertNull(PropertyConvertor.getInstance().convertProperty(dataTypes, property, false));
}
@Test
public void convertPropertyWhenValueNullAndDefaultNotEmpty() {
final String def = "1";
property.setDefaultValue(def);
ToscaProperty result = PropertyConvertor.getInstance().convertProperty(dataTypes, property, false);
assertNotNull(result);
assertEquals(Integer.valueOf(def).intValue(), result.getDefaultp());
}
@Test
public void convertPropertiesWhenValueAndDefaultNullInOne() {
PropertyDefinition property1 = new PropertyDefinition();
property1.setName("otherProperty");
property1.setType(ToscaPropertyType.INTEGER.getType());
property1.setDefaultValue("2");
dataTypes.put(property1.getName(), new DataTypeDefinition());
Resource resource = new Resource();
List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
properties.add(property);
properties.add(property1);
resource.setProperties(properties);
Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
assertTrue(result.isLeft());
assertEquals(1, result.left().value().getProperties().size());
}
@Test
public void convertPropertiesWhenValueAndDefaultExist() {
PropertyDefinition property1 = new PropertyDefinition();
property1.setName("otherProperty");
property1.setType(ToscaPropertyType.INTEGER.getType());
property1.setDefaultValue("2");
property.setDefaultValue("1");
dataTypes.put(property1.getName(), new DataTypeDefinition());
Resource resource = new Resource();
List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
properties.add(property);
properties.add(property1);
resource.setProperties(properties);
Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
assertTrue(result.isLeft());
assertEquals(2, result.left().value().getProperties().size());
}
@Test
public void convertPropertiesWhenValueAndDefaultNullInAll() {
PropertyDefinition property1 = new PropertyDefinition();
property1.setName("otherProperty");
property1.setType(ToscaPropertyType.INTEGER.getType());
dataTypes.put(property1.getName(), new DataTypeDefinition());
Resource resource = new Resource();
List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
properties.add(property);
properties.add(property1);
resource.setProperties(properties);
Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
assertTrue(result.isLeft());
assertNull(result.left().value().getProperties());
}
}
|