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