1 package org.openecomp.sdc.vendorsoftwareproduct;
3 public class ComputeTest {
5 /*private static final String USER1 = "componentsTestUser1";
6 private static final String USER2 = "componentsTestUser2";
7 private static final Version VERSION01 = new Version(0, 1);
8 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
9 new VendorSoftwareProductManagerImpl();
10 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
11 VendorSoftwareProductDaoFactory
12 .getInstance().createInterface();
14 private static String vsp1Id;
15 private static String vsp2Id;
16 private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
17 "\"description\": \"desc manual\"}";
18 private static String compute1 = "{\"name\": \"Compute_A\", " +
19 "\"description\": \"desc manual compute\"}";
20 private static String computeDelete = "{\"name\": \"Compute_Delete\", " +
21 "\"description\": \"desc manual compute delete\"}";
23 private static String comp1Id;
24 private static String compute1Id;
25 private ComputeEntity createdCompute;
27 static ComponentEntity createComponent(String vspId, Version version, String compId) {
28 ComponentEntity componentEntity = new ComponentEntity(vspId, version, compId);
29 ComponentData compData = new ComponentData();
30 compData.setName(compId + " name");
31 compData.setDisplayName(compId + " display name");
32 compData.setDescription(compId + " desc");
33 componentEntity.setComponentCompositionData(compData);
34 vendorSoftwareProductDao.createComponent(componentEntity);
35 return componentEntity;
38 static ComputeEntity createComputeEntity(String vspId, String componentId, String data ){
39 ComputeEntity comp = new ComputeEntity();
41 comp.setComponentId(componentId);
42 comp.setCompositionData(data);
49 vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
50 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
51 "vlm1Id", "icon", "category", "subCategory", "123", null,
52 VSPCommon.OnboardingMethod.HEAT.name()), USER1
54 vsp1Id = vsp1.getId(); //HEAT onboarded
56 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
57 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
59 "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
60 .OnboardingMethod.Manual.name()), USER1);
61 vsp2Id = vsp2.getId(); //MANUAL onboarded
63 ComponentEntity component = new ComponentEntity();
64 component.setVspId(vsp2Id);
65 component.setCompositionData(comp1);
66 ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(component, USER1);
67 comp1Id = createdComp.getId();
71 public void testListWhenNone() {
73 final Collection<ListComputeResponse> listComputeResponses =
74 vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
75 Assert.assertEquals(listComputeResponses.size(), 0);
79 public void testCreateComputeInHeatOnboardedVsp_negative() {
80 ComputeEntity comp = createComputeEntity(vsp1Id,comp1Id,compute1);
82 createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
85 catch(CoreException exception){
86 Assert.assertEquals(exception.code().id(),ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
90 @Test(dependsOnMethods = "testListWhenNone")
91 public void testCreateCompute() {
92 ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);
94 createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
95 compute1Id = createdCompute.getId();
96 Assert.assertNotNull(compute1Id);
97 Assert.assertNotNull(createdCompute.getCompositionData());
99 vendorSoftwareProductManager.getCompute(vsp2Id, VERSION01, comp1Id,compute1Id,
103 @Test(dependsOnMethods = "testCreateCompute")
104 public void testCreateComputeNegative() {
105 ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);
108 ComputeEntity createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
111 catch (CoreException exception) {
112 Assert.assertEquals(exception.code().id(),DUPLICATE_COMPUTE_NAME_NOT_ALLOWED);
117 public void testGetNonExistingComponentId_negative() {
118 testGet_negative(vsp1Id, null, "non existing component id", compute1Id, USER1,
119 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
123 public void testGetNonExistingVspId_negative() {
124 testGet_negative("non existing vsp id", null, comp1Id, compute1Id, USER1,
125 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
129 public void testGetNonExistingComputeId_negative() {
130 testGet_negative(vsp1Id, null, comp1Id, "non existing compute id", USER1,
131 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
134 @Test(dependsOnMethods = "testCreateCompute")
135 public void testGetCompute() {
136 testGet(vsp2Id, VERSION01, comp1Id, compute1Id, USER1, createdCompute);
140 @Test(dependsOnMethods = "testCreateCompute")
141 public void testListCompute() {
143 final Collection<ListComputeResponse> actual =
144 vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
145 Assert.assertEquals(actual.size(), 1);
146 actual.forEach(listComputeResponse -> {
147 Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), false);
152 @Test(dependsOnMethods = "testListCompute")
153 public void testListComputeAssociatedWithDeployment() {
155 //Create DF and associate compute1Id CF to it
156 String deployment1Id = null;
157 DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id,
158 VERSION01, deployment1Id);
159 DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
160 deploymentFlavor.setModel("DF_testListComputeAssociatedWithDeployment");
161 deploymentFlavor.setDescription("creating a deployment flavor with compute flavor association");
162 ComponentComputeAssociation association = new ComponentComputeAssociation();
163 association.setComponentId(comp1Id);
164 association.setComputeFlavorId(compute1Id);
165 List<ComponentComputeAssociation> associations = new ArrayList<ComponentComputeAssociation>();
166 associations.add(association);
167 deploymentFlavor.setComponentComputeAssociations(associations);
168 deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);
170 DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor
171 (deploymentFlavorEntity, USER1);
172 Assert.assertEquals((createddeployment.getId() != null), true);
173 deployment1Id = createddeployment.getId();
175 final Collection<ListComputeResponse> actual =
176 vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
177 Assert.assertEquals(actual.size(), 1);
178 actual.forEach(listComputeResponse -> {
179 Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), true);
184 public void testUpdateNonExistingComponentId_negative() {
185 testUpdate_negative(vsp1Id, "non existing component id", USER1,
186 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
190 public void testUpdateNonExistingVspId_negative() {
191 testUpdate_negative("non existing vsp id", comp1Id, USER1,
192 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
196 public void testDelete() {
197 ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,computeDelete);
199 ComputeEntity created = vendorSoftwareProductManager.createCompute(comp, USER1);
201 vendorSoftwareProductManager.deleteCompute(vsp2Id,comp1Id,created.getId(),USER1);
202 testGet_negative(vsp2Id,null, comp1Id, created.getId(),USER1,
203 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
207 public void testDeleteNonExistingComputeId_negative() {
208 testDelete_negative(vsp2Id,comp1Id,"InvalidComputeId",USER1,
209 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
213 public void testDeleteNonExistingComponentId_negative() {
214 testDelete_negative(vsp2Id,"InvalidComponentId",compute1Id,USER1,
215 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
219 public void testDeleteNonExistingVspId_negative() {
220 testDelete_negative("InvalidVspId",comp1Id,compute1Id,USER1,
221 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
224 private void testGet(String vspId, Version version, String componentId, String computeId, String
225 user, ComputeEntity expected) {
226 CompositionEntityResponse<ComputeData>
227 response = vendorSoftwareProductManager.getCompute(vspId, null, componentId, computeId,
229 Assert.assertEquals(response.getId(), expected.getId());
230 Assert.assertEquals(response.getData(), expected.getComputeCompositionData());
231 Assert.assertNotNull(response.getSchema());
234 private void testGet_negative(String vspId, Version version, String componentId, String computeId,
235 String user, String expectedErrorCode) {
237 vendorSoftwareProductManager.getCompute(vspId, version, componentId, computeId, user);
239 } catch (CoreException exception) {
240 Assert.assertEquals(exception.code().id(), expectedErrorCode);
244 private void testDelete_negative(String vspId, String componentId, String computeId, String user,
245 String expectedErrorCode){
247 vendorSoftwareProductManager.deleteCompute(vspId, componentId, computeId, user);
250 catch(CoreException exception){
251 Assert.assertEquals(exception.code().id(), expectedErrorCode);
255 private void testUpdate_negative(String vspId, String componentId, String user,
256 String expectedErrorCode) {
258 vendorSoftwareProductManager
259 .updateComponent(new ComponentEntity(vspId, null, componentId), user);
261 } catch (CoreException exception) {
262 Assert.assertEquals(exception.code().id(), expectedErrorCode);