aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
blob: 5a2f76b6faf735b7de6f5f9a463de2a2a4b56692 (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
/*-
 * ============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.vendorsoftwareproduct.impl;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
import org.openecomp.core.enrichment.types.ArtifactType;
import org.openecomp.core.factory.impl.AbstractFactoryBase;
import org.openecomp.core.model.dao.EnrichedServiceModelDao;
import org.openecomp.core.model.dao.ServiceModelDao;
import org.openecomp.core.model.types.ServiceElement;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.activityLog.ActivityLogManager;
import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
import org.openecomp.sdc.healing.api.HealingManager;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
import org.openecomp.sdc.vendorsoftwareproduct.MibManager;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl;
import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.errors.EditOnEntityLockedByOtherErrorBuilder;
import org.openecomp.sdc.versioning.errors.EntityNotExistErrorBuilder;
import org.openecomp.sdc.versioning.types.VersionInfo;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;


/**
 * Created by TALIO on 4/23/2016
 */
public class VendorSoftwareProductManagerImplTest {
  private static final String INVALID_VERSION_MSG = "Invalid requested version.";

  private static String VSP_ID = "vspId";
  private static String VERSION_ID = "versionId";
  public static final Version VERSION01 = new Version(0, 1);
  private static final Version VERSION10 = new Version(1, 0);
  private static final String USER1 = "vspTestUser1";
  private static final String USER2 = "vspTestUser2";
  private static final String USER3 = "vspTestUser3";
  private static String id006 = null;
  private static String id007 = null;

  @Mock
  private VersioningManager versioningManagerMock;
  @Mock
  private VendorSoftwareProductDao vendorSoftwareProductDaoMock; // todo get rid of
  @Mock
  private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
  @Mock
  private VendorLicenseFacade vendorLicenseFacadeMock;
  @Mock
  private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
  @Mock
  private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
  @Mock
  private HealingManager healingManagerMock;
  @Mock
  private VendorLicenseArtifactsService licenseArtifactsServiceMock;
  @Mock
  private CompositionEntityDataManager compositionEntityDataManagerMock;
  @Mock
  private InformationArtifactGenerator informationArtifactGeneratorMock;
  @Mock
  private ActivityLogManager activityLogManagerMock;
  @Mock
  private PackageInfoDao packageInfoDao;
  @Mock
  private VendorSoftwareProductInfoDao vspInfoDaoMock;


  @Spy
  @InjectMocks
  private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;

  private OrchestrationTemplateCandidateManager candidateManager;
  private MibManager mibManager;

  @Captor
  private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;

  @BeforeMethod
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
  }

  @Test
  public void testListWhenNone() {
    doReturn(new HashMap<>()).when(versioningManagerMock).listEntitiesVersionInfo
        (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
            VersionableEntityAction.Read);
    List<VersionedVendorSoftwareProductInfo> vsps =
        vendorSoftwareProductManager.listVsps(null, USER1);
    Assert.assertEquals(vsps.size(), 0);
  }

  @Test
  public void testList() {
    String vsp1id = "vsp1_id";
    String vsp2id = "vsp2_id";
    Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();

    VersionInfo versionInfo1 = new VersionInfo();
    versionInfo1.setActiveVersion(VERSION01);
    vspsTobeReturned.put(vsp1id, versionInfo1);

    VersionInfo versionInfo2 = new VersionInfo();
    versionInfo2.setActiveVersion(VERSION10);
    vspsTobeReturned.put(vsp2id, versionInfo2);

    doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
        (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
            VersionableEntityAction.Read);

    VspDetails vsp1 = new VspDetails(vsp1id, VERSION01);
    vsp1.setWritetimeMicroSeconds(8L);
    doReturn(vsp1).when(vspInfoDaoMock)
        .get(any(VspDetails.class));

    List<VersionedVendorSoftwareProductInfo> vsps =
        vendorSoftwareProductManager.listVsps(null, USER1);
    Assert.assertEquals(vsps.size(), 2);
  }

  @Test
  public void testListFinalsWhenNone() {
    String vsp1id = "vsp1_id";
    String vsp2id = "vsp2_id";
    Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();

    VersionInfo versionInfo1 = new VersionInfo();
    versionInfo1.setActiveVersion(VERSION01);
    vspsTobeReturned.put(vsp1id, versionInfo1);

    VersionInfo versionInfo2 = new VersionInfo();
    versionInfo2.setActiveVersion(VERSION10);
    vspsTobeReturned.put(vsp2id, versionInfo2);

    doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
        (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
            VersionableEntityAction.Read);

    List<VersionedVendorSoftwareProductInfo> vsps =
        vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
    Assert.assertEquals(vsps.size(), 0);
  }

  @Test
  public void testListFinals() {
    String vsp1id = "vsp1_id";
    String vsp2id = "vsp2_id";
    Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();

    VersionInfo versionInfo1 = new VersionInfo();
    versionInfo1.setActiveVersion(VERSION01);
    vspsTobeReturned.put(vsp1id, versionInfo1);

    VersionInfo versionInfo2 = new VersionInfo();
    versionInfo2.setActiveVersion(new Version(1, 3));
    versionInfo2.setLatestFinalVersion(VERSION10);
    vspsTobeReturned.put(vsp2id, versionInfo2);

    doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
        (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
            VersionableEntityAction.Read);

    VspDetails vsp2 = new VspDetails(vsp2id, VERSION10);
    vsp2.setWritetimeMicroSeconds(8L);
    doReturn(vsp2).when(vspInfoDaoMock)
        .get(any(VspDetails.class));

    List<VersionedVendorSoftwareProductInfo> vsps =
        vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
    Assert.assertEquals(vsps.size(), 1);
  }

  @Test(expectedExceptions = CoreException.class)
  public void testCreateWithExistingName_negative() {
    doThrow(new CoreException(
        new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
        .when(vendorSoftwareProductManager).validateUniqueName("Vsp1");
    VspDetails expectedVsp =
        createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
            "category", "subCategory", "123", null);

    vendorSoftwareProductManager.createVsp(expectedVsp, USER1);
  }

  @Test
  public void testCreate() {
    doNothing().when(vendorSoftwareProductManager).validateUniqueName("Vsp1");
    doNothing().when(vendorSoftwareProductManager).createUniqueName("Vsp1");
    doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
    doReturn("{}")
        .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());

    VspDetails vspToCreate =
        createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
            "category", "subCategory", "123", null);

    VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate, USER1);

    Assert.assertNotNull(vsp);
    vspToCreate.setId(vsp.getId());
    vspToCreate.setVersion(VERSION01);
    assertVspsEquals(vsp, vspToCreate);
    verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
    ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
    Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
    Assert.assertTrue(activityLogEntity.isSuccess());
  }

  @Test(expectedExceptions = CoreException.class)
  public void testUpdateWithExistingName_negative() {
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(VERSION01);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
        VersionableEntityAction.Write);

    VspDetails existingVsp =
        createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
            "icon", "category", "subCategory", "123", null);
    VspDetails updatedVsp =
        createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
            "vlm1Id", "icon", "category", "subCategory", "123", null);
    doReturn(existingVsp).when(vspInfoDaoMock)
        .get(any(VspDetails.class));
    doThrow(new CoreException(
        new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
        .when(vendorSoftwareProductManager)
        .updateUniqueName(existingVsp.getName(), updatedVsp.getName());

    vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
  }

  @Test
  public void testUpdate() {
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(VERSION01);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
        VersionableEntityAction.Write);
    VspDetails existingVsp =
        createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
            "category",
            "subCategory", "456", null);
    VspDetails updatedVsp =
        createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
            "category_updated",
            "subCategory", "456", null);
    existingVsp.setWritetimeMicroSeconds(8L);
    doReturn(existingVsp).when(vspInfoDaoMock)
        .get(any(VspDetails.class));
    doNothing().when(vendorSoftwareProductManager)
        .updateUniqueName(existingVsp.getName(), updatedVsp.getName());

    vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);

    verify(vspInfoDaoMock).update(updatedVsp);
  }

  @Test(expectedExceptions = CoreException.class)
  public void testGetNonExistingVersion_negative() {
    Version notExistversion = new Version(43, 8);
    doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
    vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion, USER1);
  }

  @Test
  public void testGetCheckedOutVersion() {
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(VERSION01);
    versionInfo.setStatus(VersionStatus.Locked);
    versionInfo.setLockingUser(USER1);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
        VersionableEntityAction.Read);

    VspDetails existingVsp =
        createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
            "category",
            "subCategory", "456", null);
    existingVsp.setWritetimeMicroSeconds(8L);
    doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));

    VspDetails actualVsp =
        vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);

    assertVspsEquals(actualVsp, existingVsp);
  }

  @Test
  public void testGetOldVersion() {
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(new Version(0, 2));
    versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version(0, 2)));
    versionInfo.setStatus(VersionStatus.Locked);
    versionInfo.setLockingUser(USER2);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
        VersionableEntityAction.Read);

    VspDetails existingVsp =
        createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
            "category",
            "subCategory", "456", null);
    existingVsp.setWritetimeMicroSeconds(8L);
    doReturn(existingVsp)
        .when(vspInfoDaoMock).get(any(VspDetails.class));

    VspDetails actualVsp =
        vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);

    VspDetails expectedVsp =
        vspInfoDaoMock
            .get(new VspDetails(VSP_ID, VERSION01));
    assertVspsEquals(actualVsp, expectedVsp);
  }

  @Test
  public void testCheckin() {
    doReturn(VERSION01).when(versioningManagerMock)
        .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
            USER1, null);
    Version version = vendorSoftwareProductManager.checkin(VSP_ID, USER1);

    Assert.assertEquals(version, VERSION01);
    verify(versioningManagerMock)
        .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
            USER1, null);
    verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
    ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
    Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
    Assert.assertTrue(activityLogEntity.isSuccess());
  }

  @Test
  public void testCheckout() {
    doReturn(VERSION01).when(versioningManagerMock)
        .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
            USER1);
    Version version = vendorSoftwareProductManager.checkout(VSP_ID, USER1);

    Assert.assertEquals(version, VERSION01);
    verify(versioningManagerMock)
        .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
            USER1);

    verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
    ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
    Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
    Assert.assertTrue(activityLogEntity.isSuccess());
  }


  @Test
  public void testUndoCheckout() {
    Version existingVersion = new Version(0, 2);
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(existingVersion);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
        VSP_ID, USER1, VersionableEntityAction.Read);

    doReturn(VERSION01).when(versioningManagerMock).undoCheckout(VendorSoftwareProductConstants
        .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1);

    VspDetails vsp = new VspDetails(VSP_ID, existingVersion);
    vsp.setName("ExistingName");
    doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
    doNothing().when(vendorSoftwareProductManager).updateUniqueName(vsp.getName(), vsp.getName());

    Version undoCheckoutVersion = vendorSoftwareProductManager.undoCheckout(VSP_ID, USER1);

    Assert.assertEquals(undoCheckoutVersion, VERSION01);
  }


  @Test
  public void testSubmitWithMissingData() throws IOException {
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(VERSION01);

    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
        VSP_ID, USER1, VersionableEntityAction.Read);

    VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
    doReturn(vsp).when(vspInfoDaoMock).get(anyObject());

    VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
    vspQuestionnaire.setQuestionnaireData("{}");
    doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);

    ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
    comp1.setQuestionnaireData("{}");
    doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
        .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);

    NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
    nic1.setQuestionnaireData("{}");
    doReturn(Collections.singleton(nic1))
        .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);

    ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
    Assert.assertNotNull(validationResponse);
    Assert.assertFalse(validationResponse.isValid());
    List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
        .collect(Collectors.toList());
    Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
    Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));

    verify(versioningManagerMock, never())
        .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
            USER1, null);
    verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
  }

  // TODO: 3/15/2017 fix and enable
  //@Test
  public void testSubmitWithInvalidLicensingData() throws IOException {
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(VERSION01);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
        VSP_ID, USER1, VersionableEntityAction.Read);

    VspDetails vsp =
        createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
            "category", "subCategory", "licenseAgreementId",
            Collections.singletonList("featureGroupId"));
    doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
    UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01);
    uploadData.setContentData(
        ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
    doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
        .getOrchestrationTemplate(anyObject(), anyObject());
    doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
        "MainServiceTemplate.yaml"))
        .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);

    ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
    Assert.assertNotNull(validationResponse);
    Assert.assertFalse(validationResponse.isValid());
    Assert.assertNull(validationResponse.getVspErrors());
    Assert.assertEquals(validationResponse.getLicensingDataErrors(), 1);

    verify(versioningManagerMock, never())
        .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
            USER1, null);

    //TODO - check..
    verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
  }

  // TODO: 3/15/2017 fix and enable
  //@Test
  public void testSubmit() throws IOException {
    mockVersioning(VersionableEntityAction.Read);

    EnrichmentManagerFactory.getInstance();
    AbstractFactoryBase
        .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);

    VspDetails vsp =
        createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
            "category", "subCategory", "123", Collections.singletonList("fg1"));
    doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
    UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01);
    uploadData.setContentData(
        ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
    doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
        .getOrchestrationTemplate(anyObject(), anyObject());
    doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
        "MainServiceTemplate.yaml"))
        .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);

    ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
    Assert.assertTrue(validationResponse.isValid());

