aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/US/ImportUpdateInformationalDeploymentArtifacts.java
blob: a711d4ce4e9d8146972162eac8e749c006d5c65d (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
/*-
 * ============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 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.annotations.Test;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.testng.AssertJUnit.assertTrue;

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 {
		
		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()
					//filter out all nulls
					.filter( e -> e.getDeploymentArtifacts() != null )
					//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));
			});
		
	}

	// 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 {
		
		String filePath = FileHandling.getFilePath(folder);
		String fileName = "TC1407998.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.cm")) {
				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.cm");
				
			} 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");
			}
		});
			
	}
	
	// US747946 - Import artifacts to component instances
	// TC1410352 - Import VFC Artifacts - Deployment Artifacts - Extra folder Under VFC-Identification
	@Test
	public void importVfcArtifactsDeploymentArtifactsExtraFolderUnderVfcIdentification() throws Exception {
		
		String filePath = FileHandling.getFilePath(folder);
		String fileName = "TC1410352.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>> 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");
			}
		});
	}
	
	
	// US747946 - Import artifacts to component instances
	// TC1410352 - Import VFC Artifacts - Deployment Artifacts - Invalid Artifact Type
	@Test
	public void importVfcArtifactsDeploymentArtifactsInvalidArtifactType() throws Exception {
		
		String filePath = FileHandling.getFilePath(folder);
		String fileName = "TC1425032.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>> 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");
			}
		});
	}

	private void validateDeploymentArtifactOnComponetInstance(ComponentInstance instance, Map<String, List<String>> artifactsMap, String endswith){
		if(instance.getToscaComponentName().endsWith(endswith) ){
			Set<String> types = artifactsMap.keySet();

			Map<String, List<ArtifactDefinition>> collect = instance.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;
	}

}