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