2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.utilities;
23 import static org.testng.AssertJUnit.assertEquals;
26 import java.io.FileNotFoundException;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.io.StringWriter;
30 import java.nio.file.FileSystems;
31 import java.util.Arrays;
32 import java.util.HashMap;
33 import java.util.Iterator;
34 import java.util.LinkedList;
35 import java.util.List;
37 import java.util.UUID;
39 import org.apache.commons.io.IOUtils;
40 import org.apache.http.HttpEntity;
41 import org.apache.http.client.ClientProtocolException;
42 import org.apache.http.client.methods.CloseableHttpResponse;
43 import org.apache.http.client.methods.HttpPost;
44 import org.apache.http.entity.mime.MultipartEntityBuilder;
45 import org.apache.http.entity.mime.content.FileBody;
46 import org.apache.http.impl.client.CloseableHttpClient;
47 import org.apache.http.impl.client.HttpClients;
48 import org.json.JSONException;
49 import org.json.JSONObject;
50 import org.json.simple.JSONArray;
51 import org.json.simple.JSONValue;
52 import org.openecomp.sdc.be.model.User;
53 import org.openecomp.sdc.ci.tests.config.Config;
54 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
55 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
56 import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
57 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
58 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
59 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
60 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
61 import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
62 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
63 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
64 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
65 import org.openecomp.sdc.ci.tests.pages.HomePage;
66 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
67 import org.openecomp.sdc.ci.tests.utils.Utils;
68 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
69 import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
70 import org.openqa.selenium.WebElement;
71 import org.openqa.selenium.support.ui.ExpectedConditions;
72 import org.openqa.selenium.support.ui.WebDriverWait;
73 import org.testng.Assert;
75 import com.aventstack.extentreports.Status;
76 import com.clearspring.analytics.util.Pair;
78 public class OnboardingUtils {
80 public OnboardingUtils() {
83 private static String vendorId;
84 private static String vendorLicenseName;
85 private static String vendorLicenseAgreementId;
86 private static String featureGroupId;
88 public static Pair<String, Map<String, String>> createVendorSoftwareProduct(String HeatFileName, String filepath, User user)
90 Pair<String, Map<String, String>> pair = createVSP(HeatFileName, filepath, user);
92 String vspid = pair.right.get("vspId");
94 prepareVspForUse(user, vspid);
99 public static void prepareVspForUse(User user, String vspid) throws Exception {
100 RestResponse checkin = checkinVendorSoftwareProduct(vspid, user);
101 assertEquals("did not succeed to checking new VSP", 200, checkin.getErrorCode().intValue());
103 RestResponse submit = submitVendorSoftwareProduct(vspid, user);
104 assertEquals("did not succeed to submit new VSP", 200, submit.getErrorCode().intValue());
106 RestResponse createPackage = createPackageOfVendorSoftwareProduct(vspid, user);
107 assertEquals("did not succeed to create package of new VSP ", 200, createPackage.getErrorCode().intValue());
109 SetupCDTest.getExtendTest().log(Status.INFO, "Succeeded in creating the vendor software product");
112 public static Pair<String, Map<String, String>> createVSP(String HeatFileName, String filepath, User user) throws Exception {
113 String vspName = handleFilename(HeatFileName);
115 SetupCDTest.getExtendTest().log(Status.INFO, "Starting to create the vendor software product");
117 Pair<RestResponse, Map<String, String>> createNewVspPair = createNewVendorSoftwareProduct(vspName, vendorLicenseName, vendorId, vendorLicenseAgreementId, featureGroupId, user);
118 RestResponse createNewVendorSoftwareProduct = createNewVspPair.left;
119 assertEquals("did not succeed to create new VSP", 200,createNewVendorSoftwareProduct.getErrorCode().intValue());
120 String vspid = ResponseParser.getValueFromJsonResponse(createNewVendorSoftwareProduct.getResponse(), "vspId");
121 String componentId = ResponseParser.getValueFromJsonResponse(createNewVendorSoftwareProduct.getResponse(), "componentId");
123 Map<String, String> vspMeta = createNewVspPair.right;
124 Map<String, String> vspObject = new HashMap<String, String>();
125 Iterator<String> iterator = vspMeta.keySet().iterator();
126 while(iterator.hasNext()){
127 Object key = iterator.next();
128 Object value = vspMeta.get(key);
129 vspObject.put(key.toString(), value.toString());
131 vspObject.put("vspId", vspid);
132 vspObject.put("componentId", componentId);
133 vspObject.put("vendorName", vendorLicenseName);
134 vspObject.put("attContact", user.getUserId());
136 RestResponse uploadHeatPackage = uploadHeatPackage(filepath, HeatFileName, vspid, user);
137 assertEquals("did not succeed to upload HEAT package", 200, uploadHeatPackage.getErrorCode().intValue());
139 RestResponse validateUpload = validateUpload(vspid, user);
140 assertEquals("did not succeed to validate upload process", 200, validateUpload.getErrorCode().intValue());
142 Pair<String, Map<String, String>> pair = new Pair<String, Map<String, String>>(vspName, vspObject);
147 public static void updateVspWithVfcArtifacts(String filepath, String vspId, String updatedSnmpPoll, String updatedSnmpTrap, String componentId, User user) throws Exception{
148 RestResponse checkout = checkoutVendorSoftwareProduct(vspId, user);
149 assertEquals("did not succeed to checkout new VSP", 200, checkout.getErrorCode().intValue());
150 ExtentTestActions.log(Status.INFO, "Deleting SNMP POLL");
151 deleteSnmpArtifact(componentId, vspId, user, SnmpTypeEnum.SNMP_POLL);
152 ExtentTestActions.log(Status.INFO, "Deleting SNMP TRAP");
153 deleteSnmpArtifact(componentId, vspId, user, SnmpTypeEnum.SNMP_TRAP);
154 addVFCArtifacts(filepath, updatedSnmpPoll, updatedSnmpTrap, vspId, user, componentId);
155 prepareVspForUse(user, vspId);
158 public static String updateVendorSoftwareProduct(String vspId, String HeatFileName, String filepath, User user)
159 throws Exception, Throwable {
160 String vspName = handleFilename(HeatFileName);
161 SetupCDTest.getExtendTest().log(Status.INFO, "Starting to update the vendor software product");
163 RestResponse checkout = checkoutVendorSoftwareProduct(vspId, user);
164 assertEquals("did not succeed to checkout new VSP", 200, checkout.getErrorCode().intValue());
166 RestResponse uploadHeatPackage = uploadHeatPackage(filepath, HeatFileName, vspId, user);
167 assertEquals("did not succeed to upload HEAT package", 200, uploadHeatPackage.getErrorCode().intValue());
169 RestResponse validateUpload = validateUpload(vspId, user);
170 assertEquals("did not succeed to validate upload process", 200, validateUpload.getErrorCode().intValue());
172 RestResponse checkin = checkinVendorSoftwareProduct(vspId, user);
173 assertEquals("did not succeed to checking VSP", 200, checkin.getErrorCode().intValue());
176 RestResponse submit = submitVendorSoftwareProduct(vspId, user);
177 assertEquals("did not succeed to submit VSP", 200, submit.getErrorCode().intValue());
179 RestResponse createPackage = createPackageOfVendorSoftwareProduct(vspId, user);
180 assertEquals("did not succeed to update package of VSP ", 200, createPackage.getErrorCode().intValue());
182 SetupCDTest.getExtendTest().log(Status.INFO, "Succeeded in updating the vendor software product");
187 public static String handleFilename(String heatFileName) {
188 final String namePrefix = "ciVFOnboarded-";
189 final String nameSuffix = "-" + getShortUUID();
191 String subHeatFileName = heatFileName.substring(0, heatFileName.lastIndexOf("."));
193 if ((namePrefix + subHeatFileName + nameSuffix).length() >= 50) {
194 subHeatFileName = subHeatFileName.substring(0, 50 - namePrefix.length() - nameSuffix.length());
197 if (subHeatFileName.contains("(") || subHeatFileName.contains(")")) {
198 subHeatFileName = subHeatFileName.replace("(", "-");
199 subHeatFileName = subHeatFileName.replace(")", "-");
202 String vnfName = namePrefix + subHeatFileName + nameSuffix;
206 public static String addVFCArtifacts(String filepath, String snmpPoll, String snmpTrap, String vspid, User user, String vspComponentId) throws Exception{
207 vspComponentId = (vspComponentId == null) ? getVSPComponentId(vspid, user) : vspComponentId;
208 if (vspComponentId != null){
209 if (snmpPoll != null){
210 ExtentTestActions.log(Status.INFO, "Adding VFC artifact of type SNMP POLL with the file " + snmpPoll);
211 RestResponse uploadSnmpPollArtifact = uploadSnmpPollArtifact(filepath, snmpPoll, vspid, user, vspComponentId);
212 assertEquals("Did not succeed to add SNMP POLL", 200, uploadSnmpPollArtifact.getErrorCode().intValue());
214 if (snmpTrap != null){
215 ExtentTestActions.log(Status.INFO, "Adding VFC artifact of type SNMP TRAP with the file " + snmpTrap);
216 RestResponse uploadSnmpTrapArtifact = uploadSnmpTrapArtifact(filepath, snmpTrap, vspid, user, vspComponentId);
217 assertEquals("Did not succeed to add SNMP TRAP", 200, uploadSnmpTrapArtifact.getErrorCode().intValue());
221 return vspComponentId;
224 public static String addVFCArtifacts(String filepath, String snmpPoll, String snmpTrap, String vspid, User user) throws Exception{
225 return addVFCArtifacts(filepath, snmpPoll, snmpTrap, vspid, user, null);
228 private static RestResponse uploadSnmpPollArtifact(String filepath, String zipArtifact, String vspid, User user,
229 String vspComponentId) throws FileNotFoundException, IOException, ClientProtocolException {
230 Config config = Utils.getConfig();
231 String snmpPollUrl = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/versions/0.1/components/%s/monitors/snmp/upload",
232 config.getCatalogBeHost(),config.getCatalogBePort(), vspid, vspComponentId);
233 return uploadFile(filepath, zipArtifact, snmpPollUrl, user);
236 private static RestResponse uploadSnmpTrapArtifact(String filepath, String zipArtifact, String vspid, User user,
237 String vspComponentId) throws FileNotFoundException, IOException, ClientProtocolException {
238 Config config = Utils.getConfig();
239 String snmpTrapUrl = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/versions/0.1/components/%s/monitors/snmp-trap/upload",
240 config.getCatalogBeHost(),config.getCatalogBePort(), vspid, vspComponentId);
241 return uploadFile(filepath, zipArtifact, snmpTrapUrl, user);
244 private static RestResponse deleteSnmpArtifact(String componentId, String vspId, User user, SnmpTypeEnum snmpType) throws Exception
246 Config config = Utils.getConfig();
247 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/versions/0.1/components/%s/monitors/%s",
248 config.getCatalogBeHost(),config.getCatalogBePort(), vspId, componentId, snmpType.getValue());
249 String userId = user.getUserId();
251 Map<String, String> headersMap = prepareHeadersMap(userId);
253 HttpRequest http = new HttpRequest();
254 RestResponse response = http.httpSendDelete(url, headersMap);
260 private static String getVSPComponentId(String vspid, User user) throws Exception, JSONException {
261 RestResponse components = getVSPComponents(vspid, user);
262 String response = components.getResponse();
263 Map<String, Object> responseMap = (Map<String, Object>) JSONValue.parse(response);
264 JSONArray results = (JSONArray)responseMap.get("results");
265 for (Object res : results){
266 Map<String, Object> compMap= (Map<String, Object>) JSONValue.parse(res.toString());
267 String componentId = compMap.get("id").toString();
273 private static RestResponse getVSPComponents(String vspid, User user) throws Exception{
274 Config config = Utils.getConfig();
275 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/versions/0.1/components", config.getCatalogBeHost(),config.getCatalogBePort(), vspid);
276 String userId = user.getUserId();
278 Map<String, String> headersMap = prepareHeadersMap(userId);
280 HttpRequest http = new HttpRequest();
281 RestResponse response = http.httpSendGet(url, headersMap);
285 public static void createVendorLicense(User user) throws Exception {
286 SetupCDTest.getExtendTest().log(Status.INFO, "Starting to create the vendor license");
287 vendorLicenseName = "ciLicense" + getShortUUID();
288 RestResponse vendorLicenseResponse = createVendorLicenseModels_1(vendorLicenseName, user);
289 assertEquals("did not succeed to create vendor license model", 200,
290 vendorLicenseResponse.getErrorCode().intValue());
291 vendorId = ResponseParser.getValueFromJsonResponse(vendorLicenseResponse.getResponse(), "value");
293 RestResponse vendorKeyGroupsResponse = createVendorKeyGroups_2(vendorId, user);
294 assertEquals("did not succeed to create vendor key groups", 200,
295 vendorKeyGroupsResponse.getErrorCode().intValue());
296 String keyGroupId = ResponseParser.getValueFromJsonResponse(vendorKeyGroupsResponse.getResponse(), "value");
298 RestResponse vendorEntitlementPool = createVendorEntitlementPool_3(vendorId, user);
299 assertEquals("did not succeed to create vendor entitlement pool", 200,
300 vendorEntitlementPool.getErrorCode().intValue());
301 String entitlementPoolId = ResponseParser.getValueFromJsonResponse(vendorEntitlementPool.getResponse(),
304 RestResponse vendorLicenseFeatureGroups = createVendorLicenseFeatureGroups_4(vendorId, keyGroupId,
305 entitlementPoolId, user);
306 assertEquals("did not succeed to create vendor license feature groups", 200,
307 vendorLicenseFeatureGroups.getErrorCode().intValue());
308 featureGroupId = ResponseParser.getValueFromJsonResponse(vendorLicenseFeatureGroups.getResponse(), "value");
310 RestResponse vendorLicenseAgreement = createVendorLicenseAgreement_5(vendorId, featureGroupId, user);
311 assertEquals("did not succeed to create vendor license agreement", 200,
312 vendorLicenseAgreement.getErrorCode().intValue());
313 vendorLicenseAgreementId = ResponseParser.getValueFromJsonResponse(vendorLicenseAgreement.getResponse(),
316 RestResponse checkinVendorLicense = checkinVendorLicense(vendorId, user);
317 assertEquals("did not succeed to checkin vendor license", 200, checkinVendorLicense.getErrorCode().intValue());
319 RestResponse submitVendorLicense = submitVendorLicense(vendorId, user);
320 assertEquals("did not succeed to submit vendor license", 200, submitVendorLicense.getErrorCode().intValue());
322 SetupCDTest.getExtendTest().log(Status.INFO, "Succeeded in creating the vendor license");
325 private static String getShortUUID() {
326 return UUID.randomUUID().toString().split("-")[0];
329 private static RestResponse actionOnComponent(String vspid, String action, String onboardComponent, User user)
331 Config config = Utils.getConfig();
332 String url = String.format("http://%s:%s/onboarding-api/v1.0/" + onboardComponent + "/%s/versions/0.1/actions",
333 config.getCatalogBeHost(), config.getCatalogBePort(), vspid);
334 String userId = user.getUserId();
336 JSONObject jObject = new JSONObject();
337 jObject.put("action", action);
339 Map<String, String> headersMap = prepareHeadersMap(userId);
341 HttpRequest http = new HttpRequest();
342 RestResponse response = http.httpSendPut(url, jObject.toString(), headersMap);
346 public static RestResponse checkinVendorLicense(String vspid, User user) throws Exception {
347 return actionOnComponent(vspid, "Checkin", "vendor-license-models", user);
350 public static RestResponse submitVendorLicense(String vspid, User user) throws Exception {
351 return actionOnComponent(vspid, "Submit", "vendor-license-models", user);
354 public static RestResponse createVendorLicenseModels_1(String name, User user) throws Exception {
355 Config config = Utils.getConfig();
356 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-license-models", config.getCatalogBeHost(),
357 config.getCatalogBePort());
358 String userId = user.getUserId();
360 JSONObject jObject = new JSONObject();
361 jObject.put("vendorName", name);
362 jObject.put("description", "new vendor license model");
363 jObject.put("iconRef", "icon");
365 Map<String, String> headersMap = prepareHeadersMap(userId);
367 HttpRequest http = new HttpRequest();
368 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
373 public static RestResponse createVendorLicenseAgreement_5(String vspid, String featureGroupId, User user)
375 Config config = Utils.getConfig();
376 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-license-models/%s/versions/0.1/license-agreements",
377 config.getCatalogBeHost(), config.getCatalogBePort(), vspid);
378 String userId = user.getUserId();
380 JSONObject licenseTermpObject = new JSONObject();
381 licenseTermpObject.put("choice", "Fixed_Term");
382 licenseTermpObject.put("other", "");
384 JSONObject jObjectBody = new JSONObject();
385 jObjectBody.put("name", "abc");
386 jObjectBody.put("description", "new vendor license agreement");
387 jObjectBody.put("requirementsAndConstrains", "abc");
388 jObjectBody.put("licenseTerm", licenseTermpObject);
389 jObjectBody.put("addedFeatureGroupsIds", Arrays.asList(featureGroupId).toArray());
391 Map<String, String> headersMap = prepareHeadersMap(userId);
393 HttpRequest http = new HttpRequest();
394 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
398 public static RestResponse createVendorLicenseFeatureGroups_4(String vspid, String licenseKeyGroupId,
399 String entitlementPoolId, User user) throws Exception {
400 Config config = Utils.getConfig();
401 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-license-models/%s/versions/0.1/feature-groups",
402 config.getCatalogBeHost(), config.getCatalogBePort(), vspid);
403 String userId = user.getUserId();
405 JSONObject jObject = new JSONObject();
406 jObject.put("name", "xyz");
407 jObject.put("description", "new vendor license feature groups");
408 jObject.put("partNumber", "123abc456");
409 jObject.put("addedLicenseKeyGroupsIds", Arrays.asList(licenseKeyGroupId).toArray());
410 jObject.put("addedEntitlementPoolsIds", Arrays.asList(entitlementPoolId).toArray());
412 Map<String, String> headersMap = prepareHeadersMap(userId);
414 HttpRequest http = new HttpRequest();
415 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
420 public static RestResponse createVendorEntitlementPool_3(String vspid, User user) throws Exception {
421 Config config = Utils.getConfig();
422 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-license-models/%s/versions/0.1/entitlement-pools",
423 config.getCatalogBeHost(), config.getCatalogBePort(), vspid);
424 String userId = user.getUserId();
426 JSONObject jEntitlementMetricObject = new JSONObject();
427 jEntitlementMetricObject.put("choice", "CPU");
428 jEntitlementMetricObject.put("other", "");
430 JSONObject jAggregationFunctionObject = new JSONObject();
431 jAggregationFunctionObject.put("choice", "Peak");
432 jAggregationFunctionObject.put("other", "");
434 JSONObject jOperationalScope = new JSONObject();
435 jOperationalScope.put("choices", Arrays.asList("Availability_Zone").toArray());
436 jOperationalScope.put("other", "");
438 JSONObject jTimeObject = new JSONObject();
439 jTimeObject.put("choice", "Hour");
440 jTimeObject.put("other", "");
442 JSONObject jObjectBody = new JSONObject();
443 jObjectBody.put("name", "def");
444 jObjectBody.put("description", "new vendor license entitlement pool");
445 jObjectBody.put("thresholdValue", "23");
446 jObjectBody.put("thresholdUnits", "Absolute");
447 jObjectBody.put("entitlementMetric", jEntitlementMetricObject);
448 jObjectBody.put("increments", "abcd");
449 jObjectBody.put("aggregationFunction", jAggregationFunctionObject);
450 jObjectBody.put("operationalScope", jOperationalScope);
451 jObjectBody.put("time", jTimeObject);
452 jObjectBody.put("manufacturerReferenceNumber", "123aaa");
454 Map<String, String> headersMap = prepareHeadersMap(userId);
456 HttpRequest http = new HttpRequest();
457 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
461 public static RestResponse createVendorKeyGroups_2(String vspid, User user) throws Exception {
462 Config config = Utils.getConfig();
463 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-license-models/%s/versions/0.1/license-key-groups",
464 config.getCatalogBeHost(), config.getCatalogBePort(), vspid);
465 String userId = user.getUserId();
467 JSONObject jOperationalScope = new JSONObject();
468 jOperationalScope.put("choices", Arrays.asList("Tenant").toArray());
469 jOperationalScope.put("other", "");
471 JSONObject jObjectBody = new JSONObject();
472 jObjectBody.put("name", "keyGroup");
473 jObjectBody.put("description", "new vendor license key group");
474 jObjectBody.put("operationalScope", jOperationalScope);
475 jObjectBody.put("type", "Universal");
477 Map<String, String> headersMap = prepareHeadersMap(userId);
479 HttpRequest http = new HttpRequest();
480 RestResponse response = http.httpSendPost(url, jObjectBody.toString(), headersMap);
484 public static Pair<RestResponse, Map<String, String>> createNewVendorSoftwareProduct(String name, String vendorName, String vendorId,
485 String licenseAgreementId, String featureGroupsId, User user) throws Exception {
487 Map<String, String> vspMetadta = new HashMap<String, String>();
489 Config config = Utils.getConfig();
490 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products",
491 config.getCatalogBeHost(), config.getCatalogBePort());
493 String userId = user.getUserId();
495 JSONObject jlicensingDataObj = new JSONObject();
496 jlicensingDataObj.put("licenseAgreement", licenseAgreementId);
497 jlicensingDataObj.put("featureGroups", Arrays.asList(featureGroupsId).toArray());
499 JSONObject jlicensingVersionObj = new JSONObject();
500 jlicensingVersionObj.put("id", "1.0");
501 jlicensingVersionObj.put("label", "1.0");
503 JSONObject jObject = new JSONObject();
504 jObject.put("name", name);
505 jObject.put("description", "new VSP description");
506 jObject.put("category", "resourceNewCategory.generic");
507 jObject.put("subCategory", "resourceNewCategory.generic.database");
508 jObject.put("licensingVersion", jlicensingVersionObj);
509 jObject.put("vendorName", vendorName);
510 jObject.put("vendorId", vendorId);
511 jObject.put("icon", "icon");
512 jObject.put("licensingData", jlicensingDataObj);
514 vspMetadta.put("description", jObject.getString("description"));
515 vspMetadta.put("category", jObject.getString("category"));
516 vspMetadta.put("subCategory", jObject.getString("subCategory").split("\\.")[2]);
518 Map<String, String> headersMap = prepareHeadersMap(userId);
519 HttpRequest http = new HttpRequest();
521 RestResponse response = http.httpSendPost(url, jObject.toString(), headersMap);
523 return new Pair<RestResponse, Map<String, String>>(response, vspMetadta);
526 public static RestResponse getVendorSoftwareProduct(Map vspObject, User user) throws Exception {
527 Config config = Utils.getConfig();
528 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/" + vspObject.get("vspId"),
529 config.getCatalogBeHost(), config.getCatalogBePort());
531 String userId = user.getUserId();
533 Map<String, String> headersMap = prepareHeadersMap(userId);
534 HttpRequest http = new HttpRequest();
536 RestResponse response = http.httpsSendGet(url, headersMap);
541 public static RestResponse validateUpload(String vspid, User user) throws Exception {
542 Config config = Utils.getConfig();
543 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/versions/0.1/orchestration-template-candidate/process",
544 config.getCatalogBeHost(), config.getCatalogBePort(), vspid);
546 String userId = user.getUserId();
548 Map<String, String> headersMap = prepareHeadersMap(userId);
549 HttpRequest http = new HttpRequest();
553 RestResponse response = http.httpSendPut(url, body, headersMap);
558 public static RestResponse uploadHeatPackage(String filepath, String filename, String vspid, User user) throws Exception {
559 Config config = Utils.getConfig();
560 String url = String.format("http://%s:%s/onboarding-api/v1.0/vendor-software-products/%s/versions/0.1/orchestration-template-candidate", config.getCatalogBeHost(), config.getCatalogBePort(), vspid);
561 return uploadFile(filepath, filename, url, user);
564 private static RestResponse uploadFile(String filepath, String filename, String url, User user)
565 throws FileNotFoundException, IOException, ClientProtocolException {
566 CloseableHttpResponse response = null;
568 MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create();
569 mpBuilder.addPart("upload", new FileBody(getTestZipFile(filepath, filename)));
571 Map<String, String> headersMap = prepareHeadersMap(user.getUserId());
572 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "multipart/form-data");
574 CloseableHttpClient client = HttpClients.createDefault();
576 HttpPost httpPost = new HttpPost(url);
577 RestResponse restResponse = new RestResponse();
579 Iterator<String> iterator = headersMap.keySet().iterator();
580 while (iterator.hasNext()) {
581 String key = iterator.next();
582 String value = headersMap.get(key);
583 httpPost.addHeader(key, value);
585 httpPost.setEntity(mpBuilder.build());
586 response = client.execute(httpPost);
587 HttpEntity entity = response.getEntity();
588 String responseBody = null;
589 if (entity != null) {
590 InputStream instream = entity.getContent();
591 StringWriter writer = new StringWriter();
592 IOUtils.copy(instream, writer);
593 responseBody = writer.toString();
601 restResponse.setErrorCode(response.getStatusLine().getStatusCode());
602 restResponse.setResponse(responseBody);
607 closeResponse(response);
608 closeHttpClient(client);
613 private static void closeResponse(CloseableHttpResponse response) {
615 if (response != null) {
618 } catch (IOException e) {
619 System.out.println(String.format("failed to close client or response: %s", e.getMessage()));
623 private static void closeHttpClient(CloseableHttpClient client) {
625 if (client != null) {
628 } catch (IOException e) {
629 System.out.println(String.format("failed to close client or response: %s", e.getMessage()));
633 private static File getTestZipFile(String filepath, String filename) throws IOException {
634 Config config = Utils.getConfig();
635 String sourceDir = config.getImportResourceTestsConfigDir();
636 java.nio.file.Path filePath = FileSystems.getDefault().getPath(filepath + File.separator + filename);
637 return filePath.toFile();
640 public static RestResponse checkinVendorSoftwareProduct(String vspid, User user) throws Exception {
641 return actionOnComponent(vspid, "Checkin", "vendor-software-products", user);
644 private static RestResponse checkoutVendorSoftwareProduct(String vspid, User user) throws Exception {
645 return actionOnComponent(vspid, "Checkout", "vendor-software-products", user);
648 public static RestResponse submitVendorSoftwareProduct(String vspid, User user) throws Exception {
649 return actionOnComponent(vspid, "Submit", "vendor-software-products", user);
652 public static RestResponse createPackageOfVendorSoftwareProduct(String vspid, User user) throws Exception {
653 return actionOnComponent(vspid, "Create_Package", "vendor-software-products", user);
656 protected static Map<String, String> prepareHeadersMap(String userId) {
657 Map<String, String> headersMap = new HashMap<String, String>();
658 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
659 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
660 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
665 private static void importUpdateVSP(Pair<String, Map<String, String>> vsp, boolean isUpdate) throws Exception{
666 String vspName = vsp.left;
667 Map<String, String> vspMetadata = vsp.right;
668 boolean vspFound = HomePage.searchForVSP(vspName);
672 List<WebElement> elemenetsFromTable = HomePage.getElemenetsFromTable();
673 // WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 30);
674 // WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elemenetsFromTable.get(1)));
675 // findElement.click();
676 elemenetsFromTable.get(1).click();
677 GeneralUIUtils.waitForLoader();
680 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.UPDATE_VSP.getValue());
684 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
687 String lifeCycleState = ResourceGeneralPage.getLifeCycleState();
688 boolean needCheckout = lifeCycleState.equals(LifeCycleStateEnum.CHECKIN.getValue()) || lifeCycleState.equals(LifeCycleStateEnum.CERTIFIED.getValue());
692 ResourceGeneralPage.clickCheckoutButton();
693 Assert.assertTrue(ResourceGeneralPage.getLifeCycleState().equals(LifeCycleStateEnum.CHECKOUT.getValue()), "Did not succeed to checkout");
695 } catch (Exception e) {
696 ExtentTestActions.log(Status.ERROR, "Did not succeed to checkout");
699 GeneralUIUtils.waitForLoader();
702 //Metadata verification
703 VfVerificator.verifyOnboardedVnfMetadata(vspName, vspMetadata);
705 ExtentTestActions.log(Status.INFO, "Clicking create/update VNF");
706 String duration = GeneralUIUtils.getActionDuration(() -> waitUntilVnfCreated());
707 ExtentTestActions.log(Status.INFO, "Succeeded in importing/updating " + vspName, duration);
710 Assert.fail("Did not find VSP named " + vspName);
714 private static void waitUntilVnfCreated() {
715 GeneralUIUtils.clickOnElementByTestIdWithoutWait(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
716 GeneralUIUtils.waitForLoader(60*10);
717 GeneralUIUtils.waitForAngular();
718 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
721 public static void updateVSP(Pair<String, Map<String, String>> vsp) throws Exception{
722 ExtentTestActions.log(Status.INFO, "Updating VSP " + vsp.left);
723 importUpdateVSP(vsp, true);
726 public static void importVSP(Pair<String, Map<String, String>> vsp) throws Exception{
727 ExtentTestActions.log(Status.INFO, "Importing VSP " + vsp.left);
728 importUpdateVSP(vsp, false);
731 public static void updateVnfAndValidate(String filepath, Pair<String, Map<String, String>> vsp, String updatedVnfFile, User user) throws Exception, Throwable {
732 ExtentTestActions.log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
733 System.out.println(String.format("Going to update the VNF with %s......", updatedVnfFile));
735 Map<String, String> vspMap = vsp.right;
736 String vspId = vspMap.get("vspId");
738 updateVendorSoftwareProduct(vspId, updatedVnfFile, filepath, user);
739 HomePage.showVspRepository();
741 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
742 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, updatedVnfFile);
745 public static Pair<String, Map<String, String>> onboardAndValidate(String filepath, String vnfFile, User user) throws Exception {
746 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
747 System.out.println(String.format("Going to onboard the VNF %s", vnfFile));
749 createVendorLicense(user);
750 Pair<String, Map<String, String>> createVendorSoftwareProduct = createVendorSoftwareProduct(vnfFile, filepath, user);
751 String vspName = createVendorSoftwareProduct.left;
753 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, createVendorSoftwareProduct.right.get("vspId"));
754 File latestFilefromDir = FileHandling.getLastModifiedFileFromDir();
756 ExtentTestActions.log(Status.INFO, String.format("Searching for onboarded %s", vnfFile));
757 HomePage.showVspRepository();
758 ExtentTestActions.log(Status.INFO,String.format("Going to import %s", vnfFile.substring(0, vnfFile.indexOf("."))));
759 importVSP(createVendorSoftwareProduct);
761 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
763 // Verify deployment artifacts
764 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
766 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
767 ArtifactsCorrelationManager.addVNFartifactDetails(vspName, deploymentArtifacts);
769 for(HeatMetaFirstLevelDefinition deploymentArtifact: deploymentArtifacts) {
770 if(deploymentArtifact.getType().equals("HEAT_ENV")) {
772 } else if(deploymentArtifact.getFileName().contains(".")) {
773 ArtifactUIUtils.validateArtifactNameVersionType(deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf(".")), "1", deploymentArtifact.getType());
775 ArtifactUIUtils.validateArtifactNameVersionType(deploymentArtifact.getFileName().trim(), "1", deploymentArtifact.getType());
780 DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
781 return createVendorSoftwareProduct;
788 SNMP_TRAP ("snmp-trap");
790 private String value;
792 public String getValue() {
796 private SnmpTypeEnum(String value) {