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