update sdc to version 1.3.2
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / ComputeTest.java
1 package org.openecomp.sdc.vendorsoftwareproduct;
2
3 public class ComputeTest {
4
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();
13
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\"}";
22
23   private static String comp1Id;
24   private static String compute1Id;
25   private ComputeEntity createdCompute;
26
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;
36   }
37
38   static ComputeEntity createComputeEntity(String vspId, String componentId, String data ){
39     ComputeEntity comp = new ComputeEntity();
40     comp.setVspId(vspId);
41     comp.setComponentId(componentId);
42     comp.setCompositionData(data);
43     return comp;
44   }
45
46   @BeforeClass
47   private void init() {
48     VspDetails
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
53     );
54     vsp1Id = vsp1.getId(); //HEAT onboarded
55
56     VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
57         .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
58             "vendorName",
59             "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
60                 .OnboardingMethod.Manual.name()), USER1);
61     vsp2Id = vsp2.getId(); //MANUAL onboarded
62
63     ComponentEntity component = new ComponentEntity();
64     component.setVspId(vsp2Id);
65     component.setCompositionData(comp1);
66     ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(component, USER1);
67     comp1Id = createdComp.getId();
68   }
69
70   @Test
71   public void testListWhenNone() {
72
73     final Collection<ListComputeResponse> listComputeResponses =
74         vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
75     Assert.assertEquals(listComputeResponses.size(), 0);
76   }
77
78   @Test
79   public void testCreateComputeInHeatOnboardedVsp_negative() {
80     ComputeEntity comp = createComputeEntity(vsp1Id,comp1Id,compute1);
81     try {
82       createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
83       Assert.fail();
84     }
85     catch(CoreException exception){
86       Assert.assertEquals(exception.code().id(),ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
87     }
88   }
89
90   @Test(dependsOnMethods = "testListWhenNone")
91   public void testCreateCompute() {
92     ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);
93
94     createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
95     compute1Id = createdCompute.getId();
96     Assert.assertNotNull(compute1Id);
97     Assert.assertNotNull(createdCompute.getCompositionData());
98     Assert.assertNotNull(
99         vendorSoftwareProductManager.getCompute(vsp2Id, VERSION01, comp1Id,compute1Id,
100             USER1).getData());
101   }
102
103   @Test(dependsOnMethods = "testCreateCompute")
104   public void testCreateComputeNegative() {
105     ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);
106
107     try {
108       ComputeEntity createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
109       Assert.fail();
110     }
111     catch (CoreException exception) {
112       Assert.assertEquals(exception.code().id(),DUPLICATE_COMPUTE_NAME_NOT_ALLOWED);
113     }
114   }
115
116   @Test
117   public void testGetNonExistingComponentId_negative() {
118     testGet_negative(vsp1Id, null, "non existing component id", compute1Id, USER1,
119         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
120   }
121
122   @Test
123   public void testGetNonExistingVspId_negative() {
124     testGet_negative("non existing vsp id", null, comp1Id, compute1Id, USER1,
125         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
126   }
127
128   @Test
129   public void testGetNonExistingComputeId_negative() {
130     testGet_negative(vsp1Id, null, comp1Id, "non existing compute id", USER1,
131         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
132   }
133
134   @Test(dependsOnMethods = "testCreateCompute")
135   public void testGetCompute() {
136     testGet(vsp2Id, VERSION01, comp1Id, compute1Id, USER1, createdCompute);
137   }
138
139
140   @Test(dependsOnMethods = "testCreateCompute")
141   public void testListCompute() {
142
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);
148     } );
149   }
150
151
152   @Test(dependsOnMethods = "testListCompute")
153   public void testListComputeAssociatedWithDeployment() {
154
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);
169
170     DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor
171         (deploymentFlavorEntity, USER1);
172     Assert.assertEquals((createddeployment.getId() != null), true);
173     deployment1Id = createddeployment.getId();
174
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);
180     } );
181   }
182
183   @Test
184   public void testUpdateNonExistingComponentId_negative() {
185     testUpdate_negative(vsp1Id, "non existing component id", USER1,
186         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
187   }
188
189   @Test
190   public void testUpdateNonExistingVspId_negative() {
191     testUpdate_negative("non existing vsp id", comp1Id, USER1,
192         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
193   }
194
195   @Test
196   public void testDelete() {
197     ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,computeDelete);
198
199     ComputeEntity created = vendorSoftwareProductManager.createCompute(comp, USER1);
200
201     vendorSoftwareProductManager.deleteCompute(vsp2Id,comp1Id,created.getId(),USER1);
202     testGet_negative(vsp2Id,null, comp1Id, created.getId(),USER1,
203         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
204   }
205
206   @Test
207   public void testDeleteNonExistingComputeId_negative() {
208     testDelete_negative(vsp2Id,comp1Id,"InvalidComputeId",USER1,
209         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
210   }
211
212   @Test
213   public void testDeleteNonExistingComponentId_negative() {
214     testDelete_negative(vsp2Id,"InvalidComponentId",compute1Id,USER1,
215         VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
216   }
217
218   @Test
219   public void testDeleteNonExistingVspId_negative() {
220     testDelete_negative("InvalidVspId",comp1Id,compute1Id,USER1,
221         VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
222   }
223
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,
228         user);
229     Assert.assertEquals(response.getId(), expected.getId());
230     Assert.assertEquals(response.getData(), expected.getComputeCompositionData());
231     Assert.assertNotNull(response.getSchema());
232   }
233
234   private void testGet_negative(String vspId, Version version, String componentId, String computeId,
235                                 String user, String expectedErrorCode) {
236     try {
237       vendorSoftwareProductManager.getCompute(vspId, version, componentId, computeId, user);
238       Assert.fail();
239     } catch (CoreException exception) {
240       Assert.assertEquals(exception.code().id(), expectedErrorCode);
241     }
242   }
243
244   private void testDelete_negative(String vspId, String componentId, String computeId, String user,
245                                    String expectedErrorCode){
246     try {
247       vendorSoftwareProductManager.deleteCompute(vspId, componentId, computeId, user);
248       Assert.fail();
249     }
250     catch(CoreException exception){
251       Assert.assertEquals(exception.code().id(), expectedErrorCode);
252     }
253   }
254
255   private void testUpdate_negative(String vspId, String componentId, String user,
256                                    String expectedErrorCode) {
257     try {
258       vendorSoftwareProductManager
259           .updateComponent(new ComponentEntity(vspId, null, componentId), user);
260       Assert.fail();
261     } catch (CoreException exception) {
262       Assert.assertEquals(exception.code().id(), expectedErrorCode);
263     }
264   }*/
265 }