d2fb48cb7d90f9658d0e8e3b6665548299c4fa03
[sdc.git] /
1 package org.openecomp.sdc.enrichment.impl.tosca;
2
3
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;
12
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;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29
30 public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest {
31   @Mock
32   ComponentQuestionnaireData utilMock;
33
34   @InjectMocks
35   AbstractSubstituteToscaEnricher toscaEnricher;
36
37   String vspId = null;
38   Version version = new Version();
39
40   @BeforeMethod(alwaysRun = true)
41   public void injectDoubles() {
42     MockitoAnnotations.initMocks(this);
43     vspId = "123";
44     version.setMajor(1);
45     version.setMinor(0);
46   }
47
48   @Test
49   public void testEnrich() throws Exception {
50     outputFilesPath = "/mock/enrichHA/out/";
51
52     ToscaServiceModel toscaServiceModel =
53         loadToscaServiceModel("/mock/enrichHA/in/", "/mock/toscaGlobalServiceTemplates/",
54             "MainServiceTemplate.yaml");
55
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);
65
66     componentTypetoParams.put("pd_server", innerProps);
67
68     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
69         (componentTypetoParams);
70
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);
76
77     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
78
79     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
80
81     Map<String, List<ErrorMessage>> errors =
82         toscaEnricher.enrich(toscaServiceModel, vspId, version );
83
84     compareActualAndExpectedModel(toscaServiceModel);
85
86     Assert.assertEquals(errors.size(), 0);
87   }
88
89   @Test
90   public void testEnrichWithoutServiceTemplateFilter() throws Exception {
91     outputFilesPath = "/mock/enrichHANoServiceTemplateFilter/out";
92
93     ToscaServiceModel toscaServiceModel =
94         loadToscaServiceModel("/mock/enrichHANoServiceTemplateFilter/in",
95             "/mock/toscaGlobalServiceTemplates/",
96             "MainServiceTemplate.yaml");
97
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);
107
108     componentTypetoParams.put("pd_server", innerProps);
109
110     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
111         (componentTypetoParams);
112
113     Map<String,String> map = new HashMap<String,String>();
114     Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
115
116     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
117     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
118
119     Map<String, List<ErrorMessage>> errors =
120         toscaEnricher.enrich(toscaServiceModel, vspId, version );
121
122     compareActualAndExpectedModel(toscaServiceModel);
123
124     Assert.assertEquals(errors.size(), 0);
125   }
126
127   @Test
128   public void testEnrichNotMandatory() throws Exception {
129     outputFilesPath = "/mock/enrichHANotMandatory/out";
130
131     ToscaServiceModel toscaServiceModel =
132         loadToscaServiceModel("/mock/enrichHANotMandatory/in",
133             "/mock/toscaGlobalServiceTemplates/",
134             "MainServiceTemplate.yaml");
135
136     Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
137     Map<String, Object> innerProps = new HashedMap();
138
139     innerProps.put(MANDATORY, "");
140     innerProps.put(MIN_INSTANCES, 1);
141     innerProps.put(MAX_INSTANCES, 5);
142
143     componentTypetoParams.put("pd_server_vm", innerProps);
144
145     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
146         (componentTypetoParams);
147
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>();
151     targets.add("fe");
152     sourceToTargetDependencies.put("pd_server_vm", targets);
153
154     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
155
156     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
157
158     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
159     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
160
161     Map<String, List<ErrorMessage>> errors =
162         toscaEnricher.enrich(toscaServiceModel, vspId, version );
163
164     compareActualAndExpectedModel(toscaServiceModel);
165
166     Assert.assertEquals(errors.size(), 0);
167   }
168
169   @Test
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");
176
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);
182
183     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
184
185     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
186     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
187     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
188
189     Map<String, List<ErrorMessage>> errors =
190         toscaEnricher.enrich(toscaServiceModel, vspId, version );
191
192     compareActualAndExpectedModel(toscaServiceModel);
193
194     Assert.assertEquals(errors.size(), 0);
195   }
196
197   @Test
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");
204
205     Map<String,String> map = new HashMap<>();
206     Map<String, List<String>> sourceToTargetDependencies = new HashMap<>();
207
208     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
209
210     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
211     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
212     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
213
214     Map<String, List<ErrorMessage>> errors =
215         toscaEnricher.enrich(toscaServiceModel, vspId, version );
216
217     compareActualAndExpectedModel(toscaServiceModel);
218
219     Assert.assertEquals(errors.size(), 0);
220   }
221 }