summaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/US/ImportUpdateInformationalDeploymentArtifacts.java
blob: 913064b7fdf279a098a408f13dba05ff2708e810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.ci.tests.US;

import static org.testng.AssertJUnit.assertTrue;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.utilities.FileHandling;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.testng.SkipException;
import org.testng.annotations.Test;

public class ImportUpdateInformationalDeploymentArtifacts extends SetupCDTest {
	
	private String folder ="US747946";

	// US747946 - Import artifacts to component instances
	// TC1407822 - 	Import VFC Artifacts - Deployment Artifacts - Multiple Artifacts, Multiple Types
	@Test
	public void importVfvArtifactsDeploymentArtifactsMultipleArtifactsMultipleTypes() throws Exception {
		
		if(true){
			throw new SkipException("Open bug 197126");			
		}
		
		String filePath = FileHandling.getFilePath(folder);
		ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
		
		String fileName = "TC1407822.csar";
		
		ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
		
		Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
		
		List<String> snmpPollArtifactList = Stream
				.of("base_cgi_frwl.mib", "base_vIECCF_volume.yml", "node_userdata_script.sh", "vendor-license-model.xml")
				.collect(Collectors.toList());
		List<String> snmpTrapArtifactList = Stream
				.of("module_1_ixlt.mib", "module_1_ixlt.yaml")
				.collect(Collectors.toList());
		
	
		List<ArtifactDefinition> filteredArtifactNames = 
				//Stream of component Instances
				resource.getComponentInstances().stream()
					//Stream of all the artifacts on all the component instances
					.flatMap( e -> e.getDeploymentArtifacts().values().stream())
					//filter relevant artifact types
					.filter( e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_TRAP.getType()) || e.getArtifactType().equals(ArtifactTypeEnum.SNMP_POLL.getType()))
					//collect to list
					.collect(Collectors.toList());

		
		assertTrue("Not contain all SNMP TRAP artifacts.", filteredArtifactNames.stream()
				.filter(e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_TRAP.getType()))
				.map(e -> e.getArtifactName())
				.collect(Collectors.toList())
				.containsAll(snmpTrapArtifactList));
		
		assertTrue("Not contain all SNMP POLL artifacts.", filteredArtifactNames.stream()
				.filter(e -> e.getArtifactType().equals(ArtifactTypeEnum.SNMP_POLL.getType()))
				.map(e -> e.getArtifactName())
				.collect(Collectors.toList())
				.containsAll(snmpPollArtifactList));
		
		filteredArtifactNames.stream()
			.map(e->e.getArtifactDisplayName())
			.collect(Collectors.toList())
			.forEach(e -> {
				assertTrue("Wrong artifact appear on deployment artifact UI page.", 
						!GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + e));
			});
		
	}
	
	
	
	// US747946 - Import artifacts to component instances
	// TC1408044 - Import VFC Artifacts - Informational Artifacts on Single VFC
	@Test
	public void importVfcArtifactsInformationalArtifactsOnSingleVfc() throws Exception {
		
		if(true){
			throw new SkipException("Open bug 197126");			
		}
		
		String filePath = FileHandling.getFilePath(folder);
		String fileName = "TC1408044.csar";
		
		ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
		
		ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
		
		Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
		
		resource.getComponentInstances().forEach(e -> {
			
			if(e.getToscaComponentName().endsWith("heat.ltm")) {
				Map<String, List<String>> artifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("module_1_ldsa.yaml", "vendor-license-model.xml"));
						put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("module_2_ldsa.yaml", "vf-license-model.xml"));
					}
				};
					
				validateInformationalArtifactOnComponetInstance(e, artifactsMap, "heat.ltm");
			}
		});
	}
	
	// TODO: Note there is performance issue with this CSAR
	// US747946 - Import artifacts to component instances
	// TC1407998 - Import VFC Artifacts - Deployment & Informational Artifacts - Multiple VFCs
	@Test
	public void importVfcArtifactsDeploymentAndInformationalArtifactsMultipleVfcs() throws Exception {
		
		if(true){
			throw new SkipException("Open bug 197126");			
		}
		
		String filePath = FileHandling.getFilePath(folder);
		String fileName = "TC1407998.csar";
			
		ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
			
		ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
		
//		resourceMetaData.setName("TC1407998");
		Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
			
		resource.getComponentInstances().forEach(e -> {
				
			if(e.getToscaComponentName().endsWith("heat.ps")) {
				Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("PS_DEPL_Poll1.mib", "PS_DEPL_Poll2.xml", "PS_DEPL_Poll3.yaml"));
						put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("PS_DEPL_Trap1.mib", "PS_DEPL_Trap2.xml", "PS_DEPL_Trap3.sh", "PS_DEPL_Trap4.yml"));
					}
				};
				validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ps");
				
				Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("PS_INFO_GUIDE1.yaml", "PS_INFO_GUIDE2.xml"));
						put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("PS_INFO_OTHER1.yaml", "PS_INFO_OTHER2.xml"));
					}
				};
				validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ps");
				
				
			} else if (e.getToscaComponentName().endsWith("heat.sm")) {
				Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("SM_DEPL_Poll1.mib", "SM_DEPL_Poll2.mib", "SM_DEPL_Poll3.xml"));
						put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("SM_DEPL_Trap1.mib", "SM_DEPL_Trap2.xml"));
					}
				};
				validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.sm");
				
				Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("SM_INFO_GUIDE1.yaml", "SM_INFO_GUIDE2.xml"));
						put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("SM_INFO_OTHER1.yaml", "SM_INFO_OTHER2.xml"));
					}
				};
				validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.sm");
			}
		});
			
	}
	
	// US747946 - Import artifacts to component instances
	// TC1410352 - Import VFC Artifacts - Deployment Artifacts - Extra folder Under VFC-Identification
	@Test
	public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception {
		
		if(true){
			throw new SkipException("Open bug 197126");			
		}
		
		String filePath = FileHandling.getFilePath(folder);
		String fileName = "TC1410352.csar";
			
		ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
			
		ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
		
//		resourceMetaData.setName("TC1410352");
		Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
			
		resource.getComponentInstances().forEach(e -> {
				
			if(e.getToscaComponentName().endsWith("heat.ltm")) {
				Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("Poll1.mib", "Poll2.xml", "Poll3.sh", "Poll4.yml"));
						put(ArtifactTypeEnum.SNMP_TRAP.getType(), Arrays.asList("Trap1.mib", "Trap2.yaml"));
					}
				};
				validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
				
				Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("GUIDE1.yaml", "GUIDE2.xml"));
						put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("OTHER1.yaml", "OTHER2.xml"));
					}
				};
				validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ltm");
			}
		});
	}
	
	
	// US747946 - Import artifacts to component instances
	// TC1410352 - Import VFC Artifacts - Deployment Artifacts - Invalid Artifact Type
	@Test
	public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception {
		
		if(true){
			throw new SkipException("Open bug 197126");			
		}
		
		String filePath = FileHandling.getFilePath(folder);
		String fileName = "TC1425032.csar";
				
		ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
				
		ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, fileName, getUser());
			
