2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct;
23 import org.junit.After;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.MockitoAnnotations;
30 import org.mockito.Spy;
31 import org.openecomp.sdc.common.errors.CoreException;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity;
34 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
35 import org.openecomp.sdc.vendorsoftwareproduct.impl.ImageManagerImpl;
36 import org.openecomp.sdc.versioning.dao.types.Version;
38 import static org.mockito.ArgumentMatchers.any;
39 import static org.mockito.Mockito.doReturn;
40 import static org.mockito.Mockito.verify;
42 public class ImagesTest {
44 private static String VSP_ID = "VSP_ID";
45 private static String COMP_ID = "COMP_ID";
46 private static String ID = "ID";
47 public static final Version VERSION01 = new Version("version_id");
50 private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao;
53 private CompositionEntityDataManager compositionEntityDataManager;
57 private ImageManagerImpl imageManager;
60 public void setUp() throws Exception {
61 MockitoAnnotations.initMocks(this);
65 public void tearDown(){
70 public void createImage() {
71 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
72 doReturn(true).when(vendorSoftwareProductInfoDao).isManual(any(), any());
74 imageManager.createImage(imageEntity);
75 verify(compositionEntityDataManager).createImage(imageEntity);
79 public void createImageHeat() {
80 ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID);
81 doReturn(false).when(vendorSoftwareProductInfoDao).isManual(any(), any());
84 imageManager.createImage(imageEntity);
86 } catch (CoreException exception) {
87 Assert.assertEquals(exception.code().id(),
88 VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
91 /*private static final String USER1 = "imageTestUser1";
92 private static final String USER2 = "imageTestUser2";
93 private static final Version VERSION01 = new Version(0, 1);
94 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
95 new VendorSoftwareProductManagerImpl();
96 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
97 VendorSoftwareProductDaoFactory
98 .getInstance().createInterface();
100 private static String image1Id;
103 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
104 "\"description\": \"desc manual\"}";
106 private static String vsp1Id;
107 private static String vsp2Id;
108 private static String vsp3Id;
109 private static String comp1Id;
111 private static String image2Id;
114 private void init() {
116 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
117 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
118 "vlm1Id", "icon", "category", "subCategory", "123", null,
119 VSPCommon.OnboardingMethod.Manual.name())1
121 vsp1Id = vsp1.getId();
123 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
124 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
125 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon.OnboardingMethod.
127 vsp2Id = vsp2.getId();
129 VspDetails vsp3 = vendorSoftwareProductManager.createNewVsp(VSPCommon
130 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
132 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
133 .OnboardingMethod.HEAT.name())1);
134 vsp3Id = vsp3.getId();
136 ComponentEntity comp = new ComponentEntity();
137 comp.setVspId(vsp2Id);
138 comp.setCompositionData(comp1);
139 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
140 comp1Id = createdComp.getId();
144 public void testListImagesNonExistingVspId_negative() {
145 testList_negative("non existing vsp id", null, image1Id1,
146 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
147 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
151 public void testListImagesNonExistingVfcId_negative() {
152 testList_negative(vsp1Id, VERSION01, "444"1,
153 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
154 "Vendor Software Product Component with Id 444 does not exist for Vendor Software Product "
155 + "with id "+vsp1Id+ " and version "+VERSION01);
159 public void testListImages() {
160 createImageEntity("media-vsrx-vmdisk-15.1X49-D40.6.aki", "aki");
161 createImageEntity("riverbed-15.1X49-D40.6.vdi", "vdi");
162 final Collection<ImageEntity> imageEntities =
163 vendorSoftwareProductManager.listImages(vsp2Id, VERSION01, comp1Id1);
164 System.out.println("size::"+imageEntities.size());
168 public void testCreateNonExistingVspId_negative() {
169 testCreate_negative(new ImageEntity("non existing vsp id", null, null, null)1,
170 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
171 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist.");
175 public void testCreateNonExistingVfcId_negative() {
176 testCreate_negative(new ImageEntity(vsp1Id, VERSION01, "222", null)1,
177 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
178 "Vendor Software Product Component with Id 222 does not exist for Vendor Software Product "
179 + "with id "+vsp1Id + " and version "+VERSION01);
182 @Test(dependsOnMethods = "testUpdateNonExistingImageId_negative")
183 public void testCreateOnAvailableVsp_negative() {
184 vendorSoftwareProductManager.checkin(vsp1Id1);
185 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)1,
186 VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY,
187 "Can not edit versionable entity VendorSoftwareProduct with id "+vsp1Id+ " since it is not"
191 @Test(dependsOnMethods = "testCreateOnAvailableVsp_negative")
192 public void testCreateOnVspOtherUser_negative() {
193 vendorSoftwareProductManager.checkout(vsp1Id1);
194 testCreate_negative(new ImageEntity(vsp1Id, null, null, null)2,
195 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER,
196 "Versionable entity VendorSoftwareProduct with id " +vsp1Id+
197 " can not be edited since it is locked by other user "+ USER1+ ".");
200 @Test(dependsOnMethods = "testCreateOnVspOtherUser_negative")
201 public void testOnUndoCheckoutImagesDeleted() {
203 ComponentEntity comp = new ComponentEntity();
204 comp.setVspId(vsp1Id);
205 comp.setCompositionData(comp1);
206 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(comp1);
207 String compId = createdComp.getId();
209 vendorSoftwareProductManager.checkin(vsp1Id1);
210 vendorSoftwareProductManager.checkout(vsp1Id1);
212 for(int i = 1; i<=3; i++) {
213 ImageEntity imageEntity = new ImageEntity();
214 imageEntity.setVspId(vsp1Id);
215 imageEntity.setComponentId(compId);
216 Image image = new Image();
217 image.setFileName(i + "testimage.aki");
218 //image.setVersion("9.2.0");
219 image.setDescription("riverbed image");
220 //image.setFormat("aki");
221 //image.setMd5("233343DDDD");
222 imageEntity.setImageCompositionData(image);
223 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
226 Collection<ImageEntity> imageEntities =
227 vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
229 Assert.assertEquals(imageEntities.size(), 3);
231 vendorSoftwareProductManager.undoCheckout(vsp1Id1);
233 imageEntities = vendorSoftwareProductManager.listImages(vsp1Id, null, compId1);
235 Assert.assertEquals(imageEntities.size(), 0);
239 public void testCreateOnHeatVsp_negative() {
240 final ErrorCode addImageNotSupportedHeatOnboardMethodErrorBuilder =
241 NotSupportedHeatOnboardMethodErrorBuilder
242 .getAddImageNotSupportedHeatOnboardMethodErrorBuilder();
243 testCreate_negative(new ImageEntity(vsp3Id, null, null, null)1,
244 addImageNotSupportedHeatOnboardMethodErrorBuilder.id(),
245 addImageNotSupportedHeatOnboardMethodErrorBuilder.message()
249 @Test(dependsOnMethods = "testListImages")
250 public void testCreateImage() {
251 ImageEntity createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
252 Assert.assertNotNull(image1Id);
253 Assert.assertNotNull(createdImage.getCompositionData());
254 Assert.assertNotNull(
255 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,image1Id,
259 @Test(dependsOnMethods = "testCreateImage")
260 public void testCreateDupImageNameForSameComponent_negative() {
261 ImageEntity createdImage = null;
263 createdImage = createImageEntity("riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
266 catch(CoreException exception) {
267 Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.
268 DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
269 Assert.assertEquals(exception.getMessage(),
270 String.format("Invalid request, Image with name riverbed-WX-IMG-9.2.0.qcow2 already " +
271 "exists for component with ID "+comp1Id)+".");
276 public void testGet() {
277 ImageEntity createdImage = createImageEntity("read-riverbed-WX-IMG-9.2.0.qcow2", "qcow2");
278 testGet(vsp2Id, VERSION01, comp1Id, createdImage.getId()1, createdImage);
282 public void testGetNonExistingVspId_negative() {
283 testGet_negative("non existing vsp id", null, null, image1Id1,
284 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
285 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
289 public void testGetNonExistingVfcId_negative() {
290 testGet_negative(vsp1Id, VERSION01, "111", null1,
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);
297 public void testUpdateNonExistingVspId_negative() {
298 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
300 testUpdate_negative(imageEntity1,
301 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
302 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
305 @Test(dependsOnMethods = "testUpdateNonExistingVspId_negative")
306 public void testUpdateNonExistingVfcId_negative() {
307 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
309 testUpdate_negative(imageEntity1,
310 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
311 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
312 + "with id "+vsp1Id + " and version "+VERSION01);
315 @Test(dependsOnMethods = "testUpdateNonExistingVfcId_negative")
316 public void testUpdateNonExistingImageId_negative() {
317 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
319 testUpdate_negative(imageEntity1,
320 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
321 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
322 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
325 @Test(dependsOnMethods = "testCreateImage")
326 public void testUpdate() {
327 ImageEntity imageEntity = createImageEntity("testimage1","qcow2");
328 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
330 final Image imageCompositionData = imageEntity.getImageCompositionData();
331 //imageCompositionData.setVersion("10.0");
332 imageCompositionData.setDescription("updated image");
334 vendorSoftwareProductManager.updateImage(imageEntity1);
336 testGet(vsp2Id, VERSION01, comp1Id, imageEntity.getId(),USER1, imageEntity );
337 image2Id = imageEntity.getId();
340 @Test(dependsOnMethods = "testUpdate")
341 public void testUpdateNegative_UniqueName() {
342 final CompositionEntityResponse<Image> image =
343 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id,
345 final Image data = image.getData();
347 final Image imageCompositionData = data;
348 imageCompositionData.setFileName("riverbed-WX-IMG-9.2.0.qcow2");
350 ImageEntity entity = new ImageEntity(vsp2Id, VERSION01, comp1Id, image2Id );
351 entity.setImageCompositionData(imageCompositionData);
352 testUpdate_negative(entity1, ImageErrorBuilder.getDuplicateImageNameErrorBuilder(
353 "riverbed-WX-IMG-9.2.0.qcow2", comp1Id).id()
354 ,ImageErrorBuilder.getDuplicateImageNameErrorBuilder("riverbed-WX-IMG-9.2.0.qcow2", comp1Id)
358 @Test(dependsOnMethods = "testUpdateNegative_UniqueName")
359 public void testDeleteImage() {
360 CompositionEntityResponse<Image> image =
361 vendorSoftwareProductManager.getImage(vsp2Id, VERSION01, comp1Id, image2Id1);
363 Assert.assertNotNull(image.getData());
365 vendorSoftwareProductManager.deleteImage(vsp2Id, comp1Id, image2Id1);
367 testGet_negative(vsp2Id, VERSION01, comp1Id, image2Id1,
368 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
369 "Vendor Software Product Component Image with Id "+image2Id+ " does not exist for " +
370 "Vendor Software Product with id "+vsp2Id+ " and version "+VERSION01 );
375 public void testDeleteNonExistingVspId_negative() {
376 ImageEntity imageEntity = new ImageEntity("non existing vsp id", null, null, image1Id);
378 testDelete_negative(imageEntity1,
379 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST,
380 "Versionable entity VendorSoftwareProduct with id non existing vsp id does not exist." );
383 @Test(dependsOnMethods = "testDeleteNonExistingVspId_negative")
384 public void testDeleteNonExistingVfcId_negative() {
385 ImageEntity imageEntity = new ImageEntity(vsp1Id, VERSION01, "111", null);
387 testDelete_negative(imageEntity1,
388 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
389 "Vendor Software Product Component with Id 111 does not exist for Vendor Software Product "
390 + "with id "+vsp1Id + " and version "+VERSION01);
393 @Test(dependsOnMethods = "testDeleteNonExistingVfcId_negative")
394 public void testDeleteNonExistingImageId_negative() {
395 ImageEntity imageEntity = new ImageEntity(vsp2Id, VERSION01, comp1Id, "222");
397 testDelete_negative(imageEntity1,
398 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND,
399 "Vendor Software Product Component Image with Id 222 does not exist for Vendor " +
400 "Software Product with id "+vsp2Id+ " and version "+VERSION01 );
404 public void testUpdateandGetQuestionnaire() {
405 ImageEntity imageEntity = createImageEntity("newimage_testUpdateandGetQuestionnaire.vdi","vdi");
406 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
407 "{\"format\":\"vdi\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
410 final QuestionnaireResponse imageQuestionnaire =
411 vendorSoftwareProductManager.getImageQuestionnaire(vsp2Id, VERSION01, comp1Id,
412 imageEntity.getId()1);
414 String imageDetails = imageQuestionnaire.getData();
415 Assert.assertEquals("vdi", JsonUtil.json2Object(imageDetails, ImageDetails.class).getFormat());
416 Assert.assertEquals("1.2", JsonUtil.json2Object(imageDetails, ImageDetails.class).getVersion());
417 Assert.assertEquals("ssd3344", JsonUtil.json2Object(imageDetails, ImageDetails.class).getMd5());
421 public void testUpdateQuestionnaireInvalidFormat_negative() {
422 ImageEntity imageEntity = createImageEntity("newimage.vdi","vdi");
424 vendorSoftwareProductManager.updateImageQuestionnaire(vsp2Id, comp1Id, imageEntity.getId(),
425 "{\"format\":\"invalidformat\",\"version\":\"1.2\",\"md5\":\"ssd3344\"}",
429 catch(CoreException exception) {
430 Assert.assertEquals(exception.code().id(), "VFC_IMAGE_INVALID_FORMAT");
431 Assert.assertEquals(exception.getMessage(), "The format value doesn't meet the expected "
432 + "attribute value.");
436 private ImageEntity createImageEntity(String fileName, String format) {
437 ImageEntity imageEntity = new ImageEntity();
438 imageEntity.setVspId(vsp2Id);
439 imageEntity.setComponentId(comp1Id);
440 Image image = new Image();
441 image.setFileName(fileName);
442 //image.setVersion("9.2.0");
443 image.setDescription("riverbed image");
444 //image.setFormat(format);
445 // image.setMd5("233343DDDD");
446 imageEntity.setImageCompositionData(image);
448 ImageEntity createdImage = vendorSoftwareProductManager.createImage(imageEntity1);
449 image1Id = createdImage.getId();
453 private void testGet(String vspId, Version version, String componentId, String imageId, String
454 user, ImageEntity expected) {
455 CompositionEntityResponse<Image>
456 response = vendorSoftwareProductManager.getImage(vspId, null, componentId, imageId);
457 Assert.assertEquals(response.getId(), expected.getId());
458 Assert.assertEquals(expected.getImageCompositionData().getFileName(), response.getData().
460 Assert.assertEquals(expected.getImageCompositionData().getDescription(), response.getData().
462 Assert.assertNotNull(response.getSchema());
465 private void testCreate_negative(ImageEntity image, String user,
466 String expectedErrorCode, String expectedErrorMsg) {
468 vendorSoftwareProductManager.createImage(image);
470 } catch (CoreException exception) {
471 Assert.assertEquals(exception.code().id(), expectedErrorCode);
472 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
476 private void testGet_negative(String vspId, Version version, String componentId, String imageId,
478 String expectedErrorCode, String expectedErrorMsg) {
480 vendorSoftwareProductManager.getImage(vspId, version, componentId, imageId);
482 } catch (CoreException exception) {
483 Assert.assertEquals(exception.code().id(), expectedErrorCode);
484 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
488 private void testList_negative(String vspId, Version version, String componentId, String user,
489 String expectedErrorCode, String expectedErrorMsg) {
491 vendorSoftwareProductManager.listImages(vspId, version, componentId);
493 } catch (CoreException exception) {
494 Assert.assertEquals(exception.code().id(), expectedErrorCode);
495 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
499 private void testUpdate_negative(ImageEntity imageEntity,
501 String expectedErrorCode, String expectedErrorMsg) {
504 vendorSoftwareProductManager.updateImage(imageEntity);
506 } catch (CoreException exception) {
507 Assert.assertEquals(exception.code().id(), expectedErrorCode);
508 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);
512 private void testDelete_negative(ImageEntity imageEntity,
514 String expectedErrorCode, String expectedErrorMsg) {
517 vendorSoftwareProductManager.updateImage(imageEntity);
519 } catch (CoreException exception) {
520 Assert.assertEquals(exception.code().id(), expectedErrorCode);
521 Assert.assertEquals(exception.getMessage(), expectedErrorMsg);