summaryrefslogtreecommitdiffstats
path: root/asdc-tests/src/main/java/org/openecomp/sdc/ci/tests/execute/devCI/CRUDExternalAPI.java
blob: 418e8f6dc85b8595a2a0a9db167153578f99f6e3 (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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
/*-
 * ============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.execute.devCI;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
import org.openecomp.sdc.ci.tests.config.Config;
import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ResourceDetailedAssetStructure;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedExternalAudit;
import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.AssetRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import fj.data.Either;

public class CRUDExternalAPI extends ComponentBaseTest {

	private static Logger log = LoggerFactory.getLogger(CRUDExternalAPI.class.getName());
	protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
	protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";

	protected Config config = Config.instance();
	protected String contentTypeHeaderData = "application/json";
	protected String acceptHeaderDate = "application/json";

	protected Gson gson = new Gson();
	protected JSONParser jsonParser = new JSONParser();

	protected String serviceVersion;
	protected ResourceReqDetails resourceDetails;
	protected User sdncUserDetails;
	protected ServiceReqDetails serviceDetails;

	@BeforeMethod
	public void init() throws Exception {
		AtomicOperationUtils.createDefaultConsumer(true);
	}

	@Rule
	public static TestName name = new TestName();

	public CRUDExternalAPI() {
		super(name, CRUDExternalAPI.class.getName());

	}

	@DataProvider(name = "uploadArtifactOnVFViaExternalAPI")
	public static Object[][] dataProviderUploadArtifactOnVFViaExternalAPI() {
		return new Object[][] { { LifeCycleStatesEnum.CHECKIN, "DCAE_JSON" },
				{ LifeCycleStatesEnum.CHECKOUT, "DCAE_POLICY" }, { LifeCycleStatesEnum.CHECKOUT, "DCAE_EVENT" },
				{ LifeCycleStatesEnum.CHECKOUT, "APPC_CONFIG" }, { LifeCycleStatesEnum.CHECKOUT, "DCAE_DOC" },
				{ LifeCycleStatesEnum.CHECKOUT, "DCAE_TOSCA" }, { LifeCycleStatesEnum.CHECKOUT, "YANG_XML" },
				{ LifeCycleStatesEnum.CHECKOUT, "VNF_CATALOG" }, { LifeCycleStatesEnum.CHECKOUT, "VF_LICENSE" },
				{ LifeCycleStatesEnum.CHECKOUT, "VENDOR_LICENSE" },
				{ LifeCycleStatesEnum.CHECKOUT, "MODEL_INVENTORY_PROFILE" },
				{ LifeCycleStatesEnum.CHECKOUT, "MODEL_QUERY_SPEC" }, { LifeCycleStatesEnum.CHECKOUT, "OTHER" } };
	}

	// External API
	// Upload artifact on VF via external API - happy flow
	@Test(dataProvider = "uploadArtifactOnVFViaExternalAPI")
	public void uploadArtifactOnVFViaExternalAPI(LifeCycleStatesEnum chosenLifeCycleState, String artifactType)
			throws Exception {
		// Method passed variable
		// artifactType = "YANG_XML";
		// chosenLifeCycleState = LifeCycleStatesEnum.CHECKOUT;

		// String operationType = "Upload";
		UserRoleEnum creatorUser = UserRoleEnum.DESIGNER;
		String specificUser = "DESIGNER";

		Component resourceDetails = getComponentInTargetLifeCycleState("vf", creatorUser, chosenLifeCycleState);

		String resourceUUID = resourceDetails.getUUID();
		System.out.println("Resource UUID: " + resourceUUID);

		// get artifact data
		ArtifactReqDetails artifactReqDetails = ElementFactory.getArtifactByType("Abcd", artifactType, true);

		RestResponse restResponse = ArtifactRestUtils.externalAPIUploadArtifactOfTheAsset(resourceDetails,
				ElementFactory.getDefaultUser(UserRoleEnum.valueOf(specificUser.toUpperCase())), artifactReqDetails);

		Integer responseCode = restResponse.getErrorCode();
		Integer expectedCode = 200;
		Assert.assertEquals(responseCode, expectedCode, "Response code is not correct.");

		// ArtifactDefinition artifactJavaObject =
		// ResponseParser.convertArtifactDefinitionResponseToJavaObject(restResponse.getResponse());
		// AuditingActionEnum action =
		// AuditingActionEnum.ARTIFACT_UPLOAD_BY_API;
		// ExpectedExternalAudit expectedExternalAudit =
		// ElementFactory.getDefaultExternalArtifactAuditSuccess(AssetTypeEnum.RESOURCES,
		// action, artifactJavaObject, resourceUUID);
		// AuditValidationUtils.validateExternalAudit(expectedExternalAudit,
		// AuditingActionEnum.ARTIFACT_UPLOAD_BY_API.getName(), null);
	}

	@DataProvider(name = "uploadArtifactOnServiceViaExternalAPI")
	public static Object[][] dataProviderUploadArtifactOnServiceViaExternalAPI() {
		return new Object[][] {
				// {LifeCycleStatesEnum.CHECKOUT, "YANG_XML"},
				// {LifeCycleStatesEnum.CHECKOUT, "VNF_CATALOG"},
				// {LifeCycleStatesEnum.CHECKOUT, "MODEL_INVENTORY_PROFILE"},
				// {LifeCycleStatesEnum.CHECKOUT, "MODEL_QUERY_SPEC"},
				// {LifeCycleStatesEnum.CHECKOUT, "OTHER"},
				{ LifeCycleStatesEnum.CHECKIN, "YANG_XML" }, { LifeCycleStatesEnum.CHECKIN, "VNF_CATALOG" },
				{ LifeCycleStatesEnum.CHECKIN, "MODEL_INVENTORY_PROFILE" },
				{ LifeCycleStatesEnum.CHECKIN, "MODEL_QUERY_SPEC" }, { LifeCycleStatesEnum.CHECKIN, "OTHER" },
				{ LifeCycleStatesEnum.CERTIFICATIONREQUEST, "YANG_XML" },
				{ LifeCycleStatesEnum.CERTIFICATIONREQUEST, "VNF_CATALOG" },
				{ LifeCycleStatesEnum.CERTIFICATIONREQUEST, "MODEL_INVENTORY_PROFILE" },
				{ LifeCycleStatesEnum.CERTIFICATIONREQUEST, "MODEL_QUERY_SPEC" },
				{ LifeCycleStatesEnum.CERTIFICATIONREQUEST, "OTHER" } };
	}

	@Test(dataProvider = "uploadArtifactOnServiceViaExternalAPI")
	public void uploadArtifactOnServiceViaExternalAPI(LifeCycleStatesEnum chosenLifeCycleState, String artifactType)
			throws Exception {
		Component resourceDetails = getComponentInTargetLifeCycleState("service", UserRoleEnum.DESIGNER,
				chosenLifeCycleState);
		double resourceVersion = Double.parseDouble(resourceDetails.getVersion());

		// get artifact data
		ArtifactReqDetails artifactReqDetails = ElementFactory.getArtifactByType("Abcd", artifactType, true);

		System.out.println("Service UUID: " + resourceDetails.getUUID());
		System.out.println("Service Version: " + resourceVersion);
		System.out.println("Service life cycle state: " + chosenLifeCycleState);
		System.out.println("Artifact Type: " + artifactReqDetails.getArtifactType());

		RestResponse restResponse = ArtifactRestUtils.externalAPIUploadArtifactOfTheAsset(resourceDetails,
				ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), artifactReqDetails);

		// Check response of external API
		Integer responseCode = restResponse.getErrorCode();
		Integer expectedCode = 200;
		Assert.assertEquals(responseCode, expectedCode, "Response code is not correct.");

		// TODO: Check auditing for upload opeartion
		// ArtifactDefinition artifactJavaObject =
		// ResponseParser.convertArtifactDefinitionResponseToJavaObject(restResponse.getResponse());
		// AuditingActionEnum action =
		// AuditingActionEnum.ARTIFACT_UPLOAD_BY_API;
		// ExpectedExternalAudit expectedExternalAudit =
		// ElementFactory.getDefaultExternalArtifactAuditSuccess(AssetTypeEnum.RESOURCES,
		// action, artifactJavaObject, resourceUUID);
		// AuditValidationUtils.validateExternalAudit(expectedExternalAudit,
		// AuditingActionEnum.ARTIFACT_UPLOAD_BY_API.getName(), null);

		// Check Service version (increase by one if not in checkout)
		if (!chosenLifeCycleState.equals(LifeCycleStatesEnum.CHECKOUT)) {
			double resourceNewVersion = Double.parseDouble(resourceDetails.getVersion());

			System.out.println(resourceVersion);
			System.out.println(resourceNewVersion);
		}
	}

	@Test
	public void artifactOperationOnRIViaExternalAPI() throws Exception {
		// Method passed variable
		String operationType = "Upload";
		LifeCycleStatesEnum chosenLifeCycleState = LifeCycleStatesEnum.CHECKOUT;
		UserRoleEnum creatorUser = UserRoleEnum.DESIGNER;
		String specificUser = "DESIGNER";
		String artifactType = "OTHER";

		Component resourceDetails = getComponentInTargetLifeCycleState("service", creatorUser, chosenLifeCycleState);
		Component resourceInstanceDetails = getComponentInTargetLifeCycleState("vf", creatorUser, chosenLifeCycleState);
		ComponentInstance componentResourceInstanceDetails = AtomicOperationUtils
				.addComponentInstanceToComponentContainer(resourceInstanceDetails, resourceDetails,
						UserRoleEnum.DESIGNER, true)
				.left().value();

		String resourceUUID = resourceDetails.getUUID();
		System.out.println("Resource UUID: " + resourceUUID);

		// get artifact data
		ArtifactReqDetails artifactReqDetails = ElementFactory.getArtifactByType("Abcd", artifactType, true);

		RestResponse restResponse = null;

		if (operationType.toLowerCase().equals("upload")) {
			restResponse = ArtifactRestUtils.externalAPIUploadArtifactOfTheAsset(resourceDetails,
					ElementFactory.getDefaultUser(UserRoleEnum.valueOf(specificUser.toUpperCase())),
					artifactReqDetails);
			System.out.println("1234");
		}

		ArtifactDefinition artifactJavaObject = ResponseParser
				.convertArtifactDefinitionResponseToJavaObject(restResponse.getResponse());
		AuditingActionEnum action = AuditingActionEnum.ARTIFACT_UPLOAD_BY_API;
		ExpectedExternalAudit expectedExternalAudit = ElementFactory.getDefaultExternalArtifactAuditSuccess(
				AssetTypeEnum.RESOURCES, action, artifactJavaObject, resourceUUID);
		AuditValidationUtils.validateExternalAudit(expectedExternalAudit,
				AuditingActionEnum.ARTIFACT_UPLOAD_BY_API.getName(), null);
	}

	// @Test
	// public void artifactViaExternalAPI() throws Exception {
	// // Method passed variable
	// String operationType = "Upload";
	// String assetType = "vf";
	// LifeCycleStatesEnum chosenLifeCycleState = LifeCycleStatesEnum.CHECKOUT;
	// String componentInstanceAssetType = "vf";
	// LifeCycleStatesEnum componentInstanceChosenLifeCycleState =
	// LifeCycleStatesEnum.CHECKOUT;
	// UserRoleEnum creatorUser = UserRoleEnum.DESIGNER;
	// String specificUser = "DESIGNER";
	// String artifactType = "HEAT";
	//
	//
	// Component resourceDetails = null;
	// Component resourceInstanceDetails = null;
	// ComponentInstance componentResourceInstanceDetails = null;
	//
	// String resourceUUID = null;
	// String resourceType = null;
	// String resourceInstanceName = null;
	//
	// // Create resource & resource instance of requested type and state
	// if (assetType.toLowerCase().equals("vf")) {
	// resourceDetails = getComponentInTargetLifeCycleState("vf", creatorUser,
	// chosenLifeCycleState);
	// } else if (assetType.toLowerCase().equals("service")) {
	// resourceDetails = getComponentInTargetLifeCycleState("service",
	// creatorUser, chosenLifeCycleState);
	// } else if (assetType.toLowerCase().equals("ri")) {
	// resourceInstanceDetails = getComponentInTargetLifeCycleState("vf",
	// creatorUser, chosenLifeCycleState);
	// if(componentInstanceAssetType.toLowerCase().equals("vf")) {
	// resourceDetails = getComponentInTargetLifeCycleState("vf", creatorUser,
	// componentInstanceChosenLifeCycleState);
	// componentResourceInstanceDetails =
	// AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceInstanceDetails,
	// resourceDetails, UserRoleEnum.DESIGNER, true).left().value();
	// } else if (componentInstanceAssetType.toLowerCase().equals("service")) {
	// resourceDetails = getComponentInTargetLifeCycleState("service",
	// creatorUser, componentInstanceChosenLifeCycleState);
	// componentResourceInstanceDetails =
	// AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceInstanceDetails,
	// resourceDetails, UserRoleEnum.DESIGNER, true).left().value();
	// } else {
	// Assert.assertEquals(false, true, "Component instance asset type is
	// wrong.");
	// }
	// } else {
	// Assert.assertEquals(false, true, "Asset type is wrong.");
	// }
	//
	//
	// // print uuid & resource instance name
	// if (assetType.toLowerCase().equals("ri")) {
	// resourceUUID = resourceDetails.getUUID();
	// resourceInstanceName =
	// componentResourceInstanceDetails.getNormalizedName();
	//
	//
	// System.out.println("Resource UUID: " + resourceUUID);
	// System.out.println("Resource instance name: " + resourceInstanceName);
	// System.out.println("Resource type: " + resourceType);
	// } else {
	// resourceUUID = resourceDetails.getUUID();
	//
	// System.out.println("Resource UUID: " + resourceUUID);
	// System.out.println("Resource type: " + resourceType);
	// }
	//
	// // get artifact data
	// ArtifactReqDetails artifactReqDetails =
	// ElementFactory.getArtifactByType("Abcd", artifactType, true);
	//
	//// RestResponse restResponse;
	// // using rest external api
	//// if(operationType.toLowerCase().equals("upload")) {
	//// if (!assetType.toLowerCase().equals("ri")) {
	// RestResponse restResponse =
	// ArtifactRestUtils.externalAPIUploadArtifactOfTheAsset(resourceDetails,
	// ElementFactory.getDefaultUser(UserRoleEnum.valueOf(specificUser.toUpperCase())),
	// artifactReqDetails);
	// System.out.println("1234");
	//// } else {
	////
	//// }
	//// } else {
	////
	//// }
	//
	// ArtifactDefinition artifactJavaObject =
	// ResponseParser.convertArtifactDefinitionResponseToJavaObject(restResponse.getResponse());
	//// AuditingActionEnum action = AuditingActionEnum.ARTIFACT_UPLOAD_BY_API;
	// AuditingActionEnum action = AuditingActionEnum.ARTIFACT_UPLOAD_BY_API;
	// ExpectedExternalAudit expectedExternalAudit =
	// ElementFactory.getDefaultExternalArtifactAuditSuccess(AssetTypeEnum.RESOURCES,
	// action, artifactJavaObject, resourceUUID);
	// AuditValidationUtils.validateExternalAudit(expectedExternalAudit,
	// AuditingActionEnum.ARTIFACT_UPLOAD_BY_API.getName(), null);
	//
	//
	//
	//
	// }
	//

	@Test
	public void getResourceAssetMetadataWithNonCertifiedResourceInstancesAndArtifactsSuccess() throws Exception {

		Resource resourceVF = AtomicOperationUtils
				.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
		Resource resource2 = AtomicOperationUtils
				.createResourceByType(ResourceTypeEnum.VFC, UserRoleEnum.DESIGNER, true).left().value();
		resource2 = (Resource) AtomicOperationUtils
				.changeComponentState(resource2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
		Resource resource3 = AtomicOperationUtils
				.createResourceByType(ResourceTypeEnum.VFC, UserRoleEnum.DESIGNER, true).left().value();
		resource3 = (Resource) AtomicOperationUtils
				.changeComponentState(resource3, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFICATIONREQUEST, true)
				.getLeft();

		AtomicOperationUtils.addComponentInstanceToComponentContainer(resource2, resourceVF, UserRoleEnum.DESIGNER,
				true);
		AtomicOperationUtils.addComponentInstanceToComponentContainer(resource3, resourceVF, UserRoleEnum.DESIGNER,
				true);
		// TODO
		Either<ArtifactDefinition, RestResponse> artifactDefinition = AtomicOperationUtils
				.uploadArtifactByType(ArtifactTypeEnum.VENDOR_LICENSE, resourceVF, UserRoleEnum.DESIGNER, true, true);
		AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.APPC_CONFIG, resourceVF, UserRoleEnum.DESIGNER, true,
				true);
		resourceVF = ResponseParser.parseToObjectUsingMapper(
				ResourceRestUtils.getResource(resourceVF.getUniqueId()).getResponse(), Resource.class);

		RestResponse assetResponse = AssetRestUtils.getAssetMetadataByAssetTypeAndUuid(true, AssetTypeEnum.RESOURCES,
				resourceVF.getUUID());
		BaseRestUtils.checkSuccess(assetResponse);

		ResourceDetailedAssetStructure resourceAssetMetadata = AssetRestUtils.getResourceAssetMetadata(assetResponse);
		AssetRestUtils.resourceMetadataValidatior(resourceAssetMetadata, resourceVF, AssetTypeEnum.RESOURCES);

		// Validate audit message
		ExpectedExternalAudit expectedAssetListAudit = ElementFactory
				.getDefaultAssetMetadataAudit(AssetTypeEnum.RESOURCES, resourceVF);
		// AuditValidationUtils.validateAudit(expectedAssetListAudit,
		// AuditingActionEnum.GET_ASSET_METADATA.getName(), null);

	}

	public Component getComponentInTargetLifeCycleState(String componentType, UserRoleEnum creatorUser,
			LifeCycleStatesEnum targetLifeCycleState) throws Exception {
		Component resourceDetails = null;

		if (componentType.toLowerCase().equals("vf")) {
			Either<Resource, RestResponse> createdResource = AtomicOperationUtils
					.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT,
							ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, creatorUser, true);
			resourceDetails = createdResource.left().value();
			resourceDetails = AtomicOperationUtils
					.changeComponentState(resourceDetails, creatorUser, targetLifeCycleState, true).getLeft();
		} else {
			Either<Service, RestResponse> createdResource = AtomicOperationUtils.createDefaultService(creatorUser,
					true);
			resourceDetails = createdResource.left().value();
			resourceDetails = AtomicOperationUtils
					.changeComponentState(resourceDetails, creatorUser, targetLifeCycleState, true).getLeft();
		}

		return resourceDetails;
	}

	// // External API - Download artifact for resource - negative test
	// @Test
	// public void k() throws Exception {
	// Resource resourceDetailsVF;
	// Either<Resource, RestResponse> createdResource =
	// AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF,
	// NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE,
	// UserRoleEnum.DESIGNER, true);
	// resourceDetailsVF = createdResource.left().value();
	// ArtifactDefinition heatArtifact =
	// AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT,
	// resourceDetailsVF, UserRoleEnum.DESIGNER, true, true).left().value();
	// resourceDetails = new ResourceReqDetails(resourceDetailsVF);
	//
	// String resourceUUID = resourceDetailsVF.getUUID();
	// String artifactUUID = heatArtifact.getArtifactUUID();
	//
	// System.out.println("Resource UUID: " + resourceUUID);
	// System.out.println("Artifact UUID: " + artifactUUID);
	//
	// RestResponse restResponse =
	// ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID,
	// "dfsgfdsg324", ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER),
	// "Resource");
	//
	// Integer responseCode = restResponse.getErrorCode();
	// Integer expectedCode = 200;
	// Assert.assertEquals(responseCode,expectedCode, "Response code is not
	// correct.");
	// }
	//
	//
	//
	//
	//
	// // External API - Download artifact for service - negative test
	// @Test
	// public void downloadArtifactFromServiceViaExternalAPI() throws Exception
	// {
	//
	// Service resourceDetailsService;
	// Either<Service, RestResponse> createdResource =
	// AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
	// resourceDetailsService = createdResource.left().value();
	//
	// ArtifactDefinition heatArtifact =
	// AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.OTHER,
	// resourceDetailsService, UserRoleEnum.DESIGNER, true,
	// true).left().value();
	//
	// String resourceUUID = resourceDetailsService.getUUID();
	// String artifactUUID = heatArtifact.getArtifactUUID();
	//
	// System.out.println("Resource UUID: " + resourceUUID);
	// System.out.println("Artifact UUID: " + artifactUUID);
	//
	// RestResponse restResponse =
	// ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID,
	// artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER),
	// "Service");
	//
	// Integer responseCode = restResponse.getErrorCode();
	// Integer expectedCode = 200;
	// Assert.assertEquals(responseCode,expectedCode, "Response code is not
	// correct.");
	//
	// String response = restResponse.getResponse();
	//
	// String payloadData =
	// "aGVhdF90ZW1wbGF0ZV92ZXJzaW9uOiAyMDEzLTA1LTIzDQoNCmRlc2NyaXB0aW9uOiBTaW1wbGUgdGVtcGxhdGUgdG8gZGVwbG95IGEgc3RhY2sgd2l0aCB0d28gdmlydHVhbCBtYWNoaW5lIGluc3RhbmNlcw0KDQpwYXJhbWV0ZXJzOg0KICBpbWFnZV9uYW1lXzE6DQogICAgdHlwZTogc3RyaW5nDQogICAgbGFiZWw6IEltYWdlIE5hbWUNCiAgICBkZXNjcmlwdGlvbjogU0NPSU1BR0UgU3BlY2lmeSBhbiBpbWFnZSBuYW1lIGZvciBpbnN0YW5jZTENCiAgICBkZWZhdWx0OiBjaXJyb3MtMC4zLjEteDg2XzY0DQogIGltYWdlX25hbWVfMjoNCiAgICB0eXBlOiBzdHJpbmcNCiAgICBsYWJlbDogSW1hZ2UgTmFtZQ0KICAgIGRlc2NyaXB0aW9uOiBTQ09JTUFHRSBTcGVjaWZ5IGFuIGltYWdlIG5hbWUgZm9yIGluc3RhbmNlMg0KICAgIGRlZmF1bHQ6IGNpcnJvcy0wLjMuMS14ODZfNjQNCiAgbmV0d29ya19pZDoNCiAgICB0eXBlOiBzdHJpbmcNCiAgICBsYWJlbDogTmV0d29yayBJRA0KICAgIGRlc2NyaXB0aW9uOiBTQ09ORVRXT1JLIE5ldHdvcmsgdG8gYmUgdXNlZCBmb3IgdGhlIGNvbXB1dGUgaW5zdGFuY2UNCiAgICBoaWRkZW46IHRydWUNCiAgICBjb25zdHJhaW50czoNCiAgICAgIC0gbGVuZ3RoOiB7IG1pbjogNiwgbWF4OiA4IH0NCiAgICAgICAgZGVzY3JpcHRpb246IFBhc3N3b3JkIGxlbmd0aCBtdXN0IGJlIGJldHdlZW4gNiBhbmQgOCBjaGFyYWN0ZXJzLg0KICAgICAgLSByYW5nZTogeyBtaW46IDYsIG1heDogOCB9DQogICAgICAgIGRlc2NyaXB0aW9uOiBSYW5nZSBkZXNjcmlwdGlvbg0KICAgICAgLSBhbGxvd2VkX3ZhbHVlczoNCiAgICAgICAgLSBtMS5zbWFsbA0KICAgICAgICAtIG0xLm1lZGl1bQ0KICAgICAgICAtIG0xLmxhcmdlDQogICAgICAgIGRlc2NyaXB0aW9uOiBBbGxvd2VkIHZhbHVlcyBkZXNjcmlwdGlvbg0KICAgICAgLSBhbGxvd2VkX3BhdHRlcm46ICJbYS16QS1aMC05XSsiDQogICAgICAgIGRlc2NyaXB0aW9uOiBQYXNzd29yZCBtdXN0IGNvbnNpc3Qgb2YgY2hhcmFjdGVycyBhbmQgbnVtYmVycyBvbmx5Lg0KICAgICAgLSBhbGxvd2VkX3BhdHRlcm46ICJbQS1aXStbYS16QS1aMC05XSoiDQogICAgICAgIGRlc2NyaXB0aW9uOiBQYXNzd29yZCBtdXN0IHN0YXJ0IHdpdGggYW4gdXBwZXJjYXNlIGNoYXJhY3Rlci4NCiAgICAgIC0gY3VzdG9tX2NvbnN0cmFpbnQ6IG5vdmEua2V5cGFpcg0KICAgICAgICBkZXNjcmlwdGlvbjogQ3VzdG9tIGRlc2NyaXB0aW9uDQoNCnJlc291cmNlczoNCiAgbXlfaW5zdGFuY2UxOg0KICAgIHR5cGU6IE9TOjpOb3ZhOjpTZXJ2ZXINCiAgICBwcm9wZXJ0aWVzOg0KICAgICAgaW1hZ2U6IHsgZ2V0X3BhcmFtOiBpbWFnZV9uYW1lXzEgfQ0KICAgICAgZmxhdm9yOiBtMS5zbWFsbA0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9DQogIG15X2luc3RhbmNlMjoNCiAgICB0eXBlOiBPUzo6Tm92YTo6U2VydmVyDQogICAgcHJvcGVydGllczoNCiAgICAgIGltYWdlOiB7IGdldF9wYXJhbTogaW1hZ2VfbmFtZV8yIH0NCiAgICAgIGZsYXZvcjogbTEudGlueQ0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9";
	// String decodedPaypload = Decoder.decode(payloadData);
	//
	// Assert.assertEquals(response, decodedPaypload, "Response deployment
	// artifact not correct.");
	//
	// String auditAction = "ArtifactDownload";
	//
	// ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new
	// ExpectedResourceAuditJavaObject();
	// expectedResourceAuditJavaObject.setAction(auditAction);
	// expectedResourceAuditJavaObject.setResourceName(resourceDetailsService.getName());
	// expectedResourceAuditJavaObject.setResourceType("Service");
	// expectedResourceAuditJavaObject.setStatus("200");
	// expectedResourceAuditJavaObject.setDesc("OK");
	//
	// expectedResourceAuditJavaObject.setCONSUMER_ID("ci");
	// String resource_url =
	// String.format("/asdc/v1/catalog/services/%s/artifacts/%s", resourceUUID,
	// artifactUUID);
	// expectedResourceAuditJavaObject.setRESOURCE_URL(resource_url);
	//
	// AuditValidationUtils.validateAuditDownloadExternalAPI(expectedResourceAuditJavaObject,
	// auditAction, null, false);
	// }
	//
	//
	//
	//
	//
	//
	// // External API - Download ComponentInstance artifact of service -
	// negative test
	// @Test
	// public void
	// downloadArtifactOfComponentInstanceFromServiceViaExternalAPI() throws
	// Exception {
	//
	// Either<Resource, RestResponse> resourceDetailsVF_01e =
	// AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF,
	// NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE,
	// UserRoleEnum.DESIGNER, true);
	// Component resourceDetailsVF_01 = resourceDetailsVF_01e.left().value();
	// ArtifactDefinition heatArtifact =
	// AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT,
	// resourceDetailsVF_01, UserRoleEnum.DESIGNER, true, true).left().value();
	//
	// resourceDetailsVF_01 =
	// AtomicOperationUtils.changeComponentState(resourceDetailsVF_01,
	// UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
	//
	// Service resourceDetailsService;
	// Either<Service, RestResponse> createdResource =
	// AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
	// resourceDetailsService = createdResource.left().value();
	//
	//
	// ComponentInstance resourceDetailsVF1ins_01 =
	// AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceDetailsVF_01,
	// resourceDetailsService, UserRoleEnum.DESIGNER, true).left().value();
	//
	//
	// System.out.println("-----");
	//
	//
	// String resourceUUID = resourceDetailsService.getUUID();
	// String componentInstanceUID = resourceDetailsVF1ins_01.getUniqueId();
	// String artifactUUID = heatArtifact.getArtifactUUID();
	//
	// System.out.println("Resource UUID: " + resourceUUID);
	// System.out.println("Component instance UID: " + componentInstanceUID);
	// System.out.println("Artifact UUID: " + artifactUUID);
	//
	// RestResponse restResponse =
	// ArtifactRestUtils.getComponentInstanceDeploymentArtifactExternalAPI(resourceUUID,
	// componentInstanceUID, artifactUUID,
	// ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), "Service");
	////
	// Integer responseCode = restResponse.getErrorCode();
	// Integer expectedCode = 200;
	// Assert.assertEquals(responseCode,expectedCode, "Response code is not
	// correct.");
	//
	// String response = restResponse.getResponse();
	//
	// String payloadData =
	// "aGVhdF90ZW1wbGF0ZV92ZXJzaW9uOiAyMDEzLTA1LTIzDQoNCmRlc2NyaXB0aW9uOiBTaW1wbGUgdGVtcGxhdGUgdG8gZGVwbG95IGEgc3RhY2sgd2l0aCB0d28gdmlydHVhbCBtYWNoaW5lIGluc3RhbmNlcw0KDQpwYXJhbWV0ZXJzOg0KICBpbWFnZV9uYW1lXzE6DQogICAgdHlwZTogc3RyaW5nDQogICAgbGFiZWw6IEltYWdlIE5hbWUNCiAgICBkZXNjcmlwdGlvbjogU0NPSU1BR0UgU3BlY2lmeSBhbiBpbWFnZSBuYW1lIGZvciBpbnN0YW5jZTENCiAgICBkZWZhdWx0OiBjaXJyb3MtMC4zLjEteDg2XzY0DQogIGltYWdlX25hbWVfMjoNCiAgICB0eXBlOiBzdHJpbmcNCiAgICBsYWJlbDogSW1hZ2UgTmFtZQ0KICAgIGRlc2NyaXB0aW9uOiBTQ09JTUFHRSBTcGVjaWZ5IGFuIGltYWdlIG5hbWUgZm9yIGluc3RhbmNlMg0KICAgIGRlZmF1bHQ6IGNpcnJvcy0wLjMuMS14ODZfNjQNCiAgbmV0d29ya19pZDoNCiAgICB0eXBlOiBzdHJpbmcNCiAgICBsYWJlbDogTmV0d29yayBJRA0KICAgIGRlc2NyaXB0aW9uOiBTQ09ORVRXT1JLIE5ldHdvcmsgdG8gYmUgdXNlZCBmb3IgdGhlIGNvbXB1dGUgaW5zdGFuY2UNCiAgICBoaWRkZW46IHRydWUNCiAgICBjb25zdHJhaW50czoNCiAgICAgIC0gbGVuZ3RoOiB7IG1pbjogNiwgbWF4OiA4IH0NCiAgICAgICAgZGVzY3JpcHRpb246IFBhc3N3b3JkIGxlbmd0aCBtdXN0IGJlIGJldHdlZW4gNiBhbmQgOCBjaGFyYWN0ZXJzLg0KICAgICAgLSByYW5nZTogeyBtaW46IDYsIG1heDogOCB9DQogICAgICAgIGRlc2NyaXB0aW9uOiBSYW5nZSBkZXNjcmlwdGlvbg0KICAgICAgLSBhbGxvd2VkX3ZhbHVlczoNCiAgICAgICAgLSBtMS5zbWFsbA0KICAgICAgICAtIG0xLm1lZGl1bQ0KICAgICAgICAtIG0xLmxhcmdlDQogICAgICAgIGRlc2NyaXB0aW9uOiBBbGxvd2VkIHZhbHVlcyBkZXNjcmlwdGlvbg0KICAgICAgLSBhbGxvd2VkX3BhdHRlcm46ICJbYS16QS1aMC05XSsiDQogICAgICAgIGRlc2NyaXB0aW9uOiBQYXNzd29yZCBtdXN0IGNvbnNpc3Qgb2YgY2hhcmFjdGVycyBhbmQgbnVtYmVycyBvbmx5Lg0KICAgICAgLSBhbGxvd2VkX3BhdHRlcm46ICJbQS1aXStbYS16QS1aMC05XSoiDQogICAgICAgIGRlc2NyaXB0aW9uOiBQYXNzd29yZCBtdXN0IHN0YXJ0IHdpdGggYW4gdXBwZXJjYXNlIGNoYXJhY3Rlci4NCiAgICAgIC0gY3VzdG9tX2NvbnN0cmFpbnQ6IG5vdmEua2V5cGFpcg0KICAgICAgICBkZXNjcmlwdGlvbjogQ3VzdG9tIGRlc2NyaXB0aW9uDQoNCnJlc291cmNlczoNCiAgbXlfaW5zdGFuY2UxOg0KICAgIHR5cGU6IE9TOjpOb3ZhOjpTZXJ2ZXINCiAgICBwcm9wZXJ0aWVzOg0KICAgICAgaW1hZ2U6IHsgZ2V0X3BhcmFtOiBpbWFnZV9uYW1lXzEgfQ0KICAgICAgZmxhdm9yOiBtMS5zbWFsbA0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9DQogIG15X2luc3RhbmNlMjoNCiAgICB0eXBlOiBPUzo6Tm92YTo6U2VydmVyDQogICAgcHJvcGVydGllczoNCiAgICAgIGltYWdlOiB7IGdldF9wYXJhbTogaW1hZ2VfbmFtZV8yIH0NCiAgICAgIGZsYXZvcjogbTEudGlueQ0KICAgICAgbmV0d29ya3M6DQogICAgICAgIC0gbmV0d29yayA6IHsgZ2V0X3BhcmFtIDogbmV0d29ya19pZCB9";
	// String decodedPaypload = Decoder.decode(payloadData);
	//
	// Assert.assertEquals(response, decodedPaypload, "Response deployment
	// artifact not correct.");
	//
	// String auditAction = "ArtifactDownload";
	//
	// ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new
	// ExpectedResourceAuditJavaObject();
	// expectedResourceAuditJavaObject.setAction(auditAction);
	// expectedResourceAuditJavaObject.setResourceName(resourceDetailsVF1ins_01.getName());
	// expectedResourceAuditJavaObject.setResourceType("Service");
	// expectedResourceAuditJavaObject.setStatus("200");
	// expectedResourceAuditJavaObject.setDesc("OK");
	//
	// expectedResourceAuditJavaObject.setCONSUMER_ID("ci");
	// String resource_url =
	// String.format("/asdc/v1/catalog/services/%s/resourceInstances/%s/artifacts/%s",
	// resourceUUID, componentInstanceUID, artifactUUID);
	// expectedResourceAuditJavaObject.setRESOURCE_URL(resource_url);
	//
	// AuditValidationUtils.validateAuditDownloadExternalAPI(expectedResourceAuditJavaObject,
	// auditAction, null, false);
	// }
	//
	//
	//
	//
	//
	//
	//
	//
	//
	// @Test
	// public void downloadArtifactFromResourceTest() throws Exception {
	//
	// CloseableHttpClient httpclient = HttpClients.createDefault();
	// try {
	// String jsonBody = createUploadArtifactBodyJson();
	//
	// String resourceId = resourceDetails.getUniqueId();
	// String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE,
	// config.getCatalogBeHost(), config.getCatalogBePort(), resourceId);
	// HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
	// HttpResponse response = httpclient.execute(httppost);
	// int status = response.getStatusLine().getStatusCode();
	// AssertJUnit.assertEquals("failed to add artifact", 200, status);
	//
	// ArtifactDefinition origArtifact = getArtifactDataFromJson(jsonBody);
	// addArtifactDataFromResponse(response, origArtifact);
	// String artifactId = origArtifact.getUniqueId();
	//
	// url = String.format(Urls.UI_DOWNLOAD_RESOURCE_ARTIFACT,
	// config.getCatalogBeHost(), config.getCatalogBePort(), resourceId,
	// artifactId);
	// HttpGet httpGet = createGetRequest(url);
	// response = httpclient.execute(httpGet);
	// status = response.getStatusLine().getStatusCode();
	// AssertJUnit.assertEquals("failed to download artifact", 200, status);
	//
	// InputStream inputStream = response.getEntity().getContent();
	// ArtifactUiDownloadData artifactUiDownloadData =
	// getArtifactUiDownloadData(IOUtils.toString(inputStream));
	// AssertJUnit.assertEquals("Downloaded payload is different from uploaded
	// one", UPLOAD_ARTIFACT_PAYLOAD,
	// artifactUiDownloadData.getBase64Contents());
	// AssertJUnit.assertEquals("Downloaded artifact name is different from
	// uploaded one", UPLOAD_ARTIFACT_NAME,
	// artifactUiDownloadData.getArtifactName());
	//
	// // validate audit
	//
	// ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject =
	// Convertor.constructFieldsForAuditValidation(resourceDetails,
	// resourceDetails.getVersion(), sdncUserDetails);
	// String auditAction = "ArtifactDownload";
	// expectedResourceAuditJavaObject.setAction(auditAction);
	// expectedResourceAuditJavaObject.setPrevState("");
	// expectedResourceAuditJavaObject.setPrevVersion("");
	// expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
	// expectedResourceAuditJavaObject.setStatus("200");
	// expectedResourceAuditJavaObject.setDesc("OK");
	// expectedResourceAuditJavaObject.setArtifactData(AuditValidationUtils.buildArtifactDataAudit(origArtifact));
	// expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
	// expectedResourceAuditJavaObject.setPrevArtifactUuid("");
	// AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
	// auditAction, null, false);
	//
	// } finally {
	// httpclient.close();
	// }
	//
	// }
	//
	// @Test
	// public void downloadArtifactFromServiceTest() throws Exception {
	//
	// CloseableHttpClient httpclient = HttpClients.createDefault();
	//
	// try {
	//
	// String jsonStr = createUploadArtifactBodyJson();
	//
	// String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE,
	// config.getCatalogBeHost(), config.getCatalogBePort(),
	// serviceDetails.getUniqueId());
	// HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
	// CloseableHttpResponse result = httpclient.execute(httpPost);
	// int status = result.getStatusLine().getStatusCode();
	// AssertJUnit.assertEquals("failed to add artifact", 200, status);
	//
	// ArtifactDefinition origArtifact = getArtifactDataFromJson(jsonStr);
	// addArtifactDataFromResponse(result, origArtifact);
	// String artifactId = origArtifact.getUniqueId();
	//
	// url = String.format(Urls.UI_DOWNLOAD_SERVICE_ARTIFACT,
	// config.getCatalogBeHost(), config.getCatalogBePort(),
	// serviceDetails.getUniqueId(), artifactId);
	// HttpGet httpGet = createGetRequest(url);
	// CloseableHttpResponse response2 = httpclient.execute(httpGet);
	// status = response2.getStatusLine().getStatusCode();
	// AssertJUnit.assertEquals("failed to download artifact", 200, status);
	// InputStream inputStream = response2.getEntity().getContent();
	// ArtifactUiDownloadData artifactUiDownloadData =
	// getArtifactUiDownloadData(IOUtils.toString(inputStream));
	// AssertJUnit.assertEquals("Downloaded payload is different from uploaded
	// one", UPLOAD_ARTIFACT_PAYLOAD,
	// artifactUiDownloadData.getBase64Contents());
	// AssertJUnit.assertEquals("Downloaded artifact name is different from
	// uploaded one", UPLOAD_ARTIFACT_NAME,
	// artifactUiDownloadData.getArtifactName());
	//
	// // validate audit
	// ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject =
	// AuditValidationUtils.constructFieldsForAuditValidation(serviceDetails,
	// serviceDetails.getVersion(), sdncUserDetails);
	// String auditAction = "ArtifactDownload";
	// expectedResourceAuditJavaObject.setAction(auditAction);
	// expectedResourceAuditJavaObject.setPrevState("");
	// expectedResourceAuditJavaObject.setPrevVersion("");
	// expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
	// expectedResourceAuditJavaObject.setStatus("200");
	// expectedResourceAuditJavaObject.setDesc("OK");
	// expectedResourceAuditJavaObject.setArtifactData(AuditValidationUtils.buildArtifactDataAudit(origArtifact));
	// expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
	// expectedResourceAuditJavaObject.setPrevArtifactUuid("");
	//
	// AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
	// auditAction, null, false);
	//
	// } finally {
	//// RestResponse response = ServiceRestUtils.deleteService(serviceDetails,
	// serviceVersion, sdncUserDetails );
	//// checkDeleteResponse(response);
	// httpclient.close();
	// }
	// }
	//
	// @Test
	// public void downloadArtifactFromResourceNotFound() throws Exception {
	//
	// CloseableHttpClient httpclient = HttpClients.createDefault();
	// try {
	//
	// String resourceId = resourceDetails.getUniqueId();
	// String artifactIdNotFound = "11111";
	//
	// ArtifactDefinition origArtifact = new ArtifactDefinition();
	// origArtifact.setUniqueId(artifactIdNotFound);
	//
	// String url = String.format(Urls.UI_DOWNLOAD_RESOURCE_ARTIFACT,
	// config.getCatalogBeHost(), config.getCatalogBePort(), resourceId,
	// artifactIdNotFound);
	// HttpGet httpGet = createGetRequest(url);
	// CloseableHttpResponse response = httpclient.execute(httpGet);
	// int status = response.getStatusLine().getStatusCode();
	// AssertJUnit.assertEquals("expected 404 not found", 404, status);
	//
	// // validate audit
	// ErrorInfo errorInfo =
	// ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.ARTIFACT_NOT_FOUND.name());
	// ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject =
	// Convertor.constructFieldsForAuditValidation(resourceDetails,
	// resourceDetails.getVersion(), sdncUserDetails);
	// String auditAction = "ArtifactDownload";
	// expectedResourceAuditJavaObject.setAction(auditAction);
	// expectedResourceAuditJavaObject.setPrevState("");
	// expectedResourceAuditJavaObject.setPrevVersion("");
	// expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
	// expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
	// expectedResourceAuditJavaObject.setDesc(errorInfo.getAuditDesc(""));
	// expectedResourceAuditJavaObject.setArtifactData("");
	// expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
	// expectedResourceAuditJavaObject.setPrevArtifactUuid("");
	// AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
	// auditAction, null, false);
	// expectedResourceAuditJavaObject.setPrevArtifactUuid(null);
	// } finally {
	// httpclient.close();
	// }
	//
	// }
	//
	// @Test
	// public void downloadArtifactFromServiceNotFound() throws Exception {
	//
	// CloseableHttpClient httpclient = HttpClients.createDefault();
	// try {
	//
	// String artifactIdNotFound = "11111";
	// ArtifactDefinition origArtifact = new ArtifactDefinition();
	// origArtifact.setUniqueId(artifactIdNotFound);
	//
	// String url = String.format(Urls.UI_DOWNLOAD_SERVICE_ARTIFACT,
	// config.getCatalogBeHost(), config.getCatalogBePort(),
	// serviceDetails.getUniqueId(), artifactIdNotFound);
	// HttpGet httpGet = createGetRequest(url);
	// CloseableHttpResponse response2 = httpclient.execute(httpGet);
	// int status = response2.getStatusLine().getStatusCode();
	// AssertJUnit.assertEquals("expected 404 not found", 404, status);
	//
	// // validate audit
	// ErrorInfo errorInfo =
	// ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.ARTIFACT_NOT_FOUND.name());
	// ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject =
	// ServiceValidationUtils.constructFieldsForAuditValidation(serviceDetails,
	// serviceDetails.getVersion(), sdncUserDetails);
	// String auditAction = "ArtifactDownload";
	// expectedResourceAuditJavaObject.setAction(auditAction);
	// expectedResourceAuditJavaObject.setPrevState("");
	// expectedResourceAuditJavaObject.setPrevVersion("");
	// expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
	// expectedResourceAuditJavaObject.setStatus(errorInfo.getCode().toString());
	// expectedResourceAuditJavaObject.setDesc(errorInfo.getAuditDesc(""));
	// expectedResourceAuditJavaObject.setArtifactData("");
	// expectedResourceAuditJavaObject.setCurrArtifactUuid(origArtifact.getUniqueId());
	// expectedResourceAuditJavaObject.setPrevArtifactUuid("");
	// AuditValidationUtils.validateAudit(expectedResourceAuditJavaObject,
	// auditAction, null, false);
	//
	// } finally {
	// httpclient.close();
	// }
	//
	// }
	//
	// @Test
	// public void addArtifactToResourceTest() throws Exception {
	//
	// ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
	//
	// RestResponse response =
	// ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact,
	// sdncUserDetails, resourceDetails.getUniqueId());
	// int status = response.getErrorCode();
	// AssertJUnit.assertEquals("add informational artifact request returned
	// status: " + response.getErrorCode(), 200, status);
	//
	// RestResponse resourceResp =
	// ResourceRestUtils.getResource(resourceDetails.getUniqueId());
	// Resource resource =
	// ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
	// AssertJUnit.assertNotNull(resource);
	//
	// Map<String, ArtifactDefinition> artifacts = resource.getArtifacts();
	// boolean isExist = false;
	// for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet())
	// {
	// if (entry.getKey().equals(defaultArtifact.getArtifactLabel())) {
	// isExist = true;
	//
	// }
	// }
	// AssertJUnit.assertTrue(isExist);
	// }

	protected String createUploadArtifactBodyJson() {
		Map<String, Object> jsonBody = new HashMap<String, Object>();
		jsonBody.put("artifactName", UPLOAD_ARTIFACT_NAME);
		jsonBody.put("artifactDisplayName", "configure");
		jsonBody.put("artifactType", "SHELL");
		jsonBody.put("mandatory", "false");
		jsonBody.put("description", "ff");
		jsonBody.put("payloadData", UPLOAD_ARTIFACT_PAYLOAD);
		jsonBody.put("artifactLabel", "configure");
		return gson.toJson(jsonBody);
	}

	protected ArtifactDefinition getArtifactDataFromJson(String json) {
		Gson gson = new Gson();
		JsonObject jsonElement = new JsonObject();
		jsonElement = gson.fromJson(json, jsonElement.getClass());
		ArtifactDefinition artifact = new ArtifactDefinition();
		String payload = null;
		JsonElement artifactPayload = jsonElement.get(Constants.ARTIFACT_PAYLOAD_DATA);
		if (artifactPayload != null && !artifactPayload.isJsonNull()) {
			payload = artifactPayload.getAsString();
		}
		jsonElement.remove(Constants.ARTIFACT_PAYLOAD_DATA);
		artifact = gson.fromJson(jsonElement, ArtifactDefinition.class);
		artifact.setPayloadData(payload);

		/*
		 * atifact.setArtifactName(UPLOAD_ARTIFACT_NAME);
		 * artifact.setArtifactDisplayName("configure");
		 * artifact.setArtifactType("SHELL"); artifact.setMandatory(false);
		 * artifact.setDescription("ff");
		 * artifact.setPayloadData(UPLOAD_ARTIFACT_PAYLOAD);
		 * artifact.setArtifactLabel("configure");
		 */
		return artifact;
	}

	protected HttpGet createGetRequest(String url) {
		HttpGet httpGet = new HttpGet(url);
		httpGet.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
		httpGet.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
		httpGet.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
		return httpGet;
	}

	protected String getArtifactUid(HttpResponse response) throws HttpResponseException, IOException, ParseException {
		String responseString = new BasicResponseHandler().handleResponse(response);
		JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
		String artifactId = (String) responseMap.get("uniqueId");
		return artifactId;
	}

	protected String getArtifactEsId(HttpResponse response) throws HttpResponseException, IOException, ParseException {
		String responseString = new BasicResponseHandler().handleResponse(response);
		JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
		String esId = (String) responseMap.get("EsId");
		return esId;
	}

	protected ArtifactDefinition addArtifactDataFromResponse(HttpResponse response, ArtifactDefinition artifact)
			throws HttpResponseException, IOException, ParseException {
		// String responseString = new
		// BasicResponseHandler().handleResponse(response);
		HttpEntity entity = response.getEntity();
		String responseString = EntityUtils.toString(entity);
		JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
		artifact.setEsId((String) responseMap.get("esId"));
		artifact.setUniqueId((String) responseMap.get("uniqueId"));
		artifact.setArtifactGroupType(ArtifactGroupTypeEnum.findType((String) responseMap.get("artifactGroupType")));
		artifact.setTimeout(((Long) responseMap.get("timeout")).intValue());
		return artifact;
	}

	protected String getLifecycleArtifactUid(CloseableHttpResponse response)
			throws HttpResponseException, IOException, ParseException {
		String responseString = new BasicResponseHandler().handleResponse(response);
		JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
		responseMap = (JSONObject) responseMap.get("implementation");
		String artifactId = (String) responseMap.get("uniqueId");
		return artifactId;
	}

	protected HttpDelete createDeleteArtifactRequest(String url) {
		HttpDelete httpDelete = new HttpDelete(url);
		httpDelete.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
		httpDelete.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
		return httpDelete;
	}

	protected HttpPost createPostAddArtifactRequeast(String jsonBody, String url, boolean addMd5Header)
			throws UnsupportedEncodingException {
		HttpPost httppost = new HttpPost(url);
		httppost.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
		httppost.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
		httppost.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
		if (addMd5Header) {
			httppost.addHeader(HttpHeaderEnum.Content_MD5.getValue(), GeneralUtility.calculateMD5ByString(jsonBody));
		}
		StringEntity input = new StringEntity(jsonBody);
		input.setContentType("application/json");
		httppost.setEntity(input);
		log.debug("Executing request {}", httppost.getRequestLine());
		return httppost;
	}

	protected String createLoadArtifactBody() {
		Map<String, Object> json = new HashMap<String, Object>();
		json.put("artifactName", "install_apache2.sh");
		json.put("artifactType", "SHELL");
		json.put("description", "ddd");
		json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
		json.put("artifactLabel", "name123");

		String jsonStr = gson.toJson(json);
		return jsonStr;
	}

	protected void checkDeleteResponse(RestResponse response) {
		BaseRestUtils.checkStatusCode(response, "delete request failed", false, 204, 404);
	}

	protected ArtifactUiDownloadData getArtifactUiDownloadData(String artifactUiDownloadDataStr) throws Exception {

		ObjectMapper mapper = new ObjectMapper();
		try {
			ArtifactUiDownloadData artifactUiDownloadData = mapper.readValue(artifactUiDownloadDataStr,
					ArtifactUiDownloadData.class);
			return artifactUiDownloadData;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}