1 package org.openecomp.sdc.enrichment.impl.tosca;
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;
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
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;
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(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);
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(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);
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);