Add collaboration feature
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / ImagesTest.java
index 5dcb7f9..d78f404 100644 (file)
@@ -21,50 +21,48 @@ import static org.mockito.Mockito.verify;
 
 public class ImagesTest {
 
-    private static String VSP_ID = "VSP_ID";
-    private static String COMP_ID = "COMP_ID";
-    private static String ID = "ID";
-    private static String USER = "USER";
-    public static final Version VERSION01 = new Version(0, 1);
+  private static String VSP_ID = "VSP_ID";
+  private static String COMP_ID = "COMP_ID";
+  private static String ID = "ID";
+  public static final Version VERSION01 = new Version("version_id");
 
-    @Mock
-    private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao;
+  @Mock
+  private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao;
 
-    @Mock
-    private CompositionEntityDataManager compositionEntityDataManager;
+  @Mock
+  private CompositionEntityDataManager compositionEntityDataManager;
 
-    @InjectMocks
-    @Spy
-    private ImageManagerImpl imageManager;
+  @InjectMocks
+  @Spy
+  private ImageManagerImpl imageManager;
 
-    @BeforeMethod
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-    }
+  @BeforeMethod
+  public void setUp() throws Exception {
+    MockitoAnnotations.initMocks(this);
+  }
 
-    @Test
-    public void createImage()
-    {
-        ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
-        doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
+  @Test
+  public void createImage() {
+    ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
+    doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
 
-        imageManager.createImage(imageEntity, USER);
-        verify(compositionEntityDataManager).createImage(imageEntity);
-    }
+    imageManager.createImage(imageEntity);
+    verify(compositionEntityDataManager).createImage(imageEntity);
+  }
 
