2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.utils.rest;
23 import static org.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
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;
32 import java.util.Map.Entry;
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;
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;
70 public class AssetRestUtils extends BaseRestUtils {
71 static Gson gson = new Gson();
72 static ObjectMapper objectMapper = new ObjectMapper();
74 private static Logger logger = LoggerFactory.getLogger(UserRestUtils.class.getName());
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";
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);
91 httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
92 httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
94 logger.debug("Send GET request to get Tosca model: {}",url);
96 return httpclient.execute(httpGet);
99 public static RestResponse getRestResponseComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
100 Config config = Utils.getConfig();
102 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
103 assetType.getValue(), uuid);
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");
110 HttpRequest http = new HttpRequest();
112 logger.debug("Send GET request to get Resource Assets: {}",url);
113 System.out.println("Send GET request to get Resource Assets: " + url);
115 logger.debug("Request headers: {}",headersMap);
116 System.out.println("Request headers: " + headersMap);
118 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
120 return sendGetResourceAssets;
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);
133 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
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);
142 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
144 return sendGetResourceAssets;
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");
155 HttpRequest http = new HttpRequest();
157 String url = String.format(Urls.GET_FILTERED_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
158 assetType.getValue(), query);
160 logger.debug("Send GET request to get Resource Assets: {}",url);
161 logger.debug("Request headers: {}",headersMap);
163 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
165 return sendGetResourceAssets;
168 public static String buildUrlWithFilter(String url, String[] filterArrayString) {
169 StringBuilder sb = new StringBuilder();
170 int length = filterArrayString.length;
172 for (String filterString : filterArrayString) {
173 sb.append(filterString);
175 if (length != count) {
179 return url + "?" + sb;
182 public static RestResponse getAssetMetadataByAssetTypeAndUuid(boolean isBasicAuthentication,
183 AssetTypeEnum assetType, String uuid) throws IOException {
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);
192 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
194 HttpRequest http = new HttpRequest();
195 String url = String.format(Urls.GET_ASSET_METADATA, config.getCatalogBeHost(), config.getCatalogBePort(),
196 assetType.getValue(), uuid);
198 logger.debug("Send GET request to get Resource Assets: {}",url);
199 logger.debug("Request headers: {}",headersMap);
201 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
203 return sendGetResourceAssets;
206 public static List<ResourceAssetStructure> getResourceAssetList(RestResponse assetResponse) {
207 List<ResourceAssetStructure> resourceAssetList = new ArrayList<>();
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);
215 return resourceAssetList;
218 public static ResourceDetailedAssetStructure getResourceAssetMetadata(RestResponse assetResponse) {
220 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
221 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
222 ResourceDetailedAssetStructure resourceAssetMetadata = new ResourceDetailedAssetStructure();
223 String response = assetResponse.getResponse();
225 JsonObject jObject = (JsonObject) new JsonParser().parse(response);
226 resourceAssetMetadata = gson.fromJson(jObject, ResourceDetailedAssetStructure.class);
228 setResourceInstanceAssetList(resourcesList, jObject);
229 resourceAssetMetadata.setResources(resourcesList);
231 setArtifactAssetList(artifactsList, jObject);
232 resourceAssetMetadata.setArtifacts(artifactsList);
234 return resourceAssetMetadata;
237 public static void generalMetadataFieldsValidatior(AssetStructure assetMetadata, Component component) {
239 assertTrue("Expected resourceUuid is " + component.getUUID() + " actual: " + assetMetadata.getUuid(),
240 assetMetadata.getUuid().equals(component.getUUID()));
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()));
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());
255 "Expected asset category is " + component.getCategories().get(0).getName() + " actual: "
256 + assetMetadata.getCategory(),
257 assetMetadata.getCategory().equals(component.getCategories().get(0).getName()));
259 "Expected asset lifeCycleState is " + component.getLifecycleState() + " actual: "
260 + assetMetadata.getLifecycleState(),
261 assetMetadata.getLifecycleState().equals(component.getLifecycleState().toString()));
265 public static void resourceMetadataValidatior(ResourceDetailedAssetStructure resourceAssetMetadata,
266 Resource resource, AssetTypeEnum assetType) {
268 generalMetadataFieldsValidatior(resourceAssetMetadata, resource);
270 "Expected asset lastUpdaterFullName is " + resource.getLastUpdaterFullName() + " actual: "
271 + resourceAssetMetadata.getLastUpdaterFullName(),
272 resourceAssetMetadata.getLastUpdaterFullName().equals(resource.getLastUpdaterFullName()));
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()));
279 "Expected asset toscaResourceName is " + resource.getToscaResourceName() + " actual: "
280 + resourceAssetMetadata.getToscaResourceName(),
281 resourceAssetMetadata.getToscaResourceName().equals(resource.getToscaResourceName()));
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(),
289 artifactAssetValidator(resourceAssetMetadata.getArtifacts(), resource, assetType);
293 public static void serviceMetadataValidatior(ServiceDetailedAssetStructure serviceAssetMetadata, Service service,
294 AssetTypeEnum assetType) {
296 generalMetadataFieldsValidatior(serviceAssetMetadata, service);
298 "Expected asset lastUpdaterFullName is " + service.getLastUpdaterFullName() + " actual: "
299 + serviceAssetMetadata.getLastUpdaterFullName(),
300 serviceAssetMetadata.getLastUpdaterFullName().equals(service.getLastUpdaterFullName()));
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(),
308 artifactAssetValidator(serviceAssetMetadata.getArtifacts(), service, assetType);
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(),
319 private static void validateArtifactMetadata(Map<String, ArtifactDefinition> componentDeploymentArtifacts,
320 List<ArtifactAssetStructure> artifactAssetStructureList, String componentUuid, AssetTypeEnum assetType,
321 String resourceInstanceName) {
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) {
329 "Expected artifact asset artifactName is " + componentDeploymentArtifactValue.getArtifactName()
330 + " actual: " + artifactAssetStructure.getArtifactName(),
331 componentDeploymentArtifactValue.getArtifactName()
332 .equals(artifactAssetStructure.getArtifactName()));
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
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());
349 expectedArtifactUrl = String.format(RESOURCE_INSTANCE_ARTIFACT_URL, assetType.getValue(),
350 componentUuid, resourceInstanceName, componentDeploymentArtifactValue.getArtifactUUID());
354 "Expected artifact asset URL is " + expectedArtifactUrl + " actual: "
355 + artifactAssetStructure.getArtifactURL(),
356 artifactAssetStructure.getArtifactURL().equals(expectedArtifactUrl));
358 "Expected artifact asset description is " + componentDeploymentArtifactValue.getDescription()
359 + " actual: " + artifactAssetStructure.getArtifactDescription(),
360 componentDeploymentArtifactValue.getDescription().toString()
361 .equals(artifactAssetStructure.getArtifactDescription()));
363 "Expected artifact asset checkSum is " + componentDeploymentArtifactValue.getArtifactChecksum()
364 + " actual: " + artifactAssetStructure.getArtifactChecksum(),
365 componentDeploymentArtifactValue.getArtifactChecksum()
366 .equals(artifactAssetStructure.getArtifactChecksum()));
368 "Expected artifact asset version is " + componentDeploymentArtifactValue.getArtifactVersion()
369 + " actual: " + artifactAssetStructure.getArtifactVersion(),
370 componentDeploymentArtifactValue.getArtifactVersion()
371 .equals(artifactAssetStructure.getArtifactVersion()));
372 if (componentDeploymentArtifactValue.getTimeout() > 0) {
374 "Expected artifact asset timeout is " + componentDeploymentArtifactValue.getTimeout()
375 + " actual: " + artifactAssetStructure.getArtifactTimeout(),
376 componentDeploymentArtifactValue.getTimeout()
377 .equals(artifactAssetStructure.getArtifactTimeout()));
381 assertTrue("artifact asset with UUID" + componentDeploymentArtifact.getValue().getArtifactUUID()
382 + " not found in get Metadata response", false);
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;
398 private static void resourceInstanceAssetValidator(
399 List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, Component component,
400 AssetTypeEnum assetType) {
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) {
409 "Expected RI asset resourceName is " + componentInstance.getComponentName() + " actual: "
410 + resourceInstanceAssetStructure.getResourceName(),
411 componentInstance.getComponentName()
412 .equals(resourceInstanceAssetStructure.getResourceName()));
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());
421 "Expected RI asset resourceVersion is " + componentInstance.getComponentVersion()
422 + " actual: " + resourceInstanceAssetStructure.getResourceVersion(),
423 componentInstance.getComponentVersion()
424 .equals(resourceInstanceAssetStructure.getResourceVersion()));
426 "Expected RI asset resourceType is " + componentInstance.getOriginType() + " actual: "
427 + resourceInstanceAssetStructure.getResoucreType(),
428 componentInstance.getOriginType().toString()
429 .equals(resourceInstanceAssetStructure.getResoucreType()));
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);
442 assertTrue("resourceInstance asset with UUID" + componentInstance.getComponentUid()
443 + " not found in get Metadata response", false);
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;
463 public static ServiceDetailedAssetStructure getServiceAssetMetadata(RestResponse assetResponse) {
465 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
466 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
467 ServiceDetailedAssetStructure serviceAssetMetadata;
469 JsonObject jObject = (JsonObject) new JsonParser().parse(assetResponse.getResponse());
470 serviceAssetMetadata = gson.fromJson(jObject, ServiceDetailedAssetStructure.class);
472 setResourceInstanceAssetList(resourcesList, jObject);
473 serviceAssetMetadata.setResources(resourcesList);
475 setArtifactAssetList(artifactsList, jObject);
476 serviceAssetMetadata.setArtifacts(artifactsList);
478 return serviceAssetMetadata;
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);
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);
502 public static List<ServiceAssetStructure> getServiceAssetList(RestResponse assetResponse) {
503 List<ServiceAssetStructure> serviceAssetList = new ArrayList<>();
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);
511 return serviceAssetList;
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());
519 return assetNamesList;
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());
527 return assetNamesList;
530 public static void checkResourceTypeInObjectList(List<ResourceAssetStructure> resourceAssetList,
531 ResourceTypeEnum resourceType) {
532 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
534 "Expected resourceType is " + resourceType.toString() + " actual: "
535 + resourceAsset.getResourceType(),
536 resourceAsset.getResourceType().equals(resourceType.toString()));
540 public static void checkComponentTypeInObjectList(List<ResourceAssetStructure> resourceAssetList,
541 ComponentTypeEnum componentType) {
542 ComponentTypeEnum actualComponentType;
543 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
544 actualComponentType = detectComponentType(resourceAsset);
546 "Expected componentType is " + componentType.getValue() + " actual: " + actualComponentType.getValue(),
547 actualComponentType.equals(componentType));
551 private static ComponentTypeEnum detectComponentType(ResourceAssetStructure resourceAsset) {
552 String resourceType = resourceAsset.getResourceType();
553 if(ResourceTypeEnum.getType(resourceType) !=null){
554 return ComponentTypeEnum.RESOURCE;