1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.mockito.InjectMocks;
4 import org.mockito.Mock;
5 import org.mockito.MockitoAnnotations;
6 import org.mockito.Spy;
7 import org.openecomp.sdc.common.errors.CoreException;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
9 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
10 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
11 import org.openecomp.sdc.vendorsoftwareproduct.impl.ImageManagerImpl;
12 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
13 import org.openecomp.sdc.versioning.dao.types.Version;
14 import org.testng.Assert;
15 import org.testng.annotations.BeforeMethod;
16 import org.testng.annotations.Test;
18 import static org.mockito.Matchers.anyObject;
19 import static org.mockito.Mockito.doReturn;
20 import static org.mockito.Mockito.verify;
22 public class ImagesTest {
24 private static String VSP_ID = "VSP_ID";
25 private static String COMP_ID = "COMP_ID";
26 private static String ID = "ID";
27 private static String USER = "USER";
28 public static final Version VERSION01 = new Version(0, 1);
31 private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao;
34 private CompositionEntityDataManager compositionEntityDataManager;
38 private ImageManagerImpl imageManager;
41 public void setUp() throws Exception {
42 MockitoAnnotations.initMocks(this);
46 public void createImage()
48 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
49 doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
51 imageManager.createImage(imageEntity, USER);
52 verify(compositionEntityDataManager).createImage(imageEntity);
56 public void createImageHeat()
58 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
59 doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
62 imageManager.createImage(imageEntity, USER);
64 } catch (CoreException exception) {
65 Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
68 /*private static final String USER1 = "imageTestUser1";
69 private static final String USER2 = "imageTestUser2";
70 private static final Version VERSION01 = new Version(0, 1);
71 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
72 new VendorSoftwareProductManagerImpl();
73 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
74 VendorSoftwareProductDaoFactory
75 .getInstance().createInterface();
77 private static String image1Id;
80 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
81 "\"description\": \"desc manual\"}";
83 private static String vsp1Id;
84 private static String vsp2Id;
85 private static String vsp3Id;
86 private static String comp1Id;
88 private static String image2Id;
93 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
94 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
95 "vlm1Id", "icon", "category", "subCategory", "123", null,
96 VSPCommon.OnboardingMethod.Manual.name()), USER1
98 vsp1Id = vsp1.getId();
100 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
101 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
102 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.
103 Manual.name()), USER1);
104 vsp2Id = vsp2.getId();
106 VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon
107 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
109 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
110 .OnboardingMethod.HEAT.name()), USER1);
111 vsp3Id = vsp3.getId();
113 ComponentEntity comp = new ComponentEntity();
114 comp.setVspId(vsp2Id);
115 comp.setCompositionData(comp1);
116 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1);
117 comp1Id = createdComp.getId();
121 public void testListImagesNonExistingVspId_negative() {
122 testList_negative("non existing vsp id", null, image1Id, USER1,
123 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
124 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
128 public void testListImagesNonExistingVfcId_negative() {
129 testList_negative(vsp1Id, VERSION01, "444", USER1,
130 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
131 "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product "
132 + "with id "+vsp1Id+ " and version "+VERSION01);
136 public void testListImages() {
137 createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki");
138 createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi");
139 final Collection<ImageEntity> imageEntities =
140 vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id, USER1);
141 System.out.println("size::"+imageEntities.size());
145 public void testCreateNonExistingVspId_negative() {
146 testCreate_negative(new ImageEntity("non existing vsp id", null, null, null), USER1,
147 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
148 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist.");
152 public void testCreateNonExistingVfcId_negative() {
153 testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null), USER1,
154 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
155 "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product "
156 + "with id "+vsp1Id + " and version "+VERSION01);
159 @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative")
160 public void testCreateOnAvailableVsp_negative() {
161 vendorSoftwareProductManager.checkin(vsp1Id, USER1);
162 testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER1,
163 VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY,
164 "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not"
168 @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative")
169 public void testCreateOnVspOtherUser_negative() {
170 vendorSoftwareProductManager.checkout(vsp1Id, USER1);
171 testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER2,
172 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER,
173 "Versionable entity VendorSoftwareProduct with id " +vsp1Id+
174 " can not be edited since it is locked by other user "+ USER1+ ".");
177 @Test(dependsOnMethods = "testCreateOnVspOtherUser_negative")
178 public void testOnUndoCheckoutImagesDeleted() {
180 ComponentEntity comp = new ComponentEntity();
181 comp.setVspId(vsp1Id);
182 comp.setCompositionData(comp1);
183 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1);
184 String compId = createdComp.getId();
186 vendorSoftwareProductManager.checkin(vsp1Id, USER1);
187 vendorSoftwareProductManager.checkout(vsp1Id, USER1);
189 for(int i = 1; i<=3; i++) {
190 ImageEntity imageEntity = new ImageEntity();
191 imageEntity.setVspId(vsp1Id);
192 imageEntity.setComponentId(compId);
193 Image image = new Image();
194 image.setFileName(i + "testimage.aki");
195 //image.setVersion("9.2.0");
196 image.setDescription("riverbed image");
197 //image.setFormat("aki");
198 //image.setMd5("233343DDDD");
199 imageEntity.setImageCompositionData(image);
200 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1);
203 Collection<ImageEntity> imageEntities =
204 vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1);
206 Assert.assertEquals(imageEntities.size(), 3);
208 vendorSoftwareProductManager.undoCheckout(vsp1Id, USER1);
210 imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1);
212 Assert.assertEquals(imageEntities.size(), 0);
216 public void testCreateOnHeatVsp_negative() {
217 final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder =
218 NotSupportedHeatOnboardMethodErrorBuilder
219 .getAddImageNotSupportedHeatOnboardMethodErrorBuilder();
220 testCreate_negative(new ImageEntity(vsp3Id, null, null, null), USER1,
221 addImageNotSupportedHeatOnboardMethodErrorBuilder.id(),
222 addImageNotSupportedHeatOnboardMethodErrorBuilder.message()
226 @Test(dependsOnMethods = "testListImages")
227 public void testCreateImage() {
228 ImageEntity createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
229 Assert.assertNotNull(image1Id);
230 Assert.assertNotNull(createdImage.getCompositionData());
231 Assert.assertNotNull(
232 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,image1Id,
236 @Test(dependsOnMethods = "testCreateImage")
237 public void testCreateDupImageNameForSameComponent_negative() {
238 ImageEntity createdImage = null;
240 createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
243 catch(CoreException exception) {
244 Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.
245 DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
246 Assert.assertEquals(exception.getMessage(),
247 String.format("Invalid request, Image with name riverbed-WX-IMG-9.2.0.qcow2 already " +
248 "exists for component with ID "+comp1Id)+".");
253 public void testGet() {
254 ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
255 testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId(), USER1, createdImage);
259 public void testGetNonExistingVspId_negative() {
260 testGet_negative("non existing vsp id", null, null, image1Id, USER1,
261 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
262 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
266 public void testGetNonExistingVfcId_negative() {
267 testGet_negative(vsp1Id, VERSION01, "111", null, USER1,
268 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
269 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
270 + "with id "+vsp1Id + " and version "+VERSION01);
274 public void testUpdateNonExistingVspId_negative() {
275 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
277 testUpdate_negative(imageEntity, USER1,
278 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
279 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
282 @Test(dependsOnMethods = "testUpdateNonExistingVspId_negative")
283 public void testUpdateNonExistingVfcId_negative() {
284 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
286 testUpdate_negative(imageEntity, USER1,
287 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
288 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
289 + "with id "+vsp1Id + " and version "+VERSION01);
292 @Test(dependsOnMethods = "testUpdateNonExistingVfcId_negative")
293 public void testUpdateNonExistingImageId_negative() {
294 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
296 testUpdate_negative(imageEntity, USER1,
297 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
298 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
299 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
302 @Test(dependsOnMethods = "testCreateImage")
303 public void testUpdate() {
304 ImageEntity imageEntity = createImageEntity("testimage1","qcow2");
305 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
307 final Image imageCompositionData = imageEntity.getImageCompositionData();
308 //imageCompositionData.setVersion("10.0");
309 imageCompositionData.setDescription("updated image");
311 vendorSoftwareProductManager.updateImage(imageEntity, USER1);
313 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
314 image2Id = imageEntity.getId();
317 @Test(dependsOnMethods = "testUpdate")
318 public void testUpdateNegative_UniqueName() {
319 final CompositionEntityResponse<Image> image =
320 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,
322 final Image data = image.getData();
324 final Image imageCompositionData = data;
325 imageCompositionData.setFileName("riverbed-WX-IMG-9.2.0.qcow2");
327 ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id );
328 entity.setImageCompositionData(imageCompositionData);
329 testUpdate_negative(entity, USER1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
330 "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id()
331 ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id)
335 @Test(dependsOnMethods = "testUpdateNegative_UniqueName")
336 public void testDeleteImage() {
337 CompositionEntityResponse<Image> image =
338 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id, USER1);
340 Assert.assertNotNull(image.getData());
342 vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id, USER1);
344 testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id, USER1,
345 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
346 "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " +
347 "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 );
352 public void testDeleteNonExistingVspId_negative() {
353 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
355 testDelete_negative(imageEntity, USER1,
356 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
357 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
360 @Test(dependsOnMethods = "testDeleteNonExistingVspId_negative")
361 public void testDeleteNonExistingVfcId_negative() {
362 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
364 testDelete_negative(imageEntity, USER1,
365 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
366 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
367 + "with id "+vsp1Id + " and version "+VERSION01);
370 @Test(dependsOnMethods = "testDeleteNonExistingVfcId_negative")
371 public void testDeleteNonExistingImageId_negative() {
372 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
374 testDelete_negative(imageEntity, USER1,
375 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
376 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
377 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
381 public void testUpdateandGetQuestionnaire() {
382 ImageEntity imageEntity = createImageEntity("newimage_testUpdateandGetQuestionnaire.vdi","vdi");
383 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
384 "{\"format\":\"vdi\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
387 final QuestionnaireResponse imageQuestionnaire =
388 vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id,
389 imageEntity.getId(), USER1);
391 String imageDetails = imageQuestionnaire.getData();
392 Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat());
393 Assert.assertEquals("1.2", JsonUtil.json2Object(imageDetails, ImageDetails.class).getVersion());
394 Assert.assertEquals("ssd3344", JsonUtil.json2Object(imageDetails, ImageDetails.class).getMd5());
398 public void testUpdateQuestionnaireInvalidFormat_negative() {
399 ImageEntity imageEntity = createImageEntity("newimage.vdi","vdi");
401 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
402 "{\"format\":\"invalidformat\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
406 catch(CoreException exception) {
407 Assert.assertEquals(exception.code().id(), "VFC_IMAGE_INVALID_FORMAT");
408 Assert.assertEquals(exception.getMessage(), "The format value doesn't meet the expected "
409 + "attribute value.");
413 private ImageEntity createImageEntity(String fileName, String format) {
414 ImageEntity imageEntity = new ImageEntity();
415 imageEntity.setVspId(vsp2Id);
416 imageEntity.setComponentId(comp1Id);
417 Image image = new Image();
418 image.setFileName(fileName);
419 //image.setVersion("9.2.0");
420 image.setDescription("riverbed image");
421 //image.setFormat(format);
422 // image.setMd5("233343DDDD");
423 imageEntity.setImageCompositionData(image);
425 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1);
426 image1Id = createdImage.getId();
430 private void testGet(String vspId, Version version, String componentId, String imageId, String
431 user, ImageEntity expected) {
432 CompositionEntityResponse<Image>
433 response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId, user);
434 Assert.assertEquals(response.getId(), expected.getId());
435 Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData().
437 Assert.assertEquals(expected.getImageCompositionData().getDescription(), response.getData().
439 Assert.assertNotNull(response.getSchema());
442 private void testCreate_negative(ImageEntity image, String user,
443 String expectedErrorCode, String expectedErrorMsg) {
445 vendorSoftwareProductManager.createImage(image, user);
447 } catch (CoreException exception) {
448 Assert.assertEquals(exception.code().id(), expectedErrorCode);
449 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
453 private void testGet_negative(String vspId, Version version, String componentId, String imageId,
455 String expectedErrorCode, String expectedErrorMsg) {
457 vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId, user);
459 } catch (CoreException exception) {
460 Assert.assertEquals(exception.code().id(), expectedErrorCode);
461 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
465 private void testList_negative(String vspId, Version version, String componentId, String user,
466 String expectedErrorCode, String expectedErrorMsg) {
468 vendorSoftwareProductManager.listImages(vspId, version, componentId, user);
470 } catch (CoreException exception) {
471 Assert.assertEquals(exception.code().id(), expectedErrorCode);
472 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
476 private void testUpdate_negative(ImageEntity imageEntity,
478 String expectedErrorCode, String expectedErrorMsg) {
481 vendorSoftwareProductManager.updateImage(imageEntity, user);
483 } catch (CoreException exception) {
484 Assert.assertEquals(exception.code().id(), expectedErrorCode);
485 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
489 private void testDelete_negative(ImageEntity imageEntity,
491 String expectedErrorCode, String expectedErrorMsg) {
494 vendorSoftwareProductManager.updateImage(imageEntity, user);
496 } catch (CoreException exception) {
497 Assert.assertEquals(exception.code().id(), expectedErrorCode);
498 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);