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;
30 import java.util.Map.Entry;
32 import org.apache.http.HttpEntity;
33 import org.apache.http.HttpResponse;
34 import org.apache.http.client.methods.CloseableHttpResponse;
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.ci.tests.api.Urls;
48 import org.openecomp.sdc.ci.tests.config.Config;
49 import org.openecomp.sdc.ci.tests.datatypes.ArtifactAssetStructure;
50 import org.openecomp.sdc.ci.tests.datatypes.AssetStructure;
51 import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure;
52 import org.openecomp.sdc.ci.tests.datatypes.ResourceDetailedAssetStructure;
53 import org.openecomp.sdc.ci.tests.datatypes.ResourceInstanceAssetStructure;
54 import org.openecomp.sdc.ci.tests.datatypes.ServiceAssetStructure;
55 import org.openecomp.sdc.ci.tests.datatypes.ServiceDetailedAssetStructure;
56 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
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.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
62 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
66 import com.google.gson.Gson;
67 import com.google.gson.JsonArray;
68 import com.google.gson.JsonElement;
69 import com.google.gson.JsonObject;
70 import com.google.gson.JsonParser;
72 public class AssetRestUtils extends BaseRestUtils {
73 static Gson gson = new Gson();
74 static ObjectMapper objectMapper = new ObjectMapper();
76 static Logger logger = LoggerFactory.getLogger(AssetRestUtils.class.getName());
77 static final String contentTypeHeaderData = "application/json";
78 static final String acceptHeaderDate = "application/json";
79 static final String basicAuthentication = "Basic Y2k6MTIzNDU2";
80 // /sdc/v1/catalog/{services/resources}/{componentUUID}/artifacts/{artifactUUID}
81 static final String COMPONENT_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/artifacts/%s";
82 // /sdc/v1/catalog/{services/resources}/{componentUUID}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}
83 static final String RESOURCE_INSTANCE_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/resourceInstances/%s/artifacts/%s";
85 public static HttpResponse getComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
86 Config config = Utils.getConfig();
87 CloseableHttpClient httpclient = HttpClients.createDefault();
88 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
89 assetType.getValue(), uuid);
90 HttpGet httpGet = new HttpGet(url);
92 httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
93 httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
95 logger.debug("Send GET request to get Tosca model: {}", url);
97 return httpclient.execute(httpGet);
100 public static File getToscaModelCsarFile(AssetTypeEnum assetType, String uuid, String fileName) throws IOException {
101 Config config = Utils.getConfig();
102 CloseableHttpClient httpclient = HttpClients.createDefault();
103 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
104 assetType.getValue(), uuid);
105 HttpGet httpGet = new HttpGet(url);
107 String csarDir = FileHandling.getCreateDirByName("outputCsar");
108 File myFile = new File(csarDir+ File.separator + "tmpCSAR_" + fileName + ".csar");
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);
129 public static RestResponse getRestResponseComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
130 Config config = Utils.getConfig();
132 String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
133 assetType.getValue(), uuid);
135 Map<String, String> headersMap = new HashMap<String,String>();
136 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
137 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
138 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
140 HttpRequest http = new HttpRequest();
142 logger.debug("Send GET request to get Resource Assets: {}", url);
143 System.out.println("Send GET request to get Resource Assets: " + url);
145 logger.debug("Request headers: {}", headersMap);
146 System.out.println("Request headers: " + headersMap);
148 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
150 return sendGetResourceAssets;
154 public static RestResponse getComponentListByAssetType(boolean isBasicAuthentication, AssetTypeEnum assetType,
155 String... filterArrayString) throws IOException {
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);
163 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
165 HttpRequest http = new HttpRequest();
166 String url = String.format(Urls.GET_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
167 assetType.getValue());
168 if (filterArrayString != null && filterArrayString.length > 0) {
169 url = buildUrlWithFilter(url, filterArrayString);
172 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
174 return sendGetResourceAssets;
177 public static RestResponse getFilteredComponentList(AssetTypeEnum assetType, String query) throws IOException {
178 Config config = Utils.getConfig();
179 Map<String, String> headersMap = new HashMap<String, String>();
180 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
181 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
182 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
183 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
185 HttpRequest http = new HttpRequest();
187 String url = String.format(Urls.GET_FILTERED_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
188 assetType.getValue(), query);
190 logger.debug("Send GET request to get Resource Assets: {}", url);
191 logger.debug("Request headers: {}", headersMap);
193 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
195 return sendGetResourceAssets;
198 public static String buildUrlWithFilter(String url, String[] filterArrayString) {
199 StringBuilder sb = new StringBuilder();
200 int length = filterArrayString.length;
202 for (String filterString : filterArrayString) {
203 sb.append(filterString);
205 if (length != count) {
209 return url + "?" + sb;
212 public static RestResponse getAssetMetadataByAssetTypeAndUuid(boolean isBasicAuthentication,
213 AssetTypeEnum assetType, String uuid) throws IOException {
215 Config config = Utils.getConfig();
216 Map<String, String> headersMap = new HashMap<String, String>();
217 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
218 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
219 if (isBasicAuthentication) {
220 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
222 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), "ci");
224 HttpRequest http = new HttpRequest();
225 String url = String.format(Urls.GET_ASSET_METADATA, config.getCatalogBeHost(), config.getCatalogBePort(),
226 assetType.getValue(), uuid);
228 logger.debug("Send GET request to get Resource Assets: {}", url);
229 logger.debug("Request headers: {}", headersMap);
231 RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);
233 return sendGetResourceAssets;
236 public static List<ResourceAssetStructure> getResourceAssetList(RestResponse assetResponse) {
237 List<ResourceAssetStructure> resourceAssetList = new ArrayList<>();
239 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
240 JsonArray componenetArray = (JsonArray) jelement;
241 for (JsonElement jElement : componenetArray) {
242 ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
243 resourceAssetList.add(resource);
245 return resourceAssetList;
248 public static ResourceDetailedAssetStructure getResourceAssetMetadata(RestResponse assetResponse) {
250 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
251 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
252 ResourceDetailedAssetStructure resourceAssetMetadata = new ResourceDetailedAssetStructure();
253 String response = assetResponse.getResponse();
255 JsonObject jObject = (JsonObject) new JsonParser().parse(response);
256 resourceAssetMetadata = gson.fromJson(jObject, ResourceDetailedAssetStructure.class);
258 setResourceInstanceAssetList(resourcesList, jObject);
259 resourceAssetMetadata.setResources(resourcesList);
261 setArtifactAssetList(artifactsList, jObject);
262 resourceAssetMetadata.setArtifacts(artifactsList);
264 return resourceAssetMetadata;
267 public static void generalMetadataFieldsValidatior(AssetStructure assetMetadata, Component component) {
269 assertTrue("Expected resourceUuid is " + component.getUUID() + " actual: " + assetMetadata.getUuid(),
270 assetMetadata.getUuid().equals(component.getUUID()));
272 "Expected resourceInvariantUuid is " + component.getInvariantUUID() + " actual: "
273 + assetMetadata.getInvariantUUID(),
274 assetMetadata.getInvariantUUID().equals(component.getInvariantUUID()));
275 assertTrue("Expected asset name is " + component.getName() + " actual: " + assetMetadata.getName(),
276 assetMetadata.getName().equals(component.getName()));
277 assertTrue("Expected asset version is " + component.getVersion() + " actual: " + assetMetadata.getVersion(),
278 assetMetadata.getVersion().equals(component.getVersion()));
280 "Expected asset lastUpdaterUserId is " + component.getLastUpdaterUserId() + " actual: "
281 + assetMetadata.getLastUpdaterUserId(),
282 assetMetadata.getLastUpdaterUserId().equals(component.getLastUpdaterUserId()));
283 assertNotNull("Expected asset toscaModel is null", assetMetadata.getToscaModelURL());
285 "Expected asset category is " + component.getCategories().get(0).getName() + " actual: "
286 + assetMetadata.getCategory(),
287 assetMetadata.getCategory().equals(component.getCategories().get(0).getName()));
289 "Expected asset lifeCycleState is " + component.getLifecycleState() + " actual: "
290 + assetMetadata.getLifecycleState(),
291 assetMetadata.getLifecycleState().equals(component.getLifecycleState().toString()));
295 public static void resourceMetadataValidatior(ResourceDetailedAssetStructure resourceAssetMetadata,
296 Resource resource, AssetTypeEnum assetType) throws Exception {
298 generalMetadataFieldsValidatior(resourceAssetMetadata, resource);
300 "Expected asset lastUpdaterFullName is " + resource.getLastUpdaterFullName() + " actual: "
301 + resourceAssetMetadata.getLastUpdaterFullName(),
302 resourceAssetMetadata.getLastUpdaterFullName().equals(resource.getLastUpdaterFullName()));
304 "Expected asset subCategory is " + resource.getCategories().get(0).getSubcategories().get(0).getName()
305 + " actual: " + resourceAssetMetadata.getSubCategory(),
306 resourceAssetMetadata.getSubCategory()
307 .equals(resource.getCategories().get(0).getSubcategories().get(0).getName()));
309 "Expected asset toscaResourceName is " + resource.getToscaResourceName() + " actual: "
310 + resourceAssetMetadata.getToscaResourceName(),
311 resourceAssetMetadata.getToscaResourceName().equals(resource.getToscaResourceName()));
313 "Expected asset resourceType is " + resource.getResourceType() + " actual: "
314 + resourceAssetMetadata.getResourceType(),
315 resourceAssetMetadata.getResourceType().equals(resource.getResourceType().toString()));
316 resourceInstanceAssetValidator(resourceAssetMetadata.getResources(), resource, assetType);
317 // resourceInstanceAssetValidator(resourceAssetMetadata.getResources(),
319 artifactAssetValidator(resourceAssetMetadata.getArtifacts(), resource, assetType);
323 public static void serviceMetadataValidatior(ServiceDetailedAssetStructure serviceAssetMetadata, Service service,
324 AssetTypeEnum assetType) throws Exception {
326 generalMetadataFieldsValidatior(serviceAssetMetadata, service);
328 "Expected asset lastUpdaterFullName is " + service.getLastUpdaterFullName() + " actual: "
329 + serviceAssetMetadata.getLastUpdaterFullName(),
330 serviceAssetMetadata.getLastUpdaterFullName().equals(service.getLastUpdaterFullName()));
331 assertTrue("Expected asset distributionStatus is " + service.getDistributionStatus() + " actual: "
332 + serviceAssetMetadata.getDistributionStatus(),
333 serviceAssetMetadata.getDistributionStatus().equals(service.getDistributionStatus().toString()));
334 resourceInstanceAssetValidator(serviceAssetMetadata.getResources(), service, assetType);
335 // resourceInstanceAssetValidator(serviceAssetMetadata.getResources(),
337 artifactAssetValidator(serviceAssetMetadata.getArtifacts(), service, assetType);
341 private static void artifactAssetValidator(List<ArtifactAssetStructure> artifactAssetStructureList,
342 Component component, AssetTypeEnum assetType) {
343 Map<String, ArtifactDefinition> componentDeploymentArtifacts = component.getDeploymentArtifacts();
344 validateArtifactMetadata(componentDeploymentArtifacts, artifactAssetStructureList, component.getUUID(),
348 private static void validateArtifactMetadata(Map<String, ArtifactDefinition> componentDeploymentArtifacts,
349 List<ArtifactAssetStructure> artifactAssetStructureList, String componentUuid, AssetTypeEnum assetType,
350 String resourceInstanceName) {
351 if(componentDeploymentArtifacts != null){
352 for (Entry<String, ArtifactDefinition> componentDeploymentArtifact : componentDeploymentArtifacts.entrySet()) {
353 ArtifactAssetStructure artifactAssetStructure = getArtifactMetadata(artifactAssetStructureList,
354 componentDeploymentArtifact.getValue().getArtifactUUID());
355 ArtifactDefinition componentDeploymentArtifactValue = componentDeploymentArtifact.getValue();
356 if (artifactAssetStructure != null) {
358 "Expected artifact asset artifactName is " + componentDeploymentArtifactValue.getArtifactName()
359 + " actual: " + artifactAssetStructure.getArtifactName(),
360 componentDeploymentArtifactValue.getArtifactName()
361 .equals(artifactAssetStructure.getArtifactName()));
363 "Expected artifact asset Type is " + componentDeploymentArtifactValue.getArtifactType()
364 + " actual: " + artifactAssetStructure.getArtifactType(),
365 componentDeploymentArtifactValue.getArtifactType()
366 .equals(artifactAssetStructure.getArtifactType()));
367 // assertNotNull("Expected artifact asset resourceInvariantUUID
369 // resourceInstanceAssetStructure.getResourceInvariantUUID());
370 // String expectedArtifactUrl = "/sdc/v1/catalog/" +
371 // assetType.getValue() + "/" + componentUuid + "/artifacts/" +
372 // componentDeploymentArtifactValue.getArtifactUUID();
373 String expectedArtifactUrl = "";
374 if (resourceInstanceName == null) {
375 expectedArtifactUrl = String.format(COMPONENT_ARTIFACT_URL, assetType.getValue(), componentUuid,
376 componentDeploymentArtifactValue.getArtifactUUID());
378 expectedArtifactUrl = String.format(RESOURCE_INSTANCE_ARTIFACT_URL, assetType.getValue(),
379 componentUuid, resourceInstanceName, componentDeploymentArtifactValue.getArtifactUUID());
383 "Expected artifact asset URL is " + expectedArtifactUrl + " actual: "
384 + artifactAssetStructure.getArtifactURL(),
385 artifactAssetStructure.getArtifactURL().equals(expectedArtifactUrl));
387 "Expected artifact asset description is " + componentDeploymentArtifactValue.getDescription()
388 + " actual: " + artifactAssetStructure.getArtifactDescription(),
389 componentDeploymentArtifactValue.getDescription().toString()
390 .equals(artifactAssetStructure.getArtifactDescription()));
392 "Expected artifact asset checkSum is " + componentDeploymentArtifactValue.getArtifactChecksum()
393 + " actual: " + artifactAssetStructure.getArtifactChecksum(),
394 componentDeploymentArtifactValue.getArtifactChecksum()
395 .equals(artifactAssetStructure.getArtifactChecksum()));
397 "Expected artifact asset version is " + componentDeploymentArtifactValue.getArtifactVersion()
398 + " actual: " + artifactAssetStructure.getArtifactVersion(),
399 componentDeploymentArtifactValue.getArtifactVersion()
400 .equals(artifactAssetStructure.getArtifactVersion()));
401 if (componentDeploymentArtifactValue.getTimeout() > 0) {
403 "Expected artifact asset timeout is " + componentDeploymentArtifactValue.getTimeout()
404 + " actual: " + artifactAssetStructure.getArtifactTimeout(),
405 componentDeploymentArtifactValue.getTimeout()
406 .equals(artifactAssetStructure.getArtifactTimeout()));
410 assertTrue("artifact asset with UUID" + componentDeploymentArtifact.getValue().getArtifactUUID()
411 + " not found in get Metadata response", false);
415 System.out.println("componentDeploymentArtifacts is null");
416 logger.debug("componentDeploymentArtifacts is null");
421 private static ArtifactAssetStructure getArtifactMetadata(List<ArtifactAssetStructure> artifactAssetStructureList,
422 String artifactUUID) {
423 for (ArtifactAssetStructure artifactAssetStructure : artifactAssetStructureList) {
424 if (artifactAssetStructure.getArtifactUUID().equals(artifactUUID)) {
425 return artifactAssetStructure;
431 private static void resourceInstanceAssetValidator(
432 List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, Component component,
433 AssetTypeEnum assetType) throws Exception {
435 List<ComponentInstance> componentInstances = component.getComponentInstances();
436 if (componentInstances != null) {
437 for (ComponentInstance componentInstance : componentInstances) {
438 ResourceInstanceAssetStructure resourceInstanceAssetStructure = getResourceInstanceMetadata(
439 resourceInstanceAssetStructures, componentInstance.getName());
440 if (resourceInstanceAssetStructure != null) {
442 "Expected RI asset resourceName is " + componentInstance.getComponentName() + " actual: "
443 + resourceInstanceAssetStructure.getResourceName(),
444 componentInstance.getComponentName()
445 .equals(resourceInstanceAssetStructure.getResourceName()));
447 "Expected RI asset Name is " + componentInstance.getName() + " actual: "
448 + resourceInstanceAssetStructure.getResourceInstanceName(),
449 componentInstance.getName()
450 .equals(resourceInstanceAssetStructure.getResourceInstanceName()));
451 assertNotNull("Expected RI asset resourceInvariantUUID is null",
452 resourceInstanceAssetStructure.getResourceInvariantUUID());
454 "Expected RI asset resourceVersion is " + componentInstance.getComponentVersion()
455 + " actual: " + resourceInstanceAssetStructure.getResourceVersion(),
456 componentInstance.getComponentVersion()
457 .equals(resourceInstanceAssetStructure.getResourceVersion()));
459 "Expected RI asset resourceType is " + componentInstance.getOriginType() + " actual: "
460 + resourceInstanceAssetStructure.getResoucreType(),
461 componentInstance.getOriginType().toString()
462 .equals(resourceInstanceAssetStructure.getResoucreType()));
463 Resource resource = AtomicOperationUtils.getResourceObject(componentInstance.getComponentUid());
464 assertTrue("Expected RI asset resourceUUID is " + resource.getUUID() + " actual: " + resourceInstanceAssetStructure.getResourceUUID(),
465 resource.getUUID().equals(resourceInstanceAssetStructure.getResourceUUID()));
466 validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
467 resourceInstanceAssetStructure.getArtifacts(), component.getUUID(), assetType,
468 componentInstance.getNormalizedName());
469 // validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
470 // resourceInstanceAssetStructure.getArtifacts(),
471 // component.getUUID(), AssetTypeEnum.RESOURCES);
473 assertTrue("resourceInstance asset with UUID" + componentInstance.getComponentUid()
474 + " not found in get Metadata response", false);
481 // private static ResourceInstanceAssetStructure
482 // getResourceInstanceMetadata(List<ResourceInstanceAssetStructure>
483 // resourceInstanceAssetStructures, String componentUid) {
484 private static ResourceInstanceAssetStructure getResourceInstanceMetadata(
485 List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, String name) {
486 for (ResourceInstanceAssetStructure resourceInstanceAssetStructure : resourceInstanceAssetStructures) {
487 if (resourceInstanceAssetStructure.getResourceInstanceName().equals(name)) {
488 return resourceInstanceAssetStructure;
494 public static ServiceDetailedAssetStructure getServiceAssetMetadata(RestResponse assetResponse) {
496 List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
497 List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
498 ServiceDetailedAssetStructure serviceAssetMetadata;
500 JsonObject jObject = (JsonObject) new JsonParser().parse(assetResponse.getResponse());
501 serviceAssetMetadata = gson.fromJson(jObject, ServiceDetailedAssetStructure.class);
503 setResourceInstanceAssetList(resourcesList, jObject);
504 serviceAssetMetadata.setResources(resourcesList);
506 setArtifactAssetList(artifactsList, jObject);
507 serviceAssetMetadata.setArtifacts(artifactsList);
509 return serviceAssetMetadata;
512 public static void setArtifactAssetList(List<ArtifactAssetStructure> artifactsList, JsonObject jObject) {
513 JsonArray artifactsArray = jObject.getAsJsonArray("artifacts");
514 if (artifactsArray != null) {
515 for (JsonElement jElement : artifactsArray) {
516 ArtifactAssetStructure artifact = gson.fromJson(jElement, ArtifactAssetStructure.class);
517 artifactsList.add(artifact);
522 public static void setResourceInstanceAssetList(List<ResourceInstanceAssetStructure> resourcesList,
523 JsonObject jObject) {
524 JsonArray resourcesArray = jObject.getAsJsonArray("resources");
525 if (resourcesArray != null) {
526 for (JsonElement jElement : resourcesArray) {
527 ResourceInstanceAssetStructure resource = gson.fromJson(jElement, ResourceInstanceAssetStructure.class);
528 resourcesList.add(resource);
533 public static List<ServiceAssetStructure> getServiceAssetList(RestResponse assetResponse) {
534 List<ServiceAssetStructure> serviceAssetList = new ArrayList<>();
536 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
537 JsonArray componenetArray = (JsonArray) jelement;
538 for (JsonElement jElement : componenetArray) {
539 ServiceAssetStructure service = gson.fromJson(jElement, ServiceAssetStructure.class);
540 serviceAssetList.add(service);
542 return serviceAssetList;
545 public static List<String> getResourceNamesList(List<ResourceAssetStructure> resourceAssetList) {
546 List<String> assetNamesList = new ArrayList<>();
547 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
548 assetNamesList.add(resourceAsset.getName());
550 return assetNamesList;
553 public static Map<String,String> getResourceAssetMap(RestResponse assetResponse) {
554 Map<String,String> resourceAssetMap = new HashMap<>();
556 JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
557 JsonArray componenetArray = (JsonArray) jelement;
558 for (JsonElement jElement : componenetArray) {
559 ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
560 resourceAssetMap.put(resource.getName(), resource.getVersion());
562 return resourceAssetMap;
565 public static Map<String,String> getResourceListFiltteredByWholeVersion(Map<String,String> resourceAssetList) {
566 Map<String,String> assetNamesMap = new HashMap<>();
567 for (Entry<String, String> entry : resourceAssetList.entrySet()) {
568 String key = entry.getKey();
569 String[] parts = entry.getValue().split("\\.");
570 String lastOne = parts[parts.length-1];
572 if (key.contains("CinderVolume") ){
573 assetNamesMap.put(key,entry.getValue());
576 if (lastOne.equals("0") && !key.contains("Ci") ){
577 assetNamesMap.put(key,entry.getValue());
581 return assetNamesMap;
584 public static List<String> getResourceObjectByNameAndVersionToscaNamesList(Map<String,String> resourceAssetList) throws Exception {
585 List<String> assetNamesList = new ArrayList<>();
586 for (Entry<String, String> entry : resourceAssetList.entrySet()) {
587 System.out.println("fetch data---->"+entry.getKey()+entry.getValue());
588 Resource resourceObjectByNameAndVersion = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, entry.getKey(), entry.getValue());
589 assetNamesList.add(resourceObjectByNameAndVersion.getToscaResourceName());
593 return assetNamesList;
597 public static List<String> getServiceNamesList(List<ServiceAssetStructure> serviceAssetList) {
598 List<String> assetNamesList = new ArrayList<>();
599 for (ServiceAssetStructure serviceAsset : serviceAssetList) {
600 assetNamesList.add(serviceAsset.getName());
602 return assetNamesList;
605 public static void checkResourceTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ResourceTypeEnum resourceType) {
606 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
607 assertTrue("Expected resourceType is " + resourceType.toString() + " actual: " + resourceAsset.getResourceType(),
608 resourceAsset.getResourceType().equals(resourceType.toString()));
612 public static void checkComponentTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ComponentTypeEnum componentType) {
613 ComponentTypeEnum actualComponentType;
614 for (ResourceAssetStructure resourceAsset : resourceAssetList) {
615 actualComponentType = detectComponentType(resourceAsset);
616 assertTrue("Expected componentType is " + componentType.getValue() + " actual: " + actualComponentType.getValue(), actualComponentType.equals(componentType));
620 private static ComponentTypeEnum detectComponentType(ResourceAssetStructure resourceAsset) {
621 String resourceType = resourceAsset.getResourceType();
622 if(ResourceTypeEnum.getType(resourceType) !=null){
623 return ComponentTypeEnum.RESOURCE;
627 private static String getShortUUID() {
628 return UUID.randomUUID().toString().split("-")[0];