//		resourceMetaData.setName("TC1425032");
		Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
				
		resource.getComponentInstances().forEach(e -> {
					
			if(e.getToscaComponentName().endsWith("heat.ltm")) {
				Map<String, List<String>> deployArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.SNMP_POLL.getType(), Arrays.asList("DeploySNMPPoll1.mib", "DeploySNMPPoll2.yml", "DeploySNMPPoll3.sh", "DeploySNMPPoll4.xml"));
						put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("DeploySNMPTrapB1.mib", "DeploySNMPTrapB2.yaml"));
					}
				};
				validateDeploymentArtifactOnComponetInstance(e, deployArtifactsMap, "heat.ltm");
					
				Map<String, List<String>> infoArtifactsMap = new HashMap<String, List<String>>() {
					{
						put(ArtifactTypeEnum.GUIDE.getType(), Arrays.asList("InfoGuide1.yaml", "InfoGuide2.xml"));
						put(ArtifactTypeEnum.OTHER.getType(), Arrays.asList("InfoOther1.yaml", "InfoOther2.xml", "InfoInvalid1.yaml"));
					}
				};
				validateInformationalArtifactOnComponetInstance(e, infoArtifactsMap, "heat.ltm");
			}
		});
	}
	
	
	private void validateInformationalArtifactOnComponetInstance(ComponentInstance instacne, Map<String, List<String>> artifactsMap, String endswith){
		if(instacne.getToscaComponentName().endsWith(endswith) ){
			Set<String> types = artifactsMap.keySet();

			Map<String, List<ArtifactDefinition>> collect = instacne.getArtifacts().values().stream()
					.filter( a -> types.contains(a.getArtifactType()))
					.collect(Collectors.groupingBy( e -> e.getArtifactType()));
				
			types.forEach(m -> {
				if(collect.containsKey(m)){
					List<String> found = collect.get(m).stream().map(e -> e.getArtifactName()).collect(Collectors.toList());
					boolean isValid = found.containsAll(artifactsMap.get(m)) && artifactsMap.get(m).containsAll(found);
					assertTrue("Not contain all artifact of type: " + m, isValid);
				} else{
					assertTrue("Contains informational artifact which not in provided list", false);
				}
			});
		}
	}
	
	private void validateDeploymentArtifactOnComponetInstance(ComponentInstance instacne, Map<String, List<String>> artifactsMap, String endswith){
		if(instacne.getToscaComponentName().endsWith(endswith) ){
			Set<String> types = artifactsMap.keySet();

			Map<String, List<ArtifactDefinition>> collect = instacne.getDeploymentArtifacts().values().stream()
					.filter( a -> types.contains(a.getArtifactType()))
					.collect(Collectors.groupingBy( e -> e.getArtifactType()));
		
			types.forEach(m -> {
				if(collect.containsKey(m)){
					List<String> found = collect.get(m).stream().map(e -> e.getArtifactName()).collect(Collectors.toList());
					boolean isValid = found.containsAll(artifactsMap.get(m)) && artifactsMap.get(m).containsAll(found);
					assertTrue("Not contain all artifact of type: " + m, isValid);
				} else{
					assertTrue("Contains deployment artifact which not in provided list", false);
				}
			});
		}
	}
	
	

	
	
	
	@Override
	protected UserRoleEnum getRole() {
		return UserRoleEnum.DESIGNER;
	}

}