add tosca parser verification step
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / AssetRestUtils.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.utils.rest;
22
23 import static org.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.util.*;
30 import java.util.Map.Entry;
31
32 import org.apache.http.HttpEntity;
33 import org.apache.http.HttpResponse;
34 import org.apache.http.client.methods.CloseableHttpResponse;
35 import org.apache.http.client.methods.HttpGet;
36 import org.apache.http.impl.client.CloseableHttpClient;
37 import org.apache.http.impl.client.HttpClients;
38 import org.codehaus.jackson.map.ObjectMapper;
39 import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
40 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
41 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
42 import org.openecomp.sdc.be.model.ArtifactDefinition;
43 import org.openecomp.sdc.be.model.Component;
44 import org.openecomp.sdc.be.model.ComponentInstance;
45 import org.openecomp.sdc.be.model.Resource;
46 import org.openecomp.sdc.be.model.Service;
47 import org.openecomp.sdc.ci.tests.api.Urls;
48 import org.openecomp.sdc.ci.tests.config.Config;
49 import org.openecomp.sdc.ci.tests.datatypes.ArtifactAssetStructure;
50 import org.openecomp.sdc.ci.tests.datatypes.AssetStructure;
51 import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure;
52 import org.openecomp.sdc.ci.tests.datatypes.ResourceDetailedAssetStructure;
53 import org.openecomp.sdc.ci.tests.datatypes.ResourceInstanceAssetStructure;
54 import org.openecomp.sdc.ci.tests.datatypes.ServiceAssetStructure;
55 import org.openecomp.sdc.ci.tests.datatypes.ServiceDetailedAssetStructure;
56 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
57 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
58 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
59 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
60 import org.openecomp.sdc.ci.tests.utils.Utils;
61 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
62 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
65
66 import com.google.gson.Gson;
67 import com.google.gson.JsonArray;
68 import com.google.gson.JsonElement;
69 import com.google.gson.JsonObject;
70 import com.google.gson.JsonParser;
71
72 public class AssetRestUtils extends BaseRestUtils {
73         static Gson gson = new Gson();
74         static ObjectMapper objectMapper = new ObjectMapper();
75
76         static Logger logger = LoggerFactory.getLogger(AssetRestUtils.class.getName());
77         static final String contentTypeHeaderData = "application/json";
78         static final String acceptHeaderDate = "application/json";
79         static final String basicAuthentication = "Basic Y2k6MTIzNDU2";
80         // /sdc/v1/catalog/{services/resources}/{componentUUID}/artifacts/{artifactUUID}
81         static final String COMPONENT_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/artifacts/%s";
82         // /sdc/v1/catalog/{services/resources}/{componentUUID}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}
83         static final String RESOURCE_INSTANCE_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/resourceInstances/%s/artifacts/%s";
84
85         public static HttpResponse getComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
86                 Config config = Utils.getConfig();
87                 CloseableHttpClient httpclient = HttpClients.createDefault();
88                 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
89                                 assetType.getValue(), uuid);
90                 HttpGet httpGet = new HttpGet(url);
91
92                 httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
93                 httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
94
95                 logger.debug("Send GET request to get Tosca model: {}", url);
96
97                 return httpclient.execute(httpGet);
98         }
99         
100         public static File getToscaModelCsarFile(AssetTypeEnum assetType, String uuid) throws IOException {
101                 Config config = Utils.getConfig();
102                 CloseableHttpClient httpclient = HttpClients.createDefault();
103                 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
104                                 assetType.getValue(), uuid);
105                 HttpGet httpGet = new HttpGet(url);
106
107                 String csarDir = FileHandling.getCreateDirByName("outputCsar");
108                 File myFile = new File(csarDir+ File.separator + "tmpCSAR" + getShortUUID()+".csar");
109
110                 
111                 httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
112                 httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
113
114                 logger.debug("Send GET request to get Tosca model: {}", url);
115                 CloseableHttpResponse execute = httpclient.execute(httpGet);
116                 
117             HttpEntity entity = execute.getEntity();
118             if (entity != null) {
119                 try (FileOutputStream outstream = new FileOutputStream(myFile)) {
120                     entity.writeTo(outstream);
121                     outstream.close();
122                 }
123             }
124                 return myFile;
125         }
126
127
128
129         public static RestResponse getRestResponseComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
130                 Config config = Utils.getConfig();
131                 
132                 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
133                                 assetType.getValue(), uuid);
134                 
135                 Map<String, String> headersMap = new HashMap<String,String>();
136                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
137                 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
138                 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
139                 
140                 HttpRequest http = new HttpRequest();
141
142                 logger.debug("Send GET request to get Resource Assets: {}", url);
143                 System.out.println("Send GET request to get Resource Assets: " + url);
144                 
145                 logger.debug("Request headers: {}", headersMap);
146                 System.out.println("Request headers: " + headersMap);
147
148                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
149
150                 return sendGetResourceAssets;
151
152         }
153
154         public static RestResponse getComponentListByAssetType(boolean isBasicAuthentication, AssetTypeEnum assetType,
155                         String... filterArrayString) throws IOException {
156                 Config config = Utils.getConfig();
157                 Map<String, String> headersMap = new HashMap<String, String>();
158                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
159                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
160                 if (isBasicAuthentication) {
161                         headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
162                 }
163                 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
164
165                 HttpRequest http = new HttpRequest();
166                 String url = String.format(Urls.GET_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
167                                 assetType.getValue());
168                 if (filterArrayString != null && filterArrayString.length > 0) {
169                         url = buildUrlWithFilter(url, filterArrayString);
170                 }
171
172                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
173
174                 return sendGetResourceAssets;
175         }
176
177         public static RestResponse getFilteredComponentList(AssetTypeEnum assetType, String query) throws IOException {
178                 Config config = Utils.getConfig();
179                 Map<String, String> headersMap = new HashMap<String, String>();
180                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
181                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
182                 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
183                 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
184
185                 HttpRequest http = new HttpRequest();
186
187                 String url = String.format(Urls.GET_FILTERED_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
188                                 assetType.getValue(), query);
189
190                 logger.debug("Send GET request to get Resource Assets: {}", url);
191                 logger.debug("Request headers: {}", headersMap);
192
193                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
194
195                 return sendGetResourceAssets;
196         }
197
198         public static String buildUrlWithFilter(String url, String[] filterArrayString) {
199                 StringBuilder sb = new StringBuilder();
200                 int length = filterArrayString.length;
201                 int count = 0;
202                 for (String filterString : filterArrayString) {
203                         sb.append(filterString);
204                         count++;
205                         if (length != count) {
206                                 sb.append("&");
207                         }
208                 }
209                 return url + "?" + sb;
210         }
211
212         public static RestResponse getAssetMetadataByAssetTypeAndUuid(boolean isBasicAuthentication,
213                         AssetTypeEnum assetType, String uuid) throws IOException {
214
215                 Config config = Utils.getConfig();
216                 Map<String, String> headersMap = new HashMap<String, String>();
217                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
218                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
219                 if (isBasicAuthentication) {
220                         headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
221                 }
222                 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
223
224                 HttpRequest http = new HttpRequest();
225                 String url = String.format(Urls.GET_ASSET_METADATA, config.getCatalogBeHost(), config.getCatalogBePort(),
226                                 assetType.getValue(), uuid);
227
228                 logger.debug("Send GET request to get Resource Assets: {}", url);
229                 logger.debug("Request headers: {}", headersMap);
230
231                 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
232
233                 return sendGetResourceAssets;
234         }
235
236         public static List<ResourceAssetStructure> getResourceAssetList(RestResponse assetResponse) {
237                 List<ResourceAssetStructure> resourceAssetList = new ArrayList<>();
238
239                 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
240                 JsonArray componenetArray = (JsonArray) jelement;
241                 for (JsonElement jElement : componenetArray) {
242                         ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
243                         resourceAssetList.add(resource);
244                 }
245                 return resourceAssetList;
246         }
247
248         public static ResourceDetailedAssetStructure getResourceAssetMetadata(RestResponse assetResponse) {
249
250                 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
251                 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
252                 ResourceDetailedAssetStructure resourceAssetMetadata = new ResourceDetailedAssetStructure();
253                 String response = assetResponse.getResponse();
254
255                 JsonObject jObject = (JsonObject) new JsonParser().parse(response);
256                 resourceAssetMetadata = gson.fromJson(jObject, ResourceDetailedAssetStructure.class);
257
258                 setResourceInstanceAssetList(resourcesList, jObject);
259                 resourceAssetMetadata.setResources(resourcesList);
260
261                 setArtifactAssetList(artifactsList, jObject);
262                 resourceAssetMetadata.setArtifacts(artifactsList);
263
264                 return resourceAssetMetadata;
265         }
266
267         public static void generalMetadataFieldsValidatior(AssetStructure assetMetadata, Component component) {
268
269                 assertTrue("Expected resourceUuid is " + component.getUUID() + " actual: " + assetMetadata.getUuid(),
270                                 assetMetadata.getUuid().equals(component.getUUID()));
271                 assertTrue(
272                                 "Expected resourceInvariantUuid is " + component.getInvariantUUID() + " actual: "
273                                                 + assetMetadata.getInvariantUUID(),
274                                 assetMetadata.getInvariantUUID().equals(component.getInvariantUUID()));
275                 assertTrue("Expected asset name is " + component.getName() + " actual: " + assetMetadata.getName(),
276                                 assetMetadata.getName().equals(component.getName()));
277                 assertTrue("Expected asset version is " + component.getVersion() + " actual: " + assetMetadata.getVersion(),
278                                 assetMetadata.getVersion().equals(component.getVersion()));
279                 assertTrue(
280                                 "Expected asset lastUpdaterUserId is " + component.getLastUpdaterUserId() + " actual: "
281                                                 + assetMetadata.getLastUpdaterUserId(),
282                                 assetMetadata.getLastUpdaterUserId().equals(component.getLastUpdaterUserId()));
283                 assertNotNull("Expected asset toscaModel is null", assetMetadata.getToscaModelURL());
284                 assertTrue(
285                                 "Expected asset category is " + component.getCategories().get(0).getName() + " actual: "
286                                                 + assetMetadata.getCategory(),
287                                 assetMetadata.getCategory().equals(component.getCategories().get(0).getName()));
288                 assertTrue(
289                                 "Expected asset lifeCycleState is " + component.getLifecycleState() + " actual: "
290                                                 + assetMetadata.getLifecycleState(),
291                                 assetMetadata.getLifecycleState().equals(component.getLifecycleState().toString()));
292
293         }
294
295         public static void resourceMetadataValidatior(ResourceDetailedAssetStructure resourceAssetMetadata,
296                         Resource resource, AssetTypeEnum assetType) throws Exception {
297
298                 generalMetadataFieldsValidatior(resourceAssetMetadata, resource);
299                 assertTrue(
300                                 "Expected asset lastUpdaterFullName is " + resource.getLastUpdaterFullName() + " actual: "
301                                                 + resourceAssetMetadata.getLastUpdaterFullName(),
302                                 resourceAssetMetadata.getLastUpdaterFullName().equals(resource.getLastUpdaterFullName()));
303                 assertTrue(
304                                 "Expected asset subCategory is " + resource.getCategories().get(0).getSubcategories().get(0).getName()
305                                                 + " actual: " + resourceAssetMetadata.getSubCategory(),
306                                 resourceAssetMetadata.getSubCategory()
307                                                 .equals(resource.getCategories().get(0).getSubcategories().get(0).getName()));
308                 assertTrue(
309                                 "Expected asset toscaResourceName is " + resource.getToscaResourceName() + " actual: "
310                                                 + resourceAssetMetadata.getToscaResourceName(),
311                                 resourceAssetMetadata.getToscaResourceName().equals(resource.getToscaResourceName()));
312                 assertTrue(
313                                 "Expected asset resourceType is " + resource.getResourceType() + " actual: "
314                                                 + resourceAssetMetadata.getResourceType(),
315                                 resourceAssetMetadata.getResourceType().equals(resource.getResourceType().toString()));
316                 resourceInstanceAssetValidator(resourceAssetMetadata.getResources(), resource, assetType);
317                 // resourceInstanceAssetValidator(resourceAssetMetadata.getResources(),
318                 // resource);
319                 artifactAssetValidator(resourceAssetMetadata.getArtifacts(), resource, assetType);
320
321         }
322
323         public static void serviceMetadataValidatior(ServiceDetailedAssetStructure serviceAssetMetadata, Service service,
324                         AssetTypeEnum assetType) throws Exception {
325
326                 generalMetadataFieldsValidatior(serviceAssetMetadata, service);
327                 assertTrue(
328                                 "Expected asset lastUpdaterFullName is " + service.getLastUpdaterFullName() + " actual: "
329                                                 + serviceAssetMetadata.getLastUpdaterFullName(),
330                                 serviceAssetMetadata.getLastUpdaterFullName().equals(service.getLastUpdaterFullName()));
331                 assertTrue("Expected asset distributionStatus is " + service.getDistributionStatus() + " actual: "
332                                                 + serviceAssetMetadata.getDistributionStatus(),
333                                 serviceAssetMetadata.getDistributionStatus().equals(service.getDistributionStatus().toString()));
334                 resourceInstanceAssetValidator(serviceAssetMetadata.getResources(), service, assetType);
335                 // resourceInstanceAssetValidator(serviceAssetMetadata.getResources(),
336                 // service);
337                 artifactAssetValidator(serviceAssetMetadata.getArtifacts(), service, assetType);
338
339         }
340
341         private static void artifactAssetValidator(List<ArtifactAssetStructure> artifactAssetStructureList,
342                         Component component, AssetTypeEnum assetType) {
343                 Map<String, ArtifactDefinition> componentDeploymentArtifacts = component.getDeploymentArtifacts();
344                 validateArtifactMetadata(componentDeploymentArtifacts, artifactAssetStructureList, component.getUUID(),
345                                 assetType, null);
346         }
347
348         private static void validateArtifactMetadata(Map<String, ArtifactDefinition> componentDeploymentArtifacts,
349                         List<ArtifactAssetStructure> artifactAssetStructureList, String componentUuid, AssetTypeEnum assetType,
350                         String resourceInstanceName) {
351                 if(componentDeploymentArtifacts != null){
352                         for (Entry<String, ArtifactDefinition> componentDeploymentArtifact : componentDeploymentArtifacts.entrySet()) {
353                                 ArtifactAssetStructure artifactAssetStructure = getArtifactMetadata(artifactAssetStructureList,
354                                                 componentDeploymentArtifact.getValue().getArtifactUUID());
355                                 ArtifactDefinition componentDeploymentArtifactValue = componentDeploymentArtifact.getValue();
356                                 if (artifactAssetStructure != null) {
357                                         assertTrue(
358                                                         "Expected artifact asset artifactName is " + componentDeploymentArtifactValue.getArtifactName()
359                                                                         + " actual: " + artifactAssetStructure.getArtifactName(),
360                                                         componentDeploymentArtifactValue.getArtifactName()
361                                                                         .equals(artifactAssetStructure.getArtifactName()));
362                                         assertTrue(
363                                                         "Expected artifact asset Type is " + componentDeploymentArtifactValue.getArtifactType()
364                                                                         + " actual: " + artifactAssetStructure.getArtifactType(),
365                                                         componentDeploymentArtifactValue.getArtifactType()
366                                                                         .equals(artifactAssetStructure.getArtifactType()));
367                                         // assertNotNull("Expected artifact asset resourceInvariantUUID
368                                         // is null",
369                                         // resourceInstanceAssetStructure.getResourceInvariantUUID());
370                                         // String expectedArtifactUrl = "/sdc/v1/catalog/" +
371                                         // assetType.getValue() + "/" + componentUuid + "/artifacts/" +
372                                         // componentDeploymentArtifactValue.getArtifactUUID();
373                                         String expectedArtifactUrl = "";
374                                         if (resourceInstanceName == null) {
375                                                 expectedArtifactUrl = String.format(COMPONENT_ARTIFACT_URL, assetType.getValue(), componentUuid,
376                                                                 componentDeploymentArtifactValue.getArtifactUUID());
377                                         } else {
378                                                 expectedArtifactUrl = String.format(RESOURCE_INSTANCE_ARTIFACT_URL, assetType.getValue(),
379                                                                 componentUuid, resourceInstanceName, componentDeploymentArtifactValue.getArtifactUUID());
380                                         }
381         
382                                         assertTrue(
383                                                         "Expected artifact asset URL is " + expectedArtifactUrl + " actual: "
384                                                                         + artifactAssetStructure.getArtifactURL(),
385                                                         artifactAssetStructure.getArtifactURL().equals(expectedArtifactUrl));
386                                         assertTrue(
387                                                         "Expected artifact asset description is " + componentDeploymentArtifactValue.getDescription()
388                                                                         + " actual: " + artifactAssetStructure.getArtifactDescription(),
389                                                         componentDeploymentArtifactValue.getDescription().toString()
390                                                                         .equals(artifactAssetStructure.getArtifactDescription()));
391                                         assertTrue(
392                                                         "Expected artifact asset checkSum is " + componentDeploymentArtifactValue.getArtifactChecksum()
393                                                                         + " actual: " + artifactAssetStructure.getArtifactChecksum(),
394                                                         componentDeploymentArtifactValue.getArtifactChecksum()
395                                                                         .equals(artifactAssetStructure.getArtifactChecksum()));
396                                         assertTrue(
397                                                         "Expected artifact asset version is " + componentDeploymentArtifactValue.getArtifactVersion()
398                                                                         + " actual: " + artifactAssetStructure.getArtifactVersion(),
399                                                         componentDeploymentArtifactValue.getArtifactVersion()
400                                                                         .equals(artifactAssetStructure.getArtifactVersion()));
401                                         if (componentDeploymentArtifactValue.getTimeout() > 0) {
402                                                 assertTrue(
403                                                                 "Expected artifact asset timeout is " + componentDeploymentArtifactValue.getTimeout()
404                                                                                 + " actual: " + artifactAssetStructure.getArtifactTimeout(),
405                                                                 componentDeploymentArtifactValue.getTimeout()
406                                                                                 .equals(artifactAssetStructure.getArtifactTimeout()));
407                                         }
408         
409                                 } else {
410                                         assertTrue("artifact asset with UUID" + componentDeploymentArtifact.getValue().getArtifactUUID()
411                                                         + " not found in get Metadata response", false);
412                                 }
413                         }
414                 }else{
415                         System.out.println("componentDeploymentArtifacts is null");
416                         logger.debug("componentDeploymentArtifacts is null");
417                 }
418
419         }
420
421         private static ArtifactAssetStructure getArtifactMetadata(List<ArtifactAssetStructure> artifactAssetStructureList,
422                         String artifactUUID) {
423                 for (ArtifactAssetStructure artifactAssetStructure : artifactAssetStructureList) {
424                         if (artifactAssetStructure.getArtifactUUID().equals(artifactUUID)) {
425                                 return artifactAssetStructure;
426                         }
427                 }
428                 return null;
429         }
430
431         private static void resourceInstanceAssetValidator(
432                         List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, Component component,
433                         AssetTypeEnum assetType) throws Exception {
434
435                 List<ComponentInstance> componentInstances = component.getComponentInstances();
436                 if (componentInstances != null) {
437                         for (ComponentInstance componentInstance : componentInstances) {
438                                 ResourceInstanceAssetStructure resourceInstanceAssetStructure = getResourceInstanceMetadata(
439                                                 resourceInstanceAssetStructures, componentInstance.getName());
440                                 if (resourceInstanceAssetStructure != null) {
441                                         assertTrue(
442                                                         "Expected RI asset resourceName is " + componentInstance.getComponentName() + " actual: "
443                                                                         + resourceInstanceAssetStructure.getResourceName(),
444                                                         componentInstance.getComponentName()
445                                                                         .equals(resourceInstanceAssetStructure.getResourceName()));
446                                         assertTrue(
447                                                         "Expected RI asset Name is " + componentInstance.getName() + " actual: "
448                                                                         + resourceInstanceAssetStructure.getResourceInstanceName(),
449                                                         componentInstance.getName()
450                                                                         .equals(resourceInstanceAssetStructure.getResourceInstanceName()));
451                                         assertNotNull("Expected RI asset resourceInvariantUUID is null",
452                                                         resourceInstanceAssetStructure.getResourceInvariantUUID());
453                                         assertTrue(
454                                                         "Expected RI asset resourceVersion is " + componentInstance.getComponentVersion()
455                                                                         + " actual: " + resourceInstanceAssetStructure.getResourceVersion(),
456                                                         componentInstance.getComponentVersion()
457                                                                         .equals(resourceInstanceAssetStructure.getResourceVersion()));
458                                         assertTrue(
459                                                         "Expected RI asset resourceType is " + componentInstance.getOriginType() + " actual: "
460                                                                         + resourceInstanceAssetStructure.getResoucreType(),
461                                                         componentInstance.getOriginType().toString()
462                                                                         .equals(resourceInstanceAssetStructure.getResoucreType()));
463                                         Resource resource = AtomicOperationUtils.getResourceObject(componentInstance.getComponentUid());
464                                         assertTrue("Expected RI asset resourceUUID is " + resource.getUUID() + " actual: " + resourceInstanceAssetStructure.getResourceUUID(),
465                                                         resource.getUUID().equals(resourceInstanceAssetStructure.getResourceUUID()));
466                                         validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
467                                                         resourceInstanceAssetStructure.getArtifacts(), component.getUUID(), assetType,
468                                                         componentInstance.getNormalizedName());
469                                         // validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
470                                         // resourceInstanceAssetStructure.getArtifacts(),
471                                         // component.getUUID(), AssetTypeEnum.RESOURCES);
472                                 } else {
473                                         assertTrue("resourceInstance asset with UUID" + componentInstance.getComponentUid()
474                                                         + " not found in get Metadata response", false);
475                                 }
476                         }
477                 }
478
479         }
480
481         // private static ResourceInstanceAssetStructure
482         // getResourceInstanceMetadata(List<ResourceInstanceAssetStructure>
483         // resourceInstanceAssetStructures, String componentUid) {
484         private static ResourceInstanceAssetStructure getResourceInstanceMetadata(
485                         List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, String name) {
486                 for (ResourceInstanceAssetStructure resourceInstanceAssetStructure : resourceInstanceAssetStructures) {
487                         if (resourceInstanceAssetStructure.getResourceInstanceName().equals(name)) {
488                                 return resourceInstanceAssetStructure;
489                         }
490                 }
491                 return null;
492         }
493
494         public static ServiceDetailedAssetStructure getServiceAssetMetadata(RestResponse assetResponse) {
495
496                 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
497                 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
498                 ServiceDetailedAssetStructure serviceAssetMetadata;
499
500                 JsonObject jObject = (JsonObject) new JsonParser().parse(assetResponse.getResponse());
501                 serviceAssetMetadata = gson.fromJson(jObject, ServiceDetailedAssetStructure.class);
502
503                 setResourceInstanceAssetList(resourcesList, jObject);
504                 serviceAssetMetadata.setResources(resourcesList);
505
506                 setArtifactAssetList(artifactsList, jObject);
507                 serviceAssetMetadata.setArtifacts(artifactsList);
508
509                 return serviceAssetMetadata;
510         }
511
512         public static void setArtifactAssetList(List<ArtifactAssetStructure> artifactsList, JsonObject jObject) {
513                 JsonArray artifactsArray = jObject.getAsJsonArray("artifacts");
514                 if (artifactsArray != null) {
515                         for (JsonElement jElement : artifactsArray) {
516                                 ArtifactAssetStructure artifact = gson.fromJson(jElement, ArtifactAssetStructure.class);
517                                 artifactsList.add(artifact);
518                         }
519                 }
520         }
521
522         public static void setResourceInstanceAssetList(List<ResourceInstanceAssetStructure> resourcesList,
523                         JsonObject jObject) {
524                 JsonArray resourcesArray = jObject.getAsJsonArray("resources");
525                 if (resourcesArray != null) {
526                         for (JsonElement jElement : resourcesArray) {
527                                 ResourceInstanceAssetStructure resource = gson.fromJson(jElement, ResourceInstanceAssetStructure.class);
528                                 resourcesList.add(resource);
529                         }
530                 }
531         }
532
533         public static List<ServiceAssetStructure> getServiceAssetList(RestResponse assetResponse) {
534                 List<ServiceAssetStructure> serviceAssetList = new ArrayList<>();
535
536                 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
537                 JsonArray componenetArray = (JsonArray) jelement;
538                 for (JsonElement jElement : componenetArray) {
539                         ServiceAssetStructure service = gson.fromJson(jElement, ServiceAssetStructure.class);
540                         serviceAssetList.add(service);
541                 }
542                 return serviceAssetList;
543         }
544
545         public static List<String> getResourceNamesList(List<ResourceAssetStructure> resourceAssetList) {
546                 List<String> assetNamesList = new ArrayList<>();
547                 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
548                         assetNamesList.add(resourceAsset.getName());
549                 }
550                 return assetNamesList;
551         }
552         
553         public static Map<String,String> getResourceAssetMap(RestResponse assetResponse) {
554                 Map<String,String> resourceAssetMap =  new HashMap<>();
555
556                 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
557                 JsonArray componenetArray = (JsonArray) jelement;
558                 for (JsonElement jElement : componenetArray) {
559                         ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
560                         resourceAssetMap.put(resource.getName(), resource.getVersion());
561                 }
562                 return resourceAssetMap;
563         }
564         
565         public static Map<String,String> getResourceListFiltteredByWholeVersion(Map<String,String> resourceAssetList) {
566                 Map<String,String> assetNamesMap = new HashMap<>();
567                         for (Entry<String, String> entry : resourceAssetList.entrySet()) {
568                             String key = entry.getKey();
569                             String[] parts = entry.getValue().split("\\.");
570                             String lastOne = parts[parts.length-1];
571                             
572                             if (key.contains("CinderVolume") ){
573                                 assetNamesMap.put(key,entry.getValue());
574                             }
575                             
576                             if (lastOne.equals("0") && !key.contains("Ci") ){
577                                 assetNamesMap.put(key,entry.getValue());
578                             }
579                         }
580                         
581                 return assetNamesMap;
582         }
583
584         public static List<String> getResourceObjectByNameAndVersionToscaNamesList(Map<String,String> resourceAssetList) throws Exception {
585                 List<String> assetNamesList = new ArrayList<>();
586                 for (Entry<String, String> entry : resourceAssetList.entrySet()) {
587                         System.out.println("fetch data---->"+entry.getKey()+entry.getValue());
588                         Resource resourceObjectByNameAndVersion = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, entry.getKey(), entry.getValue());
589                         assetNamesList.add(resourceObjectByNameAndVersion.getToscaResourceName());
590                     
591                 }
592                 
593                 return assetNamesList;
594         }
595         
596
597         public static List<String> getServiceNamesList(List<ServiceAssetStructure> serviceAssetList) {
598                 List<String> assetNamesList = new ArrayList<>();
599                 for (ServiceAssetStructure serviceAsset : serviceAssetList) {
600                         assetNamesList.add(serviceAsset.getName());
601                 }
602                 return assetNamesList;
603         }
604
605         public static void checkResourceTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ResourceTypeEnum resourceType) {
606                 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
607                         assertTrue("Expected resourceType is " + resourceType.toString() + " actual: " + resourceAsset.getResourceType(),
608                                         resourceAsset.getResourceType().equals(resourceType.toString()));
609                 }
610         }
611
612         public static void checkComponentTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ComponentTypeEnum componentType) {
613                 ComponentTypeEnum actualComponentType;
614                 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
615                         actualComponentType = detectComponentType(resourceAsset);
616                         assertTrue("Expected componentType is " + componentType.getValue() + " actual: " + actualComponentType.getValue(), actualComponentType.equals(componentType));
617                 }
618         }
619
620         private static ComponentTypeEnum detectComponentType(ResourceAssetStructure resourceAsset) {
621                 String resourceType = resourceAsset.getResourceType();
622                 if(ResourceTypeEnum.getType(resourceType) !=null){
623                         return ComponentTypeEnum.RESOURCE;
624                 }
625                 return null;
626         }
627         private static String getShortUUID() {
628                 return UUID.randomUUID().toString().split("-")[0];
629         }
630         
631 }