1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING;
4 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_COMPUTE_NAME_NOT_ALLOWED;
6 import org.openecomp.core.utilities.CommonMethods;
7 import org.openecomp.sdc.common.errors.CoreException;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
9 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
12 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
14 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
15 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
16 import org.openecomp.sdc.vendorsoftwareproduct.types.ListComputeResponse;
17 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation;
18 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
19 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData;
20 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
21 import org.openecomp.sdc.versioning.dao.types.Version;
22 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
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 ComputeTest {
33 /*private static final String USER1 = "componentsTestUser1";
34 private static final String USER2 = "componentsTestUser2";
35 private static final Version VERSION01 = new Version(0, 1);
36 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
37 new VendorSoftwareProductManagerImpl();
38 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
39 VendorSoftwareProductDaoFactory
40 .getInstance().createInterface();
42 private static String vsp1Id;
43 private static String vsp2Id;
44 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
45 "\"description\": \"desc manual\"}";
46 private static String compute1 = "{\"name\": \"Compute_A\", " +
47 "\"description\": \"desc manual compute\"}";
48 private static String computeDelete = "{\"name\": \"Compute_Delete\", " +
49 "\"description\": \"desc manual compute delete\"}";
51 private static String comp1Id;
52 private static String compute1Id;
53 private ComputeEntity createdCompute;
55 static ComponentEntity createComponent(String vspId, Version version, String compId) {
56 ComponentEntity componentEntity = new ComponentEntity(vspId, version, compId);
57 ComponentData compData = new ComponentData();
58 compData.setName(compId + " name");
59 compData.setDisplayName(compId + " display name");
60 compData.setDescription(compId + " desc");
61 componentEntity.setComponentCompositionData(compData);
62 vendorSoftwareProductDao.createComponent(componentEntity);
63 return componentEntity;
66 static ComputeEntity createComputeEntity(String vspId, String componentId, String data ){
67 ComputeEntity comp = new ComputeEntity();
69 comp.setComponentId(componentId);
70 comp.setCompositionData(data);
77 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
78 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
79 "vlm1Id", "icon", "category", "subCategory", "123", null,
80 VSPCommon.OnboardingMethod.HEAT.name()), USER1
82 vsp1Id = vsp1.getId(); //HEAT onboarded
84 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
85 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
87 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
88 .OnboardingMethod.Manual.name()), USER1);
89 vsp2Id = vsp2.getId(); //MANUAL onboarded
91 ComponentEntity component = new ComponentEntity();
92 component.setVspId(vsp2Id);
93 component.setCompositionData(comp1);
94 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(component, USER1);
95 comp1Id = createdComp.getId();
99 public void testListWhenNone() {
101 final Collection<ListComputeResponse> listComputeResponses =
102 vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
103 Assert.assertEquals(listComputeResponses.size(), 0);
107 public void testCreateComputeInHeatOnboardedVsp_negative() {
108 ComputeEntity comp = createComputeEntity(vsp1Id,comp1Id,compute1);
110 createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
113 catch(CoreException exception){
114 Assert.assertEquals(exception.code().id(),ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
118 @Test(dependsOnMethods = "testListWhenNone")
119 public void testCreateCompute() {
120 ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);
122 createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
123 compute1Id = createdCompute.getId();
124 Assert.assertNotNull(compute1Id);
125 Assert.assertNotNull(createdCompute.getCompositionData());
126 Assert.assertNotNull(
127 vendorSoftwareProductManager.getCompute(vsp2Id, VERSION01, comp1Id,compute1Id,
131 @Test(dependsOnMethods = "testCreateCompute")
132 public void testCreateComputeNegative() {
133 ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);
136 ComputeEntity createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
139 catch (CoreException exception) {
140 Assert.assertEquals(exception.code().id(),DUPLICATE_COMPUTE_NAME_NOT_ALLOWED);
145 public void testGetNonExistingComponentId_negative() {
146 testGet_negative(vsp1Id, null, "non existing component id", compute1Id, USER1,
147 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
151 public void testGetNonExistingVspId_negative() {
152 testGet_negative("non existing vsp id", null, comp1Id, compute1Id, USER1,
153 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
157 public void testGetNonExistingComputeId_negative() {
158 testGet_negative(vsp1Id, null, comp1Id, "non existing compute id", USER1,
159 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
162 @Test(dependsOnMethods = "testCreateCompute")
163 public void testGetCompute() {
164 testGet(vsp2Id, VERSION01, comp1Id, compute1Id, USER1, createdCompute);
168 @Test(dependsOnMethods = "testCreateCompute")
169 public void testListCompute() {
171 final Collection<ListComputeResponse> actual =
172 vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
173 Assert.assertEquals(actual.size(), 1);
174 actual.forEach(listComputeResponse -> {
175 Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), false);
180 @Test(dependsOnMethods = "testListCompute")
181 public void testListComputeAssociatedWithDeployment() {
183 //Create DF and associate compute1Id CF to it
184 String deployment1Id = null;
185 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id,
186 VERSION01, deployment1Id);
187 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
188 deploymentFlavor.setModel("DF_testListComputeAssociatedWithDeployment");
189 deploymentFlavor.setDescription("creating a deployment flavor with compute flavor association");
190 ComponentComputeAssociation association = new ComponentComputeAssociation();
191 association.setComponentId(comp1Id);
192 association.setComputeFlavorId(compute1Id);
193 List<ComponentComputeAssociation> associations = new ArrayList<ComponentComputeAssociation>();
194 associations.add(association);
195 deploymentFlavor.setComponentComputeAssociations(associations);
196 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
198 DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor
199 (deploymentFlavorEntity, USER1);
200 Assert.assertEquals((createddeployment.getId() != null), true);
201 deployment1Id = createddeployment.getId();
203 final Collection<ListComputeResponse> actual =
204 vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
205 Assert.assertEquals(actual.size(), 1);
206 actual.forEach(listComputeResponse -> {
207 Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), true);
212 public void testUpdateNonExistingComponentId_negative() {
213 testUpdate_negative(vsp1Id, "non existing component id", USER1,
214 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
218 public void testUpdateNonExistingVspId_negative() {
219 testUpdate_negative("non existing vsp id", comp1Id, USER1,
220 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
224 public void testDelete() {
225 ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,computeDelete);
227 ComputeEntity created = vendorSoftwareProductManager.createCompute(comp, USER1);
229 vendorSoftwareProductManager.deleteCompute(vsp2Id,comp1Id,created.getId(),USER1);
230 testGet_negative(vsp2Id,null, comp1Id, created.getId(),USER1,
231 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
235 public void testDeleteNonExistingComputeId_negative() {
236 testDelete_negative(vsp2Id,comp1Id,"InvalidComputeId",USER1,
237 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
241 public void testDeleteNonExistingComponentId_negative() {
242 testDelete_negative(vsp2Id,"InvalidComponentId",compute1Id,USER1,
243 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
247 public void testDeleteNonExistingVspId_negative() {
248 testDelete_negative("InvalidVspId",comp1Id,compute1Id,USER1,
249 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
252 private void testGet(String vspId, Version version, String componentId, String computeId, String
253 user, ComputeEntity expected) {
254 CompositionEntityResponse<ComputeData>
255 response = vendorSoftwareProductManager.getCompute(vspId, null, componentId, computeId,
257 Assert.assertEquals(response.getId(), expected.getId());
258 Assert.assertEquals(response.getData(), expected.getComputeCompositionData());
259 Assert.assertNotNull(response.getSchema());
262 private void testGet_negative(String vspId, Version version, String componentId, String computeId,
263 String user, String expectedErrorCode) {
265 vendorSoftwareProductManager.getCompute(vspId, version, componentId, computeId, user);
267 } catch (CoreException exception) {
268 Assert.assertEquals(exception.code().id(), expectedErrorCode);
272 private void testDelete_negative(String vspId, String componentId, String computeId, String user,
273 String expectedErrorCode){
275 vendorSoftwareProductManager.deleteCompute(vspId, componentId, computeId, user);
278 catch(CoreException exception){
279 Assert.assertEquals(exception.code().id(), expectedErrorCode);
283 private void testUpdate_negative(String vspId, String componentId, String user,
284 String expectedErrorCode) {
286 vendorSoftwareProductManager
287 .updateComponent(new ComponentEntity(vspId, null, componentId), user);
289 } catch (CoreException exception) {
290 Assert.assertEquals(exception.code().id(), expectedErrorCode);