ae1b613f7578545c4e4dcbbb5d14a54158670b2e
[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 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_NAMING_CODE;
10
11 import org.apache.commons.collections.map.HashedMap;
12 import org.mockito.InjectMocks;
13 import org.mockito.Mock;
14 import org.mockito.MockitoAnnotations;
15 import org.openecomp.sdc.datatypes.error.ErrorMessage;
16 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
17 import org.openecomp.sdc.versioning.dao.types.Version;
18 import org.testng.Assert;
19 import org.testng.annotations.BeforeMethod;
20 import org.testng.annotations.Test;
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27
28 public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest {
29   @Mock
30   ComponentQuestionnaireData utilMock;
31
32   @InjectMocks
33   AbstractSubstituteToscaEnricher toscaEnricher;
34
35   String vspId = null;
36   Version version = new Version();
37
38   @BeforeMethod(alwaysRun = true)
39   public void injectDoubles() {
40     MockitoAnnotations.initMocks(this);
41     vspId = "123";
42     version.setMajor(1);
43     version.setMinor(0);
44   }
45
46   @Test
47   public void testEnrich() throws Exception {
48     outputFilesPath = "/mock/enrichHA/out/";
49
50     ToscaServiceModel toscaServiceModel =
51         loadToscaServiceModel("/mock/enrichHA/in/", "/mock/toscaGlobalServiceTemplates/",
52             "MainServiceTemplate.yaml");
53
54     Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
55     Map<String, Object> innerProps = new HashedMap();
56     innerProps.put(MANDATORY, "YES");
57     innerProps.put(HIGH_AVAIL_MODE, "geo-activestandby");
58     innerProps.put(VFC_NAMING_CODE, "Code1");
59     innerProps.put(MIN_INSTANCES, 1);
60     innerProps.put(MAX_INSTANCES, 2);
61
62     componentTypetoParams.put("pd_server", innerProps);
63
64     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
65         (componentTypetoParams);
66
67     Map<String,String> map = new HashMap<String,String>();
68     Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
69     List<String> targets = new ArrayList<String>();
70     targets.add("fe"); targets.add("be");
71     sourceToTargetDependencies.put("pd_server", targets);
72
73     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
74
75     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
76
77     Map<String, List<ErrorMessage>> errors =
78         toscaEnricher.enrich(toscaServiceModel, vspId, version );
79
80     compareActualAndExpectedModel(toscaServiceModel);
81
82     Assert.assertEquals(errors.size(), 0);
83   }
84
85   @Test
86   public void testEnrichWithoutServiceTemplateFilter() throws Exception {
87     outputFilesPath = "/mock/enrichHANoServiceTemplateFilter/out";
88
89     ToscaServiceModel toscaServiceModel =
90         loadToscaServiceModel("/mock/enrichHANoServiceTemplateFilter/in",
91             "/mock/toscaGlobalServiceTemplates/",
92             "MainServiceTemplate.yaml");
93
94     Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
95     Map<String, Object> innerProps = new HashedMap();
96     innerProps.put(MANDATORY, "NO");
97     innerProps.put(HIGH_AVAIL_MODE, "");
98     innerProps.put(VFC_NAMING_CODE, "pd_server_code1");
99     innerProps.put(MIN_INSTANCES, null);
100     innerProps.put(MAX_INSTANCES, null);
101
102     componentTypetoParams.put("pd_server", innerProps);
103
104     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
105         (componentTypetoParams);
106
107     Map<String,String> map = new HashMap<String,String>();
108     Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
109
110     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
111     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
112
113     Map<String, List<ErrorMessage>> errors =
114         toscaEnricher.enrich(toscaServiceModel, vspId, version );
115
116     compareActualAndExpectedModel(toscaServiceModel);
117
118     Assert.assertEquals(errors.size(), 0);
119   }
120
121   @Test
122   public void testEnrichNotMandatory() throws Exception {
123     outputFilesPath = "/mock/enrichHANotMandatory/out";
124
125     ToscaServiceModel toscaServiceModel =
126         loadToscaServiceModel("/mock/enrichHANotMandatory/in",
127             "/mock/toscaGlobalServiceTemplates/",
128             "MainServiceTemplate.yaml");
129
130     Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
131     Map<String, Object> innerProps = new HashedMap();
132
133     innerProps.put(MANDATORY, "");
134     innerProps.put(MIN_INSTANCES, 1);
135     innerProps.put(MAX_INSTANCES, 5);
136
137     componentTypetoParams.put("pd_server_vm", innerProps);
138
139     when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
140         (componentTypetoParams);
141
142     Map<String,String> map = new HashMap<String,String>();
143     Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
144     List<String> targets = new ArrayList<String>();
145     targets.add("fe");
146     sourceToTargetDependencies.put("pd_server_vm", targets);
147
148     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
149
150     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
151
152     when(utilMock.getSourceToTargetComponent()).thenReturn(map);
153     when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
154
155     Map<String, List<ErrorMessage>> errors =
156         toscaEnricher.enrich(toscaServiceModel, vspId, version );
157
158     compareActualAndExpectedModel(toscaServiceModel);
159
160     Assert.assertEquals(errors.size(), 0);
161   }
162 }