Sync Integ to Master
[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.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;
50
51 import com.aventstack.extentreports.Status;
52 import com.clearspring.analytics.util.Pair;
53
54 import fj.data.Either;
55
56
57
58
59
60
61 public class Onboard extends ComponentBaseTest {
62         
63         
64         @Rule
65         public static TestName name = new TestName();
66         
67         public Onboard() {
68                 super(name, Onboard.class.getName());
69         }
70
71         protected String makeDistributionValue;
72         protected String makeToscaValidationValue;
73
74
75         @Parameters({ "makeDistribution" })
76         @BeforeMethod
77         public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
78                 makeDistributionValue = makeDistributionReadValue;                             
79                 logger.info("makeDistributionReadValue - > " + makeDistributionValue);
80         }
81
82         @Parameters({ "makeToscaValidation" })
83         @BeforeClass
84         public void makeToscaValidation(@Optional("false") String makeToscaValidationReadValue) {
85                 makeToscaValidationValue = makeToscaValidationReadValue;
86                 logger.info("makeToscaValidationReadValue - > " + makeToscaValidationValue);
87         }
88         
89
90         @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
91         public void onboardVNFShotFlow(String filePath, String vnfFile) throws Exception, Throwable {
92                 setLog(vnfFile);
93                 System.out.println("print - >" + makeDistributionValue);
94                 runOnboardToDistributionFlow(filePath, vnfFile);
95         }
96         
97         @Test
98         public void passTest() {
99                 System.out.println("print - >" + "test Passed");
100         }
101         
102
103         
104
105         
106         public void runOnboardToDistributionFlow(String filePath, String vnfFile) throws Exception {
107
108                 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
109                 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER3);
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);
114
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.DESIGNER3);
120                 ExtentTestActions.log(Status.INFO, String.format("Certify VF"));
121                 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER3, LifeCycleStatesEnum.CERTIFY, true).getLeft();
122
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.DESIGNER3, true).left().value();
127                 ExtentTestActions.log(Status.INFO, String.format("add VF to Service"));
128                 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER3, true);
129                 addComponentInstanceToComponentContainer.left().value();
130                 ExtentTestActions.log(Status.INFO, String.format("Certify Service"));
131                 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER3, LifeCycleStatesEnum.CERTIFY, true).getLeft();
132
133                 if (makeDistributionValue.equals("true")) {
134                         ExtentTestActions.log(Status.INFO, String.format("Distribute Service"));
135                         AtomicOperationUtils.distributeService(service, true);
136                 }
137
138                 if (makeToscaValidationValue.equals("true")) {
139
140                         ExtentTestActions.log(Status.INFO, String.format("Start tosca validation"));
141                         AtomicOperationUtils.toscaValidation(service ,vnfFile);
142
143
144                 }
145
146
147
148                 
149                 ExtentTestActions.log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
150         }
151
152
153
154 }