13b0dff95951f6c3059c56ea2f1646c6d3bc8ae8
[sdc.git] /
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
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
57         protected ArtifactUtils artifactUtils;
58         protected Service service;
59
60         @BeforeMethod
61         public void before() throws Exception {
62
63                 initializeMembers();
64                 createComponents();
65
66         }
67
68         public void initializeMembers() throws IOException, Exception {
69                 downloadResourceDetails = ElementFactory.getDefaultResource();
70                 serviceDetails = ElementFactory.getDefaultService();
71                 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
72                 sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
73                 heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
74                 resourceInstanceReqDetails = ElementFactory.getDefaultComponentInstance();
75
76         }
77
78         protected void createComponents() throws Exception {
79
80                 RestResponse response = ResourceRestUtils.createResource(downloadResourceDetails, sdncUserDetails);
81                 AssertJUnit.assertTrue("create request returned status:" + response.getErrorCode(),
82                                 response.getErrorCode() == 201);
83                 AssertJUnit.assertNotNull("resource uniqueId is null:", downloadResourceDetails.getUniqueId());
84
85                 ArtifactReqDetails heatArtifactDetails = ElementFactory
86                                 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
87                 response = ArtifactRestUtils.addInformationalArtifactToResource(heatArtifactDetails, sdncUserDetails,
88                                 downloadResourceDetails.getUniqueId());
89                 AssertJUnit.assertTrue("add HEAT artifact to resource request returned status:" + response.getErrorCode(),
90                                 response.getErrorCode() == 200);
91
92                 // certified resource
93                 response = LCSbaseTest.certifyResource(downloadResourceDetails, sdncDesignerDetails1);
94                 AssertJUnit.assertTrue("certify resource request returned status:" + response.getErrorCode(),
95                                 response.getErrorCode() == 200);
96
97                 response = ServiceRestUtils.createService(serviceDetails, sdncUserDetails);
98                 AssertJUnit.assertTrue("create request returned status:" + response.getErrorCode(),
99                                 response.getErrorCode() == 201);
100                 AssertJUnit.assertNotNull("service uniqueId is null:", serviceDetails.getUniqueId());
101
102                 // add resource instance with HEAT deployment artifact to the service
103                 resourceInstanceReqDetails.setComponentUid(downloadResourceDetails.getUniqueId());
104                 response = ComponentInstanceRestUtils.createComponentInstance(resourceInstanceReqDetails, sdncUserDetails,
105                                 serviceDetails.getUniqueId(), ComponentTypeEnum.SERVICE);
106                 AssertJUnit.assertTrue("response code is not 201, returned: " + response.getErrorCode(),
107                                 response.getErrorCode() == 201);
108
109                 response = ServiceRestUtils.getService(serviceDetails, sdncUserDetails);
110                 AssertJUnit.assertTrue("response code is not 200, returned: " + response.getErrorCode(),
111                                 response.getErrorCode() == 200);
112                 service = ResponseParser.convertServiceResponseToJavaObject(response.getResponse());
113
114                 DbUtils.cleanAllAudits();
115
116         }
117 }