1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING;
4 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED;
5 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.FEATURE_GROUP_NOT_EXIST_FOR_VSP;
6 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.INVALID_COMPONENT_COMPUTE_ASSOCIATION;
7 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.INVALID_COMPUTE_FLAVOR_ID;
8 import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST;
9 import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND;
11 import org.openecomp.core.utilities.CommonMethods;
12 import org.openecomp.sdc.common.errors.CoreException;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
16 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
17 import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
18 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
19 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation;
20 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityValidationData;
21 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
22 import org.openecomp.sdc.versioning.dao.types.Version;
23 import org.testng.Assert;
24 import org.testng.annotations.BeforeClass;
25 import org.testng.annotations.Test;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.List;
31 public class DeploymentFlavorTest {
32 /*private static final String USER1 = "deploymentTestUser1";
33 private static final String USER2 = "deploymentTestUser2";
34 private static final Version VERSION01 = new Version(0, 1);
35 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
36 new VendorSoftwareProductManagerImpl();
37 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
38 VendorSoftwareProductDaoFactory.getInstance().createInterface();
40 private static String vsp1Id;
41 private static String vsp2Id;
42 private static String vsp3Id;
43 private static String component11Id;
44 private static String component21Id;
45 private static String deployment1Id = "deployment1";
46 private static String deployment2Id = "deployment2";
50 List<String> featureGroups = new ArrayList<>();
51 featureGroups.add("fg01");
52 featureGroups.add("fg02");
53 vsp1Id = vendorSoftwareProductManager.createNewVsp(VSPCommon
54 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1",
55 "vlm1Id", "icon", "category", "subCategory", "123", featureGroups,
56 VSPCommon.OnboardingMethod.
57 Manual.name()), USER1).getId();
58 component11Id = ComponentsTest.createComponent(vsp1Id, VERSION01, "component11").getId();
60 vsp2Id = vendorSoftwareProductManager.createNewVsp(VSPCommon
61 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName1",
62 "vlm1Id", "icon", "category", "subCategory", "123", null,
63 VSPCommon.OnboardingMethod.Manual.name()), USER1).getId();
64 component21Id = ComponentsTest.createComponent(vsp2Id, VERSION01, "component21").getId();
66 vsp3Id = vendorSoftwareProductManager.createNewVsp(VSPCommon
67 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3forDeployment",
69 "vlm1Id", "icon", "category", "subCategory", "123", null,
70 VSPCommon.OnboardingMethod.HEAT.name()), USER1).getId();
73 static DeploymentFlavorEntity createDeploymentFlavor(String vspId, Version version, String deploymentFlavorId) {
74 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vspId, version, deploymentFlavorId);
75 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
76 deploymentFlavor.setModel(deploymentFlavorId + " name");
77 deploymentFlavor.setDescription(deploymentFlavorId + " desc");
78 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
79 DeploymentFlavorEntity createdDeployment = vendorSoftwareProductManager
80 .createDeploymentFlavor(deploymentFlavorEntity, USER1);
81 deployment2Id = createdDeployment.getId();
82 return deploymentFlavorEntity;
86 public void testCreate() {
87 DeploymentFlavorEntity deploymentFlavorEntity =
88 new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id);
89 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
90 deploymentFlavor.setModel("TestDeploymentcreatewithoutFG");
91 deploymentFlavor.setDescription("creating a deployment flavor without any FG and any " +
93 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
94 DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor
95 (deploymentFlavorEntity, USER1);
96 Assert.assertEquals((createddeployment.getId() != null), true);
97 deployment1Id = createddeployment.getId();
100 @Test(dependsOnMethods = "testCreate")
101 public void testUniqueModelCreate() {
102 DeploymentFlavorEntity deploymentFlavorEntity =
103 new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id);
104 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
105 deploymentFlavor.setModel("TestDeploymentcreatewithoutFG");
106 deploymentFlavor.setDescription("creating a deployment flavor without any FG and any " +
108 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
110 vendorSoftwareProductManager.createDeploymentFlavor
111 (deploymentFlavorEntity, USER1);
112 } catch (CoreException exception) {
113 Assert.assertEquals(exception.code().id(), DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED);
118 public void testInvalidFeatureGroup() {
119 DeploymentFlavorEntity deploymentFlavorEntity =
120 new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id);
121 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
122 deploymentFlavor.setModel("TestInvalidFeatureGroup");
123 deploymentFlavor.setDescription("creating a deployment flavor with invalid FG and without any" +
126 deploymentFlavor.setFeatureGroupId("fg01");
127 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
129 vendorSoftwareProductManager.createDeploymentFlavor
130 (deploymentFlavorEntity, USER1);
131 } catch (CoreException exception) {
132 Assert.assertEquals(exception.code().id(), FEATURE_GROUP_NOT_EXIST_FOR_VSP);
137 public void testInvalidAssociation() {
138 DeploymentFlavorEntity deploymentFlavorEntity =
139 new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id);
140 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
141 deploymentFlavor.setModel("testInvalidAssociation");
142 deploymentFlavor.setDescription("creating a deployment flavor with wrong association with " +
143 "null compute flavor id");
144 List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>();
145 ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation();
146 componentComputeAssociation.setComputeFlavorId("72138712");
147 componentComputeAssociationList.add(componentComputeAssociation);
148 deploymentFlavor.setComponentComputeAssociations(componentComputeAssociationList);
149 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
151 vendorSoftwareProductManager.createDeploymentFlavor
152 (deploymentFlavorEntity, USER1);
153 } catch (CoreException exception) {
154 Assert.assertEquals(exception.code().id(), INVALID_COMPONENT_COMPUTE_ASSOCIATION);
160 public void testInvalidComputeFlavorIdAssociation() {
161 DeploymentFlavorEntity deploymentFlavorEntity =
162 new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id);
163 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
164 deploymentFlavor.setModel("testInvalidComputeFlavorIdAssociation");
165 deploymentFlavor.setDescription("creating a deployment flavor with wrong compute flavor id in" +
167 List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>();
168 ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation();
169 componentComputeAssociation.setComponentId(component21Id);
170 componentComputeAssociation.setComputeFlavorId("123123");
171 componentComputeAssociationList.add(componentComputeAssociation);
172 deploymentFlavor.setComponentComputeAssociations(componentComputeAssociationList);
173 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
175 vendorSoftwareProductManager.createDeploymentFlavor
176 (deploymentFlavorEntity, USER1);
177 } catch (CoreException exception) {
178 Assert.assertEquals(exception.code().id(), INVALID_COMPUTE_FLAVOR_ID);
184 public void testInvalidVfcIdAssociation() {
185 DeploymentFlavorEntity deploymentFlavorEntity =
186 new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id);
187 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
188 deploymentFlavor.setModel("testInvalidVfcIdAssociation");
189 deploymentFlavor.setDescription("creating a deployment flavor with invalid vfcid association");
190 List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>();
191 ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation();
192 componentComputeAssociation.setComponentId("WRONGVFCID");
193 componentComputeAssociation.setComputeFlavorId("123123");
194 componentComputeAssociationList.add(componentComputeAssociation);
195 deploymentFlavor.setComponentComputeAssociations(componentComputeAssociationList);
196 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
198 vendorSoftwareProductManager.createDeploymentFlavor
199 (deploymentFlavorEntity, USER1);
200 } catch (CoreException exception) {
201 Assert.assertEquals(exception.code().id(), VERSIONABLE_SUB_ENTITY_NOT_FOUND);
206 public void testNegativeforVspHeatOnboarded() {
207 DeploymentFlavorEntity deploymentFlavorEntity =
208 new DeploymentFlavorEntity(vsp3Id, VERSION01, deployment1Id);
209 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
210 deploymentFlavor.setModel("TestDeploymentcreatewithoutFG");
211 deploymentFlavor.setDescription("creating a deployment flavor for VSP onboarded with HEAT");
212 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
214 vendorSoftwareProductManager.createDeploymentFlavor
215 (deploymentFlavorEntity, USER1);
216 } catch (CoreException exception) {
217 Assert.assertEquals(exception.code().id(),
218 CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING);
223 public void testGetNegative_InvalidVspId(){
224 testGetNegative("InvalidVspId", VERSION01, deployment1Id, USER1, VERSIONABLE_ENTITY_NOT_EXIST);
228 public void testGetNegative_InvalidDeploymentFlavorId(){
229 testGetNegative(vsp1Id, VERSION01, deployment1Id, USER1, VERSIONABLE_SUB_ENTITY_NOT_FOUND);
233 public void testGet(){
234 DeploymentFlavorEntity expected = createDeploymentFlavor(vsp1Id, VERSION01,deployment2Id);
235 testGet(vsp1Id, VERSION01, deployment2Id, USER1, expected);
238 private void testGet(String vspId, Version version, String componentId, String user,
239 DeploymentFlavorEntity expected) {
240 CompositionEntityResponse<DeploymentFlavor> response = vendorSoftwareProductManager
241 .getDeploymentFlavor(vspId, null, componentId, user);
242 Assert.assertEquals(response.getId(), expected.getId());
243 Assert.assertEquals(response.getData().getDescription(),
244 expected.getDeploymentFlavorCompositionData().getDescription());
245 Assert.assertEquals(response.getData().getModel(),
246 expected.getDeploymentFlavorCompositionData().getModel());
247 Assert.assertEquals(response.getData().getFeatureGroupId(),
248 expected.getDeploymentFlavorCompositionData().getFeatureGroupId());
249 Assert.assertEquals(response.getData().getComponentComputeAssociations(),
250 expected.getDeploymentFlavorCompositionData().getComponentComputeAssociations());
251 Assert.assertNotNull(response.getSchema());
254 private void testGetNegative(String vspId, Version version, String deploymentFlavorId, String User,
255 String expectedErrorCode){
257 vendorSoftwareProductManager.getDeploymentFlavor(vspId, version, deploymentFlavorId, User);
259 } catch (CoreException exception){
260 Assert.assertEquals(exception.code().id(), expectedErrorCode);
265 public void testUpdateNegative_InvalidVspId(){
266 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity("InvalidVspId",
267 VERSION01,deployment2Id);
268 DeploymentFlavor deploymentFlavorData = new DeploymentFlavor();
269 deploymentFlavorData.setModel(deployment2Id);
270 deploymentFlavorData.setDescription("updating a deployment flavor with invalid VspId and without any" +
272 deploymentFlavorData.setFeatureGroupId("fg01");
273 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavorData);
275 testUpdateNegative(deploymentFlavorEntity, USER1, VERSIONABLE_ENTITY_NOT_EXIST);
279 public void testUpdateNegative_InvalidDeploymentFlavorId(){
280 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp1Id,
281 VERSION01,"InvalidDeploymentFlavorId");
282 testUpdateNegative(deploymentFlavorEntity, USER1, VERSIONABLE_SUB_ENTITY_NOT_FOUND);
285 @Test(dependsOnMethods = "testCreate")
286 public void testUpdateNegative_InvalidFeatureGroup(){
287 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id,
288 VERSION01,deployment1Id);
289 DeploymentFlavor deploymentFlavorData = new DeploymentFlavor();
290 deploymentFlavorData.setModel("TestDeploymentCreateWithoutFG");
291 deploymentFlavorData.setDescription("updating a deployment flavor with invalid FeatureGroupId and without any" +
293 deploymentFlavorData.setFeatureGroupId("fg01");
294 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavorData);
295 String expectedError = "#/featureGroupId: "
296 +deploymentFlavorData.getFeatureGroupId()+" is not a valid value. Possible values: ";
298 final CompositionEntityValidationData validationData = vendorSoftwareProductManager
299 .updateDeploymentFlavor(deploymentFlavorEntity, USER1);
300 final Collection<String> errors = validationData.getErrors();
301 final Object[] objects = errors.toArray();
302 Assert.assertEquals(errors.size(), 1);
303 Assert.assertEquals(objects[0], expectedError);
306 @Test(dependsOnMethods = "testCreate")
307 public void testUpdateNegative_InvalidComputeFlavorIdAssociation(){
308 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id,
309 VERSION01,deployment1Id);
310 DeploymentFlavor deploymentFlavorData = new DeploymentFlavor();
311 deploymentFlavorData.setModel("TestDeploymentcreatewithInvalidComputFlavorId");
312 deploymentFlavorData.setDescription("updating a deployment flavor with wrong compute flavor id in" +
314 List<ComponentComputeAssociation> componentComputeAssociationList = new ArrayList<>();
315 ComponentComputeAssociation componentComputeAssociation = new ComponentComputeAssociation();
316 componentComputeAssociation.setComponentId(component21Id);
317 componentComputeAssociation.setComputeFlavorId("123123");
318 componentComputeAssociationList.add(componentComputeAssociation);
319 deploymentFlavorData.setComponentComputeAssociations(componentComputeAssociationList);
320 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavorData);
322 testUpdateNegative(deploymentFlavorEntity, USER1, INVALID_COMPUTE_FLAVOR_ID);
326 public void testUpdate(){
327 //Creating a separate deployment flavor for testing deletion
328 DeploymentFlavorEntity deploymentFlavorEntity =
329 new DeploymentFlavorEntity(vsp1Id, VERSION01, deployment2Id);
330 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
331 deploymentFlavor.setModel("TestDeploymentCreateforUpdate");
332 deploymentFlavor.setDescription("creating a deployment flavor for updation");
333 deploymentFlavor.setFeatureGroupId("fg01");
334 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
335 DeploymentFlavorEntity createdDeployment = vendorSoftwareProductManager.createDeploymentFlavor
336 (deploymentFlavorEntity, USER1);
337 deployment2Id = createdDeployment.getId();
339 final DeploymentFlavor deploymentFlavorCompositionData = createdDeployment.getDeploymentFlavorCompositionData();
340 deploymentFlavorCompositionData.setModel("TestDeploymentCreateforUpdate"); //no change
341 deploymentFlavorCompositionData.setDescription("updating deployment flavor"); //allow change
342 deploymentFlavorCompositionData.setFeatureGroupId("fg01"); //no change
343 createdDeployment.setDeploymentFlavorCompositionData(deploymentFlavorCompositionData);
345 vendorSoftwareProductManager.updateDeploymentFlavor(createdDeployment, USER1);
346 CompositionEntityResponse<DeploymentFlavor> deploymentFlavorCompositionEntityResponse = vendorSoftwareProductManager
347 .getDeploymentFlavor(vsp1Id, VERSION01, deployment2Id, USER1);
348 final DeploymentFlavor data = deploymentFlavorCompositionEntityResponse.getData();
351 data.getDescription(),createdDeployment.getDeploymentFlavorCompositionData().getDescription());
355 public void testUpdateVspWithNoFeatureGroup(){
356 //Creating a separate deployment flavor for testing deletion
357 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment1Id);
358 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
359 deploymentFlavor.setModel("TestDeploymentCreateforUpdate");
360 deploymentFlavor.setDescription("creating a deployment flavor for updation");
361 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
362 DeploymentFlavorEntity createdDeployment = vendorSoftwareProductManager
363 .createDeploymentFlavor(deploymentFlavorEntity, USER1);
364 deployment1Id = createdDeployment.getId();
366 final DeploymentFlavor deploymentFlavorCompositionData = createdDeployment.getDeploymentFlavorCompositionData();
367 deploymentFlavorCompositionData.setModel("TestDeploymentCreateforUpdate"); //no change
368 deploymentFlavorCompositionData.setDescription("updating deployment flavor"); //allow change
369 createdDeployment.setDeploymentFlavorCompositionData(deploymentFlavorCompositionData);
371 vendorSoftwareProductManager.updateDeploymentFlavor(createdDeployment, USER1);
372 CompositionEntityResponse<DeploymentFlavor> deploymentFlavorCompositionEntityResponse =
373 vendorSoftwareProductManager.getDeploymentFlavor(vsp2Id, VERSION01, deployment1Id, USER1);
374 final DeploymentFlavor data = deploymentFlavorCompositionEntityResponse.getData();
376 Assert.assertEquals(data.getDescription(),createdDeployment.getDeploymentFlavorCompositionData()
380 private void testUpdateNegative(DeploymentFlavorEntity deploymentFlavorEntity, String user,
381 String expectedErrorCode) {
383 vendorSoftwareProductManager
384 .updateDeploymentFlavor(deploymentFlavorEntity, user);
385 System.out.print("updated");
387 } catch (CoreException exception) {
388 Assert.assertEquals(exception.code().id(), expectedErrorCode);
393 public void testDelete(){
394 //Creating a separate deployment flavor for testing deletion
395 DeploymentFlavorEntity deploymentFlavorEntity =
396 new DeploymentFlavorEntity(vsp2Id, VERSION01, deployment2Id);
397 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
398 deploymentFlavor.setModel("TestDeploymentcreateWithoutFG");
399 deploymentFlavor.setDescription("creating a deployment flavor without any FG and any " +
401 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
402 DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor
403 (deploymentFlavorEntity, USER1);
404 deployment2Id = createddeployment.getId();
405 vendorSoftwareProductManager.deleteDeploymentFlavor(vsp2Id, deployment2Id, USER1);
406 testDeleteNegative(vsp2Id, deployment2Id, USER1,
407 VERSIONABLE_SUB_ENTITY_NOT_FOUND);
411 public void testDeleteNegative_InvalidVspId(){
412 testDeleteNegative("InvalidVspId", deployment2Id, USER1,
413 VERSIONABLE_ENTITY_NOT_EXIST);
417 public void testDeleteNegative_NonExistingDeploymentFlavorId(){
418 testDeleteNegative(vsp2Id, "NonExistingDeploymentFlavorId", USER1,
419 VERSIONABLE_SUB_ENTITY_NOT_FOUND);
422 private void testDeleteNegative(String vspId, String deploymentId, String user,
423 String expectedErrorCode) {
425 vendorSoftwareProductManager
426 .deleteDeploymentFlavor(vspId, deploymentId, user);
428 } catch (CoreException exception) {
429 Assert.assertEquals(exception.code().id(), expectedErrorCode);