1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.openecomp.core.utilities.CommonMethods;
4 import org.openecomp.core.utilities.json.JsonUtil;
5 import org.openecomp.sdc.common.errors.CoreException;
6 import org.openecomp.sdc.common.errors.ErrorCode;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
9 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
12 import org.openecomp.sdc.vendorsoftwareproduct.errors.ImageErrorBuilder;
13 import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder;
14 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
15 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
16 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
17 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
18 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image;
19 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.image.ImageDetails;
20 import org.openecomp.sdc.versioning.dao.types.Version;
21 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
22 import org.testng.Assert;
23 import org.testng.annotations.BeforeClass;
24 import org.testng.annotations.Test;
26 import java.util.Collection;
28 public class ImagesTest {
30 /*private static final String USER1 = "imageTestUser1";
31 private static final String USER2 = "imageTestUser2";
32 private static final Version VERSION01 = new Version(0, 1);
33 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
34 new VendorSoftwareProductManagerImpl();
35 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
36 VendorSoftwareProductDaoFactory
37 .getInstance().createInterface();
39 private static String image1Id;
42 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
43 "\"description\": \"desc manual\"}";
45 private static String vsp1Id;
46 private static String vsp2Id;
47 private static String vsp3Id;
48 private static String comp1Id;
50 private static String image2Id;
55 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
56 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
57 "vlm1Id", "icon", "category", "subCategory", "123", null,
58 VSPCommon.OnboardingMethod.Manual.name()), USER1
60 vsp1Id = vsp1.getId();
62 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
63 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
64 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.
65 Manual.name()), USER1);
66 vsp2Id = vsp2.getId();
68 VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon
69 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
71 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
72 .OnboardingMethod.HEAT.name()), USER1);
73 vsp3Id = vsp3.getId();
75 ComponentEntity comp = new ComponentEntity();
76 comp.setVspId(vsp2Id);
77 comp.setCompositionData(comp1);
78 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1);
79 comp1Id = createdComp.getId();
83 public void testListImagesNonExistingVspId_negative() {
84 testList_negative("non existing vsp id", null, image1Id, USER1,
85 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
86 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
90 public void testListImagesNonExistingVfcId_negative() {
91 testList_negative(vsp1Id, VERSION01, "444", USER1,
92 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
93 "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product "
94 + "with id "+vsp1Id+ " and version "+VERSION01);
98 public void testListImages() {
99 createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki");
100 createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi");
101 final Collection<ImageEntity> imageEntities =
102 vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id, USER1);
103 System.out.println("size::"+imageEntities.size());
107 public void testCreateNonExistingVspId_negative() {
108 testCreate_negative(new ImageEntity("non existing vsp id", null, null, null), USER1,
109 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
110 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist.");
114 public void testCreateNonExistingVfcId_negative() {
115 testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null), USER1,
116 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
117 "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product "
118 + "with id "+vsp1Id + " and version "+VERSION01);
121 @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative")
122 public void testCreateOnAvailableVsp_negative() {
123 vendorSoftwareProductManager.checkin(vsp1Id, USER1);
124 testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER1,
125 VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY,
126 "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not"
130 @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative")
131 public void testCreateOnVspOtherUser_negative() {
132 vendorSoftwareProductManager.checkout(vsp1Id, USER1);
133 testCreate_negative(new ImageEntity(vsp1Id, null, null, null), USER2,
134 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER,
135 "Versionable entity VendorSoftwareProduct with id " +vsp1Id+
136 " can not be edited since it is locked by other user "+ USER1+ ".");
139 @Test(dependsOnMethods = "testCreateOnVspOtherUser_negative")
140 public void testOnUndoCheckoutImagesDeleted() {
142 ComponentEntity comp = new ComponentEntity();
143 comp.setVspId(vsp1Id);
144 comp.setCompositionData(comp1);
145 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp, USER1);
146 String compId = createdComp.getId();
148 vendorSoftwareProductManager.checkin(vsp1Id, USER1);
149 vendorSoftwareProductManager.checkout(vsp1Id, USER1);
151 for(int i = 1; i<=3; i++) {
152 ImageEntity imageEntity = new ImageEntity();
153 imageEntity.setVspId(vsp1Id);
154 imageEntity.setComponentId(compId);
155 Image image = new Image();
156 image.setFileName(i + "testimage.aki");
157 //image.setVersion("9.2.0");
158 image.setDescription("riverbed image");
159 //image.setFormat("aki");
160 //image.setMd5("233343DDDD");
161 imageEntity.setImageCompositionData(image);
162 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1);
165 Collection<ImageEntity> imageEntities =
166 vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1);
168 Assert.assertEquals(imageEntities.size(), 3);
170 vendorSoftwareProductManager.undoCheckout(vsp1Id, USER1);
172 imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId, USER1);
174 Assert.assertEquals(imageEntities.size(), 0);
178 public void testCreateOnHeatVsp_negative() {
179 final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder =
180 NotSupportedHeatOnboardMethodErrorBuilder
181 .getAddImageNotSupportedHeatOnboardMethodErrorBuilder();
182 testCreate_negative(new ImageEntity(vsp3Id, null, null, null), USER1,
183 addImageNotSupportedHeatOnboardMethodErrorBuilder.id(),
184 addImageNotSupportedHeatOnboardMethodErrorBuilder.message()
188 @Test(dependsOnMethods = "testListImages")
189 public void testCreateImage() {
190 ImageEntity createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
191 Assert.assertNotNull(image1Id);
192 Assert.assertNotNull(createdImage.getCompositionData());
193 Assert.assertNotNull(
194 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,image1Id,
198 @Test(dependsOnMethods = "testCreateImage")
199 public void testCreateDupImageNameForSameComponent_negative() {
200 ImageEntity createdImage = null;
202 createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
205 catch(CoreException exception) {
206 Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.
207 DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
208 Assert.assertEquals(exception.getMessage(),
209 String.format("Invalid request, Image with name riverbed-WX-IMG-9.2.0.qcow2 already " +
210 "exists for component with ID "+comp1Id)+".");
215 public void testGet() {
216 ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
217 testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId(), USER1, createdImage);
221 public void testGetNonExistingVspId_negative() {
222 testGet_negative("non existing vsp id", null, null, image1Id, USER1,
223 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
224 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
228 public void testGetNonExistingVfcId_negative() {
229 testGet_negative(vsp1Id, VERSION01, "111", null, USER1,
230 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
231 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
232 + "with id "+vsp1Id + " and version "+VERSION01);
236 public void testUpdateNonExistingVspId_negative() {
237 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
239 testUpdate_negative(imageEntity, USER1,
240 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
241 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
244 @Test(dependsOnMethods = "testUpdateNonExistingVspId_negative")
245 public void testUpdateNonExistingVfcId_negative() {
246 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
248 testUpdate_negative(imageEntity, USER1,
249 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
250 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
251 + "with id "+vsp1Id + " and version "+VERSION01);
254 @Test(dependsOnMethods = "testUpdateNonExistingVfcId_negative")
255 public void testUpdateNonExistingImageId_negative() {
256 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
258 testUpdate_negative(imageEntity, USER1,
259 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
260 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
261 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
264 @Test(dependsOnMethods = "testCreateImage")
265 public void testUpdate() {
266 ImageEntity imageEntity = createImageEntity("testimage1","qcow2");
267 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
269 final Image imageCompositionData = imageEntity.getImageCompositionData();
270 //imageCompositionData.setVersion("10.0");
271 imageCompositionData.setDescription("updated image");
273 vendorSoftwareProductManager.updateImage(imageEntity, USER1);
275 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
276 image2Id = imageEntity.getId();
279 @Test(dependsOnMethods = "testUpdate")
280 public void testUpdateNegative_UniqueName() {
281 final CompositionEntityResponse<Image> image =
282 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,
284 final Image data = image.getData();
286 final Image imageCompositionData = data;
287 imageCompositionData.setFileName("riverbed-WX-IMG-9.2.0.qcow2");
289 ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id );
290 entity.setImageCompositionData(imageCompositionData);
291 testUpdate_negative(entity, USER1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
292 "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id()
293 ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id)
297 @Test(dependsOnMethods = "testUpdateNegative_UniqueName")
298 public void testDeleteImage() {
299 CompositionEntityResponse<Image> image =
300 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id, USER1);
302 Assert.assertNotNull(image.getData());
304 vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id, USER1);
306 testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id, USER1,
307 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
308 "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " +
309 "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 );
314 public void testDeleteNonExistingVspId_negative() {
315 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
317 testDelete_negative(imageEntity, USER1,
318 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
319 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
322 @Test(dependsOnMethods = "testDeleteNonExistingVspId_negative")
323 public void testDeleteNonExistingVfcId_negative() {
324 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
326 testDelete_negative(imageEntity, USER1,
327 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
328 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
329 + "with id "+vsp1Id + " and version "+VERSION01);
332 @Test(dependsOnMethods = "testDeleteNonExistingVfcId_negative")
333 public void testDeleteNonExistingImageId_negative() {
334 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
336 testDelete_negative(imageEntity, USER1,
337 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
338 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
339 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
343 public void testUpdateandGetQuestionnaire() {
344 ImageEntity imageEntity = createImageEntity("newimage_testUpdateandGetQuestionnaire.vdi","vdi");
345 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
346 "{\"format\":\"vdi\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
349 final QuestionnaireResponse imageQuestionnaire =
350 vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id,
351 imageEntity.getId(), USER1);
353 String imageDetails = imageQuestionnaire.getData();
354 Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat());
355 Assert.assertEquals("1.2", JsonUtil.json2Object(imageDetails, ImageDetails.class).getVersion());
356 Assert.assertEquals("ssd3344", JsonUtil.json2Object(imageDetails, ImageDetails.class).getMd5());
360 public void testUpdateQuestionnaireInvalidFormat_negative() {
361 ImageEntity imageEntity = createImageEntity("newimage.vdi","vdi");
363 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
364 "{\"format\":\"invalidformat\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
368 catch(CoreException exception) {
369 Assert.assertEquals(exception.code().id(), "VFC_IMAGE_INVALID_FORMAT");
370 Assert.assertEquals(exception.getMessage(), "The format value doesn't meet the expected "
371 + "attribute value.");
375 private ImageEntity createImageEntity(String fileName, String format) {
376 ImageEntity imageEntity = new ImageEntity();
377 imageEntity.setVspId(vsp2Id);
378 imageEntity.setComponentId(comp1Id);
379 Image image = new Image();
380 image.setFileName(fileName);
381 //image.setVersion("9.2.0");
382 image.setDescription("riverbed image");
383 //image.setFormat(format);
384 // image.setMd5("233343DDDD");
385 imageEntity.setImageCompositionData(image);
387 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity, USER1);
388 image1Id = createdImage.getId();
392 private void testGet(String vspId, Version version, String componentId, String imageId, String
393 user, ImageEntity expected) {
394 CompositionEntityResponse<Image>
395 response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId, user);
396 Assert.assertEquals(response.getId(), expected.getId());
397 Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData().
399 Assert.assertEquals(expected.getImageCompositionData().getDescription(), response.getData().
401 Assert.assertNotNull(response.getSchema());
404 private void testCreate_negative(ImageEntity image, String user,
405 String expectedErrorCode, String expectedErrorMsg) {
407 vendorSoftwareProductManager.createImage(image, user);
409 } catch (CoreException exception) {
410 Assert.assertEquals(exception.code().id(), expectedErrorCode);
411 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
415 private void testGet_negative(String vspId, Version version, String componentId, String imageId,
417 String expectedErrorCode, String expectedErrorMsg) {
419 vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId, user);
421 } catch (CoreException exception) {
422 Assert.assertEquals(exception.code().id(), expectedErrorCode);
423 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
427 private void testList_negative(String vspId, Version version, String componentId, String user,
428 String expectedErrorCode, String expectedErrorMsg) {
430 vendorSoftwareProductManager.listImages(vspId, version, componentId, user);
432 } catch (CoreException exception) {
433 Assert.assertEquals(exception.code().id(), expectedErrorCode);
434 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
438 private void testUpdate_negative(ImageEntity imageEntity,
440 String expectedErrorCode, String expectedErrorMsg) {
443 vendorSoftwareProductManager.updateImage(imageEntity, user);
445 } catch (CoreException exception) {
446 Assert.assertEquals(exception.code().id(), expectedErrorCode);
447 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
451 private void testDelete_negative(ImageEntity imageEntity,
453 String expectedErrorCode, String expectedErrorMsg) {
456 vendorSoftwareProductManager.updateImage(imageEntity, user);
458 } catch (CoreException exception) {
459 Assert.assertEquals(exception.code().id(), expectedErrorCode);
460 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);