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_NAMING_CODE;
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;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
28 public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest {
30 ComponentQuestionnaireData utilMock;
33 AbstractSubstituteToscaEnricher toscaEnricher;
36 Version version = new Version();
38 @BeforeMethod(alwaysRun = true)
39 public void injectDoubles() {
40 MockitoAnnotations.initMocks(this);
47 public void testEnrich() throws Exception {
48 outputFilesPath = "/mock/enrichHA/out/";
50 ToscaServiceModel toscaServiceModel =
51 loadToscaServiceModel("/mock/enrichHA/in/", "/mock/toscaGlobalServiceTemplates/",
52 "MainServiceTemplate.yaml");
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);
62 componentTypetoParams.put("pd_server", innerProps);
64 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
65 (componentTypetoParams);
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);
73 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
75 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
77 Map<String, List<ErrorMessage>> errors =
78 toscaEnricher.enrich(toscaServiceModel, vspId, version );
80 compareActualAndExpectedModel(toscaServiceModel);
82 Assert.assertEquals(errors.size(), 0);
86 public void testEnrichWithoutServiceTemplateFilter() throws Exception {
87 outputFilesPath = "/mock/enrichHANoServiceTemplateFilter/out";
89 ToscaServiceModel toscaServiceModel =
90 loadToscaServiceModel("/mock/enrichHANoServiceTemplateFilter/in",
91 "/mock/toscaGlobalServiceTemplates/",
92 "MainServiceTemplate.yaml");
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);
102 componentTypetoParams.put("pd_server", innerProps);
104 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
105 (componentTypetoParams);
107 Map<String,String> map = new HashMap<String,String>();
108 Map<String, List<String>> sourceToTargetDependencies = new HashMap<String, List<String>>();
110 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
111 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
113 Map<String, List<ErrorMessage>> errors =
114 toscaEnricher.enrich(toscaServiceModel, vspId, version );
116 compareActualAndExpectedModel(toscaServiceModel);
118 Assert.assertEquals(errors.size(), 0);
122 public void testEnrichNotMandatory() throws Exception {
123 outputFilesPath = "/mock/enrichHANotMandatory/out";
125 ToscaServiceModel toscaServiceModel =
126 loadToscaServiceModel("/mock/enrichHANotMandatory/in",
127 "/mock/toscaGlobalServiceTemplates/",
128 "MainServiceTemplate.yaml");
130 Map<String, Map<String, Object>> componentTypetoParams = new HashMap();
131 Map<String, Object> innerProps = new HashedMap();
133 innerProps.put(MANDATORY, "");
134 innerProps.put(MIN_INSTANCES, 1);
135 innerProps.put(MAX_INSTANCES, 5);
137 componentTypetoParams.put("pd_server_vm", innerProps);
139 when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn
140 (componentTypetoParams);
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>();
146 sourceToTargetDependencies.put("pd_server_vm", targets);
148 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
150 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
152 when(utilMock.getSourceToTargetComponent()).thenReturn(map);
153 when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies);
155 Map<String, List<ErrorMessage>> errors =
156 toscaEnricher.enrich(toscaServiceModel, vspId, version );
158 compareActualAndExpectedModel(toscaServiceModel);
160 Assert.assertEquals(errors.size(), 0);