-    @Test
-    public void createImageHeat()
-    {
-        ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
-        doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
-
-        try {
-            imageManager.createImage(imageEntity, USER);
-            Assert.fail();
-        } catch (CoreException exception) {
-            Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
-        }
+  @Test
+  public void createImageHeat() {
+    ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
+    doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
+
+    try {
+      imageManager.createImage(imageEntity);
+      Assert.fail();
+    } catch (CoreException exception) {
+      Assert.assertEquals(exception.code().id(),
+          VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
     }
+  }
   /*private static final String USER1 = "imageTestUser1";
   private static final String USER2 = "imageTestUser2";
   private static final Version VERSION01 = new Version(0, 1);
@@ -93,40 +91,40 @@ public class ImagesTest {
         vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
         .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
             "vlm1Id", "icon", "category", "subCategory", "123", null,
-            VSPCommon.OnboardingMethod.Manual.name()), USER1
+            VSPCommon.OnboardingMethod.Manual.name())1
         );
     vsp1Id = vsp1.getId();
 
     VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
         .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
             "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.
-                Manual.name()), USER1);
+                Manual.name())1);
     vsp2Id = vsp2.getId();
 
     VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon
         .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
             "vendorName",
             "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
-                .OnboardingMethod.HEAT.name()), USER1);
+                .OnboardingMethod.HEAT.name())1);
     vsp3Id = vsp3.getId();
 
     ComponentEntity comp = new ComponentEntity();
     comp.setVspId(vsp2Id);
     comp.setCompositionData(comp1);
-    ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1);
+    ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
     comp1Id = createdComp.getId();
   }
 
   @Test
   public void testListImagesNonExistingVspId_negative() {
-    testList_negative("non existing vsp id", null, image1Id, USER1,
+    testList_negative("non existing vsp id", null, image1Id1,
         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
         "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
   }
 
   @Test
   public void testListImagesNonExistingVfcId_negative() {
-    testList_negative(vsp1Id, VERSION01, "444", USER1,
+    testList_negative(vsp1Id, VERSION01, "444"1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product "
             + "with id "+vsp1Id+ " and version "+VERSION01);
@@ -137,20 +135,20 @@ public class ImagesTest {
     createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki");
     createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi");
     final Collection<ImageEntity> imageEntities =
-        vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id, USER1);
+        vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id1);
     System.out.println("size::"+imageEntities.size());
   }
 
   @Test
   public void testCreateNonExistingVspId_negative() {
-    testCreate_negative(new ImageEntity("non existing vsp id", null, null, null), USER1,
+    testCreate_negative(new ImageEntity("non existing vsp id", null, null, null)1,
         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
         "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist.");
   }
 
   @Test
   public void testCreateNonExistingVfcId_negative() {
-    testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null), USER1,
+    testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null)1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product "
             + "with id "+vsp1Id + " and version "+VERSION01);
@@ -158,8 +156,8 @@ public class ImagesTest {
 
   @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative")
   public void testCreateOnAvailableVsp_negative() {
-    vendorSoftwareProductManager.checkin(vsp1Id, USER1);
-    testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER1,
+    vendorSoftwareProductManager.checkin(vsp1Id1);
+    testCreate_negative(new ImageEntity(vsp1Id, null, null, null)1,
         VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY,
         "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not"
             + " checked out.");
@@ -167,8 +165,8 @@ public class ImagesTest {
 
   @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative")
   public void testCreateOnVspOtherUser_negative() {
-    vendorSoftwareProductManager.checkout(vsp1Id, USER1);
-    testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER2,
+    vendorSoftwareProductManager.checkout(vsp1Id1);
+    testCreate_negative(new ImageEntity(vsp1Id, null, null, null)2,
         VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER,
         "Versionable entity VendorSoftwareProduct with id " +vsp1Id+
             " can not be edited since it is locked by other user "+ USER1+ ".");
@@ -180,11 +178,11 @@ public class ImagesTest {
     ComponentEntity comp = new ComponentEntity();
     comp.setVspId(vsp1Id);
     comp.setCompositionData(comp1);
-    ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1);
+    ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
     String compId = createdComp.getId();
 
-    vendorSoftwareProductManager.checkin(vsp1Id, USER1);
-    vendorSoftwareProductManager.checkout(vsp1Id, USER1);
+    vendorSoftwareProductManager.checkin(vsp1Id1);
+    vendorSoftwareProductManager.checkout(vsp1Id1);
 
     for(int i = 1; i<=3; i++) {
       ImageEntity imageEntity = new ImageEntity();
@@ -197,17 +195,17 @@ public class ImagesTest {
       //image.setFormat("aki");
       //image.setMd5("233343DDDD");
       imageEntity.setImageCompositionData(image);
-      ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1);
+      ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
     }
 
     Collection<ImageEntity> imageEntities =
-        vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1);
+        vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
 
     Assert.assertEquals(imageEntities.size(), 3);
 
-    vendorSoftwareProductManager.undoCheckout(vsp1Id, USER1);
+    vendorSoftwareProductManager.undoCheckout(vsp1Id1);
 
-    imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1);
+    imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
 
     Assert.assertEquals(imageEntities.size(), 0);
   }
@@ -217,7 +215,7 @@ public class ImagesTest {
     final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder =
         NotSupportedHeatOnboardMethodErrorBuilder
             .getAddImageNotSupportedHeatOnboardMethodErrorBuilder();
-    testCreate_negative(new ImageEntity(vsp3Id, null, null, null), USER1,
+    testCreate_negative(new ImageEntity(vsp3Id, null, null, null)1,
         addImageNotSupportedHeatOnboardMethodErrorBuilder.id(),
         addImageNotSupportedHeatOnboardMethodErrorBuilder.message()
         );
@@ -252,19 +250,19 @@ public class ImagesTest {
   @Test
   public void testGet() {
     ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
-    testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId(), USER1, createdImage);
+    testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId()1, createdImage);
   }
 
   @Test
   public void testGetNonExistingVspId_negative() {
-    testGet_negative("non existing vsp id", null, null, image1Id, USER1,
+    testGet_negative("non existing vsp id", null, null, image1Id1,
         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
         "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
   }
 
   @Test
   public void testGetNonExistingVfcId_negative() {
-    testGet_negative(vsp1Id, VERSION01, "111", null, USER1,
+    testGet_negative(vsp1Id, VERSION01, "111", null1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
             + "with id "+vsp1Id + " and version "+VERSION01);
@@ -274,7 +272,7 @@ public class ImagesTest {
   public void testUpdateNonExistingVspId_negative() {
     ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
 
-    testUpdate_negative(imageEntity, USER1,
+    testUpdate_negative(imageEntity1,
         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
         "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
   }
@@ -283,7 +281,7 @@ public class ImagesTest {
   public void testUpdateNonExistingVfcId_negative() {
     ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
 
-    testUpdate_negative(imageEntity, USER1,
+    testUpdate_negative(imageEntity1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
             + "with id "+vsp1Id + " and version "+VERSION01);
@@ -293,7 +291,7 @@ public class ImagesTest {
   public void testUpdateNonExistingImageId_negative() {
     ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
 
-    testUpdate_negative(imageEntity, USER1,
+    testUpdate_negative(imageEntity1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
             "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
@@ -308,7 +306,7 @@ public class ImagesTest {
     //imageCompositionData.setVersion("10.0");
     imageCompositionData.setDescription("updated image");
 
-    vendorSoftwareProductManager.updateImage(imageEntity, USER1);
+    vendorSoftwareProductManager.updateImage(imageEntity1);
 
     testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
     image2Id = imageEntity.getId();
@@ -318,7 +316,7 @@ public class ImagesTest {
   public void testUpdateNegative_UniqueName() {
     final CompositionEntityResponse<Image> image =
         vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,
-            image2Id, USER1);
+            image2Id1);
     final Image data = image.getData();
 
     final Image imageCompositionData = data;
@@ -326,7 +324,7 @@ public class ImagesTest {
 
     ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id );
     entity.setImageCompositionData(imageCompositionData);
-    testUpdate_negative(entity, USER1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
+    testUpdate_negative(entity1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
         "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id()
         ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id)
             .message() );
@@ -335,13 +333,13 @@ public class ImagesTest {
   @Test(dependsOnMethods = "testUpdateNegative_UniqueName")
   public void testDeleteImage() {
     CompositionEntityResponse<Image> image =
-        vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id, USER1);
+        vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id1);
 
     Assert.assertNotNull(image.getData());
 
-    vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id, USER1);
+    vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id1);
 
-    testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id, USER1,
+    testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " +
             "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 );
@@ -352,7 +350,7 @@ public class ImagesTest {
   public void testDeleteNonExistingVspId_negative() {
     ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
 
-    testDelete_negative(imageEntity, USER1,
+    testDelete_negative(imageEntity1,
         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
         "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
   }
@@ -361,7 +359,7 @@ public class ImagesTest {
   public void testDeleteNonExistingVfcId_negative() {
     ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
 
-    testDelete_negative(imageEntity, USER1,
+    testDelete_negative(imageEntity1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
             + "with id "+vsp1Id + " and version "+VERSION01);
@@ -371,7 +369,7 @@ public class ImagesTest {
   public void testDeleteNonExistingImageId_negative() {
     ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
 
-    testDelete_negative(imageEntity, USER1,
+    testDelete_negative(imageEntity1,
         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
         "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
             "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
@@ -386,7 +384,7 @@ public class ImagesTest {
 
     final QuestionnaireResponse imageQuestionnaire =
         vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id,
-            imageEntity.getId(), USER1);
+            imageEntity.getId()1);
 
     String imageDetails = imageQuestionnaire.getData();
     Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat());
@@ -422,7 +420,7 @@ public class ImagesTest {
     // image.setMd5("233343DDDD");
     imageEntity.setImageCompositionData(image);
 
-    ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1);
+    ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
     image1Id = createdImage.getId();
     return createdImage;
   }
@@ -430,7 +428,7 @@ public class ImagesTest {
   private void testGet(String vspId, Version version, String componentId, String imageId, String
       user, ImageEntity expected) {
     CompositionEntityResponse<Image>
-        response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId, user);
+        response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId);
     Assert.assertEquals(response.getId(), expected.getId());
     Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData().
         getFileName());
@@ -442,7 +440,7 @@ public class ImagesTest {
   private void testCreate_negative(ImageEntity image, String user,
                                    String expectedErrorCode, String expectedErrorMsg) {
     try {
-      vendorSoftwareProductManager.createImage(image, user);
+      vendorSoftwareProductManager.createImage(image);
       Assert.fail();
     } catch (CoreException exception) {
       Assert.assertEquals(exception.code().id(), expectedErrorCode);
@@ -454,7 +452,7 @@ public class ImagesTest {
                                 String user,
                                 String expectedErrorCode, String expectedErrorMsg) {
     try {
-      vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId, user);
+      vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId);
       Assert.fail();
     } catch (CoreException exception) {
       Assert.assertEquals(exception.code().id(), expectedErrorCode);
@@ -465,7 +463,7 @@ public class ImagesTest {
   private void testList_negative(String vspId, Version version, String componentId, String user,
                                  String expectedErrorCode, String expectedErrorMsg) {
     try {
-      vendorSoftwareProductManager.listImages(vspId, version, componentId, user);
+      vendorSoftwareProductManager.listImages(vspId, version, componentId);
       Assert.fail();
     } catch (CoreException exception) {
       Assert.assertEquals(exception.code().id(), expectedErrorCode);
@@ -478,7 +476,7 @@ public class ImagesTest {
                                 String expectedErrorCode, String expectedErrorMsg) {
     try {
 
-      vendorSoftwareProductManager.updateImage(imageEntity, user);
+      vendorSoftwareProductManager.updateImage(imageEntity);
       Assert.fail();
     } catch (CoreException exception) {
       Assert.assertEquals(exception.code().id(), expectedErrorCode);
@@ -491,7 +489,7 @@ public class ImagesTest {
                                    String expectedErrorCode, String expectedErrorMsg) {
     try {
 
-      vendorSoftwareProductManager.updateImage(imageEntity, user);
+      vendorSoftwareProductManager.updateImage(imageEntity);
       Assert.fail();
     } catch (CoreException exception) {
       Assert.assertEquals(exception.code().id(), expectedErrorCode);