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.AfterMethod;
16 import org.testng.annotations.BeforeMethod;
17 import org.testng.annotations.Test;
19 import static org.mockito.Matchers.anyObject;
20 import static org.mockito.Mockito.doReturn;
21 import static org.mockito.Mockito.verify;
23 public class ImagesTest {
25 private static String VSP_ID = "VSP_ID";
26 private static String COMP_ID = "COMP_ID";
27 private static String ID = "ID";
28 public static final Version VERSION01 = new Version("version_id");
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 tearDown(){
51 public void createImage() {
52 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
53 doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
55 imageManager.createImage(imageEntity);
56 verify(compositionEntityDataManager).createImage(imageEntity);
60 public void createImageHeat() {
61 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
62 doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject());
65 imageManager.createImage(imageEntity);
67 } catch (CoreException exception) {
68 Assert.assertEquals(exception.code().id(),
69 VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
72 /*private static final String USER1 = "imageTestUser1";
73 private static final String USER2 = "imageTestUser2";
74 private static final Version VERSION01 = new Version(0, 1);
75 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
76 new VendorSoftwareProductManagerImpl();
77 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
78 VendorSoftwareProductDaoFactory
79 .getInstance().createInterface();
81 private static String image1Id;
84 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
85 "\"description\": \"desc manual\"}";
87 private static String vsp1Id;
88 private static String vsp2Id;
89 private static String vsp3Id;
90 private static String comp1Id;
92 private static String image2Id;
97 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
98 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
99 "vlm1Id", "icon", "category", "subCategory", "123", null,
100 VSPCommon.OnboardingMethod.Manual.name())1
102 vsp1Id = vsp1.getId();
104 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
105 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
106 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.
108 vsp2Id = vsp2.getId();
110 VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon
111 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
113 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
114 .OnboardingMethod.HEAT.name())1);
115 vsp3Id = vsp3.getId();
117 ComponentEntity comp = new ComponentEntity();
118 comp.setVspId(vsp2Id);
119 comp.setCompositionData(comp1);
120 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
121 comp1Id = createdComp.getId();
125 public void testListImagesNonExistingVspId_negative() {
126 testList_negative("non existing vsp id", null, image1Id1,
127 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
128 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
132 public void testListImagesNonExistingVfcId_negative() {
133 testList_negative(vsp1Id, VERSION01, "444"1,
134 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
135 "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product "
136 + "with id "+vsp1Id+ " and version "+VERSION01);
140 public void testListImages() {
141 createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki");
142 createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi");
143 final Collection<ImageEntity> imageEntities =
144 vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id1);
145 System.out.println("size::"+imageEntities.size());
149 public void testCreateNonExistingVspId_negative() {
150 testCreate_negative(new ImageEntity("non existing vsp id", null, null, null)1,
151 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
152 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist.");
156 public void testCreateNonExistingVfcId_negative() {
157 testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null)1,
158 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
159 "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product "
160 + "with id "+vsp1Id + " and version "+VERSION01);
163 @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative")
164 public void testCreateOnAvailableVsp_negative() {
165 vendorSoftwareProductManager.checkin(vsp1Id1);
166 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)1,
167 VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY,
168 "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not"
172 @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative")
173 public void testCreateOnVspOtherUser_negative() {
174 vendorSoftwareProductManager.checkout(vsp1Id1);
175 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)2,
176 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER,
177 "Versionable entity VendorSoftwareProduct with id " +vsp1Id+
178 " can not be edited since it is locked by other user "+ USER1+ ".");
181 @Test(dependsOnMethods = "testCreateOnVspOtherUser_negative")
182 public void testOnUndoCheckoutImagesDeleted() {
184 ComponentEntity comp = new ComponentEntity();
185 comp.setVspId(vsp1Id);
186 comp.setCompositionData(comp1);
187 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
188 String compId = createdComp.getId();
190 vendorSoftwareProductManager.checkin(vsp1Id1);
191 vendorSoftwareProductManager.checkout(vsp1Id1);
193 for(int i = 1; i<=3; i++) {
194 ImageEntity imageEntity = new ImageEntity();
195 imageEntity.setVspId(vsp1Id);
196 imageEntity.setComponentId(compId);
197 Image image = new Image();
198 image.setFileName(i + "testimage.aki");
199 //image.setVersion("9.2.0");
200 image.setDescription("riverbed image");
201 //image.setFormat("aki");
202 //image.setMd5("233343DDDD");
203 imageEntity.setImageCompositionData(image);
204 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
207 Collection<ImageEntity> imageEntities =
208 vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
210 Assert.assertEquals(imageEntities.size(), 3);
212 vendorSoftwareProductManager.undoCheckout(vsp1Id1);
214 imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
216 Assert.assertEquals(imageEntities.size(), 0);
220 public void testCreateOnHeatVsp_negative() {
221 final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder =
222 NotSupportedHeatOnboardMethodErrorBuilder
223 .getAddImageNotSupportedHeatOnboardMethodErrorBuilder();
224 testCreate_negative(new ImageEntity(vsp3Id, null, null, null)1,
225 addImageNotSupportedHeatOnboardMethodErrorBuilder.id(),
226 addImageNotSupportedHeatOnboardMethodErrorBuilder.message()
230 @Test(dependsOnMethods = "testListImages")
231 public void testCreateImage() {
232 ImageEntity createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
233 Assert.assertNotNull(image1Id);
234 Assert.assertNotNull(createdImage.getCompositionData());
235 Assert.assertNotNull(
236 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,image1Id,
240 @Test(dependsOnMethods = "testCreateImage")
241 public void testCreateDupImageNameForSameComponent_negative() {
242 ImageEntity createdImage = null;
244 createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
247 catch(CoreException exception) {
248 Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.
249 DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
250 Assert.assertEquals(exception.getMessage(),
251 String.format("Invalid request, Image with name riverbed-WX-IMG-9.2.0.qcow2 already " +
252 "exists for component with ID "+comp1Id)+".");
257 public void testGet() {
258 ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
259 testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId()1, createdImage);
263 public void testGetNonExistingVspId_negative() {
264 testGet_negative("non existing vsp id", null, null, image1Id1,
265 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
266 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
270 public void testGetNonExistingVfcId_negative() {
271 testGet_negative(vsp1Id, VERSION01, "111", null1,
272 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
273 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
274 + "with id "+vsp1Id + " and version "+VERSION01);
278 public void testUpdateNonExistingVspId_negative() {
279 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
281 testUpdate_negative(imageEntity1,
282 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
283 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
286 @Test(dependsOnMethods = "testUpdateNonExistingVspId_negative")
287 public void testUpdateNonExistingVfcId_negative() {
288 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
290 testUpdate_negative(imageEntity1,
291 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
292 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
293 + "with id "+vsp1Id + " and version "+VERSION01);
296 @Test(dependsOnMethods = "testUpdateNonExistingVfcId_negative")
297 public void testUpdateNonExistingImageId_negative() {
298 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
300 testUpdate_negative(imageEntity1,
301 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
302 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
303 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
306 @Test(dependsOnMethods = "testCreateImage")
307 public void testUpdate() {
308 ImageEntity imageEntity = createImageEntity("testimage1","qcow2");
309 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
311 final Image imageCompositionData = imageEntity.getImageCompositionData();
312 //imageCompositionData.setVersion("10.0");
313 imageCompositionData.setDescription("updated image");
315 vendorSoftwareProductManager.updateImage(imageEntity1);
317 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
318 image2Id = imageEntity.getId();
321 @Test(dependsOnMethods = "testUpdate")
322 public void testUpdateNegative_UniqueName() {
323 final CompositionEntityResponse<Image> image =
324 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,
326 final Image data = image.getData();
328 final Image imageCompositionData = data;
329 imageCompositionData.setFileName("riverbed-WX-IMG-9.2.0.qcow2");
331 ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id );
332 entity.setImageCompositionData(imageCompositionData);
333 testUpdate_negative(entity1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
334 "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id()
335 ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id)
339 @Test(dependsOnMethods = "testUpdateNegative_UniqueName")
340 public void testDeleteImage() {
341 CompositionEntityResponse<Image> image =
342 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id1);
344 Assert.assertNotNull(image.getData());
346 vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id1);
348 testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id1,
349 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
350 "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " +
351 "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 );
356 public void testDeleteNonExistingVspId_negative() {
357 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
359 testDelete_negative(imageEntity1,
360 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
361 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
364 @Test(dependsOnMethods = "testDeleteNonExistingVspId_negative")
365 public void testDeleteNonExistingVfcId_negative() {
366 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
368 testDelete_negative(imageEntity1,
369 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
370 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
371 + "with id "+vsp1Id + " and version "+VERSION01);
374 @Test(dependsOnMethods = "testDeleteNonExistingVfcId_negative")
375 public void testDeleteNonExistingImageId_negative() {
376 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
378 testDelete_negative(imageEntity1,
379 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
380 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
381 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
385 public void testUpdateandGetQuestionnaire() {
386 ImageEntity imageEntity = createImageEntity("newimage_testUpdateandGetQuestionnaire.vdi","vdi");
387 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
388 "{\"format\":\"vdi\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
391 final QuestionnaireResponse imageQuestionnaire =
392 vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id,
393 imageEntity.getId()1);
395 String imageDetails = imageQuestionnaire.getData();
396 Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat());
397 Assert.assertEquals("1.2", JsonUtil.json2Object(imageDetails, ImageDetails.class).getVersion());
398 Assert.assertEquals("ssd3344", JsonUtil.json2Object(imageDetails, ImageDetails.class).getMd5());
402 public void testUpdateQuestionnaireInvalidFormat_negative() {
403 ImageEntity imageEntity = createImageEntity("newimage.vdi","vdi");
405 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
406 "{\"format\":\"invalidformat\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
410 catch(CoreException exception) {
411 Assert.assertEquals(exception.code().id(), "VFC_IMAGE_INVALID_FORMAT");
412 Assert.assertEquals(exception.getMessage(), "The format value doesn't meet the expected "
413 + "attribute value.");
417 private ImageEntity createImageEntity(String fileName, String format) {
418 ImageEntity imageEntity = new ImageEntity();
419 imageEntity.setVspId(vsp2Id);
420 imageEntity.setComponentId(comp1Id);
421 Image image = new Image();
422 image.setFileName(fileName);
423 //image.setVersion("9.2.0");
424 image.setDescription("riverbed image");
425 //image.setFormat(format);
426 // image.setMd5("233343DDDD");
427 imageEntity.setImageCompositionData(image);
429 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
430 image1Id = createdImage.getId();
434 private void testGet(String vspId, Version version, String componentId, String imageId, String
435 user, ImageEntity expected) {
436 CompositionEntityResponse<Image>
437 response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId);
438 Assert.assertEquals(response.getId(), expected.getId());
439 Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData().
441 Assert.assertEquals(expected.getImageCompositionData().getDescription(), response.getData().
443 Assert.assertNotNull(response.getSchema());
446 private void testCreate_negative(ImageEntity image, String user,
447 String expectedErrorCode, String expectedErrorMsg) {
449 vendorSoftwareProductManager.createImage(image);
451 } catch (CoreException exception) {
452 Assert.assertEquals(exception.code().id(), expectedErrorCode);
453 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
457 private void testGet_negative(String vspId, Version version, String componentId, String imageId,
459 String expectedErrorCode, String expectedErrorMsg) {
461 vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId);
463 } catch (CoreException exception) {
464 Assert.assertEquals(exception.code().id(), expectedErrorCode);
465 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
469 private void testList_negative(String vspId, Version version, String componentId, String user,
470 String expectedErrorCode, String expectedErrorMsg) {
472 vendorSoftwareProductManager.listImages(vspId, version, componentId);
474 } catch (CoreException exception) {
475 Assert.assertEquals(exception.code().id(), expectedErrorCode);
476 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
480 private void testUpdate_negative(ImageEntity imageEntity,
482 String expectedErrorCode, String expectedErrorMsg) {
485 vendorSoftwareProductManager.updateImage(imageEntity);
487 } catch (CoreException exception) {
488 Assert.assertEquals(exception.code().id(), expectedErrorCode);
489 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
493 private void testDelete_negative(ImageEntity imageEntity,
495 String expectedErrorCode, String expectedErrorMsg) {
498 vendorSoftwareProductManager.updateImage(imageEntity);
500 } catch (CoreException exception) {
501 Assert.assertEquals(exception.code().id(), expectedErrorCode);
502 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);