/*    Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10);
    Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Final);
    Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/

    verify(versioningManagerMock)
        .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
            USER1, null);
    verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
    ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
    Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION10.getMajor()));
    Assert.assertTrue(activityLogEntity.isSuccess());
  }

  @Test(expectedExceptions = CoreException.class)
  public void testCreatePackageOnNonFinalVersion_negative() throws IOException {
    vendorSoftwareProductManager.createPackage(VSP_ID, VERSION01, USER1);
  }

  @Test
  public void testCreatePackage() throws IOException {
    /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
    doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(VERSION10);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
        VersionableEntityAction.Read);

    doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
        (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);

    VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
    vsp.setVendorId("vendorId");
    vsp.setVlmVersion(VERSION10);
    vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
    doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));

    doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
        .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(),
            USER1);

    PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10, USER1);
    Assert.assertNotNull(packageInfo.getVspId());
  }

  // TODO: 3/15/2017 fix and enable
  //@Test(dependsOnMethods = {"testListFinals"})
  public void testUploadFileMissingFile() {
    InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");

    UploadFileResponse uploadFileResponse =
        candidateManager.upload(VSP_ID, VERSION01, zis, USER1);

    Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
  }

  // TODO: 3/15/2017 fix and enable
  //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
  public void testUploadNotZipFile() throws IOException {
    URL url = this.getClass().getResource("/notZipFile");

    try {
      candidateManager
          .upload(VSP_ID, VERSION01,
              url.openStream(), USER1);
      candidateManager.process(VSP_ID, VERSION01, USER1);
    } catch (Exception ce) {
      Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
    }

    verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
  }
/*
  @Test
  public void testEnrichModelInSubmit() {
    UniqueValueUtil
        .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
            "VSP_syb");
    VspDetails vspDetails = vendorSoftwareProductManager.createVsp(
        createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", "vlm1Id", "icon",
            "category", "subCategory", "456", null), USER1);
    String id = vspDetails.getId();

    //upload file
    InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
    candidateManager.upload(id, VERSION01, zis, USER1);
    OrchestrationTemplateActionResponse uploadFileResponse =
        candidateManager.process(id, VERSION01, USER1);

    //check in
    vendorSoftwareProductManager.checkin(id, USER1);
    //submit
    try {
      ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1);
    } catch (IOException exception) {
      Assert.fail();
    }
    VersionedVendorSoftwareProductInfo details =
        vendorSoftwareProductManager.getVsp(id, null, USER1);
    Collection<ComponentEntity> components =vendorSoftwareProductManager
        .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1);

    ToscaServiceModel model =
        (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
            .getServiceModel(id, details.getVersionInfo().getActiveVersion());

    Map<String, CapabilityDefinition> capabilities = new HashMap<>();
    for (ComponentEntity component : components) {
      model.getServiceTemplates().
          entrySet().
          stream().
          filter(entryValue -> entryValue.getValue() != null &&
              entryValue.getValue().getNode_types() != null &&
              entryValue.getValue().
                  getNode_types().
                  containsKey(component.getComponentCompositionData().getName())).
          forEach(entryValue -> entryValue.getValue().getNode_types().
              values().
              stream().
              filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
              forEach(type -> type.getCapabilities().
                  entrySet().
                  forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
                      entry.getValue()))));

    }

    Assert.assertNotNull(capabilities);
  }

  @Test(dependsOnMethods = {"testCreatePackage"})
  public void testEnrichedFilesDeletedOnNewUpload() throws IOException {
    Version activeVersion;

    createPackageFromUpload(VSP_ID, USER1, "/fullComposition");
    activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
        .getActiveVersion();

    List<ServiceArtifact> firstExternalArtifacts = enrichedServiceModelDaoMock
        .getExternalArtifacts(VSP_ID, activeVersion);
    ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
        activeVersion);

    createPackageFromUpload(VSP_ID, USER1, "/emptyComposition");
    activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
        .getActiveVersion();

    List<ServiceArtifact> secondExternalArtifacts = enrichedServiceModelDaoMock
        .getExternalArtifacts(VSP_ID, activeVersion);
    ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
        activeVersion);

    Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts);
    Assert.assertNotEquals(firstServiceModel, secondServiceModel);

  }

  @Test(dependsOnMethods = {"testMibsDeletedInCsar"})
  public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException {
    String nestedPath = "Definitions" + File.separator + "nested";

    uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip");
    checkinSubmitCreatePackage(VSP_ID, USER1);
    List<String> nestedFileNamesServiceTemplates =
        getWantedFileNamesFromCsar(nestedPath);

    uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip");
    checkinSubmitCreatePackage(VSP_ID, USER1);
    List<String> emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath);

    Assert.assertEquals(emptyNestedNamesList.size(), 0);
    Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size());
  }*/

  private List<String> getWantedFileNamesFromCsar(String pathInCsar)
      throws IOException {
    File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10, USER1);

    return getFileNamesFromFolderInCsar(translatedFile,
        pathInCsar);
  }

  private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
      throws IOException {
    List<String> fileNames = new ArrayList<>();

    ZipInputStream zip = new ZipInputStream(new FileInputStream(csar));
    ZipEntry ze;

    while ((ze = zip.getNextEntry()) != null) {
      String name = ze.getName();
      if (name.contains(folderName)) {
        fileNames.add(name);
      }
    }

    return fileNames;
  }

  private Pair<String, String> uploadMib(String vspId, String user, String filePath,
                                         String fileName) {
    List<ComponentEntity> componentEntities = null;
    //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
    mibManager.upload(getFileInputStream(filePath),
        fileName, vspId,
        VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL, user);
    //TODO: add validate of addActionLog() func call

    return new ImmutablePair<>(componentEntities.get(0).getId(),
        componentEntities.get(0).getComponentCompositionData()
            .getDisplayName());
  }

  private void createPackageFromUpload(String vspId, String user, String filePath)
      throws IOException {
    uploadFileAndProcess(vspId, user, filePath);
    checkinSubmitCreatePackage(vspId, user);
  }

  private void uploadFileAndProcess(String vspId, String user, String filePath) {
    vendorSoftwareProductManager.checkout(vspId, user);
    candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user);
    candidateManager.process(vspId, VERSION01, user);
  }

  private void checkinSubmitCreatePackage(String vspId, String user) throws IOException {
    vendorSoftwareProductManager.checkin(vspId, user);
    ValidationResponse submitResponse = vendorSoftwareProductManager.submit(vspId, user);
    Assert.assertTrue(submitResponse.isValid());
    vendorSoftwareProductManager.createPackage(vspId, VERSION10, user);
  }

  // TODO: 3/15/2017 fix and enable
