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;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
33 import java.util.Map.Entry;
35 import org.apache.http.HttpEntity;
36 import org.apache.http.HttpResponse;
37 import org.apache.http.client.methods.CloseableHttpResponse;
38 import org.apache.http.client.methods.HttpGet;
39 import org.apache.http.impl.client.CloseableHttpClient;
40 import org.apache.http.impl.client.HttpClients;
41 import org.codehaus.jackson.map.ObjectMapper;
42 import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
43 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
44 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
45 import org.openecomp.sdc.be.model.ArtifactDefinition;
46 import org.openecomp.sdc.be.model.Component;
47 import org.openecomp.sdc.be.model.ComponentInstance;
48 import org.openecomp.sdc.be.model.Resource;
49 import org.openecomp.sdc.be.model.Service;
50 import org.openecomp.sdc.ci.tests.api.Urls;
51 import org.openecomp.sdc.ci.tests.config.Config;
52 import org.openecomp.sdc.ci.tests.datatypes.ArtifactAssetStructure;
53 import org.openecomp.sdc.ci.tests.datatypes.AssetStructure;
54 import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure;
55 import org.openecomp.sdc.ci.tests.datatypes.ResourceDetailedAssetStructure;
56 import org.openecomp.sdc.ci.tests.datatypes.ResourceInstanceAssetStructure;
57 import org.openecomp.sdc.ci.tests.datatypes.ServiceAssetStructure;
58 import org.openecomp.sdc.ci.tests.datatypes.ServiceDetailedAssetStructure;
59 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
60 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
61 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
62 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
63 import org.openecomp.sdc.ci.tests.utils.Utils;
64 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
68 import com.google.gson.Gson;
69 import com.google.gson.JsonArray;
70 import com.google.gson.JsonElement;
71 import com.google.gson.JsonObject;
72 import com.google.gson.JsonParser;
74 public class AssetRestUtils extends BaseRestUtils {
75 static Gson gson = new Gson();
76 static ObjectMapper objectMapper = new ObjectMapper();
78 static Logger logger = LoggerFactory.getLogger(AssetRestUtils.class.getName());
79 static final String contentTypeHeaderData = "application/json";
80 static final String acceptHeaderDate = "application/json";
81 static final String basicAuthentication = "Basic Y2k6MTIzNDU2";
82 // /sdc/v1/catalog/{services/resources}/{componentUUID}/artifacts/{artifactUUID}
83 static final String COMPONENT_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/artifacts/%s";
84 // /sdc/v1/catalog/{services/resources}/{componentUUID}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}
85 static final String RESOURCE_INSTANCE_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/resourceInstances/%s/artifacts/%s";
87 public static HttpResponse getComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
88 Config config = Utils.getConfig();
89 CloseableHttpClient httpclient = HttpClients.createDefault();
90 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
91 assetType.getValue(), uuid);
92 HttpGet httpGet = new HttpGet(url);
94 httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
95 httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
97 logger.debug("Send GET request to get Tosca model: {}", url);
99 return httpclient.execute(httpGet);
102 public static File getToscaModelCsarFile(AssetTypeEnum assetType, String uuid) throws IOException {
103 Config config = Utils.getConfig();
104 CloseableHttpClient httpclient = HttpClients.createDefault();
105 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
106 assetType.getValue(), uuid);
107 HttpGet httpGet = new HttpGet(url);
108 File myFile = new File("tmpCSAR");
111 httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
112 httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
114 logger.debug("Send GET request to get Tosca model: {}", url);
115 CloseableHttpResponse execute = httpclient.execute(httpGet);
117 HttpEntity entity = execute.getEntity();
118 if (entity != null) {
119 try (FileOutputStream outstream = new FileOutputStream(myFile)) {
120 entity.writeTo(outstream);
127 public static RestResponse getRestResponseComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
128 Config config = Utils.getConfig();
130 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
131 assetType.getValue(), uuid);
133 Map<String, String> headersMap = new HashMap<String,String>();
134 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
135 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
136 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
138 HttpRequest http = new HttpRequest();
140 logger.debug("Send GET request to get Resource Assets: {}", url);
141 System.out.println("Send GET request to get Resource Assets: " + url);
143 logger.debug("Request headers: {}", headersMap);
144 System.out.println("Request headers: " + headersMap);
146 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
148 return sendGetResourceAssets;
152 public static RestResponse getComponentListByAssetType(boolean isBasicAuthentication, AssetTypeEnum assetType,
153 String... filterArrayString) throws IOException {
154 Config config = Utils.getConfig();
155 Map<String, String> headersMap = new HashMap<String, String>();
156 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
157 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
158 if (isBasicAuthentication) {
159 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
161 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
163 HttpRequest http = new HttpRequest();
164 String url = String.format(Urls.GET_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
165 assetType.getValue());
166 if (filterArrayString != null && filterArrayString.length > 0) {
167 url = buildUrlWithFilter(url, filterArrayString);
170 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
172 return sendGetResourceAssets;
175 public static RestResponse getFilteredComponentList(AssetTypeEnum assetType, String query) throws IOException {
176 Config config = Utils.getConfig();
177 Map<String, String> headersMap = new HashMap<String, String>();
178 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
179 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
180 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
181 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
183 HttpRequest http = new HttpRequest();
185 String url = String.format(Urls.GET_FILTERED_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
186 assetType.getValue(), query);
188 logger.debug("Send GET request to get Resource Assets: {}", url);
189 logger.debug("Request headers: {}", headersMap);
191 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
193 return sendGetResourceAssets;
196 public static String buildUrlWithFilter(String url, String[] filterArrayString) {
197 StringBuilder sb = new StringBuilder();
198 int length = filterArrayString.length;
200 for (String filterString : filterArrayString) {
201 sb.append(filterString);
203 if (length != count) {
207 return url + "?" + sb;
210 public static RestResponse getAssetMetadataByAssetTypeAndUuid(boolean isBasicAuthentication,
211 AssetTypeEnum assetType, String uuid) throws IOException {
213 Config config = Utils.getConfig();
214 Map<String, String> headersMap = new HashMap<String, String>();
215 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
216 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
217 if (isBasicAuthentication) {
218 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
220 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
222 HttpRequest http = new HttpRequest();
223 String url = String.format(Urls.GET_ASSET_METADATA, config.getCatalogBeHost(), config.getCatalogBePort(),
224 assetType.getValue(), uuid);
226 logger.debug("Send GET request to get Resource Assets: {}", url);
227 logger.debug("Request headers: {}", headersMap);
229 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
231 return sendGetResourceAssets;
234 public static List<ResourceAssetStructure> getResourceAssetList(RestResponse assetResponse) {
235 List<ResourceAssetStructure> resourceAssetList = new ArrayList<>();
237 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
238 JsonArray componenetArray = (JsonArray) jelement;
239 for (JsonElement jElement : componenetArray) {
240 ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
241 resourceAssetList.add(resource);
243 return resourceAssetList;
246 public static ResourceDetailedAssetStructure getResourceAssetMetadata(RestResponse assetResponse) {
248 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
249 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
250 ResourceDetailedAssetStructure resourceAssetMetadata = new ResourceDetailedAssetStructure();
251 String response = assetResponse.getResponse();
253 JsonObject jObject = (JsonObject) new JsonParser().parse(response);
254 resourceAssetMetadata = gson.fromJson(jObject, ResourceDetailedAssetStructure.class);
256 setResourceInstanceAssetList(resourcesList, jObject);
257 resourceAssetMetadata.setResources(resourcesList);
259 setArtifactAssetList(artifactsList, jObject);
260 resourceAssetMetadata.setArtifacts(artifactsList);
262 return resourceAssetMetadata;
265 public static void generalMetadataFieldsValidatior(AssetStructure assetMetadata, Component component) {
267 assertTrue("Expected resourceUuid is " + component.getUUID() + " actual: " + assetMetadata.getUuid(),
268 assetMetadata.getUuid().equals(component.getUUID()));
270 "Expected resourceInvariantUuid is " + component.getInvariantUUID() + " actual: "
271 + assetMetadata.getInvariantUUID(),
272 assetMetadata.getInvariantUUID().equals(component.getInvariantUUID()));
273 assertTrue("Expected asset name is " + component.getName() + " actual: " + assetMetadata.getName(),
274 assetMetadata.getName().equals(component.getName()));
275 assertTrue("Expected asset version is " + component.getVersion() + " actual: " + assetMetadata.getVersion(),
276 assetMetadata.getVersion().equals(component.getVersion()));
278 "Expected asset lastUpdaterUserId is " + component.getLastUpdaterUserId() + " actual: "
279 + assetMetadata.getLastUpdaterUserId(),
280 assetMetadata.getLastUpdaterUserId().equals(component.getLastUpdaterUserId()));
281 assertNotNull("Expected asset toscaModel is null", assetMetadata.getToscaModelURL());
283 "Expected asset category is " + component.getCategories().get(0).getName() + " actual: "
284 + assetMetadata.getCategory(),
285 assetMetadata.getCategory().equals(component.getCategories().get(0).getName()));
287 "Expected asset lifeCycleState is " + component.getLifecycleState() + " actual: "
288 + assetMetadata.getLifecycleState(),
289 assetMetadata.getLifecycleState().equals(component.getLifecycleState().toString()));
293 public static void resourceMetadataValidatior(ResourceDetailedAssetStructure resourceAssetMetadata,
294 Resource resource, AssetTypeEnum assetType) throws Exception {
296 generalMetadataFieldsValidatior(resourceAssetMetadata, resource);
298 "Expected asset lastUpdaterFullName is " + resource.getLastUpdaterFullName() + " actual: "
299 + resourceAssetMetadata.getLastUpdaterFullName(),
300 resourceAssetMetadata.getLastUpdaterFullName().equals(resource.getLastUpdaterFullName()));
302 "Expected asset subCategory is " + resource.getCategories().get(0).getSubcategories().get(0).getName()
303 + " actual: " + resourceAssetMetadata.getSubCategory(),
304 resourceAssetMetadata.getSubCategory()
305 .equals(resource.getCategories().get(0).getSubcategories().get(0).getName()));
307 "Expected asset toscaResourceName is " + resource.getToscaResourceName() + " actual: "
308 + resourceAssetMetadata.getToscaResourceName(),
309 resourceAssetMetadata.getToscaResourceName().equals(resource.getToscaResourceName()));
311 "Expected asset resourceType is " + resource.getResourceType() + " actual: "
312 + resourceAssetMetadata.getResourceType(),
313 resourceAssetMetadata.getResourceType().equals(resource.getResourceType().toString()));
314 resourceInstanceAssetValidator(resourceAssetMetadata.getResources(), resource, assetType);
315 // resourceInstanceAssetValidator(resourceAssetMetadata.getResources(),
317 artifactAssetValidator(resourceAssetMetadata.getArtifacts(), resource, assetType);
321 public static void serviceMetadataValidatior(ServiceDetailedAssetStructure serviceAssetMetadata, Service service,
322 AssetTypeEnum assetType) throws Exception {
324 generalMetadataFieldsValidatior(serviceAssetMetadata, service);
326 "Expected asset lastUpdaterFullName is " + service.getLastUpdaterFullName() + " actual: "
327 + serviceAssetMetadata.getLastUpdaterFullName(),
328 serviceAssetMetadata.getLastUpdaterFullName().equals(service.getLastUpdaterFullName()));
329 assertTrue("Expected asset distributionStatus is " + service.getDistributionStatus() + " actual: "
330 + serviceAssetMetadata.getDistributionStatus(),
331 serviceAssetMetadata.getDistributionStatus().equals(service.getDistributionStatus().toString()));
332 resourceInstanceAssetValidator(serviceAssetMetadata.getResources(), service, assetType);
333 // resourceInstanceAssetValidator(serviceAssetMetadata.getResources(),
335 artifactAssetValidator(serviceAssetMetadata.getArtifacts(), service, assetType);
339 private static void artifactAssetValidator(List<ArtifactAssetStructure> artifactAssetStructureList,
340 Component component, AssetTypeEnum assetType) {
341 Map<String, ArtifactDefinition> componentDeploymentArtifacts = component.getDeploymentArtifacts();
342 validateArtifactMetadata(componentDeploymentArtifacts, artifactAssetStructureList, component.getUUID(),
346 private static void validateArtifactMetadata(Map<String, ArtifactDefinition> componentDeploymentArtifacts,
347 List<ArtifactAssetStructure> artifactAssetStructureList, String componentUuid, AssetTypeEnum assetType,
348 String resourceInstanceName) {
349 if(componentDeploymentArtifacts != null){
350 for (Entry<String, ArtifactDefinition> componentDeploymentArtifact : componentDeploymentArtifacts.entrySet()) {
351 ArtifactAssetStructure artifactAssetStructure = getArtifactMetadata(artifactAssetStructureList,
352 componentDeploymentArtifact.getValue().getArtifactUUID());
353 ArtifactDefinition componentDeploymentArtifactValue = componentDeploymentArtifact.getValue();
354 if (artifactAssetStructure != null) {
356 "Expected artifact asset artifactName is " + componentDeploymentArtifactValue.getArtifactName()
357 + " actual: " + artifactAssetStructure.getArtifactName(),
358 componentDeploymentArtifactValue.getArtifactName()
359 .equals(artifactAssetStructure.getArtifactName()));
361 "Expected artifact asset Type is " + componentDeploymentArtifactValue.getArtifactType()
362 + " actual: " + artifactAssetStructure.getArtifactType(),
363 componentDeploymentArtifactValue.getArtifactType()
364 .equals(artifactAssetStructure.getArtifactType()));
365 // assertNotNull("Expected artifact asset resourceInvariantUUID
367 // resourceInstanceAssetStructure.getResourceInvariantUUID());
368 // String expectedArtifactUrl = "/sdc/v1/catalog/" +
369 // assetType.getValue() + "/" + componentUuid + "/artifacts/" +
370 // componentDeploymentArtifactValue.getArtifactUUID();
371 String expectedArtifactUrl = "";
372 if (resourceInstanceName == null) {
373 expectedArtifactUrl = String.format(COMPONENT_ARTIFACT_URL, assetType.getValue(), componentUuid,
374 componentDeploymentArtifactValue.getArtifactUUID());
376 expectedArtifactUrl = String.format(RESOURCE_INSTANCE_ARTIFACT_URL, assetType.getValue(),
377 componentUuid, resourceInstanceName, componentDeploymentArtifactValue.getArtifactUUID());
381 "Expected artifact asset URL is " + expectedArtifactUrl + " actual: "
382 + artifactAssetStructure.getArtifactURL(),
383 artifactAssetStructure.getArtifactURL().equals(expectedArtifactUrl));
385 "Expected artifact asset description is " + componentDeploymentArtifactValue.getDescription()
386 + " actual: " + artifactAssetStructure.getArtifactDescription(),
387 componentDeploymentArtifactValue.getDescription().toString()
388 .equals(artifactAssetStructure.getArtifactDescription()));
390 "Expected artifact asset checkSum is " + componentDeploymentArtifactValue.getArtifactChecksum()
391 + " actual: " + artifactAssetStructure.getArtifactChecksum(),
392 componentDeploymentArtifactValue.getArtifactChecksum()
393 .equals(artifactAssetStructure.getArtifactChecksum()));
395 "Expected artifact asset version is " + componentDeploymentArtifactValue.getArtifactVersion()
396 + " actual: " + artifactAssetStructure.getArtifactVersion(),
397 componentDeploymentArtifactValue.getArtifactVersion()
398 .equals(artifactAssetStructure.getArtifactVersion()));
399 if (componentDeploymentArtifactValue.getTimeout() > 0) {
401 "Expected artifact asset timeout is " + componentDeploymentArtifactValue.getTimeout()
402 + " actual: " + artifactAssetStructure.getArtifactTimeout(),
403 componentDeploymentArtifactValue.getTimeout()
404 .equals(artifactAssetStructure.getArtifactTimeout()));
408 assertTrue("artifact asset with UUID" + componentDeploymentArtifact.getValue().getArtifactUUID()
409 + " not found in get Metadata response", false);
413 System.out.println("componentDeploymentArtifacts is null");
414 logger.debug("componentDeploymentArtifacts is null");
419 private static ArtifactAssetStructure getArtifactMetadata(List<ArtifactAssetStructure> artifactAssetStructureList,
420 String artifactUUID) {
421 for (ArtifactAssetStructure artifactAssetStructure : artifactAssetStructureList) {
422 if (artifactAssetStructure.getArtifactUUID().equals(artifactUUID)) {
423 return artifactAssetStructure;
429 private static void resourceInstanceAssetValidator(
430 List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, Component component,
431 AssetTypeEnum assetType) throws Exception {
433 List<ComponentInstance> componentInstances = component.getComponentInstances();
434 if (componentInstances != null) {
435 for (ComponentInstance componentInstance : componentInstances) {
436 ResourceInstanceAssetStructure resourceInstanceAssetStructure = getResourceInstanceMetadata(
437 resourceInstanceAssetStructures, componentInstance.getName());
438 if (resourceInstanceAssetStructure != null) {
440 "Expected RI asset resourceName is " + componentInstance.getComponentName() + " actual: "
441 + resourceInstanceAssetStructure.getResourceName(),
442 componentInstance.getComponentName()
443 .equals(resourceInstanceAssetStructure.getResourceName()));
445 "Expected RI asset Name is " + componentInstance.getName() + " actual: "
446 + resourceInstanceAssetStructure.getResourceInstanceName(),
447 componentInstance.getName()
448 .equals(resourceInstanceAssetStructure.getResourceInstanceName()));
449 assertNotNull("Expected RI asset resourceInvariantUUID is null",
450 resourceInstanceAssetStructure.getResourceInvariantUUID());
452 "Expected RI asset resourceVersion is " + componentInstance.getComponentVersion()
453 + " actual: " + resourceInstanceAssetStructure.getResourceVersion(),
454 componentInstance.getComponentVersion()
455 .equals(resourceInstanceAssetStructure.getResourceVersion()));
457 "Expected RI asset resourceType is " + componentInstance.getOriginType() + " actual: "
458 + resourceInstanceAssetStructure.getResoucreType(),
459 componentInstance.getOriginType().toString()
460 .equals(resourceInstanceAssetStructure.getResoucreType()));
461 Resource resource = AtomicOperationUtils.getResourceObject(componentInstance.getComponentUid());
462 assertTrue("Expected RI asset resourceUUID is " + resource.getUUID() + " actual: " + resourceInstanceAssetStructure.getResourceUUID(),
463 resource.getUUID().equals(resourceInstanceAssetStructure.getResourceUUID()));
464 validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
465 resourceInstanceAssetStructure.getArtifacts(), component.getUUID(), assetType,
466 componentInstance.getNormalizedName());
467 // validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
468 // resourceInstanceAssetStructure.getArtifacts(),
469 // component.getUUID(), AssetTypeEnum.RESOURCES);
471 assertTrue("resourceInstance asset with UUID" + componentInstance.getComponentUid()
472 + " not found in get Metadata response", false);
479 // private static ResourceInstanceAssetStructure
480 // getResourceInstanceMetadata(List<ResourceInstanceAssetStructure>
481 // resourceInstanceAssetStructures, String componentUid) {
482 private static ResourceInstanceAssetStructure getResourceInstanceMetadata(
483 List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, String name) {
484 for (ResourceInstanceAssetStructure resourceInstanceAssetStructure : resourceInstanceAssetStructures) {
485 if (resourceInstanceAssetStructure.getResourceInstanceName().equals(name)) {
486 return resourceInstanceAssetStructure;
492 public static ServiceDetailedAssetStructure getServiceAssetMetadata(RestResponse assetResponse) {
494 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
495 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
496 ServiceDetailedAssetStructure serviceAssetMetadata;
498 JsonObject jObject = (JsonObject) new JsonParser().parse(assetResponse.getResponse());
499 serviceAssetMetadata = gson.fromJson(jObject, ServiceDetailedAssetStructure.class);
501 setResourceInstanceAssetList(resourcesList, jObject);
502 serviceAssetMetadata.setResources(resourcesList);
504 setArtifactAssetList(artifactsList, jObject);
505 serviceAssetMetadata.setArtifacts(artifactsList);
507 return serviceAssetMetadata;
510 public static void setArtifactAssetList(List<ArtifactAssetStructure> artifactsList, JsonObject jObject) {
511 JsonArray artifactsArray = jObject.getAsJsonArray("artifacts");
512 if (artifactsArray != null) {
513 for (JsonElement jElement : artifactsArray) {
514 ArtifactAssetStructure artifact = gson.fromJson(jElement, ArtifactAssetStructure.class);
515 artifactsList.add(artifact);
520 public static void setResourceInstanceAssetList(List<ResourceInstanceAssetStructure> resourcesList,
521 JsonObject jObject) {
522 JsonArray resourcesArray = jObject.getAsJsonArray("resources");
523 if (resourcesArray != null) {
524 for (JsonElement jElement : resourcesArray) {
525 ResourceInstanceAssetStructure resource = gson.fromJson(jElement, ResourceInstanceAssetStructure.class);
526 resourcesList.add(resource);
531 public static List<ServiceAssetStructure> getServiceAssetList(RestResponse assetResponse) {
532 List<ServiceAssetStructure> serviceAssetList = new ArrayList<>();
534 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
535 JsonArray componenetArray = (JsonArray) jelement;
536 for (JsonElement jElement : componenetArray) {
537 ServiceAssetStructure service = gson.fromJson(jElement, ServiceAssetStructure.class);
538 serviceAssetList.add(service);
540 return serviceAssetList;
543 public static List<String> getResourceNamesList(List<ResourceAssetStructure> resourceAssetList) {
544 List<String> assetNamesList = new ArrayList<>();
545 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
546 assetNamesList.add(resourceAsset.getName());
548 return assetNamesList;
551 public static Map<String,String> getResourceAssetMap(RestResponse assetResponse) {
552 Map<String,String> resourceAssetMap = new HashMap<>();
554 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
555 JsonArray componenetArray = (JsonArray) jelement;
556 for (JsonElement jElement : componenetArray) {
557 ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
558 resourceAssetMap.put(resource.getName(), resource.getVersion());
560 return resourceAssetMap;
563 public static Map<String,String> getResourceListFiltteredByWholeVersion(Map<String,String> resourceAssetList) {
564 Map<String,String> assetNamesMap = new HashMap<>();
565 for (Entry<String, String> entry : resourceAssetList.entrySet()) {
566 String key = entry.getKey();
567 String[] parts = entry.getValue().split("\\.");
568 String lastOne = parts[parts.length-1];
570 if (key.contains("CinderVolume") ){
571 assetNamesMap.put(key,entry.getValue());
574 if (lastOne.equals("0") && !key.contains("Ci") ){
575 assetNamesMap.put(key,entry.getValue());
579 return assetNamesMap;
582 public static List<String> getResourceObjectByNameAndVersionToscaNamesList(Map<String,String> resourceAssetList) throws Exception {
583 List<String> assetNamesList = new ArrayList<>();
584 for (Entry<String, String> entry : resourceAssetList.entrySet()) {
585 System.out.println("fetch data---->"+entry.getKey()+entry.getValue());
586 Resource resourceObjectByNameAndVersion = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, entry.getKey(), entry.getValue());
587 assetNamesList.add(resourceObjectByNameAndVersion.getToscaResourceName());
591 return assetNamesList;
595 public static List<String> getServiceNamesList(List<ServiceAssetStructure> serviceAssetList) {
596 List<String> assetNamesList = new ArrayList<>();
597 for (ServiceAssetStructure serviceAsset : serviceAssetList) {
598 assetNamesList.add(serviceAsset.getName());
600 return assetNamesList;
603 public static void checkResourceTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ResourceTypeEnum resourceType) {
604 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
605 assertTrue("Expected resourceType is " + resourceType.toString() + " actual: " + resourceAsset.getResourceType(),
606 resourceAsset.getResourceType().equals(resourceType.toString()));
610 public static void checkComponentTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ComponentTypeEnum componentType) {
611 ComponentTypeEnum actualComponentType;
612 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
613 actualComponentType = detectComponentType(resourceAsset);
614 assertTrue("Expected componentType is " + componentType.getValue() + " actual: " + actualComponentType.getValue(), actualComponentType.equals(componentType));
618 private static ComponentTypeEnum detectComponentType(ResourceAssetStructure resourceAsset) {
619 String resourceType = resourceAsset.getResourceType();
620 if(ResourceTypeEnum.getType(resourceType) !=null){
621 return ComponentTypeEnum.RESOURCE;