update tosca parser verification feature
[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.datatypes.enums.AssetTypeEnum;
30 import org.openecomp.sdc.be.model.ComponentInstance;
31 import org.openecomp.sdc.be.model.Resource;
32 import org.openecomp.sdc.be.model.Service;
33 import org.openecomp.sdc.be.model.User;
34 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
35 import org.openecomp.sdc.ci.tests.api.ExtentTestActions;
36 import org.openecomp.sdc.ci.tests.dataProviders.OnboardingDataProviders;
37 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
39 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
40 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
41 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
42 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
43 import org.openecomp.sdc.ci.tests.utils.CsarToscaTester;
44 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
45 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
46 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtillViaApis;
47 import org.openecomp.sdc.ci.tests.utils.rest.AssetRestUtils;
48 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
49 import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
50 import org.testng.annotations.BeforeMethod;
51 import org.testng.annotations.Optional;
52 import org.testng.annotations.Parameters;
53 import org.testng.annotations.Test;
54
55 import com.aventstack.extentreports.Status;
56 import com.clearspring.analytics.util.Pair;
57
58 import fj.data.Either;
59
60 import java.io.File;
61
62
63 public class Onboard extends ComponentBaseTest {
64         
65         
66         @Rule
67         public static TestName name = new TestName();
68         
69         public Onboard() {
70                 super(name, Onboard.class.getName());
71         }
72
73         protected String makeDistributionValue;
74         protected ISdcCsarHelper fdntCsarHelper;
75         protected SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
76
77
78
79         @Parameters({ "makeDistribution" })
80         @BeforeMethod
81         public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
82                 makeDistributionValue = makeDistributionReadValue;                             
83         }
84         
85
86         @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "VNF_List")
87         public void onboardVNFShotFlow(String filepath, String vnfFile) throws Exception, Throwable {
88                 setLog(vnfFile);
89                 System.out.println("print - >" + makeDistributionValue);
90                 runOnboardToDistributionFlow(filepath, vnfFile);
91         }
92         
93
94         
95
96         
97         public void runOnboardToDistributionFlow(String filepath, String vnfFile) throws Exception {
98
99                 ExtentTestActions.log(Status.INFO, String.format("Going to onboard the VNF %s", vnfFile));
100                 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
101      
102                 Pair<String, VendorSoftwareProductObject> createVendorSoftwareProduct = OnboardingUtillViaApis.createVspViaApis(filepath, vnfFile, user);
103                 VendorSoftwareProductObject vendorSoftwareProductObject = createVendorSoftwareProduct.right;
104                 vendorSoftwareProductObject.setVspName(createVendorSoftwareProduct.left);
105
106                 //              create VF base on VNF imported from previous step - have, resourceReqDetails object include part of resource metadata
107                 ResourceReqDetails resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(vendorSoftwareProductObject, vendorSoftwareProductObject.getVspName());
108                 ExtentTestActions.log(Status.INFO, String.format("Create VF %s From VSP", resourceReqDetails.getName()));
109                 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails, vendorSoftwareProductObject.getVspName());
110                 ExtentTestActions.log(Status.INFO, String.format("Certify VF"));
111                 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
112
113                 //--------------------------SERVICE--------------------------------     
114                 ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(user);
115                 ExtentTestActions.log(Status.INFO, String.format("Create Service %s", serviceReqDetails.getName()));
116                 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
117                 ExtentTestActions.log(Status.INFO, String.format("add VF to Service"));
118                 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
119                 addComponentInstanceToComponentContainer.left().value();
120                 ExtentTestActions.log(Status.INFO, String.format("Certify Service"));
121                 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
122
123
124 //              ExtentTestActions.log(Status.INFO, String.format("Distribute Service"));
125 //              AtomicOperationUtils.distributeService(service, true);
126                 try{
127 //                      HttpResponse assetResponse = AssetRestUtils.getComponentToscaModel(AssetTypeEnum.SERVICES, service.getUUID());
128 //                      InputStream inputStream = assetResponse.getEntity().getContent();
129                         File csarFile = AssetRestUtils.getToscaModelCsarFile(AssetTypeEnum.SERVICES, service.getUUID(), "");
130
131                         ExtentTestActions.log(Status.INFO, "Tosca parser is going to convert service csar file to ISdcCsarHelper object...");
132                         fdntCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath());
133             CsarToscaTester.processCsar(fdntCsarHelper);
134
135                         ExtentTestActions.log(Status.INFO, String.format("Tosca parser successfully parsed service CSAR"));
136
137                         ExtentTestActions.log(Status.INFO, String.format("The onboarding %s test is passed ! ", vnfFile));
138
139                 }catch(Exception e){
140                         ExtentTestActions.log(Status.ERROR, "Tosca parser FAILED to convert service csar file to ISdcCsarHelper object...");
141                         ExtentTestActions.log(Status.FAIL, e);
142
143                 }
144
145
146
147         }
148
149 }