Catalog alignment
[sdc.git] / common-be / src / test / java / org / openecomp / sdc / be / utils / PropertyDefinitionUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Nokia 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.be.utils;
21
22 import org.junit.Test;
23 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
24 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
25
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import static java.util.Collections.emptyMap;
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertNotSame;
34
35 public class PropertyDefinitionUtilsTest {
36
37     private static final String NAME = "NAME";
38     private static final String UNIQUE_ID = "UNIQUE_ID";
39     private static final String PROP_NAME = "PROP_NAME";
40     private static final String FIRST = "FIRST";
41     private static final String SECOND = "SECOND";
42     private static final String THIRD = "THIRD";
43
44     @Test
45     public void testConvertListOfProperties() {
46         List<PropertyDataDefinition> inputDataDefinitions = createDataDefinitions();
47         List<PropertyDataDefinition> propertyDataDefinitions = PropertyDefinitionUtils
48             .convertListOfProperties(inputDataDefinitions);
49
50         assertEquals(propertyDataDefinitions.size(), 1);
51         assertEquals(propertyDataDefinitions.get(0).getName(), NAME);
52         assertEquals(propertyDataDefinitions.get(0).getUniqueId(), UNIQUE_ID);
53         assertNotSame(inputDataDefinitions, propertyDataDefinitions);
54         assertEquals(inputDataDefinitions, propertyDataDefinitions);
55         assertNotSame(inputDataDefinitions.get(0), propertyDataDefinitions.get(0));
56         assertEquals(inputDataDefinitions.get(0), propertyDataDefinitions.get(0));
57     }
58
59     @Test
60     public void testResolveGetInputPropertiesForEmptyMap() {
61         Map<String, List<PropertyDataDefinition>> inputProps = PropertyDefinitionUtils
62             .resolveGetInputProperties(null);
63         assertEquals(inputProps, emptyMap());
64     }
65
66     @Test
67     public void testResolveGetInputPropertiesForNotEmptyMap() {
68         Map<String, List<PropertyDataDefinition>> props = new HashMap<>();
69         props.put(FIRST, createDataDefinitions());
70         props.put(SECOND, createDataDefinitions());
71         props.put(THIRD, createDataDefinitionsWithEmptyGetInputValueDefinition());
72         Map<String, List<PropertyDataDefinition>> result = PropertyDefinitionUtils.resolveGetInputProperties(props);
73         assertEquals(result.size(), 3);
74         assertEquals(result.get(FIRST).size(), 1);
75         assertEquals(result.get(FIRST).get(0).getUniqueId(), UNIQUE_ID);
76         assertEquals(result.get(SECOND).size(), 1);
77         assertEquals(result.get(THIRD).size(), 0);
78     }
79
80     private List<PropertyDataDefinition> createDataDefinitions(){
81         ArrayList<PropertyDataDefinition> propertyDataDefinitions = new ArrayList<>();
82         PropertyDataDefinition dataDefinition = new PropertyDataDefinition();
83         dataDefinition.setUniqueId(UNIQUE_ID);
84         dataDefinition.setName(NAME);
85         List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
86         GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
87         getInputValueDataDefinition.setPropName(PROP_NAME);
88         getInputValues.add(getInputValueDataDefinition);
89         dataDefinition.setGetInputValues(getInputValues);
90         propertyDataDefinitions.add(dataDefinition);
91         return propertyDataDefinitions;
92     }
93
94     private List<PropertyDataDefinition> createDataDefinitionsWithEmptyGetInputValueDefinition(){
95         ArrayList<PropertyDataDefinition> propertyDataDefinitions = new ArrayList<>();
96         PropertyDataDefinition dataDefinition = new PropertyDataDefinition();
97         dataDefinition.setUniqueId(UNIQUE_ID);
98         dataDefinition.setName(NAME);
99         propertyDataDefinitions.add(dataDefinition);
100         return propertyDataDefinitions;
101     }
102 }