1 package org.openecomp.sdc.enrichment.impl.tosca;
4 import static org.mockito.Mockito.when;
5 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
6 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
7 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
8 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
9 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE;
10 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_FUNCTION;
11 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE;
13 import org.apache.commons.collections.map.HashedMap;
14 import org.mockito.InjectMocks;
15 import org.mockito.Mock;
16 import org.mockito.MockitoAnnotations;
17 import org.openecomp.sdc.datatypes.error.ErrorMessage;
18 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
19 import org.openecomp.sdc.versioning.dao.types.Version;
20 import org.testng.Assert;
21 import org.testng.annotations.BeforeMethod;
22 import org.testng.annotations.Test;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
30 public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest {
32 ComponentQuestionnaireData utilMock;
35 AbstractSubstituteToscaEnricher toscaEnricher;
38 Version version = new Version();
40 @BeforeMethod(alwaysRun = true)
41 public void injectDoubles() {
42 MockitoAnnotations.initMocks(this);
49 public void testEnrich() throws Exception {
50 outputFilesPath = "/mock/enrichHA/out/";
52 ToscaServiceModel toscaServiceModel =
53 loadToscaServiceModel("/mock/enrichHA/in/", "/mock/toscaGlobalServiceTemplates/",
54 "MainServiceTemplate.yaml");
56 Map<String, Map<String, Object>> componentTypetoParams = new HashMap<>();
57 Map<String, Object> innerProps = new HashMap<>();
58 innerProps.put(MANDATORY, "YES");
59 innerProps.put(HIGH_AVAIL_MODE, "geo-activestandby");
60 innerProps.put(NFC_NAMING_CODE, "Code1");
61 innerProps.put(VFC_CODE, "pd_server_code");
62 innerProps.put(NFC_FUNCTION, "pd_server_description");
63 innerProps.put(MIN_INSTANCES, 1);
64 innerProps.put(MAX_INSTANCES, 2);
66 componentTypetoParams.put("pd_server", innerProps);
68 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
69 (componentTypetoParams);
71 Map<String,String> map = new HashMap<String,String>();
72 Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
73 List<String> targets = new ArrayList<String>();
74 targets.add("fe"); targets.add("be");
75 sourceToTargetDependencies.put("pd_server", targets);
77 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
79 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
81 Map<String, List<ErrorMessage>> errors =
82 toscaEnricher.enrich(toscaServiceModel, vspId, version );
84 compareActualAndExpectedModel(toscaServiceModel);
86 Assert.assertEquals(errors.size(), 0);
90 public void testEnrichWithoutServiceTemplateFilter() throws Exception {
91 outputFilesPath = "/mock/enrichHANoServiceTemplateFilter/out";
93 ToscaServiceModel toscaServiceModel =
94 loadToscaServiceModel("/mock/enrichHANoServiceTemplateFilter/in",
95 "/mock/toscaGlobalServiceTemplates/",
96 "MainServiceTemplate.yaml");
98 Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
99 Map<String, Object> innerProps = new HashedMap();
100 innerProps.put(MANDATORY, "NO");
101 innerProps.put(HIGH_AVAIL_MODE, "");
102 innerProps.put(NFC_NAMING_CODE, "pd_server_code1");
103 innerProps.put(VFC_CODE, "pd_server_code");
104 innerProps.put(NFC_FUNCTION, "pd_server_description");
105 innerProps.put(MIN_INSTANCES, null);
106 innerProps.put(MAX_INSTANCES, null);
108 componentTypetoParams.put("pd_server", innerProps);
110 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
111 (componentTypetoParams);
113 Map<String,String> map = new HashMap<String,String>();
114 Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
116 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
117 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
119 Map<String, List<ErrorMessage>> errors =
120 toscaEnricher.enrich(toscaServiceModel, vspId, version );
122 compareActualAndExpectedModel(toscaServiceModel);
124 Assert.assertEquals(errors.size(), 0);
128 public void testEnrichNotMandatory() throws Exception {
129 outputFilesPath = "/mock/enrichHANotMandatory/out";
131 ToscaServiceModel toscaServiceModel =
132 loadToscaServiceModel("/mock/enrichHANotMandatory/in",
133 "/mock/toscaGlobalServiceTemplates/",
134 "MainServiceTemplate.yaml");
136 Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
137 Map<String, Object> innerProps = new HashedMap();
139 innerProps.put(MANDATORY, "");
140 innerProps.put(MIN_INSTANCES, 1);
141 innerProps.put(MAX_INSTANCES, 5);
143 componentTypetoParams.put("pd_server_vm", innerProps);
145 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
146 (componentTypetoParams);
148 Map<String,String> map = new HashMap<String,String>();
149 Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
150 List<String> targets = new ArrayList<String>();
152 sourceToTargetDependencies.put("pd_server_vm", targets);
154 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
156 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
158 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
159 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
161 Map<String, List<ErrorMessage>> errors =
162 toscaEnricher.enrich(toscaServiceModel, vspId, version );
164 compareActualAndExpectedModel(toscaServiceModel);
166 Assert.assertEquals(errors.size(), 0);
170 public void testEnrichComponentAddDependencies() throws Exception {
171 outputFilesPath = "/mock/enrichComponentAddDependencies/out";
172 ToscaServiceModel toscaServiceModel =
173 loadToscaServiceModel("/mock/enrichComponentAddDependencies/in",
174 "/mock/toscaGlobalServiceTemplates/",
175 "MainServiceTemplate.yaml");
177 Map<String,String> map = new HashMap<>();
178 Map<String, List<String>> sourceToTargetDependencies = new HashMap<>();
179 List<String> targets = new ArrayList<>();
180 targets.add("ps_server");
181 sourceToTargetDependencies.put("pd_server", targets);
183 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
185 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
186 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
187 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
189 Map<String, List<ErrorMessage>> errors =
190 toscaEnricher.enrich(toscaServiceModel, vspId, version );
192 compareActualAndExpectedModel(toscaServiceModel);
194 Assert.assertEquals(errors.size(), 0);
198 public void testEnrichComponentNoDependencies() throws Exception {
199 outputFilesPath = "/mock/enrichComponentNoDependencies/out";
200 ToscaServiceModel toscaServiceModel =
201 loadToscaServiceModel("/mock/enrichComponentNoDependencies/in",
202 "/mock/toscaGlobalServiceTemplates/",
203 "MainServiceTemplate.yaml");
205 Map<String,String> map = new HashMap<>();
206 Map<String, List<String>> sourceToTargetDependencies = new HashMap<>();
208 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
210 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
211 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
212 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
214 Map<String, List<ErrorMessage>> errors =
215 toscaEnricher.enrich(toscaServiceModel, vspId, version );
217 compareActualAndExpectedModel(toscaServiceModel);
219 Assert.assertEquals(errors.size(), 0);