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