/*

  public void testUpdatedVSPShouldBeInBeginningOfList() {
    vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
    assertVSPInWantedLocationInVSPList(id006, 0, USER3);

    InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
    candidateManager.upload(id007, VERSION01, zis, USER3);
    candidateManager.process(id007, VERSION01, USER3);
    assertVSPInWantedLocationInVSPList(id007, 0, USER3);
  }

  @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
  public void testVSPInBeginningOfListAfterCheckin() {
    vendorSoftwareProductManager.checkin(id006, USER3);
    assertVSPInWantedLocationInVSPList(id006, 0, USER3);

    vendorSoftwareProductManager.checkin(id007, USER3);
    assertVSPInWantedLocationInVSPList(id007, 0, USER3);
  }

  @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
  public void testVSPInBeginningOfListAfterCheckout() {
    vendorSoftwareProductManager.checkout(id006, USER3);
    assertVSPInWantedLocationInVSPList(id006, 0, USER3);
  }

  @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
  public void testVSPInBeginningOfListAfterUndoCheckout() {
    vendorSoftwareProductManager.checkout(id007, USER3);
    assertVSPInWantedLocationInVSPList(id007, 0, USER3);

    vendorSoftwareProductManager.undoCheckout(id006, USER3);
    assertVSPInWantedLocationInVSPList(id006, 0, USER3);
  }

  @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
  public void testVSPInBeginningOfListAfterSubmit() throws IOException {
    vendorSoftwareProductManager.checkin(id007, USER3);
    vendorSoftwareProductManager.submit(id007, USER3);

    assertVSPInWantedLocationInVSPList(id007, 0, USER3);
  }
*/

  private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
    candidateManager.upload(vspId, VERSION01, upload, USER1);
    candidateManager.process(vspId, VERSION01, user);

    UploadDataEntity uploadData =
        orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version);
    Assert.assertNotNull(uploadData);
  }

  private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
                             String key, CapabilityDefinition value) {

    capabilities.put(entryValueKey + "_" + key, value);
  }

  public InputStream getFileInputStream(String fileName) {
    URL url = this.getClass().getResource(fileName);
    try {
      return url.openStream();
    } catch (IOException exception) {
      exception.printStackTrace();
      return null;
    }
  }

  private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) {
    List<VersionedVendorSoftwareProductInfo> vspList =
        vendorSoftwareProductManager.listVsps(null, user);
    Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId);
  }


  //  private void assertInfoArtifactIsInRightPathInCsar(String vspId, String zipFileName)
