1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
7 import org.mockito.InjectMocks;
8 import org.mockito.Mock;
9 import org.mockito.MockitoAnnotations;
10 import org.mockito.Spy;
11 import org.openecomp.sdc.common.errors.CoreException;
12 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
14 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
15 import org.openecomp.sdc.vendorsoftwareproduct.impl.ImageManagerImpl;
16 import org.openecomp.sdc.versioning.dao.types.Version;
18 import static org.mockito.ArgumentMatchers.any;
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 tearDown(){
50 public void createImage() {
51 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
52 doReturn(true).when(vendorSoftwareProductInfoDao).isManual(any(), any());
54 imageManager.createImage(imageEntity);
55 verify(compositionEntityDataManager).createImage(imageEntity);
59 public void createImageHeat() {
60 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
61 doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(), any());
64 imageManager.createImage(imageEntity);
66 } catch (CoreException exception) {
67 Assert.assertEquals(exception.code().id(),
68 VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
71 /*private static final String USER1 = "imageTestUser1";
72 private static final String USER2 = "imageTestUser2";
73 private static final Version VERSION01 = new Version(0, 1);
74 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
75 new VendorSoftwareProductManagerImpl();
76 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
77 VendorSoftwareProductDaoFactory
78 .getInstance().createInterface();
80 private static String image1Id;
83 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
84 "\"description\": \"desc manual\"}";
86 private static String vsp1Id;
87 private static String vsp2Id;
88 private static String vsp3Id;
89 private static String comp1Id;
91 private static String image2Id;
96 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
97 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
98 "vlm1Id", "icon", "category", "subCategory", "123", null,
99 VSPCommon.OnboardingMethod.Manual.name())1
101 vsp1Id = vsp1.getId();
103 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
104 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
105 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.
107 vsp2Id = vsp2.getId();
109 VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon
110 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
112 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
113 .OnboardingMethod.HEAT.name())1);
114 vsp3Id = vsp3.getId();
116 ComponentEntity comp = new ComponentEntity();
117 comp.setVspId(vsp2Id);
118 comp.setCompositionData(comp1);
119 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
120 comp1Id = createdComp.getId();
124 public void testListImagesNonExistingVspId_negative() {
125 testList_negative("non existing vsp id", null, image1Id1,
126 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
127 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
131 public void testListImagesNonExistingVfcId_negative() {
132 testList_negative(vsp1Id, VERSION01, "444"1,
133 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
134 "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product "
135 + "with id "+vsp1Id+ " and version "+VERSION01);
139 public void testListImages() {
140 createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki");
141 createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi");
142 final Collection<ImageEntity> imageEntities =
143 vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id1);
144 System.out.println("size::"+imageEntities.size());
148 public void testCreateNonExistingVspId_negative() {
149 testCreate_negative(new ImageEntity("non existing vsp id", null, null, null)1,
150 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
151 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist.");
155 public void testCreateNonExistingVfcId_negative() {
156 testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null)1,
157 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
158 "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product "
159 + "with id "+vsp1Id + " and version "+VERSION01);
162 @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative")
163 public void testCreateOnAvailableVsp_negative() {
164 vendorSoftwareProductManager.checkin(vsp1Id1);
165 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)1,
166 VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY,
167 "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not"
171 @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative")
172 public void testCreateOnVspOtherUser_negative() {
173 vendorSoftwareProductManager.checkout(vsp1Id1);
174 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)2,
175 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER,
176 "Versionable entity VendorSoftwareProduct with id " +vsp1Id+
177 " can not be edited since it is locked by other user "+ USER1+ ".");
180 @Test(dependsOnMethods = "testCreateOnVspOtherUser_negative")
181 public void testOnUndoCheckoutImagesDeleted() {
183 ComponentEntity comp = new ComponentEntity();
184 comp.setVspId(vsp1Id);
185 comp.setCompositionData(comp1);
186 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
187 String compId = createdComp.getId();
189 vendorSoftwareProductManager.checkin(vsp1Id1);
190 vendorSoftwareProductManager.checkout(vsp1Id1);
192 for(int i = 1; i<=3; i++) {
193 ImageEntity imageEntity = new ImageEntity();
194 imageEntity.setVspId(vsp1Id);
195 imageEntity.setComponentId(compId);
196 Image image = new Image();
197 image.setFileName(i + "testimage.aki");
198 //image.setVersion("9.2.0");
199 image.setDescription("riverbed image");
200 //image.setFormat("aki");
201 //image.setMd5("233343DDDD");
202 imageEntity.setImageCompositionData(image);
203 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
206 Collection<ImageEntity> imageEntities =
207 vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
209 Assert.assertEquals(imageEntities.size(), 3);
211 vendorSoftwareProductManager.undoCheckout(vsp1Id1);
213 imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
215 Assert.assertEquals(imageEntities.size(), 0);
219 public void testCreateOnHeatVsp_negative() {
220 final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder =
221 NotSupportedHeatOnboardMethodErrorBuilder
222 .getAddImageNotSupportedHeatOnboardMethodErrorBuilder();
223 testCreate_negative(new ImageEntity(vsp3Id, null, null, null)1,
224 addImageNotSupportedHeatOnboardMethodErrorBuilder.id(),
225 addImageNotSupportedHeatOnboardMethodErrorBuilder.message()
229 @Test(dependsOnMethods = "testListImages")
230 public void testCreateImage() {
231 ImageEntity createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
232 Assert.assertNotNull(image1Id);
233 Assert.assertNotNull(createdImage.getCompositionData());
234 Assert.assertNotNull(
235 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,image1Id,
239 @Test(dependsOnMethods = "testCreateImage")
240 public void testCreateDupImageNameForSameComponent_negative() {
241 ImageEntity createdImage = null;
243 createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
246 catch(CoreException exception) {
247 Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.
248 DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
249 Assert.assertEquals(exception.getMessage(),
250 String.format("Invalid request, Image with name riverbed-WX-IMG-9.2.0.qcow2 already " +
251 "exists for component with ID "+comp1Id)+".");
256 public void testGet() {
257 ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
258 testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId()1, createdImage);
262 public void testGetNonExistingVspId_negative() {
263 testGet_negative("non existing vsp id", null, null, image1Id1,
264 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
265 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
269 public void testGetNonExistingVfcId_negative() {
270 testGet_negative(vsp1Id, VERSION01, "111", null1,
271 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
272 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
273 + "with id "+vsp1Id + " and version "+VERSION01);
277 public void testUpdateNonExistingVspId_negative() {
278 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
280 testUpdate_negative(imageEntity1,
281 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
282 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
285 @Test(dependsOnMethods = "testUpdateNonExistingVspId_negative")
286 public void testUpdateNonExistingVfcId_negative() {
287 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
289 testUpdate_negative(imageEntity1,
290 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
291 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
292 + "with id "+vsp1Id + " and version "+VERSION01);
295 @Test(dependsOnMethods = "testUpdateNonExistingVfcId_negative")
296 public void testUpdateNonExistingImageId_negative() {
297 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
299 testUpdate_negative(imageEntity1,
300 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
301 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
302 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
305 @Test(dependsOnMethods = "testCreateImage")
306 public void testUpdate() {
307 ImageEntity imageEntity = createImageEntity("testimage1","qcow2");
308 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
310 final Image imageCompositionData = imageEntity.getImageCompositionData();
311 //imageCompositionData.setVersion("10.0");
312 imageCompositionData.setDescription("updated image");
314 vendorSoftwareProductManager.updateImage(imageEntity1);
316 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
317 image2Id = imageEntity.getId();
320 @Test(dependsOnMethods = "testUpdate")
321 public void testUpdateNegative_UniqueName() {
322 final CompositionEntityResponse<Image> image =
323 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,
325 final Image data = image.getData();
327 final Image imageCompositionData = data;
328 imageCompositionData.setFileName("riverbed-WX-IMG-9.2.0.qcow2");
330 ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id );
331 entity.setImageCompositionData(imageCompositionData);
332 testUpdate_negative(entity1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
333 "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id()
334 ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id)
338 @Test(dependsOnMethods = "testUpdateNegative_UniqueName")
339 public void testDeleteImage() {
340 CompositionEntityResponse<Image> image =
341 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id1);
343 Assert.assertNotNull(image.getData());
345 vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id1);
347 testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id1,
348 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
349 "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " +
350 "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 );
355 public void testDeleteNonExistingVspId_negative() {
356 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
358 testDelete_negative(imageEntity1,
359 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
360 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
363 @Test(dependsOnMethods = "testDeleteNonExistingVspId_negative")
364 public void testDeleteNonExistingVfcId_negative() {
365 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
367 testDelete_negative(imageEntity1,
368 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
369 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
370 + "with id "+vsp1Id + " and version "+VERSION01);
373 @Test(dependsOnMethods = "testDeleteNonExistingVfcId_negative")
374 public void testDeleteNonExistingImageId_negative() {
375 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
377 testDelete_negative(imageEntity1,
378 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
379 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
380 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
384 public void testUpdateandGetQuestionnaire() {
385 ImageEntity imageEntity = createImageEntity("newimage_testUpdateandGetQuestionnaire.vdi","vdi");
386 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
387 "{\"format\":\"vdi\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
390 final QuestionnaireResponse imageQuestionnaire =
391 vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id,
392 imageEntity.getId()1);
394 String imageDetails = imageQuestionnaire.getData();
395 Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat());
396 Assert.assertEquals("1.2", JsonUtil.json2Object(imageDetails, ImageDetails.class).getVersion());
397 Assert.assertEquals("ssd3344", JsonUtil.json2Object(imageDetails, ImageDetails.class).getMd5());
401 public void testUpdateQuestionnaireInvalidFormat_negative() {
402 ImageEntity imageEntity = createImageEntity("newimage.vdi","vdi");
404 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
405 "{\"format\":\"invalidformat\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
409 catch(CoreException exception) {
410 Assert.assertEquals(exception.code().id(), "VFC_IMAGE_INVALID_FORMAT");
411 Assert.assertEquals(exception.getMessage(), "The format value doesn't meet the expected "
412 + "attribute value.");
416 private ImageEntity createImageEntity(String fileName, String format) {
417 ImageEntity imageEntity = new ImageEntity();
418 imageEntity.setVspId(vsp2Id);
419 imageEntity.setComponentId(comp1Id);
420 Image image = new Image();
421 image.setFileName(fileName);
422 //image.setVersion("9.2.0");
423 image.setDescription("riverbed image");
424 //image.setFormat(format);
425 // image.setMd5("233343DDDD");
426 imageEntity.setImageCompositionData(image);
428 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
429 image1Id = createdImage.getId();
433 private void testGet(String vspId, Version version, String componentId, String imageId, String
434 user, ImageEntity expected) {
435 CompositionEntityResponse<Image>
436 response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId);
437 Assert.assertEquals(response.getId(), expected.getId());
438 Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData().
440 Assert.assertEquals(expected.getImageCompositionData().getDescription(), response.getData().
442 Assert.assertNotNull(response.getSchema());
445 private void testCreate_negative(ImageEntity image, String user,
446 String expectedErrorCode, String expectedErrorMsg) {
448 vendorSoftwareProductManager.createImage(image);
450 } catch (CoreException exception) {
451 Assert.assertEquals(exception.code().id(), expectedErrorCode);
452 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
456 private void testGet_negative(String vspId, Version version, String componentId, String imageId,
458 String expectedErrorCode, String expectedErrorMsg) {
460 vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId);
462 } catch (CoreException exception) {
463 Assert.assertEquals(exception.code().id(), expectedErrorCode);
464 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
468 private void testList_negative(String vspId, Version version, String componentId, String user,
469 String expectedErrorCode, String expectedErrorMsg) {
471 vendorSoftwareProductManager.listImages(vspId, version, componentId);
473 } catch (CoreException exception) {
474 Assert.assertEquals(exception.code().id(), expectedErrorCode);
475 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
479 private void testUpdate_negative(ImageEntity imageEntity,
481 String expectedErrorCode, String expectedErrorMsg) {
484 vendorSoftwareProductManager.updateImage(imageEntity);
486 } catch (CoreException exception) {
487 Assert.assertEquals(exception.code().id(), expectedErrorCode);
488 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
492 private void testDelete_negative(ImageEntity imageEntity,
494 String expectedErrorCode, String expectedErrorMsg) {
497 vendorSoftwareProductManager.updateImage(imageEntity);
499 } catch (CoreException exception) {
500 Assert.assertEquals(exception.code().id(), expectedErrorCode);
501 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);