[SDC-31] add mising script got Comformance fix
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / product / ProductTestBase.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.execute.product;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.io.IOException;
28
29 import org.apache.log4j.lf5.util.ResourceUtils;
30 import org.junit.Before;
31 import org.junit.rules.TestName;
32 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
33 import org.openecomp.sdc.be.model.Product;
34 import org.openecomp.sdc.be.model.Resource;
35 import org.openecomp.sdc.be.model.Service;
36 import org.openecomp.sdc.be.model.User;
37 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
39 import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails;
40 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
41 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
42 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
43 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
44 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
45 import org.openecomp.sdc.ci.tests.utils.ArtifactUtils;
46 import org.openecomp.sdc.ci.tests.utils.DbUtils;
47 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
48 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
49 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
50 import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
51 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
52 import org.openecomp.sdc.ci.tests.utils.rest.ProductRestUtils;
53 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
54 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
55 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
56
57 public class ProductTestBase extends ProductBaseTest {
58
59         public ProductTestBase(TestName testName, String className) {
60                 super(testName, className);
61         }
62
63         protected ResourceReqDetails downloadResourceDetails;
64         protected ServiceReqDetails serviceDetails;
65         protected ComponentInstanceReqDetails resourceInstanceReqDetails;
66         protected User sdncUserDetails;
67         protected ArtifactReqDetails heatArtifactDetails;
68         protected ArtifactReqDetails defaultArtifactDetails;
69         protected ResourceUtils resourceUtils;
70         protected ArtifactUtils artifactUtils;
71         protected Resource resource;
72         protected Service service;
73         protected Product product;
74
75         // protected static ServiceUtils serviceUtils = new ServiceUtils();
76
77         @Before
78         public void before() throws Exception {
79
80                 initializeMembers();
81                 createComponents();
82
83         }
84
85         public void initializeMembers() throws IOException, Exception {
86
87                 downloadResourceDetails = ElementFactory.getDefaultResource();
88                 serviceDetails = ElementFactory.getDefaultService();
89                 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
90                 heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
91                 resourceInstanceReqDetails = ElementFactory.getDefaultComponentInstance();
92
93         }
94
95         protected void createComponents() throws Exception {
96
97                 RestResponse response = ResourceRestUtils.createResource(downloadResourceDetails, sdncUserDetails);
98                 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
99                 assertNotNull("resource uniqueId is null:", downloadResourceDetails.getUniqueId());
100
101                 ArtifactReqDetails heatArtifactDetails = ElementFactory
102                                 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
103                 response = ArtifactRestUtils.addInformationalArtifactToResource(heatArtifactDetails, sdncUserDetails,
104                                 downloadResourceDetails.getUniqueId());
105                 assertTrue("add HEAT artifact to resource request returned status:" + response.getErrorCode(),
106                                 response.getErrorCode() == 200);
107
108                 // certified resource
109                 response = LifecycleRestUtils.certifyResource(downloadResourceDetails);
110                 assertTrue("certify resource request returned status:" + response.getErrorCode(),
111                                 response.getErrorCode() == 200);
112
113                 response = ResourceRestUtils.getResource(downloadResourceDetails.getUniqueId());
114                 assertTrue("response code is not 200, returned: " + response.getErrorCode(), response.getErrorCode() == 200);
115                 resource = ResponseParser.convertResourceResponseToJavaObject(response.getResponse());
116
117                 response = ServiceRestUtils.createService(serviceDetails, sdncUserDetails);
118                 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
119                 assertNotNull("service uniqueId is null:", serviceDetails.getUniqueId());
120
121                 // add resource instance with HEAT deployment artifact to the service
122                 resourceInstanceReqDetails.setComponentUid(downloadResourceDetails.getUniqueId());
123                 response = ComponentInstanceRestUtils.createComponentInstance(resourceInstanceReqDetails, sdncUserDetails,
124                                 serviceDetails.getUniqueId(), ComponentTypeEnum.SERVICE);
125                 assertTrue("response code is not 201, returned: " + response.getErrorCode(), response.getErrorCode() == 201);
126
127                 // certified service
128                 response = LifecycleRestUtils.certifyService(serviceDetails);
129                 assertTrue("certify service request returned status:" + response.getErrorCode(),
130                                 response.getErrorCode() == 200);
131
132                 response = ServiceRestUtils.getService(serviceDetails, sdncUserDetails);
133                 assertTrue("response code is not 200, returned: " + response.getErrorCode(), response.getErrorCode() == 200);
134                 service = ResponseParser.convertServiceResponseToJavaObject(response.getResponse());
135
136                 DbUtils.cleanAllAudits();
137
138                 ProductReqDetails defaultProduct = ElementFactory.getDefaultProduct(defaultCategories);
139                 RestResponse createProduct = ProductRestUtils.createProduct(defaultProduct, productStrategistUser1);
140                 assertEquals("Check response code after create Product", BaseRestUtils.STATUS_CODE_CREATED,
141                                 createProduct.getErrorCode().intValue());
142                 product = ResponseParser.parseToObjectUsingMapper(createProduct.getResponse(), Product.class);
143
144                 // add service instance to product
145                 //
146
147         }
148 }