//      throws IOException {
//    ZipInputStream inputZipStream = new ZipInputStream(new FileInputStream(new File(zipFileName)));
//    boolean isInfoArtifactInZip = false;
//
//    ZipEntry zipEntry;
//    while ((zipEntry = inputZipStream.getNextEntry()) != null) {
//      String currentEntryName = zipEntry.getName();
//      if(currentEntryName.equals("Artifacts\\Informative\\Guide\\VSP_" +
//          vspId + "_Information.txt")){
//        isInfoArtifactInZip = true;
//        break;
//      }
//    }
//
//    Assert.assertTrue(isInfoArtifactInZip);
//  }
  static VspDetails createVspDetails(String id, Version version, String name, String desc,
                                     String vendorName, String vlm, String icon,
                                     String category, String subCategory,
                                     String licenseAgreement, List<String> featureGroups) {
    VspDetails vspDetails = new VspDetails(id, version);
    vspDetails.setName(name);
    vspDetails.setDescription(desc);
    vspDetails.setIcon(icon);
    vspDetails.setCategory(category);
    vspDetails.setSubCategory(subCategory);
    vspDetails.setVendorName(vendorName);
    vspDetails.setVendorId(vlm);
    vspDetails.setVlmVersion(new Version(1, 0));
    vspDetails.setLicenseAgreement(licenseAgreement);
    vspDetails.setFeatureGroups(featureGroups);
    return vspDetails;
  }

  static void assertVspsEquals(VspDetails actual, VspDetails expected) {
    Assert.assertEquals(actual.getId(), expected.getId());
    Assert.assertEquals(actual.getVersion(), expected.getVersion());
    Assert.assertEquals(actual.getName(), expected.getName());
    Assert.assertEquals(actual.getDescription(), expected.getDescription());
    Assert.assertEquals(actual.getIcon(), expected.getIcon());
    Assert.assertEquals(actual.getCategory(), expected.getCategory());
    Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
    Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
    Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
    Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
    Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
  }


