2b341f5cbfb886688fd710db8c02354d2ae0f414
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / sanity / Onboard.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.sanity;
22
23
24
25
26
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.BeforeMethod;
46 import org.testng.annotations.Optional;
47 import org.testng.annotations.Parameters;
48 import org.testng.annotations.Test;
49
50 import com.aventstack.extentreports.Status;
51 import com.clearspring.analytics.util.Pair;
52
53 import fj.data.Either;
54
55
56
57
58
59
60 public class Onboard extends ComponentBaseTest {
61         
62         
63         @Rule
64         public static TestName name = new TestName();
65         
66         public Onboard() {
67                 super(name, Onboard.class.getName());
68         }
69
70         protected String makeDistributionValue;
71
72
73
74         @Parameters({ "makeDistribution" })
75         @BeforeMethod
76         public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
77                 makeDistributionValue = makeDistributionReadValue;                             
78         }
79         
80
81         @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
82         public void onboardVNFShotFlow(String filepath, String vnfFile) throws Exception, Throwable {
83                 setLog(vnfFile);
84                 System.out.println("print - >" + makeDistributionValue);
85                 runOnboardToDistributionFlow(filepath, vnfFile);
86         }
87         
88
89         
90
91         
92         public void runOnboardToDistributionFlow(String filepath, String vnfFile) throws Exception {
93
94                 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
95                 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
96      
97                 Pair<String, VendorSoftwareProductObject> createVendorSoftwareProduct = OnboardingUtillViaApis.createVspViaApis(filepath, vnfFile, user);
98                 VendorSoftwareProductObject vendorSoftwareProductObject = createVendorSoftwareProduct.right;
99                 vendorSoftwareProductObject.setVspName(createVendorSoftwareProduct.left);
100
101                 //              create VF base on VNF imported from previous step - have, resourceReqDetails object include part of resource metadata
102                 ResourceReqDetails resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(vendorSoftwareProductObject, vendorSoftwareProductObject.getVspName());
103                 ExtentTestActions.log(Status.INFO, String.format("Create VF %s From VSP", resourceReqDetails.getName()));
104                 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails, vendorSoftwareProductObject.getVspName());
105                 ExtentTestActions.log(Status.INFO, String.format("Certify VF"));
106                 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
107
108                 //--------------------------SERVICE--------------------------------     
109                 ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(user);
110                 ExtentTestActions.log(Status.INFO, String.format("Create Service %s", serviceReqDetails.getName()));
111                 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
112                 ExtentTestActions.log(Status.INFO, String.format("add VF to Service"));
113                 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
114                 addComponentInstanceToComponentContainer.left().value();
115                 ExtentTestActions.log(Status.INFO, String.format("Certify Service"));
116                 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
117
118                 ExtentTestActions.log(Status.INFO, String.format("Distribute Service"));
119                 AtomicOperationUtils.distributeService(service, true);
120                 
121                 ExtentTestActions.log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
122         }
123
124
125
126 }