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.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.Map.Entry;
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;
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;
68 public class AssetRestUtils extends BaseRestUtils {
69 static Gson gson = new Gson();
70 static ObjectMapper objectMapper = new ObjectMapper();
72 private static Logger logger = LoggerFactory.getLogger(UserRestUtils.class.getName());
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";
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);
89 httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
90 httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
92 logger.debug("Send GET request to get Tosca model: {}",url);
94 return httpclient.execute(httpGet);
97 public static RestResponse getRestResponseComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
98 Config config = Utils.getConfig();
100 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
101 assetType.getValue(), uuid);
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");
108 HttpRequest http = new HttpRequest();
110 logger.debug("Send GET request to get Resource Assets: {}",url);
111 System.out.println("Send GET request to get Resource Assets: " + url);
113 logger.debug("Request headers: {}",headersMap);
114 System.out.println("Request headers: " + headersMap);
116 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
118 return sendGetResourceAssets;
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);
131 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
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);
140 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
142 return sendGetResourceAssets;
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");
153 HttpRequest http = new HttpRequest();
155 String url = String.format(Urls.GET_FILTERED_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
156 assetType.getValue(), query);
158 logger.debug("Send GET request to get Resource Assets: {}",url);
159 logger.debug("Request headers: {}",headersMap);
161 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
163 return sendGetResourceAssets;
166 public static String buildUrlWithFilter(String url, String[] filterArrayString) {
167 StringBuilder sb = new StringBuilder();
168 int length = filterArrayString.length;
170 for (String filterString : filterArrayString) {
171 sb.append(filterString);
173 if (length != count) {
177 return url + "?" + sb;
180 public static RestResponse getAssetMetadataByAssetTypeAndUuid(boolean isBasicAuthentication,
181 AssetTypeEnum assetType, String uuid) throws IOException {
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);
190 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
192 HttpRequest http = new HttpRequest();
193 String url = String.format(Urls.GET_ASSET_METADATA, config.getCatalogBeHost(), config.getCatalogBePort(),
194 assetType.getValue(), uuid);
196 logger.debug("Send GET request to get Resource Assets: {}",url);
197 logger.debug("Request headers: {}",headersMap);
199 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
201 return sendGetResourceAssets;
204 public static List<ResourceAssetStructure> getResourceAssetList(RestResponse assetResponse) {
205 List<ResourceAssetStructure> resourceAssetList = new ArrayList<>();
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);
213 return resourceAssetList;
216 public static ResourceDetailedAssetStructure getResourceAssetMetadata(RestResponse assetResponse) {
218 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
219 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
220 ResourceDetailedAssetStructure resourceAssetMetadata = new ResourceDetailedAssetStructure();
221 String response = assetResponse.getResponse();
223 JsonObject jObject = (JsonObject) new JsonParser().parse(response);
224 resourceAssetMetadata = gson.fromJson(jObject, ResourceDetailedAssetStructure.class);
226 setResourceInstanceAssetList(resourcesList, jObject);
227 resourceAssetMetadata.setResources(resourcesList);
229 setArtifactAssetList(artifactsList, jObject);
230 resourceAssetMetadata.setArtifacts(artifactsList);
232 return resourceAssetMetadata;
235 public static void generalMetadataFieldsValidatior(AssetStructure assetMetadata, Component component) {
237 assertTrue("Expected resourceUuid is " + component.getUUID() + " actual: " + assetMetadata.getUuid(),
238 assetMetadata.getUuid().equals(component.getUUID()));
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()));
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());
253 "Expected asset category is " + component.getCategories().get(0).getName() + " actual: "
254 + assetMetadata.getCategory(),
255 assetMetadata.getCategory().equals(component.getCategories().get(0).getName()));
257 "Expected asset lifeCycleState is " + component.getLifecycleState() + " actual: "
258 + assetMetadata.getLifecycleState(),
259 assetMetadata.getLifecycleState().equals(component.getLifecycleState().toString()));
263 public static void resourceMetadataValidatior(ResourceDetailedAssetStructure resourceAssetMetadata,
264 Resource resource, AssetTypeEnum assetType) {
266 generalMetadataFieldsValidatior(resourceAssetMetadata, resource);
268 "Expected asset lastUpdaterFullName is " + resource.getLastUpdaterFullName() + " actual: "
269 + resourceAssetMetadata.getLastUpdaterFullName(),
270 resourceAssetMetadata.getLastUpdaterFullName().equals(resource.getLastUpdaterFullName()));
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()));
277 "Expected asset toscaResourceName is " + resource.getToscaResourceName() + " actual: "
278 + resourceAssetMetadata.getToscaResourceName(),
279 resourceAssetMetadata.getToscaResourceName().equals(resource.getToscaResourceName()));
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(),
287 artifactAssetValidator(resourceAssetMetadata.getArtifacts(), resource, assetType);
291 public static void serviceMetadataValidatior(ServiceDetailedAssetStructure serviceAssetMetadata, Service service,
292 AssetTypeEnum assetType) {
294 generalMetadataFieldsValidatior(serviceAssetMetadata, service);
296 "Expected asset lastUpdaterFullName is " + service.getLastUpdaterFullName() + " actual: "
297 + serviceAssetMetadata.getLastUpdaterFullName(),
298 serviceAssetMetadata.getLastUpdaterFullName().equals(service.getLastUpdaterFullName()));
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(),
306 artifactAssetValidator(serviceAssetMetadata.getArtifacts(), service, assetType);
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(),
317 private static void validateArtifactMetadata(Map<String, ArtifactDefinition> componentDeploymentArtifacts,
318 List<ArtifactAssetStructure> artifactAssetStructureList, String componentUuid, AssetTypeEnum assetType,
319 String resourceInstanceName) {
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) {
327 "Expected artifact asset artifactName is " + componentDeploymentArtifactValue.getArtifactName()
328 + " actual: " + artifactAssetStructure.getArtifactName(),
329 componentDeploymentArtifactValue.getArtifactName()
330 .equals(artifactAssetStructure.getArtifactName()));
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
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());
347 expectedArtifactUrl = String.format(RESOURCE_INSTANCE_ARTIFACT_URL, assetType.getValue(),
348 componentUuid, resourceInstanceName, componentDeploymentArtifactValue.getArtifactUUID());
352 "Expected artifact asset URL is " + expectedArtifactUrl + " actual: "
353 + artifactAssetStructure.getArtifactURL(),
354 artifactAssetStructure.getArtifactURL().equals(expectedArtifactUrl));
356 "Expected artifact asset description is " + componentDeploymentArtifactValue.getDescription()
357 + " actual: " + artifactAssetStructure.getArtifactDescription(),
358 componentDeploymentArtifactValue.getDescription().toString()
359 .equals(artifactAssetStructure.getArtifactDescription()));
361 "Expected artifact asset checkSum is " + componentDeploymentArtifactValue.getArtifactChecksum()
362 + " actual: " + artifactAssetStructure.getArtifactChecksum(),
363 componentDeploymentArtifactValue.getArtifactChecksum()
364 .equals(artifactAssetStructure.getArtifactChecksum()));
366 "Expected artifact asset version is " + componentDeploymentArtifactValue.getArtifactVersion()
367 + " actual: " + artifactAssetStructure.getArtifactVersion(),
368 componentDeploymentArtifactValue.getArtifactVersion()
369 .equals(artifactAssetStructure.getArtifactVersion()));
370 if (componentDeploymentArtifactValue.getTimeout() > 0) {
372 "Expected artifact asset timeout is " + componentDeploymentArtifactValue.getTimeout()
373 + " actual: " + artifactAssetStructure.getArtifactTimeout(),
374 componentDeploymentArtifactValue.getTimeout()
375 .equals(artifactAssetStructure.getArtifactTimeout()));
379 assertTrue("artifact asset with UUID" + componentDeploymentArtifact.getValue().getArtifactUUID()
380 + " not found in get Metadata response", false);
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;
396 private static void resourceInstanceAssetValidator(
397 List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, Component component,
398 AssetTypeEnum assetType) {
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) {
407 "Expected RI asset resourceName is " + componentInstance.getComponentName() + " actual: "
408 + resourceInstanceAssetStructure.getResourceName(),
409 componentInstance.getComponentName()
410 .equals(resourceInstanceAssetStructure.getResourceName()));
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());
419 "Expected RI asset resourceVersion is " + componentInstance.getComponentVersion()
420 + " actual: " + resourceInstanceAssetStructure.getResourceVersion(),
421 componentInstance.getComponentVersion()
422 .equals(resourceInstanceAssetStructure.getResourceVersion()));
424 "Expected RI asset resourceType is " + componentInstance.getOriginType() + " actual: "
425 + resourceInstanceAssetStructure.getResoucreType(),
426 componentInstance.getOriginType().toString()
427 .equals(resourceInstanceAssetStructure.getResoucreType()));
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);
440 assertTrue("resourceInstance asset with UUID" + componentInstance.getComponentUid()
441 + " not found in get Metadata response", false);
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;
461 public static ServiceDetailedAssetStructure getServiceAssetMetadata(RestResponse assetResponse) {
463 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
464 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
465 ServiceDetailedAssetStructure serviceAssetMetadata;
467 JsonObject jObject = (JsonObject) new JsonParser().parse(assetResponse.getResponse());
468 serviceAssetMetadata = gson.fromJson(jObject, ServiceDetailedAssetStructure.class);
470 setResourceInstanceAssetList(resourcesList, jObject);
471 serviceAssetMetadata.setResources(resourcesList);
473 setArtifactAssetList(artifactsList, jObject);
474 serviceAssetMetadata.setArtifacts(artifactsList);
476 return serviceAssetMetadata;
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);
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);
500 public static List<ServiceAssetStructure> getServiceAssetList(RestResponse assetResponse) {
501 List<ServiceAssetStructure> serviceAssetList = new ArrayList<>();
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);
509 return serviceAssetList;
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());
517 return assetNamesList;
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());
525 return assetNamesList;
528 public static void checkResourceTypeInObjectList(List<ResourceAssetStructure> resourceAssetList,
529 ResourceTypeEnum resourceType) {
530 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
532 "Expected resourceType is " + resourceType.toString() + " actual: "
533 + resourceAsset.getResourceType(),
534 resourceAsset.getResourceType().equals(resourceType.toString()));
538 public static void checkComponentTypeInObjectList(List<ResourceAssetStructure> resourceAssetList,
539 ComponentTypeEnum componentType) {
540 ComponentTypeEnum actualComponentType;
541 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
542 actualComponentType = detectComponentType(resourceAsset);
544 "Expected componentType is " + componentType.getValue() + " actual: " + actualComponentType.getValue(),
545 actualComponentType.equals(componentType));
549 private static ComponentTypeEnum detectComponentType(ResourceAssetStructure resourceAsset) {
550 String resourceType = resourceAsset.getResourceType();
551 if(ResourceTypeEnum.getType(resourceType) !=null){
552 return ComponentTypeEnum.RESOURCE;