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.sanity;
27 import org.junit.Rule;
28 import org.junit.rules.TestName;
29 import org.openecomp.sdc.be.model.ComponentInstance;
30 import org.openecomp.sdc.be.model.Resource;
31 import org.openecomp.sdc.be.model.Service;
32 import org.openecomp.sdc.be.model.User;
33 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
34 import org.openecomp.sdc.ci.tests.api.ExtentTestActions;
35 import org.openecomp.sdc.ci.tests.dataProviders.OnbordingDataProviders;
36 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
37 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
39 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
40 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
41 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
42 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
43 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
44 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtillViaApis;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.BeforeMethod;
47 import org.testng.annotations.Optional;
48 import org.testng.annotations.Parameters;
49 import org.testng.annotations.Test;
51 import com.aventstack.extentreports.Status;
52 import com.clearspring.analytics.util.Pair;
54 import fj.data.Either;
61 public class Onboard extends ComponentBaseTest {
65 public static TestName name = new TestName();
68 super(name, Onboard.class.getName());
71 protected String makeDistributionValue;
72 protected String makeToscaValidationValue;
75 @Parameters({ "makeDistribution" })
77 public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
78 makeDistributionValue = makeDistributionReadValue;
79 logger.info("makeDistributionReadValue - > " + makeDistributionValue);
82 @Parameters({ "makeToscaValidation" })
84 public void makeToscaValidation(@Optional("false") String makeToscaValidationReadValue) {
85 makeToscaValidationValue = makeToscaValidationReadValue;
86 logger.info("makeToscaValidationReadValue - > " + makeToscaValidationValue);
90 @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
91 public void onboardVNFShotFlow(String filePath, String vnfFile) throws Exception, Throwable {
93 System.out.println("print - >" + makeDistributionValue);
94 runOnboardToDistributionFlow(filePath, vnfFile);
98 public void passTest() {
99 System.out.println("print - >" + "test Passed");
106 public void runOnboardToDistributionFlow(String filePath, String vnfFile) throws Exception {
108 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
109 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
110 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
111 Pair<String, VendorSoftwareProductObject> createVendorSoftwareProduct = OnboardingUtillViaApis.createVspViaApis(resourceReqDetails, filePath, vnfFile, user);
112 VendorSoftwareProductObject vendorSoftwareProductObject = createVendorSoftwareProduct.right;
113 vendorSoftwareProductObject.setName(createVendorSoftwareProduct.left);
115 // create VF base on VNF imported from previous step - have, resourceReqDetails object include part of resource metadata
116 // ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
117 resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
118 ExtentTestActions.log(Status.INFO, String.format("Create VF %s From VSP", resourceReqDetails.getName()));
119 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails, UserRoleEnum.DESIGNER);
120 ExtentTestActions.log(Status.INFO, String.format("Certify VF"));
121 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
123 //--------------------------SERVICE--------------------------------
124 ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(user);
125 ExtentTestActions.log(Status.INFO, String.format("Create Service %s", serviceReqDetails.getName()));
126 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
127 ExtentTestActions.log(Status.INFO, String.format("add VF to Service"));
128 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
129 addComponentInstanceToComponentContainer.left().value();
130 ExtentTestActions.log(Status.INFO, String.format("Certify Service"));
131 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
133 if (makeDistributionValue.equals("true")) {
134 ExtentTestActions.log(Status.INFO, String.format("Distribute Service"));
135 AtomicOperationUtils.distributeService(service, true);
138 if (makeToscaValidationValue.equals("true")) {
140 ExtentTestActions.log(Status.INFO, String.format("Start tosca validation"));
141 AtomicOperationUtils.toscaValidation(service ,vnfFile);
149 ExtentTestActions.log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));