aboutsummaryrefslogtreecommitdiffstats
path: root/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/sanity/CrudE2E.java
blob: f3d48bfefff0fb96a21340fbe782b61583a4153a (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
/*-
 * ============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.sanity;

import fj.data.Either;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
import org.openecomp.sdc.ci.tests.datatypes.enums.*;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class CrudE2E extends ComponentBaseTest {
	private static Logger log = LoggerFactory.getLogger(CrudE2E.class.getName());

	public Component resourceDetailsVFCcomp_01;
	public Component resourceDetailsVFCsoft_01;
	public Component resourceDetailsCP_01;
	public Component resourceDetailsVL_01;
	public Component resourceDetailsVF_01;
	public Component resourceDetailsVF_02;

	public ComponentInstance resourceDetailsVFC1compIns1;
	public ComponentInstance resourceDetailsVFC1softIns1;
	public ComponentInstance resourceDetailsCP1ins_01;
	public ComponentInstance resourceDetailsVL1ins_01;
	public ComponentInstance resourceDetailsVF1ins_01;
	public Component defaultService1;
	private List<String> variablesAsList = new ArrayList<String>();

	@Rule
	public static TestName name = new TestName();

	public CrudE2E() {
		super(name, CrudE2E.class.getName());
	}

	@Test
	public void complexScenario() throws Exception {

		User designer = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);

		//////// create defaultService1 ///////////////////////

		Either<Service, RestResponse> createDefaultService1e = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
		defaultService1 = createDefaultService1e.left().value();

		//////// create VFC1 (resourceDetailsVFCcomp_01) DerivedFrom COMPUTE
		//////// type add all possible informational artifacts and change state
		//////// to CERTIFY////////
		Either<Resource, RestResponse> resourceDetailsVFCcompE = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.COMPUTE, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, UserRoleEnum.DESIGNER,
				true);
		resourceDetailsVFCcomp_01 = resourceDetailsVFCcompE.left().value();
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.CHEF, resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.PUPPET, resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		// AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.SHELL_SCRIPT,
		// resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG, resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		// AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT,
		// resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.DG_XML, resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.MURANO_PKG, resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.OTHER, resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.changeComponentState(resourceDetailsVFCcomp_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true);

		//////// create VFC2 (resourceDetailsVFCsoft_01) DerivedFrom SOFTWARE
		//////// type and change state to CERTIFY////////
		Either<Resource, RestResponse> resourceDetailsVFCsoftE = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.SOFTWARE_COMPONENT, ResourceCategoryEnum.GENERIC_DATABASE, UserRoleEnum.DESIGNER,
				true);
		resourceDetailsVFCsoft_01 = resourceDetailsVFCsoftE.left().value();
		AtomicOperationUtils.changeComponentState(resourceDetailsVFCsoft_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true);

		//////// create CP1 (resourceDetailsVFCsoft_01) DerivedFrom PORT type
		//////// and change state to CHECKIN////////
		Either<Resource, RestResponse> resourceDetailsCP_01e = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.CP, NormativeTypesEnum.PORT, ResourceCategoryEnum.GENERIC_DATABASE, UserRoleEnum.DESIGNER, true);
		resourceDetailsCP_01 = resourceDetailsCP_01e.left().value();
		AtomicOperationUtils.changeComponentState(resourceDetailsCP_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true);

		//////// create VL1 (resourceDetailsVFCsoft_01) DerivedFrom NETWORK type
		//////// and change state to CERTIFY////////
		Either<Resource, RestResponse> resourceDetailsVL_01e = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VL, NormativeTypesEnum.NETWORK, ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS, UserRoleEnum.DESIGNER,
				true);
		resourceDetailsVL_01 = resourceDetailsVL_01e.left().value();
		AtomicOperationUtils.changeComponentState(resourceDetailsVL_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true);

		//////// create VF1 (resourceDetailsVFCcomp_01) DerivedFrom COMPUTE type
		//////// add all possible deployment and informational artifacts
		//////// //////////
		Either<Resource, RestResponse> resourceDetailsVF_01e = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, UserRoleEnum.DESIGNER, true);
		resourceDetailsVF_01 = resourceDetailsVF_01e.left().value();
		ArtifactDefinition heatArtifact = AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true, true).left().value();
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT_VOL, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT_NET, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.OTHER, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true, true);

		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.CHEF, resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.PUPPET, resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		// AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.SHELL_SCRIPT,
		// resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG, resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		// AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT,
		// resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.DG_XML, resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.MURANO_PKG, resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.OTHER, resourceDetailsVF_01, UserRoleEnum.DESIGNER, false, true);

		//////// Add VFC1 VFC2 CP and VL to VF container /////////////
		resourceDetailsVFC1compIns1 = AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceDetailsVFCcomp_01, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true).left().value();
		resourceDetailsVFC1softIns1 = AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceDetailsVFCsoft_01, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true).left().value();
		resourceDetailsCP1ins_01 = AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceDetailsCP_01, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true).left().value();
		resourceDetailsVL1ins_01 = AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceDetailsVL_01, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true).left().value();

		//////// associate cp-vl vl-vfcComp and vfcComp-vfcSoft////////
		resourceDetailsVF_01 = AtomicOperationUtils.getResourceObject(resourceDetailsVF_01, UserRoleEnum.DESIGNER);
		AtomicOperationUtils.associate2ResourceInstances(resourceDetailsVF_01, resourceDetailsCP1ins_01, resourceDetailsVL1ins_01, AssocType.LINKABLE.getAssocType(), UserRoleEnum.DESIGNER, true);
		AtomicOperationUtils.associate2ResourceInstances(resourceDetailsVF_01, resourceDetailsCP1ins_01, resourceDetailsVFC1compIns1, AssocType.BINDABLE.getAssocType(), UserRoleEnum.DESIGNER, true);
		AtomicOperationUtils.associate2ResourceInstances(resourceDetailsVF_01, resourceDetailsVFC1compIns1, resourceDetailsVFC1softIns1, AssocType.NODE.getAssocType(), UserRoleEnum.DESIGNER, true);

		//////// download all VF1 artifacts////////

		Collection<ArtifactDefinition> artifacts = resourceDetailsVF_01.getDeploymentArtifacts().values();
		List<String> collect = artifacts.stream().filter(p -> p.checkEsIdExist() == true).map(p -> p.getUniqueId()).collect(Collectors.toList());
		artifacts.stream().filter(p -> p.checkEsIdExist() == true).map(p -> p.getUniqueId()).forEach(item -> log.debug(item));

		//////// get all VF1 artifacts////////

		Collection<List<ComponentInstanceProperty>> componentInstancesProperties = resourceDetailsVF_01.getComponentInstancesProperties().values();
		List<String> collect2 = componentInstancesProperties.stream().filter(p -> p.isEmpty() == false).flatMap(l -> l.stream()).collect(Collectors.toList()).stream().map(p -> p.getUniqueId()).collect(Collectors.toList());
		// PropertyRestUtils.updateProperty(resourceDetailsVF_01.getUniqueId(),
		// propertyId, "1", designer);
		// .forEach((someOtherString) -> {
		// System.out.println("Content With Java: " + someOtherString);
		// });
		// componentInstancesProperties.stream().filter(p ->
		// p.isEmpty()==false).flatMap(l -> l.stream()).map(e ->
		// e.getUniqueId());
		// resourceDetailsVF_01.getComponentInstancesProperties().

		// ArtifactDefinition artifactDefinition =
		// resourceDetailsVF_01.getDeploymentArtifacts().get(ArtifactTypeEnum.HEAT.getType().toLowerCase()).getEsId();
		// ArtifactDefinition artifactDefinition =
		// resource.getDeploymentArtifacts().get(depResArtType);
		// ArtifactReqDetails artifacJavaObject =
		// ResponseParser.convertArtifactDefinitionToArtifactReqDetailsObject(artifactDefinition);
		// ArtifactRestUtils.updateDeploymentArtifactToRI(artifactDetails,
		// sdncModifierDetails, resourceInstanceId, serviceId)

		//////// certify VF1 - failed due to uncertified CP instance ////////

		/*RestResponse changeVfStateFailed = LifecycleRestUtils.changeComponentState(resourceDetailsVF_01, designer, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
		Resource resResourceDetailsVF_01 = (Resource) resourceDetailsVF_01;
		variablesAsList = Arrays.asList(resResourceDetailsVF_01.getResourceType().toString(), resourceDetailsCP_01.getName());
		ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.VALIDATED_RESOURCE_NOT_FOUND.name(), variablesAsList, changeVfStateFailed.getResponse());*/

		//////// certify resources CP1 ////////
		resourceDetailsCP_01 = AtomicOperationUtils.changeComponentState(resourceDetailsCP_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();

		//////// replace VF1 instances with new certified instances (CP1
		//////// replaced) ////////
		Either<Pair<Component, ComponentInstance>, RestResponse> changeComponentInstanceVersion = AtomicOperationUtils.changeComponentInstanceVersion(resourceDetailsVF_01, resourceDetailsCP1ins_01, resourceDetailsCP_01, UserRoleEnum.DESIGNER, true);
		resourceDetailsVF_01 = changeComponentInstanceVersion.left().value().getLeft();
		resourceDetailsCP1ins_01 = changeComponentInstanceVersion.left().value().getRight();

		//////// associate cp-vl and cp-vfc1,////////
		AtomicOperationUtils.associate2ResourceInstances(resourceDetailsVF_01, resourceDetailsCP1ins_01, resourceDetailsVL1ins_01, AssocType.LINKABLE.getAssocType(), UserRoleEnum.DESIGNER, true);
		AtomicOperationUtils.associate2ResourceInstances(resourceDetailsVF_01, resourceDetailsCP1ins_01, resourceDetailsVFC1compIns1, AssocType.BINDABLE.getAssocType(), UserRoleEnum.DESIGNER, true);

		/////// change VF1 state to CHECK-IN and add it as instance to service1
		/////// container
		resourceDetailsVF_01 = AtomicOperationUtils.changeComponentState(resourceDetailsVF_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
		resourceDetailsVF1ins_01 = AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceDetailsVF_01, defaultService1, UserRoleEnum.DESIGNER, true).left().value();

		//////// distribute service1 - failed due to incorrect LifeCyclestatus
		//////// ////////
		RestResponse distributeService = AtomicOperationUtils.distributeService(defaultService1, false);
		Assert.assertEquals(distributeService, null, "verification failed");

		//////// certify service1 - failed due to uncertified instances ////////
		designer = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
		/*RestResponse changeServicetStateFailed = LifecycleRestUtils.changeComponentState(defaultService1, designer, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
		variablesAsList = Arrays.asList(defaultService1.getComponentType().toString().toLowerCase(), resourceDetailsVF_01.getName());
		ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.VALIDATED_RESOURCE_NOT_FOUND.name(), variablesAsList, changeServicetStateFailed.getResponse());
*/
		////// change VF1 state to CERTIFIED
		resourceDetailsVF_01 = AtomicOperationUtils.changeComponentState(resourceDetailsVF_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();

		//////// replace VF1 instances with new certified instances ////////
		changeComponentInstanceVersion = AtomicOperationUtils.changeComponentInstanceVersion(defaultService1, resourceDetailsVF1ins_01, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true);
		resourceDetailsVF_01 = changeComponentInstanceVersion.left().value().getLeft();
		resourceDetailsVFC1compIns1 = changeComponentInstanceVersion.left().value().getRight();

		/////// certify service1 ////////
		defaultService1 = AtomicOperationUtils.changeComponentState(defaultService1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();

		//////// distribute service1 - successfully ////////
		AtomicOperationUtils.distributeService(defaultService1, true);

		/////// create VF2 ////////

		Either<Resource, RestResponse> resourceDetailsVF_02e = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, UserRoleEnum.DESIGNER, true);
		resourceDetailsVF_02 = resourceDetailsVF_02e.left().value();

	}

	// private void updateArtParameterInResource(Resource resource) throws
	// IOException {
	//
	// ArtifactRestUtils.uploadArtifact(artifactDetails, component,
	// sdncModifierDetails)
	//
	// for (String depResArtType : Utils.getListOfDepResArtLabels(true)) {
	// ArtifactDefinition artifactDefinition =
	// resource.getDeploymentArtifacts().get(depResArtType);
	// ArtifactReqDetails artifacJavaObject =
	// ResponseParser.convertArtifactDefinitionToArtifactReqDetailsObject(artifactDefinition);
	//
	// //update parameter
	// List<HeatParameterDefinition> resourceHeatParameters =
	// resource.getDeploymentArtifacts().get(depResArtType).getHeatParameters();
	// for (HeatParameterDefinition heatParameterDefinition :
	// resourceHeatParameters){
	// if (heatParameterDefinition.getName().equals("address")){
	// heatParameterDefinition.setCurrentValue("negev");
	// break;
	// }
	// }
	// artifacJavaObject.setHeatParameters(resourceHeatParameters);
	// artifacJavaObject.setPayloadData(null);
	// RestResponse updateInformationalArtifactToResource =
	// ArtifactRestUtils.updateDeploymentArtifactToResource(artifacJavaObject,
	// sdncDesignerDetails, resource.getUniqueId());
	// assertTrue("response code is not 200, returned: " +
	// updateInformationalArtifactToResource.getErrorCode(),updateInformationalArtifactToResource.getErrorCode()
	// == 200);
	// }
	// }

}