1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
5 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
6 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
8 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
9 import org.openecomp.sdc.versioning.dao.types.Version;
10 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
11 import org.openecomp.core.util.UniqueValueUtil;
12 import org.openecomp.core.utilities.CommonMethods;
14 import org.testng.Assert;
15 import org.testng.annotations.BeforeClass;
16 import org.testng.annotations.Test;
18 import java.io.ByteArrayInputStream;
20 import java.util.Collection;
22 public class ProcessesTest {
24 protected static final String USER1 = "processesTestUser1";
25 protected static final VendorSoftwareProductManager vendorSoftwareProductManager =
26 new VendorSoftwareProductManagerImpl();
27 private static final String USER2 = "processesTestUser2";
28 private static final String ARTIFACT_NAME = "artifact.sh";
29 private static final Version VERSION01 = new Version(0, 1);
30 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
31 VendorSoftwareProductDaoFactory.getInstance().createInterface();
33 protected String vsp1Id;
34 protected String vsp2Id;
35 protected String component11Id = VendorSoftwareProductConstants.GENERAL_COMPONENT_ID;
36 protected String component21Id = VendorSoftwareProductConstants.GENERAL_COMPONENT_ID;
41 protected void init() {
42 VspDetails vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
43 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1",
44 "vlm1Id", "icon", "category", "subCategory", "123", null), USER1);
45 vsp1Id = vsp1.getId();
47 VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
48 .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName1",
49 "vlm1Id", "icon", "category", "subCategory", "123", null), USER1);
50 vsp2Id = vsp2.getId();
54 public void testListWhenNone() {
55 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> processes =
56 vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1);
57 Assert.assertEquals(processes.size(), 0);
61 public void testCreateNonExistingComponentId_negative() {
62 testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, "non existing component id", null), USER1,
63 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
67 public void testCreateNonExistingVspId_negative() {
68 testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity("non existing vsp id", null, component11Id, null), USER1,
69 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
73 public void testCreateOnLockedVsp_negative() {
74 testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null), USER2,
75 VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
78 @Test(dependsOnMethods = "testListWhenNone")
79 public void testCreate() {
80 p1Id = testCreate(vsp1Id, component11Id);
83 @Test(dependsOnMethods = {"testCreate"})
84 public void testCreateWithExistingName_negative() {
85 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
86 process = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null);
87 process.setName("p1 name");
88 testCreate_negative(process, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
91 @Test(dependsOnMethods = {"testCreate"})
92 public void testCreateWithExistingNameUnderOtherComponent() {
93 // This method is implemented in the sub class ComponentProcessesTest, it is here in order to keep the tests sequence down there (using @Test).
96 @Test(dependsOnMethods = {"testCreate"})
97 public void testCreateWithExistingNameUnderOtherVsp() {
98 testCreate(vsp2Id, component21Id);
102 public void testGetNonExistingProcessId_negative() {
103 testGet_negative(vsp1Id, null, component11Id, "non existing process id", USER1,
104 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
107 @Test(dependsOnMethods = "testCreate")
108 public void testGetNonExistingComponentId_negative() {
109 testGet_negative(vsp1Id, null, "non existing component id", p1Id, USER1,
110 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
113 @Test(dependsOnMethods = "testCreate")
114 public void testGetNonExistingVspId_negative() {
115 testGet_negative("non existing vsp id", null, component11Id, p1Id, USER1,
116 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
119 @Test(dependsOnMethods = "testCreate")
120 public void testGet() {
121 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
122 actual = testGet(vsp1Id, VERSION01, component11Id, p1Id, USER1);
123 Assert.assertNull(actual.getArtifactName());
127 public void testUpdateNonExistingProcessId_negative() {
128 testUpdate_negative(vsp1Id, component11Id, "non existing process id", USER1,
129 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
132 @Test(dependsOnMethods = "testCreate")
133 public void testUpdateNonExistingComponentId_negative() {
134 testUpdate_negative(vsp1Id, "non existing component id", p1Id, USER1,
135 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
138 @Test(dependsOnMethods = "testCreate")
139 public void testUpdateNonExistingVspId_negative() {
140 testUpdate_negative("non existing vsp id", component11Id, p1Id, USER1,
141 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
144 @Test(dependsOnMethods = {"testGet"})
145 public void testUpdate() {
146 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
147 expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, p1Id);
148 expected.setName("p1 name updated");
149 expected.setDescription("p1 desc updated");
151 vendorSoftwareProductManager.updateProcess(expected, USER1);
152 expected.setVersion(VERSION01);
154 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
155 vendorSoftwareProductDao.getProcess(vsp1Id, VERSION01, component11Id, p1Id);
156 Assert.assertEquals(actual, expected);
160 public void testListNonExistingComponentId_negative() {
161 testList_negative(vsp1Id, null, "non existing component id", USER1,
162 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
166 public void testListNonExistingVspId_negative() {
167 testList_negative("non existing vsp id", null, component11Id, USER1,
168 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
171 @Test(dependsOnMethods = {"testGet"})
172 public void testList() {
173 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
174 p2 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null);
175 p2.setName("p2 name");
176 p2.setDescription("p2 desc");
178 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity createdP2 = vendorSoftwareProductManager.createProcess(p2, USER1);
179 p2Id = createdP2.getId();
181 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> actual =
182 vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1);
183 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> expected =
184 vendorSoftwareProductDao.listProcesses(vsp1Id, VERSION01, component11Id);
185 Assert.assertEquals(actual.size(), 2);
186 Assert.assertEquals(actual, expected);
189 @Test(dependsOnMethods = {"testUpdate", "testList"})
190 public void testCreateWithRemovedName() {
191 testCreate(vsp1Id, component11Id);
195 public void testDeleteNonExistingProcessId_negative() {
196 testDelete_negative(vsp1Id, component11Id, "non existing process id", USER1,
197 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
200 @Test(dependsOnMethods = "testList")
201 public void testDeleteNonExistingComponentId_negative() {
202 testDelete_negative(vsp1Id, "non existing component id", p1Id, USER1,
203 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
206 @Test(dependsOnMethods = "testList")
207 public void testDeleteNonExistingVspId_negative() {
208 testDelete_negative("non existing vsp id", component11Id, p1Id, USER1,
209 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
212 @Test(dependsOnMethods = "testList")
213 public void testDelete() {
214 vendorSoftwareProductManager.deleteProcess(vsp1Id, component11Id, p1Id, USER1);
215 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
216 vendorSoftwareProductDao.getProcess(vsp1Id, VERSION01, component11Id, p1Id);
217 Assert.assertNull(actual);
221 public void testUploadFileNonExistingProcessId_negative() {
222 testUploadFile_negative(vsp1Id, component11Id, "non existing process id", USER1,
223 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
226 @Test(dependsOnMethods = "testList")
227 public void testUploadFileNonExistingComponentId_negative() {
228 testUploadFile_negative(vsp1Id, "non existing component id", p2Id, USER1,
229 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
232 @Test(dependsOnMethods = "testList")
233 public void testUploadFileNonExistingVspId_negative() {
234 testUploadFile_negative("non existing vsp id", component11Id, p2Id, USER1,
235 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
238 @Test(dependsOnMethods = "testList")
239 public void testGetFileWhenNone_negative() {
240 testGetFile_negative(vsp1Id, null, component11Id, p2Id, USER1,
241 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
244 @Test(dependsOnMethods = "testList")
245 public void testDeleteFileWhenNone_negative() {
246 testDeleteFile_negative(vsp1Id, component11Id, p2Id, USER1,
247 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
250 @Test(dependsOnMethods = {"testGetFileWhenNone_negative", "testDeleteFileWhenNone_negative"})
251 public void testUploadFile() {
252 vendorSoftwareProductManager
253 .uploadProcessArtifact(new ByteArrayInputStream("bla bla".getBytes()), ARTIFACT_NAME,
254 vsp1Id, component11Id, p2Id, USER1);
255 ProcessArtifactEntity actual =
256 vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id);
257 Assert.assertNotNull(actual);
258 Assert.assertNotNull(actual.getArtifact());
259 Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME);
262 @Test(dependsOnMethods = "testUploadFile")
263 public void testGetAfterUploadFile() {
264 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
265 actual = testGet(vsp1Id, VERSION01, component11Id, p2Id, USER1);
266 Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME);
270 public void testGetFileNonExistingProcessId_negative() {
271 testGetFile_negative(vsp1Id, null, component11Id, "non existing process id", USER1,
272 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
275 @Test(dependsOnMethods = "testList")
276 public void testGetFileNonExistingComponentId_negative() {
277 testGetFile_negative(vsp1Id, null, "non existing component id", p2Id, USER1,
278 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
281 @Test(dependsOnMethods = "testList")
282 public void testGetFileNonExistingVspId_negative() {
283 testGetFile_negative("non existing vsp id", null, component11Id, p2Id, USER1,
284 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
287 @Test(dependsOnMethods = "testUploadFile")
288 public void testGetFile() {
290 vendorSoftwareProductManager.getProcessArtifact(vsp1Id, null, component11Id, p2Id, USER1);
291 Assert.assertNotNull(actual);
292 ProcessArtifactEntity expected =
293 vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id);
294 Assert.assertNotNull(expected);
295 Assert.assertNotNull(expected.getArtifact());
299 public void testDeleteFileNonExistingProcessId_negative() {
300 testDeleteFile_negative(vsp1Id, component11Id, "non existing process id", USER1,
301 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
304 @Test(dependsOnMethods = "testList")
305 public void testDeleteFileNonExistingComponentId_negative() {
306 testDeleteFile_negative(vsp1Id, "non existing component id", p2Id, USER1,
307 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
310 @Test(dependsOnMethods = "testList")
311 public void testDeleteFileNonExistingVspId_negative() {
312 testDeleteFile_negative("non existing vsp id", component11Id, p2Id, USER1,
313 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
316 @Test(dependsOnMethods = "testGetFile")
317 public void testDeleteFile() {
318 vendorSoftwareProductManager.deleteProcessArtifact(vsp1Id, component11Id, p2Id, USER1);
319 ProcessArtifactEntity expected =
320 vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id);
321 Assert.assertNull(expected.getArtifact());
325 public void testDeleteListNonExistingComponentId_negative() {
326 testDeleteList_negative(vsp1Id, "non existing component id", USER1,
327 VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
331 public void testDeleteListNonExistingVspId_negative() {
332 testDeleteList_negative("non existing vsp id", component11Id, USER1,
333 VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
336 @Test(dependsOnMethods = {"testDeleteFile"})
337 public void testDeleteList() {
338 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
339 p3 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null);
340 p3.setName("p3 name");
341 p3.setDescription("p3 desc");
342 vendorSoftwareProductManager.createProcess(p3, USER1);
344 vendorSoftwareProductManager.deleteProcesses(vsp1Id, component11Id, USER1);
346 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> actual =
347 vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1);
348 Assert.assertEquals(actual.size(), 0);
351 protected String testCreate(String vspId, String componentId) {
352 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
353 expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, null, componentId, null);
354 expected.setName("p1 name");
355 expected.setDescription("p1 desc");
357 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity created = vendorSoftwareProductManager.createProcess(expected, USER1);
358 Assert.assertNotNull(created);
359 expected.setId(created.getId());
360 expected.setVersion(VERSION01);
362 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
363 vendorSoftwareProductDao.getProcess(vspId, VERSION01, componentId, created.getId());
365 Assert.assertEquals(actual, expected);
367 return created.getId();
370 private org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity testGet(String vspId, Version version, String componentId, String processId,
372 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
373 vendorSoftwareProductManager.getProcess(vspId, null, componentId, processId, user);
374 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity expected =
375 vendorSoftwareProductDao.getProcess(vspId, version, componentId, processId);
376 Assert.assertEquals(actual, expected);
380 private void testCreate_negative(
381 org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity process, String user, String expectedErrorCode) {
383 vendorSoftwareProductManager.createProcess(process, user);
385 } catch (CoreException e) {
386 Assert.assertEquals(e.code().id(), expectedErrorCode);
390 private void testGet_negative(String vspId, Version version, String componentId, String processId,
391 String user, String expectedErrorCode) {
393 vendorSoftwareProductManager.getProcess(vspId, version, componentId, processId, user);
395 } catch (CoreException e) {
396 Assert.assertEquals(e.code().id(), expectedErrorCode);
400 private void testUpdate_negative(String vspId, String componentId, String processId, String user,
401 String expectedErrorCode) {
403 vendorSoftwareProductManager
404 .updateProcess(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, null, componentId, processId), user);
406 } catch (CoreException e) {
407 Assert.assertEquals(e.code().id(), expectedErrorCode);
411 private void testList_negative(String vspId, Version version, String componentId, String user,
412 String expectedErrorCode) {
414 vendorSoftwareProductManager.listProcesses(vspId, version, componentId, user);
416 } catch (CoreException e) {
417 Assert.assertEquals(e.code().id(), expectedErrorCode);
421 private void testDeleteList_negative(String vspId, String componentId, String user,
422 String expectedErrorCode) {
424 vendorSoftwareProductManager.deleteProcesses(vspId, componentId, user);
426 } catch (CoreException e) {
427 Assert.assertEquals(e.code().id(), expectedErrorCode);
431 private void testDelete_negative(String vspId, String componentId, String processId, String user,
432 String expectedErrorCode) {
434 vendorSoftwareProductManager.deleteProcess(vspId, componentId, processId, user);
436 } catch (CoreException e) {
437 Assert.assertEquals(e.code().id(), expectedErrorCode);
441 private void testGetFile_negative(String vspId, Version version, String componentId,
442 String processId, String user, String expectedErrorCode) {
444 vendorSoftwareProductManager.getProcessArtifact(vspId, version, componentId, processId, user);
446 } catch (CoreException e) {
447 Assert.assertEquals(e.code().id(), expectedErrorCode);
451 private void testUploadFile_negative(String vspId, String componentId, String processId,
452 String user, String expectedErrorCode) {
454 vendorSoftwareProductManager
455 .uploadProcessArtifact(new ByteArrayInputStream("bla bla".getBytes()), "artifact.sh",
456 vspId, componentId, processId, user);
458 } catch (CoreException e) {
459 Assert.assertEquals(e.code().id(), expectedErrorCode);
463 private void testDeleteFile_negative(String vspId, String componentId, String processId,
464 String user, String expectedErrorCode) {
466 vendorSoftwareProductManager.deleteProcessArtifact(vspId, componentId, processId, user);
468 } catch (CoreException e) {
469 Assert.assertEquals(e.code().id(), expectedErrorCode);