1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
5 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
6 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
7 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
8 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
9 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
10 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
11 import org.openecomp.sdc.versioning.dao.types.Version;
12 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
13 import org.openecomp.core.utilities.CommonMethods;
15 import org.testng.Assert;
16 import org.testng.annotations.BeforeClass;
17 import org.testng.annotations.Test;
19 import java.util.Collection;
21 public class ComponentsTest {
23 private static final String USER1 = "componentsTestUser1";
24 private static final String USER2 = "componentsTestUser2";
25 private static final Version VERSION01 = new Version(0, 1);
26 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
27 new VendorSoftwareProductManagerImpl();
28 private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao
29 vendorSoftwareProductDao =
30 VendorSoftwareProductDaoFactory.getInstance().createInterface();
32 private static String vsp1Id;
33 private static String vsp2Id;
34 private static String comp1Id = "1";
35 private static String comp2Id = "2";
37 static org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity createComponent(String vspId, Version version, String compId) {
38 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity
39 componentEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vspId, version, compId);
40 ComponentData compData = new ComponentData();
41 compData.setName(compId + " name");
42 compData.setDisplayName(compId + " display name");
43 compData.setDescription(compId + " desc");
44 componentEntity.setComponentCompositionData(compData);
45 vendorSoftwareProductDao.createComponent(componentEntity);
46 return componentEntity;
51 VspDetails vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
52 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
53 "vlm1Id", "icon", "category", "subCategory", "123", null), USER1);
54 vsp1Id = vsp1.getId();
56 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
57 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName",
58 "vlm1Id", "icon", "category", "subCategory", "123", null), USER1);
59 vsp2Id = vsp2.getId();
63 public void testListWhenNone() {
64 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components =
65 vendorSoftwareProductManager.listComponents(vsp1Id, null, USER1);
66 Assert.assertEquals(components.size(), 0);
70 public void testCreateNonExistingVspId_negative() {
71 testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity("non existing vsp id", null, null), USER1,
72 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
76 public void testCreateOnLockedVsp_negative() {
77 testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, null), USER2,
78 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
81 /* @Test(dependsOnMethods = "testListWhenNone")
82 public void testCreate() {
83 comp1Id = testCreate(vsp1Id);
86 private String testCreate(String vspId) {
87 ComponentEntity expected = new ComponentEntity(vspId, null, null);
88 ComponentData compData = new ComponentData();
89 compData.setName("comp1 name");
90 compData.setDescription("comp1 desc");
91 expected.setComponentCompositionData(compData);
93 ComponentEntity created = vendorSoftwareProductManager.createComponent(expected, USER1);
94 Assert.assertNotNull(created);
95 expected.setId(created.getId());
96 expected.setVersion(VERSION01);
98 ComponentEntity actual = vendorSoftwareProductDao.getComponent(vspId, VERSION01, created.getId());
100 Assert.assertEquals(actual, expected);
101 return created.getId();
104 /* @Test(dependsOnMethods = {"testCreate"})
105 public void testCreateWithExistingName_negative() {
106 ComponentEntity component = new ComponentEntity(vsp1Id, null, null);
107 ComponentData compData = new ComponentData();
108 compData.setName("comp1 name");
109 compData.setDescription("comp1 desc");
110 component.setComponentCompositionData(compData);
111 testCreate_negative(component, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
114 /* @Test(dependsOnMethods = {"testCreate"})
115 public void testCreateWithExistingNameUnderOtherVsp() {
120 public void testCreateOnUploadVsp_negative() {
121 testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, null), USER1,
122 VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
126 public void testGetNonExistingComponentId_negative() {
127 testGet_negative(vsp1Id, null, "non existing component id", USER1,
128 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
132 public void testGetNonExistingVspId_negative() {
133 testGet_negative("non existing vsp id", null, comp1Id, USER1,
134 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
137 @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
138 public void testGet() {
139 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity
140 expected = createComponent(vsp1Id, VERSION01, comp1Id);
141 testGet(vsp1Id, VERSION01, comp1Id, USER1, expected);
145 public void testUpdateNonExistingComponentId_negative() {
146 testUpdate_negative(vsp1Id, "non existing component id", USER1,
147 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
151 public void testUpdateNonExistingVspId_negative() {
152 testUpdate_negative("non existing vsp id", comp1Id, USER1,
153 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
156 @Test(dependsOnMethods = {"testGet"})
157 public void testUpdateOnUploadVsp() {
158 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity
159 expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, comp1Id);
160 ComponentData compData = new ComponentData();
161 compData.setName(comp1Id + " name"); // no change
162 compData.setDisplayName(comp1Id + " display name"); // no change
163 compData.setDescription(comp1Id + " desc updated"); // allowed change
164 expected.setComponentCompositionData(compData);
166 CompositionEntityValidationData validationData =
167 vendorSoftwareProductManager.updateComponent(expected, USER1);
168 Assert.assertTrue(validationData == null || validationData.getErrors() == null);
169 expected.setVersion(VERSION01);
171 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity actual = vendorSoftwareProductDao.getComponent(vsp1Id, VERSION01, comp1Id);
172 Assert.assertEquals(actual, expected);
175 @Test(dependsOnMethods = {"testUpdateOnUploadVsp"})
176 public void testIllegalUpdateOnUploadVsp() {
177 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity
178 expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vsp1Id, null, comp1Id);
179 ComponentData compData = new ComponentData();
181 .setName("comp1 name updated"); // not allowed: changed name + omitted display name
182 expected.setComponentCompositionData(compData);
184 CompositionEntityValidationData validationData =
185 vendorSoftwareProductManager.updateComponent(expected, USER1);
186 Assert.assertNotNull(validationData);
187 Assert.assertEquals(validationData.getErrors().size(), 2);
191 public void testListNonExistingVspId_negative() {
192 testList_negative("non existing vsp id", null, USER1,
193 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
196 @Test(dependsOnMethods = {"testUpdateOnUploadVsp", "testList"})
197 public void testCreateWithERemovedName() {
201 @Test(dependsOnMethods = "testList")
202 public void testDeleteNonExistingComponentId_negative() {
203 testDelete_negative(vsp1Id, "non existing component id", USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
206 @Test(dependsOnMethods = {"testGet"})
207 public void testList() {
208 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity
209 createdP2 = createComponent(vsp1Id, VERSION01, comp2Id);
211 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> actual =
212 vendorSoftwareProductManager.listComponents(vsp1Id, null, USER1);
213 Assert.assertEquals(actual.size(), 2);
217 public void testDeleteNonExistingVspId_negative() {
218 testDelete_negative("non existing vsp id", comp1Id, USER1,
219 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
222 @Test(dependsOnMethods = "testList")
223 public void testDelete() {
224 vendorSoftwareProductManager.deleteComponent(vsp1Id, comp1Id, USER1);
225 ComponentEntity actual = vendorSoftwareProductDao.getComponent(vsp1Id, VERSION01, comp1Id);
226 Assert.assertNull(actual);
230 public void testDeleteOnUploadVsp_negative() {
231 testDelete_negative(vsp1Id, comp1Id, USER1,
232 VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
236 public void testDeleteListNonExistingVspId_negative() {
237 testDeleteList_negative("non existing vsp id", USER1,
238 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
241 @Test(dependsOnMethods = "testDelete")
242 public void testDeleteList() {
243 ComponentEntity comp3 = new ComponentEntity(vsp1Id, null, null);
244 comp3.setName("comp3 name");
245 comp3.setDescription("comp3 desc");
246 vendorSoftwareProductManager.createComponent(comp3, USER1);
248 vendorSoftwareProductManager.deleteComponents(vsp1Id, USER1);
250 Collection<ComponentEntity> actual = vendorSoftwareProductManager.listComponents(vsp1Id, null, USER1);
251 Assert.assertEquals(actual.size(), 0);
255 public void testDeleteListOnUploadVsp_negative() {
256 testDeleteList_negative(vsp1Id, USER1,
257 VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
260 private void testGet(String vspId, Version version, String componentId, String user,
261 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity expected) {
262 CompositionEntityResponse<ComponentData> response =
263 vendorSoftwareProductManager.getComponent(vspId, null, componentId, user);
264 Assert.assertEquals(response.getId(), expected.getId());
265 Assert.assertEquals(response.getData(), expected.getComponentCompositionData());
266 Assert.assertNotNull(response.getSchema());
269 private void testCreate_negative(
270 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component, String user,
271 String expectedErrorCode) {
273 vendorSoftwareProductManager.createComponent(component, user);
275 } catch (CoreException e) {
276 Assert.assertEquals(e.code().id(), expectedErrorCode);
280 private void testGet_negative(String vspId, Version version, String componentId, String user,
281 String expectedErrorCode) {
283 vendorSoftwareProductManager.getComponent(vspId, version, componentId, user);
285 } catch (CoreException e) {
286 Assert.assertEquals(e.code().id(), expectedErrorCode);
290 private void testUpdate_negative(String vspId, String componentId, String user,
291 String expectedErrorCode) {
293 vendorSoftwareProductManager
294 .updateComponent(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity(vspId, null, componentId), user);
296 } catch (CoreException e) {
297 Assert.assertEquals(e.code().id(), expectedErrorCode);
301 private void testList_negative(String vspId, Version version, String user,
302 String expectedErrorCode) {
304 vendorSoftwareProductManager.listComponents(vspId, version, user);
306 } catch (CoreException e) {
307 Assert.assertEquals(e.code().id(), expectedErrorCode);
311 private void testDeleteList_negative(String vspId, String user, String expectedErrorCode) {
313 vendorSoftwareProductManager.deleteComponents(vspId, user);
315 } catch (CoreException e) {
316 Assert.assertEquals(e.code().id(), expectedErrorCode);
320 private void testDelete_negative(String vspId, String componentId, String user,
321 String expectedErrorCode) {
323 vendorSoftwareProductManager.deleteComponent(vspId, componentId, user);
325 } catch (CoreException e) {
326 Assert.assertEquals(e.code().id(), expectedErrorCode);