aboutsummaryrefslogtreecommitdiffstats
path: root/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/AssetRestUtils.java
blob: ad70c34628f95fe0b5c2d10208e181da8f591830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.ci.tests.utils.rest;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.*;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.ci.tests.api.Urls;
import org.openecomp.sdc.ci.tests.config.Config;
import org.openecomp.sdc.ci.tests.datatypes.*;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.utils.Utils;
import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;

public class AssetRestUtils extends BaseRestUtils {
	static Gson gson = new Gson();
	static ObjectMapper objectMapper = new ObjectMapper();

	static Logger logger = LoggerFactory.getLogger(AssetRestUtils.class.getName());
	static final String basicAuthentication = "Basic Y2k6MTIzNDU2";
	// /sdc/v1/catalog/{services/resources}/{componentUUID}/artifacts/{artifactUUID}
	static final String COMPONENT_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/artifacts/%s";
	// /sdc/v1/catalog/{services/resources}/{componentUUID}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}
	static final String RESOURCE_INSTANCE_ARTIFACT_URL = "/sdc/v1/catalog/%s/%s/resourceInstances/%s/artifacts/%s";

	public static HttpResponse getComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
		Config config = Utils.getConfig();
		CloseableHttpClient httpclient = HttpClients.createDefault();
		String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
				assetType.getValue(), uuid);
		HttpGet httpGet = new HttpGet(url);

		httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
		httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);

		logger.debug("Send GET request to get Tosca model: {}", url);

		return httpclient.execute(httpGet);
	}
	
	public static File getToscaModelCsarFile(AssetTypeEnum assetType, String uuid) throws IOException {
		return getToscaModelCsarFile(assetType, uuid, "");
	}
	
	public static File getToscaModelCsarFile(AssetTypeEnum assetType, String uuid, String fileName) throws IOException {
		File myFile;
		Config config = Utils.getConfig();
		CloseableHttpClient httpclient = HttpClients.createDefault();
		String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
				assetType.getValue(), uuid);
		HttpGet httpGet = new HttpGet(url);
		
		if(fileName.isEmpty()) {
			myFile = new File("tmpCSAR");			
		} else {
			String csarDir = FileHandling.getCreateDirByName("outputCsar");
			myFile = new File(csarDir+ File.separator + "tmpCSAR_" + fileName + ".csar");
		}

		
		httpGet.addHeader(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
		httpGet.addHeader(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);

		logger.debug("Send GET request to get Tosca model: {}", url);
		CloseableHttpResponse execute = httpclient.execute(httpGet);
		
	    HttpEntity entity = execute.getEntity();
	    if (entity != null) {
	        try (FileOutputStream outstream = new FileOutputStream(myFile)) {
	            entity.writeTo(outstream);
	            outstream.close();
	        }
	    }
		return myFile;
	}
	
	public static RestResponse getRestResponseComponentToscaModel(AssetTypeEnum assetType, String uuid) throws IOException {
		Config config = Utils.getConfig();
		
		String url = String.format(Urls.GET_TOSCA_MODEL, config.getCatalogBeHost(), config.getCatalogBePort(),
				assetType.getValue(), uuid);
		
		Map<String, String> headersMap = new HashMap<>();
		headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
		headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
		headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
		
		HttpRequest http = new HttpRequest();

		logger.debug("Send GET request to get Resource Assets: {}", url);
		System.out.println("Send GET request to get Resource Assets: " + url);
		
		logger.debug("Request headers: {}", headersMap);
		System.out.println("Request headers: " + headersMap);

		RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);

		return sendGetResourceAssets;

	}

	public static RestResponse getComponentListByAssetType(boolean isBasicAuthentication, AssetTypeEnum assetType,
			String... filterArrayString) throws IOException {
		Config config = Utils.getConfig();
		Map<String, String> headersMap = new HashMap<>();
		headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), BaseRestUtils.contentTypeHeaderData);
		headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), BaseRestUtils.acceptHeaderData);
		if (isBasicAuthentication) {
			headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
		}
		headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);

		HttpRequest http = new HttpRequest();
			String url = String.format(Urls.GET_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
				assetType.getValue());
		if (filterArrayString != null && filterArrayString.length > 0) {
			url = buildUrlWithFilter(url, filterArrayString);
		}

		RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);

		return sendGetResourceAssets;
	}

	public static RestResponse getFilteredComponentList(AssetTypeEnum assetType, String query) throws IOException {
		Config config = Utils.getConfig();
		Map<String, String> headersMap = new HashMap<>();
		headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), BaseRestUtils.contentTypeHeaderData);
		headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), BaseRestUtils.acceptHeaderData);
		headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
		headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);

		HttpRequest http = new HttpRequest();

		String url = String.format(Urls.GET_FILTERED_ASSET_LIST, config.getCatalogBeHost(), config.getCatalogBePort(),
				assetType.getValue(), query);

		logger.debug("Send GET request to get Resource Assets: {}", url);
		logger.debug("Request headers: {}", headersMap);

		RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);

		return sendGetResourceAssets;
	}

	public static String buildUrlWithFilter(String url, String[] filterArrayString) {
		StringBuilder sb = new StringBuilder();
		int length = filterArrayString.length;
		int count = 0;
		for (String filterString : filterArrayString) {
			sb.append(filterString);
			count++;
			if (length != count) {
				sb.append("&");
			}
		}
		return url + "?" + sb;
	}

	public static RestResponse getAssetMetadataByAssetTypeAndUuid(boolean isBasicAuthentication,
			AssetTypeEnum assetType, String uuid) throws IOException {

		Config config = Utils.getConfig();
		Map<String, String> headersMap = new HashMap<>();
		headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), BaseRestUtils.contentTypeHeaderData);
		headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), BaseRestUtils.acceptHeaderData);
		if (isBasicAuthentication) {
			headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
		}
		headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);

		HttpRequest http = new HttpRequest();
		String url = String.format(Urls.GET_ASSET_METADATA, config.getCatalogBeHost(), config.getCatalogBePort(),
				assetType.getValue(), uuid);

		logger.debug("Send GET request to get Resource Assets: {}", url);
		logger.debug("Request headers: {}", headersMap);

		RestResponse sendGetResourceAssets = http.httpSendGet(url, headersMap);

		return sendGetResourceAssets;
	}

	public static List<ResourceAssetStructure> getResourceAssetList(RestResponse assetResponse) {
		List<ResourceAssetStructure> resourceAssetList = new ArrayList<>();

		JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
		JsonArray componenetArray = (JsonArray) jelement;
		for (JsonElement jElement : componenetArray) {
			ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
			resourceAssetList.add(resource);
		}
		return resourceAssetList;
	}

	public static ResourceDetailedAssetStructure getResourceAssetMetadata(RestResponse assetResponse) {

		List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
		List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
		ResourceDetailedAssetStructure resourceAssetMetadata = new ResourceDetailedAssetStructure();
		String response = assetResponse.getResponse();

		JsonObject jObject = (JsonObject) new JsonParser().parse(response);
		resourceAssetMetadata = gson.fromJson(jObject, ResourceDetailedAssetStructure.class);

		setResourceInstanceAssetList(resourcesList, jObject);
		resourceAssetMetadata.setResources(resourcesList);

		setArtifactAssetList(artifactsList, jObject);
		resourceAssetMetadata.setArtifacts(artifactsList);

		return resourceAssetMetadata;
	}

	public static void generalMetadataFieldsValidatior(AssetStructure assetMetadata, Component component) {

		assertTrue("Expected resourceUuid is " + component.getUUID() + " actual: " + assetMetadata.getUuid(),
				assetMetadata.getUuid().equals(component.getUUID()));
		assertTrue(
				"Expected resourceInvariantUuid is " + component.getInvariantUUID() + " actual: "
						+ assetMetadata.getInvariantUUID(),
				assetMetadata.getInvariantUUID().equals(component.getInvariantUUID()));
		assertTrue("Expected asset name is " + component.getName() + " actual: " + assetMetadata.getName(),
				assetMetadata.getName().equals(component.getName()));
		assertTrue("Expected asset version is " + component.getVersion() + " actual: " + assetMetadata.getVersion(),
				assetMetadata.getVersion().equals(component.getVersion()));
		assertTrue(
				"Expected asset lastUpdaterUserId is " + component.getLastUpdaterUserId() + " actual: "
						+ assetMetadata.getLastUpdaterUserId(),
				assetMetadata.getLastUpdaterUserId().equals(component.getLastUpdaterUserId()));
		assertNotNull("Expected asset toscaModel is null", assetMetadata.getToscaModelURL());
		assertTrue(
				"Expected asset category is " + component.getCategories().get(0).getName() + " actual: "
						+ assetMetadata.getCategory(),
				assetMetadata.getCategory().equals(component.getCategories().get(0).getName()));
		assertTrue(
				"Expected asset lifeCycleState is " + component.getLifecycleState() + " actual: "
						+ assetMetadata.getLifecycleState(),
				assetMetadata.getLifecycleState().equals(component.getLifecycleState().toString()));

	}

	public static void resourceMetadataValidatior(ResourceDetailedAssetStructure resourceAssetMetadata,
			Resource resource, AssetTypeEnum assetType) throws Exception {

		generalMetadataFieldsValidatior(resourceAssetMetadata, resource);
		assertTrue(
				"Expected asset lastUpdaterFullName is " + resource.getLastUpdaterFullName() + " actual: "
						+ resourceAssetMetadata.getLastUpdaterFullName(),
				resourceAssetMetadata.getLastUpdaterFullName().equals(resource.getLastUpdaterFullName()));
		assertTrue(
				"Expected asset subCategory is " + resource.getCategories().get(0).getSubcategories().get(0).getName()
						+ " actual: " + resourceAssetMetadata.getSubCategory(),
				resourceAssetMetadata.getSubCategory()
						.equals(resource.getCategories().get(0).getSubcategories().get(0).getName()));
		assertTrue(
				"Expected asset toscaResourceName is " + resource.getToscaResourceName() + " actual: "
						+ resourceAssetMetadata.getToscaResourceName(),
				resourceAssetMetadata.getToscaResourceName().equals(resource.getToscaResourceName()));
		assertTrue(
				"Expected asset resourceType is " + resource.getResourceType() + " actual: "
						+ resourceAssetMetadata.getResourceType(),
				resourceAssetMetadata.getResourceType().equals(resource.getResourceType().toString()));
		resourceInstanceAssetValidator(resourceAssetMetadata.getResources(), resource, assetType);
		// resourceInstanceAssetValidator(resourceAssetMetadata.getResources(),
		// resource);
		artifactAssetValidator(resourceAssetMetadata.getArtifacts(), resource, assetType);

	}

	public static void serviceMetadataValidatior(ServiceDetailedAssetStructure serviceAssetMetadata, Service service,
			AssetTypeEnum assetType) throws Exception {

		generalMetadataFieldsValidatior(serviceAssetMetadata, service);
		assertTrue(
				"Expected asset lastUpdaterFullName is " + service.getLastUpdaterFullName() + " actual: "
						+ serviceAssetMetadata.getLastUpdaterFullName(),
				serviceAssetMetadata.getLastUpdaterFullName().equals(service.getLastUpdaterFullName()));
		assertTrue("Expected asset distributionStatus is " + service.getDistributionStatus() + " actual: "
						+ serviceAssetMetadata.getDistributionStatus(),
				serviceAssetMetadata.getDistributionStatus().equals(service.getDistributionStatus().toString()));
		resourceInstanceAssetValidator(serviceAssetMetadata.getResources(), service, assetType);
		// resourceInstanceAssetValidator(serviceAssetMetadata.getResources(),
		// service);
		artifactAssetValidator(serviceAssetMetadata.getArtifacts(), service, assetType);

	}

	private static void artifactAssetValidator(List<ArtifactAssetStructure> artifactAssetStructureList,
			Component component, AssetTypeEnum assetType) {
		Map<String, ArtifactDefinition> componentDeploymentArtifacts = component.getDeploymentArtifacts();
		validateArtifactMetadata(componentDeploymentArtifacts, artifactAssetStructureList, component.getUUID(),
				assetType, null);
	}

	private static void validateArtifactMetadata(Map<String, ArtifactDefinition> componentDeploymentArtifacts,
			List<ArtifactAssetStructure> artifactAssetStructureList, String componentUuid, AssetTypeEnum assetType,
			String resourceInstanceName) {
		if(componentDeploymentArtifacts != null){
			for (Entry<String, ArtifactDefinition> componentDeploymentArtifact : componentDeploymentArtifacts.entrySet()) {
				ArtifactAssetStructure artifactAssetStructure = getArtifactMetadata(artifactAssetStructureList,
						componentDeploymentArtifact.getValue().getArtifactUUID());
				ArtifactDefinition componentDeploymentArtifactValue = componentDeploymentArtifact.getValue();
				if (artifactAssetStructure != null) {
					assertTrue(
							"Expected artifact asset artifactName is " + componentDeploymentArtifactValue.getArtifactName()
									+ " actual: " + artifactAssetStructure.getArtifactName(),
							componentDeploymentArtifactValue.getArtifactName()
									.equals(artifactAssetStructure.getArtifactName()));
					assertTrue(
							"Expected artifact asset Type is " + componentDeploymentArtifactValue.getArtifactType()
									+ " actual: " + artifactAssetStructure.getArtifactType(),
							componentDeploymentArtifactValue.getArtifactType()
									.equals(artifactAssetStructure.getArtifactType()));
					// assertNotNull("Expected artifact asset resourceInvariantUUID
					// is null",
					// resourceInstanceAssetStructure.getResourceInvariantUUID());
					// String expectedArtifactUrl = "/sdc/v1/catalog/" +
					// assetType.getValue() + "/" + componentUuid + "/artifacts/" +
					// componentDeploymentArtifactValue.getArtifactUUID();
					String expectedArtifactUrl = "";
					if (resourceInstanceName == null) {
						expectedArtifactUrl = String.format(COMPONENT_ARTIFACT_URL, assetType.getValue(), componentUuid,
								componentDeploymentArtifactValue.getArtifactUUID());
					} else {
						expectedArtifactUrl = String.format(RESOURCE_INSTANCE_ARTIFACT_URL, assetType.getValue(),
								componentUuid, resourceInstanceName, componentDeploymentArtifactValue.getArtifactUUID());
					}
	
					assertTrue(
							"Expected artifact asset URL is " + expectedArtifactUrl + " actual: "
									+ artifactAssetStructure.getArtifactURL(),
							artifactAssetStructure.getArtifactURL().equals(expectedArtifactUrl));
					assertTrue(
							"Expected artifact asset description is " + componentDeploymentArtifactValue.getDescription()
									+ " actual: " + artifactAssetStructure.getArtifactDescription(),
							componentDeploymentArtifactValue.getDescription().toString()
									.equals(artifactAssetStructure.getArtifactDescription()));
					assertTrue(
							"Expected artifact asset checkSum is " + componentDeploymentArtifactValue.getArtifactChecksum()
									+ " actual: " + artifactAssetStructure.getArtifactChecksum(),
							componentDeploymentArtifactValue.getArtifactChecksum()
									.equals(artifactAssetStructure.getArtifactChecksum()));
					assertTrue(
							"Expected artifact asset version is " + componentDeploymentArtifactValue.getArtifactVersion()
									+ " actual: " + artifactAssetStructure.getArtifactVersion(),
							componentDeploymentArtifactValue.getArtifactVersion()
									.equals(artifactAssetStructure.getArtifactVersion()));
					if (componentDeploymentArtifactValue.getTimeout() > 0) {
						assertTrue(
								"Expected artifact asset timeout is " + componentDeploymentArtifactValue.getTimeout()
										+ " actual: " + artifactAssetStructure.getArtifactTimeout(),
								componentDeploymentArtifactValue.getTimeout()
										.equals(artifactAssetStructure.getArtifactTimeout()));
					}
	
				} else {
					assertTrue("artifact asset with UUID" + componentDeploymentArtifact.getValue().getArtifactUUID()
							+ " not found in get Metadata response", false);
				}
			}
		}else{
			System.out.println("componentDeploymentArtifacts is null");
			logger.debug("componentDeploymentArtifacts is null");
		}

	}

	private static ArtifactAssetStructure getArtifactMetadata(List<ArtifactAssetStructure> artifactAssetStructureList,
			String artifactUUID) {
		for (ArtifactAssetStructure artifactAssetStructure : artifactAssetStructureList) {
			if (artifactAssetStructure.getArtifactUUID().equals(artifactUUID)) {
				return artifactAssetStructure;
			}
		}
		return null;
	}

	private static void resourceInstanceAssetValidator(
			List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, Component component,
			AssetTypeEnum assetType) throws Exception {

		List<ComponentInstance> componentInstances = component.getComponentInstances();
		if (componentInstances != null) {
			for (ComponentInstance componentInstance : componentInstances) {
				ResourceInstanceAssetStructure resourceInstanceAssetStructure = getResourceInstanceMetadata(
						resourceInstanceAssetStructures, componentInstance.getName());
				if (resourceInstanceAssetStructure != null) {
					assertTrue(
							"Expected RI asset resourceName is " + componentInstance.getComponentName() + " actual: "
									+ resourceInstanceAssetStructure.getResourceName(),
							componentInstance.getComponentName()
									.equals(resourceInstanceAssetStructure.getResourceName()));
					assertTrue(
							"Expected RI asset Name is " + componentInstance.getName() + " actual: "
									+ resourceInstanceAssetStructure.getResourceInstanceName(),
							componentInstance.getName()
									.equals(resourceInstanceAssetStructure.getResourceInstanceName()));
					assertNotNull("Expected RI asset resourceInvariantUUID is null",
							resourceInstanceAssetStructure.getResourceInvariantUUID());
					assertTrue(
							"Expected RI asset resourceVersion is " + componentInstance.getComponentVersion()
									+ " actual: " + resourceInstanceAssetStructure.getResourceVersion(),
							componentInstance.getComponentVersion()
									.equals(resourceInstanceAssetStructure.getResourceVersion()));
					assertTrue(
							"Expected RI asset resourceType is " + componentInstance.getOriginType() + " actual: "
									+ resourceInstanceAssetStructure.getResoucreType(),
							componentInstance.getOriginType().toString()
									.equals(resourceInstanceAssetStructure.getResoucreType()));
					Resource resource = AtomicOperationUtils.getResourceObject(componentInstance.getComponentUid());
					assertTrue("Expected RI asset resourceUUID is " + resource.getUUID() + " actual: " + resourceInstanceAssetStructure.getResourceUUID(),
							resource.getUUID().equals(resourceInstanceAssetStructure.getResourceUUID()));
					validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
							resourceInstanceAssetStructure.getArtifacts(), component.getUUID(), assetType,
							componentInstance.getNormalizedName());
					// validateArtifactMetadata(componentInstance.getDeploymentArtifacts(),
					// resourceInstanceAssetStructure.getArtifacts(),
					// component.getUUID(), AssetTypeEnum.RESOURCES);
				} else {
					assertTrue("resourceInstance asset with UUID" + componentInstance.getComponentUid()
							+ " not found in get Metadata response", false);
				}
			}
		}

	}

	// private static ResourceInstanceAssetStructure
	// getResourceInstanceMetadata(List<ResourceInstanceAssetStructure>
	// resourceInstanceAssetStructures, String componentUid) {
	private static ResourceInstanceAssetStructure getResourceInstanceMetadata(
			List<ResourceInstanceAssetStructure> resourceInstanceAssetStructures, String name) {
		for (ResourceInstanceAssetStructure resourceInstanceAssetStructure : resourceInstanceAssetStructures) {
			if (resourceInstanceAssetStructure.getResourceInstanceName().equals(name)) {
				return resourceInstanceAssetStructure;
			}
		}
		return null;
	}

	public static ServiceDetailedAssetStructure getServiceAssetMetadata(RestResponse assetResponse) {

		List<ResourceInstanceAssetStructure> resourcesList = new ArrayList<>();
		List<ArtifactAssetStructure> artifactsList = new ArrayList<>();
		ServiceDetailedAssetStructure serviceAssetMetadata;

		JsonObject jObject = (JsonObject) new JsonParser().parse(assetResponse.getResponse());
		serviceAssetMetadata = gson.fromJson(jObject, ServiceDetailedAssetStructure.class);

		setResourceInstanceAssetList(resourcesList, jObject);
		serviceAssetMetadata.setResources(resourcesList);

		setArtifactAssetList(artifactsList, jObject);
		serviceAssetMetadata.setArtifacts(artifactsList);

		return serviceAssetMetadata;
	}

	public static void setArtifactAssetList(List<ArtifactAssetStructure> artifactsList, JsonObject jObject) {
		JsonArray artifactsArray = jObject.getAsJsonArray("artifacts");
		if (artifactsArray != null) {
			for (JsonElement jElement : artifactsArray) {
				ArtifactAssetStructure artifact = gson.fromJson(jElement, ArtifactAssetStructure.class);
				artifactsList.add(artifact);
			}
		}
	}

	public static void setResourceInstanceAssetList(List<ResourceInstanceAssetStructure> resourcesList,
			JsonObject jObject) {
		JsonArray resourcesArray = jObject.getAsJsonArray("resources");
		if (resourcesArray != null) {
			for (JsonElement jElement : resourcesArray) {
				ResourceInstanceAssetStructure resource = gson.fromJson(jElement, ResourceInstanceAssetStructure.class);
				resourcesList.add(resource);
			}
		}
	}

	public static List<ServiceAssetStructure> getServiceAssetList(RestResponse assetResponse) {
		List<ServiceAssetStructure> serviceAssetList = new ArrayList<>();

		JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
		JsonArray componenetArray = (JsonArray) jelement;
		for (JsonElement jElement : componenetArray) {
			ServiceAssetStructure service = gson.fromJson(jElement, ServiceAssetStructure.class);
			serviceAssetList.add(service);
		}
		return serviceAssetList;
	}

	public static List<String> getResourceNamesList(List<ResourceAssetStructure> resourceAssetList) {
		List<String> assetNamesList = new ArrayList<>();
		for (ResourceAssetStructure resourceAsset : resourceAssetList) {
			assetNamesList.add(resourceAsset.getName());
		}
		return assetNamesList;
	}
	
	public static Map<String,String> getResourceAssetMap(RestResponse assetResponse) {
		Map<String,String> resourceAssetMap =  new HashMap<>();

		JsonElement jelement = new JsonParser().parse(assetResponse.getResponse());
		JsonArray componenetArray = (JsonArray) jelement;
		for (JsonElement jElement : componenetArray) {
			ResourceAssetStructure resource = gson.fromJson(jElement, ResourceAssetStructure.class);
			resourceAssetMap.put(resource.getName(), resource.getVersion());
		}
		return resourceAssetMap;
	}
	
	public static Map<String,String> getResourceListFiltteredByWholeVersion(Map<String,String> resourceAssetList) {
		Map<String,String> assetNamesMap = new HashMap<>();
			for (Entry<String, String> entry : resourceAssetList.entrySet()) {
			    String key = entry.getKey();
			    String[] parts = entry.getValue().split("\\.");
			    String lastOne = parts[parts.length-1];
			    
			    if (key.contains("CinderVolume") ){
			    	assetNamesMap.put(key,entry.getValue());
			    }
			    
			    if (lastOne.equals("0") && !key.contains("Ci") ){
			    	assetNamesMap.put(key,entry.getValue());
			    }
			}
			
		return assetNamesMap;
	}

	public static List<String> getResourceObjectByNameAndVersionToscaNamesList(Map<String,String> resourceAssetList) throws Exception {
		List<String> assetNamesList = new ArrayList<>();
		for (Entry<String, String> entry : resourceAssetList.entrySet()) {
			System.out.println("fetch data---->"+entry.getKey()+entry.getValue());
			Resource resourceObjectByNameAndVersion = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, entry.getKey(), entry.getValue());
		    	assetNamesList.add(resourceObjectByNameAndVersion.getToscaResourceName());
		    
		}
		
		return assetNamesList;
	}
	

	public static List<String> getServiceNamesList(List<ServiceAssetStructure> serviceAssetList) {
		List<String> assetNamesList = new ArrayList<>();
		for (ServiceAssetStructure serviceAsset : serviceAssetList) {
			assetNamesList.add(serviceAsset.getName());
		}
		return assetNamesList;
	}

	public static void checkResourceTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ResourceTypeEnum resourceType) {
		for (ResourceAssetStructure resourceAsset : resourceAssetList) {
			assertTrue("Expected resourceType is " + resourceType.toString() + " actual: " + resourceAsset.getResourceType(),
					resourceAsset.getResourceType().equals(resourceType.toString()));
		}
	}

	public static void checkComponentTypeInObjectList(List<ResourceAssetStructure> resourceAssetList, ComponentTypeEnum componentType) {
		ComponentTypeEnum actualComponentType;
		for (ResourceAssetStructure resourceAsset : resourceAssetList) {
			actualComponentType = detectComponentType(resourceAsset);
			assertTrue("Expected componentType is " + componentType.getValue() + " actual: " + actualComponentType.getValue(), actualComponentType.equals(componentType));
		}
	}

	private static ComponentTypeEnum detectComponentType(ResourceAssetStructure resourceAsset) {
		String resourceType = resourceAsset.getResourceType();
		if(ResourceTypeEnum.getType(resourceType) !=null){
			return ComponentTypeEnum.RESOURCE;
		}
		return null;
	}
	
}