2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.enrichment.impl.tosca;
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;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
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;
45 public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest {
47 ComponentQuestionnaireData utilMock;
50 AbstractSubstituteToscaEnricher toscaEnricher;
53 Version version = new Version();
56 public void injectDoubles() {
57 MockitoAnnotations.initMocks(this);
64 public void testEnrich() throws Exception {
65 outputFilesPath = "/mock/enrichHA/out/";
67 ToscaServiceModel toscaServiceModel =
68 loadToscaServiceModel("/mock/enrichHA/in/", "/mock/toscaGlobalServiceTemplates/",
69 "MainServiceTemplate.yaml");
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);
81 componentTypetoParams.put("pd_server", innerProps);
83 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
84 (componentTypetoParams);
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);
92 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
94 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
96 Map<String, List<ErrorMessage>> errors =
97 toscaEnricher.enrich(toscaServiceModel, vspId, version );
99 compareActualAndExpectedModel(toscaServiceModel);
101 Assert.assertEquals(errors.size(), 0);
105 public void testEnrichWithoutServiceTemplateFilter() throws Exception {
106 outputFilesPath = "/mock/enrichHANoServiceTemplateFilter/out";
108 ToscaServiceModel toscaServiceModel =
109 loadToscaServiceModel("/mock/enrichHANoServiceTemplateFilter/in",
110 "/mock/toscaGlobalServiceTemplates/",
111 "MainServiceTemplate.yaml");
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);
123 componentTypetoParams.put("pd_server", innerProps);
125 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
126 (componentTypetoParams);
128 Map<String,String> map = new HashMap<String,String>();
129 Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
131 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
132 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
134 Map<String, List<ErrorMessage>> errors =
135 toscaEnricher.enrich(toscaServiceModel, vspId, version );
137 compareActualAndExpectedModel(toscaServiceModel);
139 Assert.assertEquals(errors.size(), 0);
143 public void testEnrichNotMandatory() throws Exception {
144 outputFilesPath = "/mock/enrichHANotMandatory/out";
146 ToscaServiceModel toscaServiceModel =
147 loadToscaServiceModel("/mock/enrichHANotMandatory/in",
148 "/mock/toscaGlobalServiceTemplates/",
149 "MainServiceTemplate.yaml");
151 Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
152 Map<String, Object> innerProps = new HashedMap();
154 innerProps.put(MANDATORY, "");
155 innerProps.put(MIN_INSTANCES, 1);
156 innerProps.put(MAX_INSTANCES, 5);
158 componentTypetoParams.put("pd_server_vm", innerProps);
160 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
161 (componentTypetoParams);
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>();
167 sourceToTargetDependencies.put("pd_server_vm", targets);
169 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
171 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
173 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
174 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
176 Map<String, List<ErrorMessage>> errors =
177 toscaEnricher.enrich(toscaServiceModel, vspId, version );
179 compareActualAndExpectedModel(toscaServiceModel);
181 Assert.assertEquals(errors.size(), 0);
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");
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);
198 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
200 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
201 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
202 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
204 Map<String, List<ErrorMessage>> errors =
205 toscaEnricher.enrich(toscaServiceModel, vspId, version );
207 compareActualAndExpectedModel(toscaServiceModel);
209 Assert.assertEquals(errors.size(), 0);
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");
220 Map<String,String> map = new HashMap<>();
221 Map<String, List<String>> sourceToTargetDependencies = new HashMap<>();
223 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
225 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
226 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
227 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
229 Map<String, List<ErrorMessage>> errors =
230 toscaEnricher.enrich(toscaServiceModel, vspId, version );
232 compareActualAndExpectedModel(toscaServiceModel);
234 Assert.assertEquals(errors.size(), 0);