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