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