1 package org.openecomp.sdc.vendorsoftwareproduct;
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;
10 import org.testng.Assert;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.Test;
14 import java.util.Collection;
16 public class NicsTest {
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();
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";
36 static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity createNic(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String compId, String nicId,
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);
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();
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();
66 public void testCreateNonExistingComponentId_negative() {
67 testCreate_negative(new NicEntity(vsp1Id, null, "non existing component id", null), USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
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);
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);
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);
89 // @Test(dependsOnMethods = "testListWhenNone")
90 // public void testCreate() {
91 // nic1Id = testCreate(vsp1Id, component11Id, network1.getId(), network1.getNetworkCompositionData().getName());
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);
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);
111 // String component12Id = vendorSoftwareProductManager.createComponent(component12, USER1).getId();
112 // testCreate(vsp1Id, component12Id, network1.getId(), network1.getNetworkCompositionData().getName());
115 // @Test(dependsOnMethods = {"testCreate"})
116 // public void testCreateWithExistingNameUnderOtherVsp() {
117 // testCreate(vsp2Id, component21Id, network2.getId(), network2.getNetworkCompositionData().getName());
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);
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);
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);
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);
144 @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
145 public void testGet() {
146 createNic(vsp1Id, VERSION01, component11Id, nic1Id, network1.getId());
147 testGet(vsp1Id, VERSION01, component11Id, nic1Id, USER1);
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);
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);
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);
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);
179 CompositionEntityValidationData validationData =
180 vendorSoftwareProductManager.updateNic(expected, USER1);
181 Assert.assertTrue(validationData == null || validationData.getErrors() == null);
182 expected.setVersion(VERSION01);
184 org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
185 actual = vendorSoftwareProductDao.getNic(vsp1Id, VERSION01, component11Id, nic1Id);
186 Assert.assertEquals(actual, expected);
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);
200 CompositionEntityValidationData validationData =
201 vendorSoftwareProductManager.updateNic(expected, USER1);
202 Assert.assertNotNull(validationData);
203 Assert.assertTrue(validationData.getErrors().size() > 0);
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);
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);
218 @Test(dependsOnMethods = {"testUpdateOnUploadVsp", "testList"})
219 public void testCreateWithRemovedName() {
220 testCreate(vsp1Id, component11Id);
224 public void testDeleteNonExistingNicId_negative() {
225 testDelete_negative(vsp1Id, component11Id, "non existing nic id", USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
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);
233 @Test(dependsOnMethods = {"testGet"})
234 public void testList() {
235 createNic(vsp1Id, VERSION01, component11Id, "nic2", network1.getId());
237 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> actual =
238 vendorSoftwareProductManager.listNics(vsp1Id, null, component11Id, USER1);
239 Assert.assertEquals(actual.size(), 2);
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);
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);
255 @Test(dependsOnMethods = "testList")
256 public void testDeleteOnUploadVsp_negative() {
257 testDelete_negative(vsp1Id, component11Id, nic1Id, USER1,
258 VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
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);
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);
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);
279 org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity actual =
280 vendorSoftwareProductDao.getNic(vspId, VERSION01, componentId, created.getId());
282 Assert.assertEquals(actual, expected);
284 return created.getId();
287 private void testGet(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId,
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());
298 private void testCreate_negative(org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic, String user, String expectedErrorCode) {
300 vendorSoftwareProductManager.createNic(nic, user);
302 } catch (CoreException e) {
303 Assert.assertEquals(e.code().id(), expectedErrorCode);
307 private void testGet_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId,
308 String user, String expectedErrorCode) {
310 vendorSoftwareProductManager.getNic(vspId, version, componentId, nicId, user);
312 } catch (CoreException e) {
313 Assert.assertEquals(e.code().id(), expectedErrorCode);
317 private void testUpdate_negative(String vspId, String componentId, String nicId, String user,
318 String expectedErrorCode) {
320 vendorSoftwareProductManager.updateNic(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, null, componentId, nicId), user);
322 } catch (CoreException e) {
323 Assert.assertEquals(e.code().id(), expectedErrorCode);
327 private void testList_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String user,
328 String expectedErrorCode) {
330 vendorSoftwareProductManager.listNics(vspId, version, componentId, user);
332 } catch (CoreException e) {
333 Assert.assertEquals(e.code().id(), expectedErrorCode);
337 private void testDelete_negative(String vspId, String componentId, String nicId, String user,
338 String expectedErrorCode) {
340 vendorSoftwareProductManager.deleteNic(vspId, componentId, nicId, user);
342 } catch (CoreException e) {
343 Assert.assertEquals(e.code().id(), expectedErrorCode);