//    @Test
//    public void testDownloadFile() throws IOException {
//        VspDetails expectedVsp = VSPCommon.createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null);
//        VspDetails createdVsp = vendorSoftwareProductManager.createVsp(expectedVsp, USER1);
//
//        id005 = createdVsp.getId();
//        Assert.assertNotNull(id005);
//        Assert.assertNotNull(createdVsp.getVersion());
//
//        try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) {
//
//            UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1);
//            vendorSoftwareProductManager.process(id005, USER1);
//            Optional<File> fileCandidate = vendorSoftwareProductManager.get(id005, USER1);
//
//            File latestHeatPackage = fileCandidate.get();
//
//            zipInputStream.reset();
//            byte[] uploaded = IOUtils.toByteArray(zipInputStream);
//
//            Optional<FileContentHandler> zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded);
//            FileContentHandler fileContentHandler = new FileContentHandler();
//            if(zipContentMap.isPresent()){
//                 fileContentHandler = zipContentMap.get();
//            }
//
//            uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values());
//
//            byte[] downloaded;
//            try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) {
//                downloaded = IOUtils.toByteArray(fileStream);
//            }
//
//            Assert.assertTrue(Arrays.equals(uploaded, downloaded));
//        }
//    }

  // todo ********************** move to common **************************************

  private void mockVersioning(VersionableEntityAction action) {
    VersionInfo versionInfo = new VersionInfo();
    versionInfo.setActiveVersion(VERSION01);
    doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
        action);
  }

  private void mockVersioningEntityNotExist(VersionableEntityAction action, String vspId) {
    doThrow(new CoreException(new EntityNotExistErrorBuilder(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build()))
        .when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1,
        action);
  }

  private void MockVersioningEntityLocked(VersionableEntityAction action) {
    doThrow(new CoreException(new EditOnEntityLockedByOtherErrorBuilder(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1)
        .build()))
        .when(versioningManagerMock).getEntityVersionInfo(
        VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2,
        action);
  }
}