Sorted out unit-test libraries in onboarding
[sdc.git] / openecomp-be / lib / openecomp-sdc-enrichment-lib / openecomp-sdc-enrichment-impl / src / test / java / org / openecomp / sdc / enrichment / impl / tosca / AbstractSubstituteToscaEnricherTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.enrichment.impl.tosca;
18
19
20 import static org.mockito.Mockito.when;
21 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
22 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
23 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
24 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
25 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_FUNCTION;
26 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE;
27 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE;
28
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import org.apache.commons.collections.map.HashedMap;
34 import org.junit.Assert;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.MockitoAnnotations;
40 import org.openecomp.sdc.datatypes.error.ErrorMessage;
41 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
42 import org.openecomp.sdc.versioning.dao.types.Version;
43
44
45 public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest {
46   @Mock
47   ComponentQuestionnaireData utilMock;
48
49   @InjectMocks
50   AbstractSubstituteToscaEnricher toscaEnricher;
51
52   String vspId = null;
53   Version version = new Version();
54
55   @Before
56   public void injectDoubles() {
57     MockitoAnnotations.initMocks(this);
58     vspId = "123";
59     version.setMajor(1);
60     version.setMinor(0);
61   }
62
63   @Test
64   public void testEnrich() throws Exception {
65     outputFilesPath = "/mock/enrichHA/out/";
66
67     ToscaServiceModel toscaServiceModel =
68         loadToscaServiceModel("/mock/enrichHA/in/", "/mock/toscaGlobalServiceTemplates/",
69             "MainServiceTemplate.yaml");
70
71     Map<String, Map<String, Object>> componentTypetoParams = new HashMap<>();
72     Map<String, Object> innerProps = new HashMap<>();
73     innerProps.put(MANDATORY, "YES");
74     innerProps.put(HIGH_AVAIL_MODE, "geo-activestandby");
75     innerProps.put(NFC_NAMING_CODE, "Code1");
76     innerProps.put(VFC_CODE, "pd_server_code");
77     innerProps.put(NFC_FUNCTION, "pd_server_description");
78     innerProps.put(MIN_INSTANCES, 1);
79     innerProps.put(MAX_INSTANCES, 2);
80
81     componentTypetoParams.put("pd_server", innerProps);
82
83     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
84         (componentTypetoParams);
85
86     Map<String,String> map = new HashMap<String,String>();
87     Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
88     List<String> targets = new ArrayList<String>();
89     targets.add("fe"); targets.add("be");
90     sourceToTargetDependencies.put("pd_server", targets);
91
92     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
93
94     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
95
96     Map<String, List<ErrorMessage>> errors =
97         toscaEnricher.enrich(toscaServiceModel, vspId, version );
98
99     compareActualAndExpectedModel(toscaServiceModel);
100
101     Assert.assertEquals(errors.size(), 0);
102   }
103
104   @Test
105   public void testEnrichWithoutServiceTemplateFilter() throws Exception {
106     outputFilesPath = "/mock/enrichHANoServiceTemplateFilter/out";
107
108     ToscaServiceModel toscaServiceModel =
109         loadToscaServiceModel("/mock/enrichHANoServiceTemplateFilter/in",
110             "/mock/toscaGlobalServiceTemplates/",
111             "MainServiceTemplate.yaml");
112
113     Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
114     Map<String, Object> innerProps = new HashedMap();
115     innerProps.put(MANDATORY, "NO");
116     innerProps.put(HIGH_AVAIL_MODE, "");
117     innerProps.put(NFC_NAMING_CODE, "pd_server_code1");
118     innerProps.put(VFC_CODE, "pd_server_code");
119     innerProps.put(NFC_FUNCTION, "pd_server_description");
120     innerProps.put(MIN_INSTANCES, null);
121     innerProps.put(MAX_INSTANCES, null);
122
123     componentTypetoParams.put("pd_server", innerProps);
124
125     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
126         (componentTypetoParams);
127
128     Map<String,String> map = new HashMap<String,String>();
129     Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
130
131     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
132     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
133
134     Map<String, List<ErrorMessage>> errors =
135         toscaEnricher.enrich(toscaServiceModel, vspId, version );
136
137     compareActualAndExpectedModel(toscaServiceModel);
138
139     Assert.assertEquals(errors.size(), 0);
140   }
141
142   @Test
143   public void testEnrichNotMandatory() throws Exception {
144     outputFilesPath = "/mock/enrichHANotMandatory/out";
145
146     ToscaServiceModel toscaServiceModel =
147         loadToscaServiceModel("/mock/enrichHANotMandatory/in",
148             "/mock/toscaGlobalServiceTemplates/",
149             "MainServiceTemplate.yaml");
150
151     Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
152     Map<String, Object> innerProps = new HashedMap();
153
154     innerProps.put(MANDATORY, "");
155     innerProps.put(MIN_INSTANCES, 1);
156     innerProps.put(MAX_INSTANCES, 5);
157
158     componentTypetoParams.put("pd_server_vm", innerProps);
159
160     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
161         (componentTypetoParams);
162
163     Map<String,String> map = new HashMap<String,String>();
164     Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
165     List<String> targets = new ArrayList<String>();
166     targets.add("fe");
167     sourceToTargetDependencies.put("pd_server_vm", targets);
168
169     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
170
171     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
172
173     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
174     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
175
176     Map<String, List<ErrorMessage>> errors =
177         toscaEnricher.enrich(toscaServiceModel, vspId, version );
178
179     compareActualAndExpectedModel(toscaServiceModel);
180
181     Assert.assertEquals(errors.size(), 0);
182   }
183
184   @Test
185   public void testEnrichComponentAddDependencies() throws Exception {
186     outputFilesPath = "/mock/enrichComponentAddDependencies/out";
187     ToscaServiceModel toscaServiceModel =
188         loadToscaServiceModel("/mock/enrichComponentAddDependencies/in",
189             "/mock/toscaGlobalServiceTemplates/",
190             "MainServiceTemplate.yaml");
191
192     Map<String,String> map = new HashMap<>();
193     Map<String, List<String>> sourceToTargetDependencies = new HashMap<>();
194     List<String> targets = new ArrayList<>();
195     targets.add("ps_server");
196     sourceToTargetDependencies.put("pd_server", targets);
197
198     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
199
200     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
201     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
202     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
203
204     Map<String, List<ErrorMessage>> errors =
205         toscaEnricher.enrich(toscaServiceModel, vspId, version );
206
207     compareActualAndExpectedModel(toscaServiceModel);
208
209     Assert.assertEquals(errors.size(), 0);
210   }
211
212   @Test
213   public void testEnrichComponentNoDependencies() throws Exception {
214     outputFilesPath = "/mock/enrichComponentNoDependencies/out";
215     ToscaServiceModel toscaServiceModel =
216         loadToscaServiceModel("/mock/enrichComponentNoDependencies/in",
217             "/mock/toscaGlobalServiceTemplates/",
218             "MainServiceTemplate.yaml");
219
220     Map<String,String> map = new HashMap<>();
221     Map<String, List<String>> sourceToTargetDependencies = new HashMap<>();
222
223     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
224
225     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
226     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
227     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
228
229     Map<String, List<ErrorMessage>> errors =
230         toscaEnricher.enrich(toscaServiceModel, vspId, version );
231
232     compareActualAndExpectedModel(toscaServiceModel);
233
234     Assert.assertEquals(errors.size(), 0);
235   }
236 }