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