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