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