[SDC] Onboarding 1710 rebase.
[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 package org.openecomp.sdc.enrichment.impl.tosca;
2
3
4 import org.apache.commons.collections.map.HashedMap;
5 import org.mockito.InjectMocks;
6 import org.mockito.Mock;
7 import org.mockito.MockitoAnnotations;
8 import org.openecomp.sdc.datatypes.error.ErrorMessage;
9 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
10 import org.openecomp.sdc.versioning.dao.types.Version;
11 import org.testng.Assert;
12 import org.testng.annotations.BeforeMethod;
13 import org.testng.annotations.Test;
14
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
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.VFC_CODE;
26 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_FUNCTION;
27 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE;
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(VFC_NAMING_CODE, "Code1");
61     innerProps.put(VFC_CODE, "pd_server_code");
62     innerProps.put(VFC_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(VFC_NAMING_CODE, "pd_server_code1");
103     innerProps.put(VFC_CODE, "pd_server_code");
104     innerProps.put(VFC_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 }