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 public static final Version VERSION01 = new Version("version_id");
30 private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao;
33 private CompositionEntityDataManager compositionEntityDataManager;
37 private ImageManagerImpl imageManager;
40 public void setUp() throws Exception {
41 MockitoAnnotations.initMocks(this);
45 public void createImage() {
46 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
47 doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
49 imageManager.createImage(imageEntity);
50 verify(compositionEntityDataManager).createImage(imageEntity);
54 public void createImageHeat() {
55 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
56 doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
59 imageManager.createImage(imageEntity);
61 } catch (CoreException exception) {
62 Assert.assertEquals(exception.code().id(),
63 VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
66 /*private static final String USER1 = "imageTestUser1";
67 private static final String USER2 = "imageTestUser2";
68 private static final Version VERSION01 = new Version(0, 1);
69 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
70 new VendorSoftwareProductManagerImpl();
71 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
72 VendorSoftwareProductDaoFactory
73 .getInstance().createInterface();
75 private static String image1Id;
78 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
79 "\"description\": \"desc manual\"}";
81 private static String vsp1Id;
82 private static String vsp2Id;
83 private static String vsp3Id;
84 private static String comp1Id;
86 private static String image2Id;
91 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
92 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
93 "vlm1Id", "icon", "category", "subCategory", "123", null,
94 VSPCommon.OnboardingMethod.Manual.name())1
96 vsp1Id = vsp1.getId();
98 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
99 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
100 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.
102 vsp2Id = vsp2.getId();
104 VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon
105 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
107 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
108 .OnboardingMethod.HEAT.name())1);
109 vsp3Id = vsp3.getId();
111 ComponentEntity comp = new ComponentEntity();
112 comp.setVspId(vsp2Id);
113 comp.setCompositionData(comp1);
114 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
115 comp1Id = createdComp.getId();
119 public void testListImagesNonExistingVspId_negative() {
120 testList_negative("non existing vsp id", null, image1Id1,
121 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
122 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
126 public void testListImagesNonExistingVfcId_negative() {
127 testList_negative(vsp1Id, VERSION01, "444"1,
128 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
129 "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product "
130 + "with id "+vsp1Id+ " and version "+VERSION01);
134 public void testListImages() {
135 createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki");
136 createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi");
137 final Collection<ImageEntity> imageEntities =
138 vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id1);
139 System.out.println("size::"+imageEntities.size());
143 public void testCreateNonExistingVspId_negative() {
144 testCreate_negative(new ImageEntity("non existing vsp id", null, null, null)1,
145 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
146 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist.");
150 public void testCreateNonExistingVfcId_negative() {
151 testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null)1,
152 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
153 "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product "
154 + "with id "+vsp1Id + " and version "+VERSION01);
157 @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative")
158 public void testCreateOnAvailableVsp_negative() {
159 vendorSoftwareProductManager.checkin(vsp1Id1);
160 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)1,
161 VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY,
162 "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not"
166 @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative")
167 public void testCreateOnVspOtherUser_negative() {
168 vendorSoftwareProductManager.checkout(vsp1Id1);
169 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)2,
170 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER,
171 "Versionable entity VendorSoftwareProduct with id " +vsp1Id+
172 " can not be edited since it is locked by other user "+ USER1+ ".");
175 @Test(dependsOnMethods = "testCreateOnVspOtherUser_negative")
176 public void testOnUndoCheckoutImagesDeleted() {
178 ComponentEntity comp = new ComponentEntity();
179 comp.setVspId(vsp1Id);
180 comp.setCompositionData(comp1);
181 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
182 String compId = createdComp.getId();
184 vendorSoftwareProductManager.checkin(vsp1Id1);
185 vendorSoftwareProductManager.checkout(vsp1Id1);
187 for(int i = 1; i<=3; i++) {
188 ImageEntity imageEntity = new ImageEntity();
189 imageEntity.setVspId(vsp1Id);
190 imageEntity.setComponentId(compId);
191 Image image = new Image();
192 image.setFileName(i + "testimage.aki");
193 //image.setVersion("9.2.0");
194 image.setDescription("riverbed image");
195 //image.setFormat("aki");
196 //image.setMd5("233343DDDD");
197 imageEntity.setImageCompositionData(image);
198 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
201 Collection<ImageEntity> imageEntities =
202 vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
204 Assert.assertEquals(imageEntities.size(), 3);
206 vendorSoftwareProductManager.undoCheckout(vsp1Id1);
208 imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
210 Assert.assertEquals(imageEntities.size(), 0);
214 public void testCreateOnHeatVsp_negative() {
215 final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder =
216 NotSupportedHeatOnboardMethodErrorBuilder
217 .getAddImageNotSupportedHeatOnboardMethodErrorBuilder();
218 testCreate_negative(new ImageEntity(vsp3Id, null, null, null)1,
219 addImageNotSupportedHeatOnboardMethodErrorBuilder.id(),
220 addImageNotSupportedHeatOnboardMethodErrorBuilder.message()
224 @Test(dependsOnMethods = "testListImages")
225 public void testCreateImage() {
226 ImageEntity createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
227 Assert.assertNotNull(image1Id);
228 Assert.assertNotNull(createdImage.getCompositionData());
229 Assert.assertNotNull(
230 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,image1Id,
234 @Test(dependsOnMethods = "testCreateImage")
235 public void testCreateDupImageNameForSameComponent_negative() {
236 ImageEntity createdImage = null;
238 createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
241 catch(CoreException exception) {
242 Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.
243 DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
244 Assert.assertEquals(exception.getMessage(),
245 String.format("Invalid request, Image with name riverbed-WX-IMG-9.2.0.qcow2 already " +
246 "exists for component with ID "+comp1Id)+".");
251 public void testGet() {
252 ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
253 testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId()1, createdImage);
257 public void testGetNonExistingVspId_negative() {
258 testGet_negative("non existing vsp id", null, null, image1Id1,
259 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
260 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
264 public void testGetNonExistingVfcId_negative() {
265 testGet_negative(vsp1Id, VERSION01, "111", null1,
266 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
267 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
268 + "with id "+vsp1Id + " and version "+VERSION01);
272 public void testUpdateNonExistingVspId_negative() {
273 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
275 testUpdate_negative(imageEntity1,
276 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
277 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
280 @Test(dependsOnMethods = "testUpdateNonExistingVspId_negative")
281 public void testUpdateNonExistingVfcId_negative() {
282 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
284 testUpdate_negative(imageEntity1,
285 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
286 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
287 + "with id "+vsp1Id + " and version "+VERSION01);
290 @Test(dependsOnMethods = "testUpdateNonExistingVfcId_negative")
291 public void testUpdateNonExistingImageId_negative() {
292 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
294 testUpdate_negative(imageEntity1,
295 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
296 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
297 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
300 @Test(dependsOnMethods = "testCreateImage")
301 public void testUpdate() {
302 ImageEntity imageEntity = createImageEntity("testimage1","qcow2");
303 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
305 final Image imageCompositionData = imageEntity.getImageCompositionData();
306 //imageCompositionData.setVersion("10.0");
307 imageCompositionData.setDescription("updated image");
309 vendorSoftwareProductManager.updateImage(imageEntity1);
311 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
312 image2Id = imageEntity.getId();
315 @Test(dependsOnMethods = "testUpdate")
316 public void testUpdateNegative_UniqueName() {
317 final CompositionEntityResponse<Image> image =
318 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,
320 final Image data = image.getData();
322 final Image imageCompositionData = data;
323 imageCompositionData.setFileName("riverbed-WX-IMG-9.2.0.qcow2");
325 ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id );
326 entity.setImageCompositionData(imageCompositionData);
327 testUpdate_negative(entity1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
328 "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id()
329 ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id)
333 @Test(dependsOnMethods = "testUpdateNegative_UniqueName")
334 public void testDeleteImage() {
335 CompositionEntityResponse<Image> image =
336 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id1);
338 Assert.assertNotNull(image.getData());
340 vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id1);
342 testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id1,
343 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
344 "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " +
345 "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 );
350 public void testDeleteNonExistingVspId_negative() {
351 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
353 testDelete_negative(imageEntity1,
354 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
355 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
358 @Test(dependsOnMethods = "testDeleteNonExistingVspId_negative")
359 public void testDeleteNonExistingVfcId_negative() {
360 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
362 testDelete_negative(imageEntity1,
363 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
364 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
365 + "with id "+vsp1Id + " and version "+VERSION01);
368 @Test(dependsOnMethods = "testDeleteNonExistingVfcId_negative")
369 public void testDeleteNonExistingImageId_negative() {
370 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
372 testDelete_negative(imageEntity1,
373 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
374 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
375 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
379 public void testUpdateandGetQuestionnaire() {
380 ImageEntity imageEntity = createImageEntity("newimage_testUpdateandGetQuestionnaire.vdi","vdi");
381 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
382 "{\"format\":\"vdi\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
385 final QuestionnaireResponse imageQuestionnaire =
386 vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id,
387 imageEntity.getId()1);
389 String imageDetails = imageQuestionnaire.getData();
390 Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat());
391 Assert.assertEquals("1.2", JsonUtil.json2Object(imageDetails, ImageDetails.class).getVersion());
392 Assert.assertEquals("ssd3344", JsonUtil.json2Object(imageDetails, ImageDetails.class).getMd5());
396 public void testUpdateQuestionnaireInvalidFormat_negative() {
397 ImageEntity imageEntity = createImageEntity("newimage.vdi","vdi");
399 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
400 "{\"format\":\"invalidformat\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
404 catch(CoreException exception) {
405 Assert.assertEquals(exception.code().id(), "VFC_IMAGE_INVALID_FORMAT");
406 Assert.assertEquals(exception.getMessage(), "The format value doesn't meet the expected "
407 + "attribute value.");
411 private ImageEntity createImageEntity(String fileName, String format) {
412 ImageEntity imageEntity = new ImageEntity();
413 imageEntity.setVspId(vsp2Id);
414 imageEntity.setComponentId(comp1Id);
415 Image image = new Image();
416 image.setFileName(fileName);
417 //image.setVersion("9.2.0");
418 image.setDescription("riverbed image");
419 //image.setFormat(format);
420 // image.setMd5("233343DDDD");
421 imageEntity.setImageCompositionData(image);
423 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
424 image1Id = createdImage.getId();
428 private void testGet(String vspId, Version version, String componentId, String imageId, String
429 user, ImageEntity expected) {
430 CompositionEntityResponse<Image>
431 response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId);
432 Assert.assertEquals(response.getId(), expected.getId());
433 Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData().
435 Assert.assertEquals(expected.getImageCompositionData().getDescription(), response.getData().
437 Assert.assertNotNull(response.getSchema());
440 private void testCreate_negative(ImageEntity image, String user,
441 String expectedErrorCode, String expectedErrorMsg) {
443 vendorSoftwareProductManager.createImage(image);
445 } catch (CoreException exception) {
446 Assert.assertEquals(exception.code().id(), expectedErrorCode);
447 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
451 private void testGet_negative(String vspId, Version version, String componentId, String imageId,
453 String expectedErrorCode, String expectedErrorMsg) {
455 vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId);
457 } catch (CoreException exception) {
458 Assert.assertEquals(exception.code().id(), expectedErrorCode);
459 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
463 private void testList_negative(String vspId, Version version, String componentId, String user,
464 String expectedErrorCode, String expectedErrorMsg) {
466 vendorSoftwareProductManager.listImages(vspId, version, componentId);
468 } catch (CoreException exception) {
469 Assert.assertEquals(exception.code().id(), expectedErrorCode);
470 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
474 private void testUpdate_negative(ImageEntity imageEntity,
476 String expectedErrorCode, String expectedErrorMsg) {
479 vendorSoftwareProductManager.updateImage(imageEntity);
481 } catch (CoreException exception) {
482 Assert.assertEquals(exception.code().id(), expectedErrorCode);
483 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
487 private void testDelete_negative(ImageEntity imageEntity,
489 String expectedErrorCode, String expectedErrorMsg) {
492 vendorSoftwareProductManager.updateImage(imageEntity);
494 } catch (CoreException exception) {
495 Assert.assertEquals(exception.code().id(), expectedErrorCode);
496 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);