[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / artifacts / DownloadComponentArt.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.artifacts;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.UnsupportedEncodingException;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.apache.commons.io.IOUtils;
30 import org.apache.http.HttpEntity;
31 import org.apache.http.HttpResponse;
32 import org.apache.http.client.HttpResponseException;
33 import org.apache.http.client.methods.CloseableHttpResponse;
34 import org.apache.http.client.methods.HttpDelete;
35 import org.apache.http.client.methods.HttpGet;
36 import org.apache.http.client.methods.HttpPost;
37 import org.apache.http.entity.StringEntity;
38 import org.apache.http.impl.client.BasicResponseHandler;
39 import org.apache.http.impl.client.CloseableHttpClient;
40 import org.apache.http.impl.client.HttpClients;
41 import org.apache.http.util.EntityUtils;
42 import org.codehaus.jackson.map.ObjectMapper;
43 import org.json.simple.JSONObject;
44 import org.json.simple.parser.JSONParser;
45 import org.json.simple.parser.ParseException;
46 import org.junit.Rule;
47 import org.junit.rules.TestName;
48 import org.openecomp.sdc.be.dao.api.ActionStatus;
49 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
50 import org.openecomp.sdc.be.model.ArtifactDefinition;
51 import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
52 import org.openecomp.sdc.be.model.Component;
53 import org.openecomp.sdc.be.model.ComponentInstance;
54 import org.openecomp.sdc.be.model.LifecycleStateEnum;
55 import org.openecomp.sdc.be.model.Resource;
56 import org.openecomp.sdc.be.model.Service;
57 import org.openecomp.sdc.be.model.User;
58 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
59 import org.openecomp.sdc.ci.tests.api.Urls;
60 import org.openecomp.sdc.ci.tests.config.Config;
61 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
62 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
63 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
64 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
65 import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
66 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
67 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
68 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
69 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
70 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedResourceAuditJavaObject;
71 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
72 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
73 import org.openecomp.sdc.ci.tests.utils.Decoder;
74 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
75 import org.openecomp.sdc.ci.tests.utils.general.Convertor;
76 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
77 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
78 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
79 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
80 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
81 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
82 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
83 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
84 import org.openecomp.sdc.ci.tests.utils.validation.ServiceValidationUtils;
85 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
86 import org.openecomp.sdc.common.api.Constants;
87 import org.openecomp.sdc.common.util.GeneralUtility;
88 import org.slf4j.Logger;
89 import org.slf4j.LoggerFactory;
90 import org.testng.Assert;
91 import org.testng.AssertJUnit;
92 import org.testng.annotations.BeforeMethod;
93 import org.testng.annotations.Test;
94 import org.testng.internal.Yaml;
95
96 import com.google.gson.Gson;
97 import com.google.gson.JsonElement;
98 import com.google.gson.JsonObject;
99 import com.typesafe.config.ConfigException.Null;
100
101 import fj.data.Either;
102 import fj.data.List;
103
104 public class DownloadComponentArt extends ComponentBaseTest {
105
106         private static Logger log = LoggerFactory.getLogger(DownloadComponentArt.class.getName());
107         protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
108         protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";
109
110         protected Config config = Config.instance();
111         protected String contentTypeHeaderData = "application/json";
112         protected String acceptHeaderDate = "application/json";
113
114
115
116         protected Gson gson = new Gson();
117         protected JSONParser jsonParser = new JSONParser();
118
119
120         protected String serviceVersion;
121         protected ResourceReqDetails resourceDetails;
122         protected User sdncUserDetails;
123         protected ServiceReqDetails serviceDetails;
124         
125
126         @BeforeMethod
127         public void init() throws Exception{
128                 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
129                 Resource resourceObj = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VFC, UserRoleEnum.DESIGNER, true).left().value();
130                 Service serviceObj = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
131                 
132                 
133                 resourceDetails = new ResourceReqDetails(resourceObj); 
134                 serviceDetails = new ServiceReqDetails(serviceObj);
135         }
136         
137         @Rule 
138         public static TestName name = new TestName();
139
140         public DownloadComponentArt() {
141                 super(name, DownloadComponentArt.class.getName());
142
143         }
144                 
145
146         
147         // External API - Download artifact for resource
148         @Test
149         public void downloadArtifactFromResourceViaExternalAPI() throws Exception {
150                 Resource resourceDetailsVF;
151                 Either<Resource, RestResponse> createdResource = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, UserRoleEnum.DESIGNER, true);
152                 resourceDetailsVF = createdResource.left().value();
153                 ArtifactDefinition heatArtifact = AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT, resourceDetailsVF, UserRoleEnum.DESIGNER, true, true).left().value();
154                 resourceDetails = new ResourceReqDetails(resourceDetailsVF); 
155                 
156                 String resourceUUID = resourceDetailsVF.getUUID();
157                 String artifactUUID = heatArtifact.getArtifactUUID();
158                 
159                 System.out.println("Resource UUID: " + resourceUUID);
160                 System.out.println("Artifact UUID: " + artifactUUID);
161                 
162                 RestResponse restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), "Resource");
163                 
164                 Integer responseCode = restResponse.getErrorCode();
165                 Integer expectedCode = 200;
166                 Assert.assertEquals(responseCode,expectedCode, "Response code is not correct.");
167                 
168                 String response = restResponse.getResponse();
169                 
170                 String payloadData = "aGVhdF90ZW1wbGF0ZV92ZXJzaW9uOiAyMDEzLTA1LTIzDQoNCmRlc2NyaXB0aW9uOiBTaW1wbGUgdGVtcGxhdGUgdG8gZGVwbG95IGEgc3RhY2sgd2l0aCB0d28gdmlydHVhbCBtYWNoaW5lIGluc3RhbmNlcw0KDQpwYXJhbWV0ZXJzOg0KICBpbWFnZV9uYW1lXzE6DQogICAgdHlwZTogc3RyaW5nDQog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W9uOiBQYXNzd29yZCBtdXN0IGNvbnNpc3Qgb2YgY2hhcmFjdGVycyBhbmQgbnVtYmVycyBvbmx5Lg0KICAgICAgLSBhbGxvd2VkX3BhdHRlcm46ICJbQS1aXStbYS16QS1aMC05XSoiDQogICAgICAgIGRlc2NyaXB0aW9uOiBQYXNzd29yZCBtdXN0IHN0YXJ0IHdpdGggYW4gdXBwZXJjYXNlIGNoYXJhY3Rlci4NCiAgICAgIC0gY3VzdG9tX2NvbnN0cmFpbnQ6IG5vdmEua2V5cGFpcg0KICAgICAgICBkZXNjcmlwdGlvbjogQ3VzdG9tIGRlc2NyaXB0aW9uDQoNCnJlc291cmNlczoNCiAgbXlfaW5zdGFuY2UxOg0KICAgIHR5cGU6IE9TOjpOb3ZhOjpTZXJ2ZXINCiAgICBwcm9wZXJ0aWVzOg0KICAgICAgaW1hZ2U6IHsgZ2V0X3BhcmFtOiBpbWFnZV9uYW1lXzEgfQ0KICAgICAgZmxhdm9yOiBtMS5zbWFsbA0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9DQogIG15X2luc3RhbmNlMjoNCiAgICB0eXBlOiBPUzo6Tm92YTo6U2VydmVyDQogICAgcHJvcGVydGllczoNCiAgICAgIGltYWdlOiB7IGdldF9wYXJhbTogaW1hZ2VfbmFtZV8yIH0NCiAgICAgIGZsYXZvcjogbTEudGlueQ0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9";
171                 String decodedPaypload = Decoder.decode(payloadData);
172                 
173                 Assert.assertEquals(response, decodedPaypload, "Response deployment artifact not correct.");
174                 
175                 String auditAction = "DownloadArtifact";
176                 
177                 ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
178                 expectedResourceAuditJavaObject.setAction(auditAction);
179                 expectedResourceAuditJavaObject.setResourceName(resourceDetails.getName());
180                 expectedResourceAuditJavaObject.setResourceType("Resource");
181                 expectedResourceAuditJavaObject.setStatus("200");
182                 expectedResourceAuditJavaObject.setDesc("OK");
183                 
184                 expectedResourceAuditJavaObject.setCONSUMER_ID("ci");
185                 String resource_url = String.format("/sdc/v1/catalog/resources/%s/artifacts/%s", resourceUUID, artifactUUID);
186                 expectedResourceAuditJavaObject.setRESOURCE_URL(resource_url);
187                 
188                 AuditValidationUtils.validateAuditDownloadExternalAPI(expectedResourceAuditJavaObject, auditAction, null, false);
189         }
190         
191         
192         // External API - Download artifact for resource - negative test
193         @Test
194         public void downloadArtifactFromResourceViaExternalAPINegativeTest() throws Exception {
195                 Resource resourceDetailsVF;
196                 Either<Resource, RestResponse> createdResource = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, UserRoleEnum.DESIGNER, true);
197                 resourceDetailsVF = createdResource.left().value();
198                 ArtifactDefinition heatArtifact = AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT, resourceDetailsVF, UserRoleEnum.DESIGNER, true, true).left().value();
199                 resourceDetails = new ResourceReqDetails(resourceDetailsVF); 
200                 
201                 String resourceUUID = resourceDetailsVF.getUUID();
202                 String artifactUUID = heatArtifact.getArtifactUUID();
203                 
204                 System.out.println("Resource UUID: " + resourceUUID);
205                 System.out.println("Artifact UUID: " + artifactUUID);
206                 
207                 RestResponse restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, "dfsgfdsg324", ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), "Resource");
208                 
209                 Integer responseCode = restResponse.getErrorCode();
210                 Integer expectedCode = 200;
211                 Assert.assertEquals(responseCode,expectedCode, "Response code is not correct.");
212         }
213         
214         
215         
216         
217         
218         // External API - Download artifact for service - negative test
219         @Test
220         public void downloadArtifactFromServiceViaExternalAPI() throws Exception {
221                 
222                 Service resourceDetailsService;
223                 Either<Service, RestResponse> createdResource = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
224                 resourceDetailsService = createdResource.left().value();
225                 
226                 ArtifactDefinition heatArtifact = AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.OTHER, resourceDetailsService, UserRoleEnum.DESIGNER, true, true).left().value();
227
228                 String resourceUUID = resourceDetailsService.getUUID();
229                 String artifactUUID = heatArtifact.getArtifactUUID();
230                 
231                 System.out.println("Resource UUID: " + resourceUUID);
232                 System.out.println("Artifact UUID: " + artifactUUID);
233                 
234                 RestResponse restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), "Service");
235                 
236                 Integer responseCode = restResponse.getErrorCode();
237                 Integer expectedCode = 200;
238                 Assert.assertEquals(responseCode,expectedCode, "Response code is not correct.");
239                 
240                 String response = restResponse.getResponse();
241                 
242                 String payloadData = "aGVhdF90ZW1wbGF0ZV92ZXJzaW9uOiAyMDEzLTA1LTIzDQoNCmRlc2NyaXB0aW9uOiBTaW1wbGUgdGVtcGxhdGUgdG8gZGVwbG95IGEgc3RhY2sgd2l0aCB0d28gdmlydHVhbCBtYWNoaW5lIGluc3RhbmNlcw0KDQpwYXJhbWV0ZXJzOg0KICBpbWFnZV9uYW1lXzE6DQogICAgdHlwZTogc3RyaW5nDQogICAgbGFiZWw6IEltYWdlIE5hbWUNCiAgICBkZXNjcmlwdGlvbjogU0NPSU1BR0UgU3BlY2lmeSBhbiBpbWFnZSBuYW1lIGZvciBpbnN0YW5jZTENCiAgICBkZWZhdWx0OiBjaXJyb3MtMC4zLjEteDg2XzY0DQogIGltYWdlX25hbWVfMjoNCiAgICB0eXBlOiBzdHJpbmcNCiAgICBsYWJlbDogSW1hZ2UgTmFtZQ0KICAgIGRlc2NyaXB0aW9uOiBTQ09JTUFHRSBTcGVjaWZ5IGFuIGltYWdlIG5hbWUgZm9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NjcmlwdGlvbjogQ3VzdG9tIGRlc2NyaXB0aW9uDQoNCnJlc291cmNlczoNCiAgbXlfaW5zdGFuY2UxOg0KICAgIHR5cGU6IE9TOjpOb3ZhOjpTZXJ2ZXINCiAgICBwcm9wZXJ0aWVzOg0KICAgICAgaW1hZ2U6IHsgZ2V0X3BhcmFtOiBpbWFnZV9uYW1lXzEgfQ0KICAgICAgZmxhdm9yOiBtMS5zbWFsbA0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9DQogIG15X2luc3RhbmNlMjoNCiAgICB0eXBlOiBPUzo6Tm92YTo6U2VydmVyDQogICAgcHJvcGVydGllczoNCiAgICAgIGltYWdlOiB7IGdldF9wYXJhbTogaW1hZ2VfbmFtZV8yIH0NCiAgICAgIGZsYXZvcjogbTEudGlueQ0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9";
243                 String decodedPaypload = Decoder.decode(payloadData);
244                 
245                 Assert.assertEquals(response, decodedPaypload, "Response deployment artifact not correct.");
246                 
247                 String auditAction = "DownloadArtifact";
248                 
249                 ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
250                 expectedResourceAuditJavaObject.setAction(auditAction);
251                 expectedResourceAuditJavaObject.setResourceName(resourceDetailsService.getName());
252                 expectedResourceAuditJavaObject.setResourceType("Service");
253                 expectedResourceAuditJavaObject.setStatus("200");
254                 expectedResourceAuditJavaObject.setDesc("OK");
255                 
256                 expectedResourceAuditJavaObject.setCONSUMER_ID("ci");
257                 String resource_url = String.format("/sdc/v1/catalog/services/%s/artifacts/%s", resourceUUID, artifactUUID);
258                 expectedResourceAuditJavaObject.setRESOURCE_URL(resource_url);
259                 
260                 AuditValidationUtils.validateAuditDownloadExternalAPI(expectedResourceAuditJavaObject, auditAction, null, false);
261         }
262         
263         
264         
265         
266         
267         
268         // External API - Download ComponentInstance artifact of service - negative test
269         @Test
270         public void downloadArtifactOfComponentInstanceFromServiceViaExternalAPI() throws Exception {
271                 
272                 Either<Resource, RestResponse> resourceDetailsVF_01e = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, UserRoleEnum.DESIGNER, true);
273                 Component resourceDetailsVF_01 = resourceDetailsVF_01e.left().value();
274                 ArtifactDefinition heatArtifact = AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT, resourceDetailsVF_01, UserRoleEnum.DESIGNER, true, true).left().value();
275
276                 resourceDetailsVF_01 = AtomicOperationUtils.changeComponentState(resourceDetailsVF_01, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
277                 
278                 Service resourceDetailsService;
279                 Either<Service, RestResponse> createdResource = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
280                 resourceDetailsService = createdResource.left().value();
281                 
282                 
283                 ComponentInstance resourceDetailsVF1ins_01 = AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceDetailsVF_01, resourceDetailsService, UserRoleEnum.DESIGNER, true).left().value();
284                 
285                 
286                 System.out.println("-----");
287                 
288                 
289                 String resourceUUID = resourceDetailsService.getUUID();
290                 String componentNormalizedName = resourceDetailsVF1ins_01.getNormalizedName();
291                 String artifactUUID = heatArtifact.getArtifactUUID();
292                         
293                 System.out.println("Resource UUID: " + resourceUUID);
294                 System.out.println("Component NormalizedName: " + componentNormalizedName);
295                 System.out.println("Artifact UUID: " + artifactUUID);
296                 
297                 RestResponse restResponse = ArtifactRestUtils.getComponentInstanceDeploymentArtifactExternalAPI(resourceUUID, componentNormalizedName, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), "Service");
298 //                      
299                 Integer responseCode = restResponse.getErrorCode();
300                 Integer expectedCode = 200;
301                 Assert.assertEquals(responseCode,expectedCode, "Response code is not correct.");
302                         
303                 String response = restResponse.getResponse();
304                         
305                 String payloadData = "aGVhdF90ZW1wbGF0ZV92ZXJzaW9uOiAyMDEzLTA1LTIzDQoNCmRlc2NyaXB0aW9uOiBTaW1wbGUgdGVtcGxhdGUgdG8gZGVwbG95IGEgc3RhY2sgd2l0aCB0d28gdmlydHVhbCBtYWNoaW5lIGluc3RhbmNlcw0KDQpwYXJhbWV0ZXJzOg0KICBpbWFnZV9uYW1lXzE6DQogICAgdHlwZTogc3RyaW5nDQogICAgbGFiZWw6IEltYWdlIE5hbWUNCiAgICBkZXNjcmlwdGlvbjogU0NPSU1BR0UgU3BlY2lmeSBhbiBpbWFnZSBuYW1lIGZvciBpbnN0YW5jZTENCiAgICBkZWZhdWx0OiBjaXJyb3MtMC4zLjEteDg2XzY0DQogIGltYWdlX25hbWVfMjoNCiAgICB0eXBlOiBzdHJpbmcNCiAgICBsYWJlbDogSW1hZ2UgTmFtZQ0KICAgIGRlc2NyaXB0aW9uOiBTQ09JTUFHRSBTcGVjaWZ5IGFuIGltYWdlIG5hbWUgZm9yIGluc3RhbmNlMg0KICAgIGRlZmF1bHQ6IGNpcnJvcy0wLjMuMS14ODZfNjQNCiAgbmV0d29ya19pZDoNCiAgICB0eXBlOiBzdHJpbmcNCiAgICBsYWJlbDogTmV0d29yayBJRA0KICAgIGRlc2NyaXB0aW9uOiBTQ09ORVRXT1JLIE5ldHdvcmsgdG8gYmUgdXNlZCBmb3IgdGhlIGNvbXB1dGUgaW5zdGFuY2UNCiAgICBoaWRkZW46IHRydWUNCiAgICBjb25zdHJhaW50czoNCiAgICAgIC0gbGVuZ3RoOiB7IG1pbjogNiwgbWF4OiA4IH0NCiAgICAgICAgZGVzY3JpcHRpb246IFBhc3N3b3JkIGxlbmd0aCBtdXN0IGJlIGJldHdlZW4gNiBhbmQgOCBjaGFyYWN0ZXJzLg0KICAgICAgLSByYW5nZTogeyBtaW46IDYsIG1heDogOCB9DQogICAgICAg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Q0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9";
306                 String decodedPaypload = Decoder.decode(payloadData);
307                         
308                 Assert.assertEquals(response, decodedPaypload, "Response deployment artifact not correct.");
309                         
310                 String auditAction = "DownloadArtifact";
311                         
312                 ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
313                 expectedResourceAuditJavaObject.setAction(auditAction);
314                 expectedResourceAuditJavaObject.setResourceName(resourceDetailsVF1ins_01.getName());
315                 expectedResourceAuditJavaObject.setResourceType("Service");
316                 expectedResourceAuditJavaObject.setStatus("200");
317                 expectedResourceAuditJavaObject.setDesc("OK");
318                         
319                 expectedResourceAuditJavaObject.setCONSUMER_ID("ci");
320                 String resource_url = String.format("/sdc/v1/catalog/services/%s/resourceInstances/%s/artifacts/%s", resourceUUID, componentNormalizedName, artifactUUID);
321                 expectedResourceAuditJavaObject.setRESOURCE_URL(resource_url);
322                         
323                 AuditValidationUtils.validateAuditDownloadExternalAPI(expectedResourceAuditJavaObject, auditAction, null, false);
324         }
325         
326         
327         
328         
329         
330         
331         
332         
333         
334         @Test
335         public void downloadArtifactFromResourceTest() throws Exception {
336
337                 CloseableHttpClient httpclient = HttpClients.createDefault();
338                 try {
339                         String jsonBody = createUploadArtifactBodyJson();
340
341                         String resourceId = resourceDetails.getUniqueId();
342                         String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resourceId);
343                         HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
344                         HttpResponse response = httpclient.execute(httppost);
345                         int status = response.getStatusLine().getStatusCode();
346                         AssertJUnit.assertEquals("failed to add artifact", 200, status);
347
348                         ArtifactDefinition origArtifact = getArtifactDataFromJson(jsonBody);
349                         addArtifactDataFromResponse(response, origArtifact);
350                         String artifactId = origArtifact.getUniqueId();
351                         
352                         url = String.format(Urls.UI_DOWNLOAD_RESOURCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), resourceId, artifactId);
353                         HttpGet httpGet = createGetRequest(url);
354                         response = httpclient.execute(httpGet);
355                         status = response.getStatusLine().getStatusCode();
356                         AssertJUnit.assertEquals("failed to download artifact", 200, status);
357                                                                         
358                         InputStream inputStream = response.getEntity().getContent();
359                         ArtifactUiDownloadData artifactUiDownloadData = getArtifactUiDownloadData(IOUtils.toString(inputStream));
360                         AssertJUnit.assertEquals("Downloaded payload is different from uploaded one", UPLOAD_ARTIFACT_PAYLOAD, artifactUiDownloadData.getBase64Contents());
361                         AssertJUnit.assertEquals("Downloaded artifact name is different from uploaded one", UPLOAD_ARTIFACT_NAME, artifactUiDownloadData.getArtifactName());
362
363                         // validate audit
364                                         
365                         ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor.constructFieldsForAuditValidation(resourceDetails, resourceDetails.getVersion(), sdncUserDetails);
366                         String auditAction = "ArtifactDownload";
367                         expectedResourceAuditJavaObject.setAction(auditAction);
368                         expectedResourceAuditJavaObject.setPrevState("");
369                         expectedResourceAuditJavaObject.setPrevVersion("");
370                         expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
371                         expectedResourceAuditJavaObject.setStatus("200");
372                         expectedResourceAuditJavaObject.setDesc("OK");
373                         expectedResourceAuditJavaObject.setArtifactData(AuditValidationUtils.buildArtifactDataAudit(origArtifact));
374                         expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
375                         expectedResourceAuditJavaObject.setPrevArtifactUuid("");
376                         AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
377                         
378                 } finally {
379                         httpclient.close();
380                 }
381
382         }
383
384         @Test
385         public void downloadArtifactFromServiceTest() throws Exception {
386
387                 CloseableHttpClient httpclient = HttpClients.createDefault();
388
389                 try {
390
391                         String jsonStr = createUploadArtifactBodyJson();
392
393                         String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(), config.getCatalogBePort(), serviceDetails.getUniqueId());
394                         HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
395                         CloseableHttpResponse result = httpclient.execute(httpPost);
396                         int status = result.getStatusLine().getStatusCode();
397                         AssertJUnit.assertEquals("failed to add artifact", 200, status);
398
399                         ArtifactDefinition origArtifact = getArtifactDataFromJson(jsonStr);
400                         addArtifactDataFromResponse(result, origArtifact);
401                         String artifactId = origArtifact.getUniqueId();
402
403                         url = String.format(Urls.UI_DOWNLOAD_SERVICE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceDetails.getUniqueId(), artifactId);
404                         HttpGet httpGet = createGetRequest(url);
405                         CloseableHttpResponse response2 = httpclient.execute(httpGet);
406                         status = response2.getStatusLine().getStatusCode();
407                         AssertJUnit.assertEquals("failed to download artifact", 200, status);
408                         InputStream inputStream = response2.getEntity().getContent();
409                         ArtifactUiDownloadData artifactUiDownloadData = getArtifactUiDownloadData(IOUtils.toString(inputStream));
410                         AssertJUnit.assertEquals("Downloaded payload is different from uploaded one", UPLOAD_ARTIFACT_PAYLOAD, artifactUiDownloadData.getBase64Contents());
411                         AssertJUnit.assertEquals("Downloaded artifact name is different from uploaded one", UPLOAD_ARTIFACT_NAME, artifactUiDownloadData.getArtifactName());
412
413                         // validate audit
414                         ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = AuditValidationUtils.constructFieldsForAuditValidation(serviceDetails, serviceDetails.getVersion(), sdncUserDetails);
415                         String auditAction = "ArtifactDownload";
416                         expectedResourceAuditJavaObject.setAction(auditAction);
417                         expectedResourceAuditJavaObject.setPrevState("");
418                         expectedResourceAuditJavaObject.setPrevVersion("");
419                         expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
420                         expectedResourceAuditJavaObject.setStatus("200");
421                         expectedResourceAuditJavaObject.setDesc("OK");
422                         expectedResourceAuditJavaObject.setArtifactData(AuditValidationUtils.buildArtifactDataAudit(origArtifact));
423                         expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
424                         expectedResourceAuditJavaObject.setPrevArtifactUuid("");
425                         
426                         AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
427
428                 } finally {
429 //                      RestResponse response = ServiceRestUtils.deleteService(serviceDetails, serviceVersion, sdncUserDetails );
430 //                      checkDeleteResponse(response);
431                         httpclient.close();
432                 }
433         }
434
435         @Test
436         public void downloadArtifactFromResourceNotFound() throws Exception {
437
438                 CloseableHttpClient httpclient = HttpClients.createDefault();
439                 try {
440
441                         String resourceId = resourceDetails.getUniqueId();
442                         String artifactIdNotFound = "11111";
443
444                         ArtifactDefinition origArtifact = new ArtifactDefinition();
445                         origArtifact.setUniqueId(artifactIdNotFound);
446                         
447                         String url = String.format(Urls.UI_DOWNLOAD_RESOURCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), resourceId, artifactIdNotFound);
448                         HttpGet httpGet = createGetRequest(url);
449                         CloseableHttpResponse response = httpclient.execute(httpGet);
450                         int status = response.getStatusLine().getStatusCode();
451                         AssertJUnit.assertEquals("expected 404 not found", 404, status);
452
453                         // validate audit
454                         ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.ARTIFACT_NOT_FOUND.name());
455                         ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = Convertor.constructFieldsForAuditValidation(resourceDetails, resourceDetails.getVersion(), sdncUserDetails);
456                         String auditAction = "ArtifactDownload";
457                         expectedResourceAuditJavaObject.setAction(auditAction);
458                         expectedResourceAuditJavaObject.setPrevState("");
459                         expectedResourceAuditJavaObject.setPrevVersion("");
460                         expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
461                         expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
462                         expectedResourceAuditJavaObject.setDesc(errorInfo.getAuditDesc(""));
463                         expectedResourceAuditJavaObject.setArtifactData("");
464                         expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
465                         expectedResourceAuditJavaObject.setPrevArtifactUuid("");
466                         AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
467                         expectedResourceAuditJavaObject.setPrevArtifactUuid(null);
468                 } finally {
469                         httpclient.close();
470                 }
471
472         }
473
474         @Test
475         public void downloadArtifactFromServiceNotFound() throws Exception {
476
477                 CloseableHttpClient httpclient = HttpClients.createDefault();
478                 try {
479
480                         String artifactIdNotFound = "11111";
481                         ArtifactDefinition origArtifact = new ArtifactDefinition();
482                         origArtifact.setUniqueId(artifactIdNotFound);
483
484                         String url = String.format(Urls.UI_DOWNLOAD_SERVICE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), serviceDetails.getUniqueId(), artifactIdNotFound);
485                         HttpGet httpGet = createGetRequest(url);
486                         CloseableHttpResponse response2 = httpclient.execute(httpGet);
487                         int status = response2.getStatusLine().getStatusCode();
488                         AssertJUnit.assertEquals("expected 404 not found", 404, status);
489
490                         // validate audit
491                         ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.ARTIFACT_NOT_FOUND.name());
492                         ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = ServiceValidationUtils.constructFieldsForAuditValidation(serviceDetails, serviceDetails.getVersion(), sdncUserDetails);
493                         String auditAction = "ArtifactDownload";
494                         expectedResourceAuditJavaObject.setAction(auditAction);
495                         expectedResourceAuditJavaObject.setPrevState("");
496                         expectedResourceAuditJavaObject.setPrevVersion("");
497                         expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
498                         expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
499                         expectedResourceAuditJavaObject.setDesc(errorInfo.getAuditDesc(""));
500                         expectedResourceAuditJavaObject.setArtifactData("");
501                         expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
502                         expectedResourceAuditJavaObject.setPrevArtifactUuid("");
503                         AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject, auditAction, null, false);
504
505                 } finally {
506                         httpclient.close();
507                 }
508
509         }
510
511         @Test
512         public void addArtifactToResourceTest() throws Exception {
513
514                 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
515
516                 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails, resourceDetails.getUniqueId());
517                 int status = response.getErrorCode();
518                 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200, status);
519
520                 RestResponse resourceResp = ResourceRestUtils.getResource(resourceDetails.getUniqueId());
521                 Resource resource = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
522                 AssertJUnit.assertNotNull(resource);
523
524                 Map<String, ArtifactDefinition> artifacts = resource.getArtifacts();
525                 boolean isExist = false;
526                 for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet()) {
527                         if (entry.getKey().equals(defaultArtifact.getArtifactLabel())) {
528                                 isExist = true;
529
530                         }
531                 }
532                 AssertJUnit.assertTrue(isExist);
533         }
534         
535         
536         protected String createUploadArtifactBodyJson() {
537                 Map<String, Object> jsonBody = new HashMap<String, Object>();
538                 jsonBody.put("artifactName", UPLOAD_ARTIFACT_NAME);
539                 jsonBody.put("artifactDisplayName", "configure");
540                 jsonBody.put("artifactType", "SHELL");
541                 jsonBody.put("mandatory", "false");
542                 jsonBody.put("description", "ff");
543                 jsonBody.put("payloadData", UPLOAD_ARTIFACT_PAYLOAD);
544                 jsonBody.put("artifactLabel", "configure");
545                 return gson.toJson(jsonBody);
546         }
547         
548         protected ArtifactDefinition getArtifactDataFromJson(String json) {
549                 Gson gson = new Gson();
550                 JsonObject jsonElement = new JsonObject();
551                 jsonElement = gson.fromJson(json, jsonElement.getClass());
552                 ArtifactDefinition artifact = new ArtifactDefinition(); 
553                 String payload = null;
554                 JsonElement artifactPayload = jsonElement.get(Constants.ARTIFACT_PAYLOAD_DATA);
555                 if (artifactPayload != null && !artifactPayload.isJsonNull()) {
556                         payload = artifactPayload.getAsString();
557                 }
558                 jsonElement.remove(Constants.ARTIFACT_PAYLOAD_DATA);
559                 artifact = gson.fromJson(jsonElement, ArtifactDefinition.class);
560                 artifact.setPayloadData(payload);
561                 
562                 /*atifact.setArtifactName(UPLOAD_ARTIFACT_NAME);
563 artifact.setArtifactDisplayName("configure");
564 artifact.setArtifactType("SHELL");
565 artifact.setMandatory(false);
566 artifact.setDescription("ff");
567 artifact.setPayloadData(UPLOAD_ARTIFACT_PAYLOAD);
568 artifact.setArtifactLabel("configure");*/
569                 return artifact;
570         }
571         
572         protected HttpGet createGetRequest(String url) {
573                 HttpGet httpGet = new HttpGet(url);
574                 httpGet.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
575                 httpGet.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
576                 httpGet.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
577                 return httpGet;
578         }
579         
580         protected String getArtifactUid(HttpResponse response) throws HttpResponseException, IOException, ParseException {
581                 String responseString = new BasicResponseHandler().handleResponse(response);
582                 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
583                 String artifactId = (String) responseMap.get("uniqueId");
584                 return artifactId;
585         }
586         
587         protected String getArtifactEsId(HttpResponse response) throws HttpResponseException, IOException, ParseException {
588                 String responseString = new BasicResponseHandler().handleResponse(response);
589                 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
590                 String esId = (String) responseMap.get("EsId");
591                 return esId;
592         }
593         
594         protected ArtifactDefinition addArtifactDataFromResponse(HttpResponse response, ArtifactDefinition artifact) throws HttpResponseException, IOException, ParseException {
595                 //String responseString = new BasicResponseHandler().handleResponse(response);
596                 HttpEntity entity = response.getEntity();
597                 String responseString = EntityUtils.toString(entity);                           
598                 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
599                 artifact.setEsId((String)responseMap.get("esId"));
600                 artifact.setUniqueId((String) responseMap.get("uniqueId"));
601                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.findType((String) responseMap.get("artifactGroupType")));
602                 artifact.setTimeout(((Long) responseMap.get("timeout")).intValue());
603                 return artifact;
604         }
605         
606         protected String getLifecycleArtifactUid(CloseableHttpResponse response) throws HttpResponseException, IOException, ParseException {
607                 String responseString = new BasicResponseHandler().handleResponse(response);
608                 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
609                 responseMap = (JSONObject) responseMap.get("implementation");
610                 String artifactId = (String) responseMap.get("uniqueId");
611                 return artifactId;
612         }
613         
614         protected HttpDelete createDeleteArtifactRequest(String url) {
615                 HttpDelete httpDelete = new HttpDelete(url);
616                 httpDelete.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
617                 httpDelete.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
618                 return httpDelete;
619         }
620         
621         protected HttpPost createPostAddArtifactRequeast(String jsonBody, String url, boolean addMd5Header) throws UnsupportedEncodingException {
622                 HttpPost httppost = new HttpPost(url);
623                 httppost.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
624                 httppost.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
625                 httppost.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
626                 if (addMd5Header) {
627                         httppost.addHeader(HttpHeaderEnum.Content_MD5.getValue(), GeneralUtility.calculateMD5ByString(jsonBody));
628                 }
629                 StringEntity input = new StringEntity(jsonBody);
630                 input.setContentType("application/json");
631                 httppost.setEntity(input);
632                 log.debug("Executing request {}" , httppost.getRequestLine());
633                 return httppost;
634         }
635         
636         protected String createLoadArtifactBody() {
637                 Map<String, Object> json = new HashMap<String, Object>();
638                 json.put("artifactName", "install_apache2.sh");
639                 json.put("artifactType", "SHELL");
640                 json.put("description", "ddd");
641                 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
642                 json.put("artifactLabel", "name123");
643                 
644                 String jsonStr = gson.toJson(json);
645                 return jsonStr;
646         }
647         
648         protected void checkDeleteResponse(RestResponse response) {
649                 BaseRestUtils.checkStatusCode(response, "delete request failed", false, 204, 404);
650         }
651         
652         protected ArtifactUiDownloadData getArtifactUiDownloadData(String artifactUiDownloadDataStr) throws Exception {
653                 
654                 ObjectMapper mapper = new ObjectMapper();
655                 try {
656                         ArtifactUiDownloadData artifactUiDownloadData = mapper.readValue(artifactUiDownloadDataStr, ArtifactUiDownloadData.class);
657                         return artifactUiDownloadData;
658                 } catch (Exception e) {
659                         e.printStackTrace();
660                 }
661                 return null;
662         }
663
664         
665 }