[sdc] docker file fix for cassandra
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / NicsTest.java
1 package org.openecomp.sdc.vendorsoftwareproduct;
2
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
5 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
6 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
7 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
8 import org.openecomp.core.utilities.CommonMethods;
9
10 import org.testng.Assert;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.Test;
13
14 import java.util.Collection;
15
16 public class NicsTest {
17
18   private static final String USER1 = "nicsTestUser1";
19   private static final String USER2 = "nicsTestUser2";
20   private static final org.openecomp.sdc.versioning.dao.types.Version
21       VERSION01 = new org.openecomp.sdc.versioning.dao.types.Version(0, 1);
22   private static final VendorSoftwareProductManager vendorSoftwareProductManager =
23       new VendorSoftwareProductManagerImpl();
24   private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao
25       vendorSoftwareProductDao =
26       org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory.getInstance().createInterface();
27
28   private static String vsp1Id;
29   private static String vsp2Id;
30   private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity network1;
31   private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity network2;
32   private static String component11Id;
33   private static String component21Id;
34   private static String nic1Id = "nic1";
35
36   static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity createNic(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String compId, String nicId,
37                                                                               String networkId) {
38     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
39         nicEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, version, compId, nicId);
40     org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
41         nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
42     nicData.setName(nicId + " name");
43     nicData.setDescription(nicId + " desc");
44     nicData.setNetworkId(networkId);
45     nicEntity.setNicCompositionData(nicData);
46     vendorSoftwareProductDao.createNic(nicEntity);
47     return nicEntity;
48   }
49
50   @BeforeClass
51   private void init() {
52     vsp1Id = vendorSoftwareProductManager.createNewVsp(VSPCommon
53         .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1",
54             "vlm1Id", "icon", "category", "subCategory", "123", null), USER1).getId();
55     network1 = NetworksTest.createNetwork(vsp1Id, VERSION01, "network1");
56     component11Id = ComponentsTest.createComponent(vsp1Id, VERSION01, "component11").getId();
57
58     vsp2Id = vendorSoftwareProductManager.createNewVsp(VSPCommon
59         .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName1",
60             "vlm1Id", "icon", "category", "subCategory", "123", null), USER1).getId();
61     network2 = NetworksTest.createNetwork(vsp2Id, VERSION01, "network2");
62     component21Id = ComponentsTest.createComponent(vsp2Id, VERSION01, "component21").getId();
63   }
64
65 /*    @Test
66     public void testCreateNonExistingComponentId_negative() {
67         testCreate_negative(new NicEntity(vsp1Id, null, "non existing component id", null), USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
68     }*/
69
70   @Test
71   public void testListWhenNone() {
72     Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> nics =
73         vendorSoftwareProductManager.listNics(vsp1Id, null, component11Id, USER1);
74     Assert.assertEquals(nics.size(), 0);
75   }
76
77   @Test
78   public void testCreateNonExistingVspId_negative() {
79     testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity("non existing vsp id", null, component11Id, null), USER1,
80         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
81   }
82
83   @Test
84   public void testCreateOnLockedVsp_negative() {
85     testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, null), USER2,
86         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
87   }
88
89 //    @Test(dependsOnMethods = "testListWhenNone")
90 //    public void testCreate() {
91 //        nic1Id = testCreate(vsp1Id, component11Id, network1.getId(), network1.getNetworkCompositionData().getName());
92 //    }
93
94 /*    @Test(dependsOnMethods = {"testCreate"})
95     public void testCreateWithExistingName_negative() {
96         NicEntity nic = new NicEntity(vsp1Id, null, component11Id, null);
97         Nic nicData = new Nic();
98         nicData.setName("nic1 name");
99         nic.setNicCompositionData(nicData);
100         testCreate_negative(nic, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
101     }*/
102
103 //    @Test(dependsOnMethods = {"testCreate"})
104 //    public void testCreateWithExistingNameUnderOtherComponent() {
105 //        ComponentEntity component12 = new ComponentEntity(vsp1Id, null, null);
106 //        ComponentData compData12 = new ComponentData();
107 //        compData12.setName("comp12 name");
108 //        compData12.setDescription("comp12 desc");
109 //        component12.setComponentCompositionData(compData12);
110 //
111 //        String component12Id = vendorSoftwareProductManager.createComponent(component12, USER1).getId();
112 //        testCreate(vsp1Id, component12Id, network1.getId(), network1.getNetworkCompositionData().getName());
113 //    }
114
115 //    @Test(dependsOnMethods = {"testCreate"})
116 //    public void testCreateWithExistingNameUnderOtherVsp() {
117 //        testCreate(vsp2Id, component21Id, network2.getId(), network2.getNetworkCompositionData().getName());
118 //    }
119
120   @Test
121   public void testCreateOnUploadVsp_negative() {
122     testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, null), USER1,
123         VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
124   }
125
126   @Test
127   public void testGetNonExistingNicId_negative() {
128     testGet_negative(vsp1Id, null, component11Id, "non existing nic id", USER1,
129         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
130   }
131
132   @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
133   public void testGetNonExistingComponentId_negative() {
134     testGet_negative(vsp1Id, null, "non existing component id", nic1Id, USER1,
135         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
136   }
137
138   @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
139   public void testGetNonExistingVspId_negative() {
140     testGet_negative("non existing vsp id", null, component11Id, nic1Id, USER1,
141         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
142   }
143
144   @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
145   public void testGet() {
146     createNic(vsp1Id, VERSION01, component11Id, nic1Id, network1.getId());
147     testGet(vsp1Id, VERSION01, component11Id, nic1Id, USER1);
148   }
149
150   @Test
151   public void testUpdateNonExistingNicId_negative() {
152     testUpdate_negative(vsp1Id, component11Id, "non existing nic id", USER1,
153         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
154   }
155
156   @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
157   public void testUpdateNonExistingComponentId_negative() {
158     testUpdate_negative(vsp1Id, "non existing component id", nic1Id, USER1,
159         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
160   }
161
162   @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
163   public void testUpdateNonExistingVspId_negative() {
164     testUpdate_negative("non existing vsp id", component11Id, nic1Id, USER1,
165         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
166   }
167
168   @Test(dependsOnMethods = {"testGet"})
169   public void testUpdateOnUploadVsp() {
170     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
171         expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, nic1Id);
172     org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
173         nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
174     nicData.setName(nic1Id + " name");
175     nicData.setDescription(nic1Id + " desc updated");
176     nicData.setNetworkId(network1.getId());
177     expected.setNicCompositionData(nicData);
178
179     CompositionEntityValidationData validationData =
180         vendorSoftwareProductManager.updateNic(expected, USER1);
181     Assert.assertTrue(validationData == null || validationData.getErrors() == null);
182     expected.setVersion(VERSION01);
183
184     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
185         actual = vendorSoftwareProductDao.getNic(vsp1Id, VERSION01, component11Id, nic1Id);
186     Assert.assertEquals(actual, expected);
187   }
188
189   @Test(dependsOnMethods = {"testGet"})
190   public void testIllegalUpdateOnUploadVsp() {
191     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
192         expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, nic1Id);
193     org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
194         nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
195     nicData.setName(nic1Id + " name updated");
196     nicData.setDescription(nic1Id + " desc updated");
197     nicData.setNetworkId(network1.getId());
198     expected.setNicCompositionData(nicData);
199
200     CompositionEntityValidationData validationData =
201         vendorSoftwareProductManager.updateNic(expected, USER1);
202     Assert.assertNotNull(validationData);
203     Assert.assertTrue(validationData.getErrors().size() > 0);
204   }
205
206   @Test
207   public void testListNonExistingComponentId_negative() {
208     testList_negative(vsp1Id, null, "non existing component id", USER1,
209         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
210   }
211
212   @Test
213   public void testListNonExistingVspId_negative() {
214     testList_negative("non existing vsp id", null, component11Id, USER1,
215         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
216   }
217 /*
218     @Test(dependsOnMethods = {"testUpdateOnUploadVsp", "testList"})
219     public void testCreateWithRemovedName() {
220         testCreate(vsp1Id, component11Id);
221     }
222
223     @Test
224     public void testDeleteNonExistingNicId_negative() {
225         testDelete_negative(vsp1Id, component11Id, "non existing nic id", USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
226     }
227
228     @Test(dependsOnMethods = "testList")
229     public void testDeleteNonExistingComponentId_negative() {
230         testDelete_negative(vsp1Id, "non existing component id", nic1Id, USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
231     }*/
232
233   @Test(dependsOnMethods = {"testGet"})
234   public void testList() {
235     createNic(vsp1Id, VERSION01, component11Id, "nic2", network1.getId());
236
237     Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> actual =
238         vendorSoftwareProductManager.listNics(vsp1Id, null, component11Id, USER1);
239     Assert.assertEquals(actual.size(), 2);
240   }
241
242   @Test(dependsOnMethods = "testList")
243   public void testDeleteNonExistingVspId_negative() {
244     testDelete_negative("non existing vsp id", component11Id, nic1Id, USER1,
245         org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
246   }
247 /*
248     @Test(dependsOnMethods = "testList")
249     public void testDelete() {
250         vendorSoftwareProductManager.deleteNic(vsp1Id, component11Id, nic1Id, USER1);
251         NicEntity actual = vendorSoftwareProductDao.getNic(vsp1Id, VERSION01, component11Id, nic1Id);
252         Assert.assertNull(actual);
253     }*/
254
255   @Test(dependsOnMethods = "testList")
256   public void testDeleteOnUploadVsp_negative() {
257     testDelete_negative(vsp1Id, component11Id, nic1Id, USER1,
258         VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
259   }
260
261   private String testCreate(String vspId, String componentId, String networkId,
262                             String networkName) {
263     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
264         expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, null, componentId, null);
265
266     org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
267         nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
268     nicData.setName("nic1 name");
269     nicData.setNetworkId(networkId);
270     //nicData.setNetworkName(networkName);
271     nicData.setNetworkType(org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType.External);
272     expected.setNicCompositionData(nicData);
273
274     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity created = vendorSoftwareProductManager.createNic(expected, USER1);
275     Assert.assertNotNull(created);
276     expected.setId(created.getId());
277     expected.setVersion(VERSION01);
278
279     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity actual =
280         vendorSoftwareProductDao.getNic(vspId, VERSION01, componentId, created.getId());
281
282     Assert.assertEquals(actual, expected);
283
284     return created.getId();
285   }
286
287   private void testGet(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId,
288                        String user) {
289     CompositionEntityResponse<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic> response =
290         vendorSoftwareProductManager.getNic(vspId, null, componentId, nicId, user);
291     org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
292         expected = vendorSoftwareProductDao.getNic(vspId, version, componentId, nicId);
293     Assert.assertEquals(response.getId(), expected.getId());
294     Assert.assertEquals(response.getData(), expected.getNicCompositionData());
295     Assert.assertNotNull(response.getSchema());
296   }
297
298   private void testCreate_negative(org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic, String user, String expectedErrorCode) {
299     try {
300       vendorSoftwareProductManager.createNic(nic, user);
301       Assert.fail();
302     } catch (CoreException e) {
303       Assert.assertEquals(e.code().id(), expectedErrorCode);
304     }
305   }
306
307   private void testGet_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId,
308                                 String user, String expectedErrorCode) {
309     try {
310       vendorSoftwareProductManager.getNic(vspId, version, componentId, nicId, user);
311       Assert.fail();
312     } catch (CoreException e) {
313       Assert.assertEquals(e.code().id(), expectedErrorCode);
314     }
315   }
316
317   private void testUpdate_negative(String vspId, String componentId, String nicId, String user,
318                                    String expectedErrorCode) {
319     try {
320       vendorSoftwareProductManager.updateNic(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, null, componentId, nicId), user);
321       Assert.fail();
322     } catch (CoreException e) {
323       Assert.assertEquals(e.code().id(), expectedErrorCode);
324     }
325   }
326
327   private void testList_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String user,
328                                  String expectedErrorCode) {
329     try {
330       vendorSoftwareProductManager.listNics(vspId, version, componentId, user);
331       Assert.fail();
332     } catch (CoreException e) {
333       Assert.assertEquals(e.code().id(), expectedErrorCode);
334     }
335   }
336
337   private void testDelete_negative(String vspId, String componentId, String nicId, String user,
338                                    String expectedErrorCode) {
339     try {
340       vendorSoftwareProductManager.deleteNic(vspId, componentId, nicId, user);
341       Assert.fail();
342     } catch (CoreException e) {
343       Assert.assertEquals(e.code().id(), expectedErrorCode);
344     }
345   }
346 }