[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / preRequisites / DownloadArtifactBaseTest.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.preRequisites;
22
23 import java.io.IOException;
24
25 import org.apache.log4j.lf5.util.ResourceUtils;
26 import org.junit.rules.TestName;
27 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
28 import org.openecomp.sdc.be.model.Service;
29 import org.openecomp.sdc.be.model.User;
30 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
31 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
32 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
33 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
34 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
35 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
37 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
38 import org.openecomp.sdc.ci.tests.execute.lifecycle.LCSbaseTest;
39 import org.openecomp.sdc.ci.tests.utils.ArtifactUtils;
40 import org.openecomp.sdc.ci.tests.utils.DbUtils;
41 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
42 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
43 import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
44 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
45 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
46 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
47 import org.testng.AssertJUnit;
48 import org.testng.annotations.BeforeMethod;
49
50 public class DownloadArtifactBaseTest extends ComponentBaseTest {
51
52         protected ResourceReqDetails downloadResourceDetails;
53         protected ServiceReqDetails serviceDetails;
54         protected ComponentInstanceReqDetails resourceInstanceReqDetails;
55         protected User sdncUserDetails;
56         protected User sdncDesignerDetails1;
57         protected ArtifactReqDetails heatArtifactDetails;
58
59         protected ArtifactReqDetails defaultArtifactDetails;
60         protected ResourceUtils resourceUtils;
61         protected ArtifactUtils artifactUtils;
62         protected Service service;
63
64         public DownloadArtifactBaseTest(TestName testName, String className) {
65                 super(testName, className);
66         }
67
68         @BeforeMethod
69         public void before() throws Exception {
70
71                 initializeMembers();
72                 createComponents();
73
74         }
75
76         public void initializeMembers() throws IOException, Exception {
77                 downloadResourceDetails = ElementFactory.getDefaultResource();
78                 serviceDetails = ElementFactory.getDefaultService();
79                 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
80                 sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
81                 heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
82                 resourceInstanceReqDetails = ElementFactory.getDefaultComponentInstance();
83
84         }
85
86         protected void createComponents() throws Exception {
87
88                 RestResponse response = ResourceRestUtils.createResource(downloadResourceDetails, sdncUserDetails);
89                 AssertJUnit.assertTrue("create request returned status:" + response.getErrorCode(),
90                                 response.getErrorCode() == 201);
91                 AssertJUnit.assertNotNull("resource uniqueId is null:", downloadResourceDetails.getUniqueId());
92
93                 ArtifactReqDetails heatArtifactDetails = ElementFactory
94                                 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
95                 response = ArtifactRestUtils.addInformationalArtifactToResource(heatArtifactDetails, sdncUserDetails,
96                                 downloadResourceDetails.getUniqueId());
97                 AssertJUnit.assertTrue("add HEAT artifact to resource request returned status:" + response.getErrorCode(),
98                                 response.getErrorCode() == 200);
99
100                 // certified resource
101                 response = LCSbaseTest.certifyResource(downloadResourceDetails, sdncDesignerDetails1);
102                 AssertJUnit.assertTrue("certify resource request returned status:" + response.getErrorCode(),
103                                 response.getErrorCode() == 200);
104
105                 response = ServiceRestUtils.createService(serviceDetails, sdncUserDetails);
106                 AssertJUnit.assertTrue("create request returned status:" + response.getErrorCode(),
107                                 response.getErrorCode() == 201);
108                 AssertJUnit.assertNotNull("service uniqueId is null:", serviceDetails.getUniqueId());
109
110                 // add resource instance with HEAT deployment artifact to the service
111                 resourceInstanceReqDetails.setComponentUid(downloadResourceDetails.getUniqueId());
112                 response = ComponentInstanceRestUtils.createComponentInstance(resourceInstanceReqDetails, sdncUserDetails,
113                                 serviceDetails.getUniqueId(), ComponentTypeEnum.SERVICE);
114                 AssertJUnit.assertTrue("response code is not 201, returned: " + response.getErrorCode(),
115                                 response.getErrorCode() == 201);
116
117                 response = ServiceRestUtils.getService(serviceDetails, sdncUserDetails);
118                 AssertJUnit.assertTrue("response code is not 200, returned: " + response.getErrorCode(),
119                                 response.getErrorCode() == 200);
120                 service = ResponseParser.convertServiceResponseToJavaObject(response.getResponse());
121
122                 DbUtils.cleanAllAudits();
123
124         }
125 }