aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ProcessesTest.java
blob: 8571088be10f232076e67f323711cecb7ccf99ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
package org.openecomp.sdc.vendorsoftwareproduct;

import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.core.utilities.CommonMethods;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.Collection;

public class ProcessesTest {

  protected static final String USER1 = "processesTestUser1";
  protected static final VendorSoftwareProductManager vendorSoftwareProductManager =
      new VendorSoftwareProductManagerImpl();
  private static final String USER2 = "processesTestUser2";
  private static final String ARTIFACT_NAME = "artifact.sh";
  private static final Version VERSION01 = new Version(0, 1);
  private static final VendorSoftwareProductDao vendorSoftwareProductDao =
      VendorSoftwareProductDaoFactory.getInstance().createInterface();

  protected String vsp1Id;
  protected String vsp2Id;
  protected String component11Id = VendorSoftwareProductConstants.GENERAL_COMPONENT_ID;
  protected String component21Id = VendorSoftwareProductConstants.GENERAL_COMPONENT_ID;
  private String p1Id;
  private String p2Id;

  @BeforeClass
  protected void init() {
    VspDetails vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
        .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1",
            "vlm1Id", "icon", "category", "subCategory", "123", null), USER1);
    vsp1Id = vsp1.getId();

    VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
        .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName1",
            "vlm1Id", "icon", "category", "subCategory", "123", null), USER1);
    vsp2Id = vsp2.getId();
  }

  @Test
  public void testListWhenNone() {
    Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> processes =
        vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1);
    Assert.assertEquals(processes.size(), 0);
  }

  @Test
  public void testCreateNonExistingComponentId_negative() {
    testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, "non existing component id", null), USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test
  public void testCreateNonExistingVspId_negative() {
    testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity("non existing vsp id", null, component11Id, null), USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test
  public void testCreateOnLockedVsp_negative() {
    testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null), USER2,
        VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
  }

  @Test(dependsOnMethods = "testListWhenNone")
  public void testCreate() {
    p1Id = testCreate(vsp1Id, component11Id);
  }

  @Test(dependsOnMethods = {"testCreate"})
  public void testCreateWithExistingName_negative() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
        process = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null);
    process.setName("p1 name");
    testCreate_negative(process, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
  }

  @Test(dependsOnMethods = {"testCreate"})
  public void testCreateWithExistingNameUnderOtherComponent() {
    // This method is implemented in the sub class ComponentProcessesTest, it is here in order to keep the tests sequence down there (using @Test).
  }

  @Test(dependsOnMethods = {"testCreate"})
  public void testCreateWithExistingNameUnderOtherVsp() {
    testCreate(vsp2Id, component21Id);
  }

  @Test
  public void testGetNonExistingProcessId_negative() {
    testGet_negative(vsp1Id, null, component11Id, "non existing process id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testCreate")
  public void testGetNonExistingComponentId_negative() {
    testGet_negative(vsp1Id, null, "non existing component id", p1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testCreate")
  public void testGetNonExistingVspId_negative() {
    testGet_negative("non existing vsp id", null, component11Id, p1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = "testCreate")
  public void testGet() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
        actual = testGet(vsp1Id, VERSION01, component11Id, p1Id, USER1);
    Assert.assertNull(actual.getArtifactName());
  }

  @Test
  public void testUpdateNonExistingProcessId_negative() {
    testUpdate_negative(vsp1Id, component11Id, "non existing process id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testCreate")
  public void testUpdateNonExistingComponentId_negative() {
    testUpdate_negative(vsp1Id, "non existing component id", p1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testCreate")
  public void testUpdateNonExistingVspId_negative() {
    testUpdate_negative("non existing vsp id", component11Id, p1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = {"testGet"})
  public void testUpdate() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
        expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, p1Id);
    expected.setName("p1 name updated");
    expected.setDescription("p1 desc updated");

    vendorSoftwareProductManager.updateProcess(expected, USER1);
    expected.setVersion(VERSION01);

    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
        vendorSoftwareProductDao.getProcess(vsp1Id, VERSION01, component11Id, p1Id);
    Assert.assertEquals(actual, expected);
  }

  @Test
  public void testListNonExistingComponentId_negative() {
    testList_negative(vsp1Id, null, "non existing component id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test
  public void testListNonExistingVspId_negative() {
    testList_negative("non existing vsp id", null, component11Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = {"testGet"})
  public void testList() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
        p2 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null);
    p2.setName("p2 name");
    p2.setDescription("p2 desc");

    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity createdP2 = vendorSoftwareProductManager.createProcess(p2, USER1);
    p2Id = createdP2.getId();

    Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> actual =
        vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1);
    Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> expected =
        vendorSoftwareProductDao.listProcesses(vsp1Id, VERSION01, component11Id);
    Assert.assertEquals(actual.size(), 2);
    Assert.assertEquals(actual, expected);
  }

  @Test(dependsOnMethods = {"testUpdate", "testList"})
  public void testCreateWithRemovedName() {
    testCreate(vsp1Id, component11Id);
  }

  @Test
  public void testDeleteNonExistingProcessId_negative() {
    testDelete_negative(vsp1Id, component11Id, "non existing process id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testDeleteNonExistingComponentId_negative() {
    testDelete_negative(vsp1Id, "non existing component id", p1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testDeleteNonExistingVspId_negative() {
    testDelete_negative("non existing vsp id", component11Id, p1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = "testList")
  public void testDelete() {
    vendorSoftwareProductManager.deleteProcess(vsp1Id, component11Id, p1Id, USER1);
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
        vendorSoftwareProductDao.getProcess(vsp1Id, VERSION01, component11Id, p1Id);
    Assert.assertNull(actual);
  }

  @Test
  public void testUploadFileNonExistingProcessId_negative() {
    testUploadFile_negative(vsp1Id, component11Id, "non existing process id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testUploadFileNonExistingComponentId_negative() {
    testUploadFile_negative(vsp1Id, "non existing component id", p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testUploadFileNonExistingVspId_negative() {
    testUploadFile_negative("non existing vsp id", component11Id, p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = "testList")
  public void testGetFileWhenNone_negative() {
    testGetFile_negative(vsp1Id, null, component11Id, p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testDeleteFileWhenNone_negative() {
    testDeleteFile_negative(vsp1Id, component11Id, p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = {"testGetFileWhenNone_negative", "testDeleteFileWhenNone_negative"})
  public void testUploadFile() {
    vendorSoftwareProductManager
        .uploadProcessArtifact(new ByteArrayInputStream("bla bla".getBytes()), ARTIFACT_NAME,
            vsp1Id, component11Id, p2Id, USER1);
    ProcessArtifactEntity actual =
        vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id);
    Assert.assertNotNull(actual);
    Assert.assertNotNull(actual.getArtifact());
    Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME);
  }

  @Test(dependsOnMethods = "testUploadFile")
  public void testGetAfterUploadFile() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
        actual = testGet(vsp1Id, VERSION01, component11Id, p2Id, USER1);
    Assert.assertEquals(actual.getArtifactName(), ARTIFACT_NAME);
  }

  @Test
  public void testGetFileNonExistingProcessId_negative() {
    testGetFile_negative(vsp1Id, null, component11Id, "non existing process id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testGetFileNonExistingComponentId_negative() {
    testGetFile_negative(vsp1Id, null, "non existing component id", p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testGetFileNonExistingVspId_negative() {
    testGetFile_negative("non existing vsp id", null, component11Id, p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = "testUploadFile")
  public void testGetFile() {
    File actual =
        vendorSoftwareProductManager.getProcessArtifact(vsp1Id, null, component11Id, p2Id, USER1);
    Assert.assertNotNull(actual);
    ProcessArtifactEntity expected =
        vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id);
    Assert.assertNotNull(expected);
    Assert.assertNotNull(expected.getArtifact());
  }

  @Test
  public void testDeleteFileNonExistingProcessId_negative() {
    testDeleteFile_negative(vsp1Id, component11Id, "non existing process id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testDeleteFileNonExistingComponentId_negative() {
    testDeleteFile_negative(vsp1Id, "non existing component id", p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testList")
  public void testDeleteFileNonExistingVspId_negative() {
    testDeleteFile_negative("non existing vsp id", component11Id, p2Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = "testGetFile")
  public void testDeleteFile() {
    vendorSoftwareProductManager.deleteProcessArtifact(vsp1Id, component11Id, p2Id, USER1);
    ProcessArtifactEntity expected =
        vendorSoftwareProductDao.getProcessArtifact(vsp1Id, VERSION01, component11Id, p2Id);
    Assert.assertNull(expected.getArtifact());
  }

  @Test
  public void testDeleteListNonExistingComponentId_negative() {
    testDeleteList_negative(vsp1Id, "non existing component id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test
  public void testDeleteListNonExistingVspId_negative() {
    testDeleteList_negative("non existing vsp id", component11Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = {"testDeleteFile"})
  public void testDeleteList() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
        p3 = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vsp1Id, null, component11Id, null);
    p3.setName("p3 name");
    p3.setDescription("p3 desc");
    vendorSoftwareProductManager.createProcess(p3, USER1);

    vendorSoftwareProductManager.deleteProcesses(vsp1Id, component11Id, USER1);

    Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity> actual =
        vendorSoftwareProductManager.listProcesses(vsp1Id, null, component11Id, USER1);
    Assert.assertEquals(actual.size(), 0);
  }

  protected String testCreate(String vspId, String componentId) {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity
        expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, null, componentId, null);
    expected.setName("p1 name");
    expected.setDescription("p1 desc");

    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity created = vendorSoftwareProductManager.createProcess(expected, USER1);
    Assert.assertNotNull(created);
    expected.setId(created.getId());
    expected.setVersion(VERSION01);

    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
        vendorSoftwareProductDao.getProcess(vspId, VERSION01, componentId, created.getId());

    Assert.assertEquals(actual, expected);

    return created.getId();
  }

  private org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity testGet(String vspId, Version version, String componentId, String processId,
                                                                                 String user) {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity actual =
        vendorSoftwareProductManager.getProcess(vspId, null, componentId, processId, user);
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity expected =
        vendorSoftwareProductDao.getProcess(vspId, version, componentId, processId);
    Assert.assertEquals(actual, expected);
    return actual;
  }

  private void testCreate_negative(
      org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity process, String user, String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.createProcess(process, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testGet_negative(String vspId, Version version, String componentId, String processId,
                                String user, String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.getProcess(vspId, version, componentId, processId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testUpdate_negative(String vspId, String componentId, String processId, String user,
                                   String expectedErrorCode) {
    try {
      vendorSoftwareProductManager
          .updateProcess(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, null, componentId, processId), user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testList_negative(String vspId, Version version, String componentId, String user,
                                 String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.listProcesses(vspId, version, componentId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testDeleteList_negative(String vspId, String componentId, String user,
                                       String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.deleteProcesses(vspId, componentId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testDelete_negative(String vspId, String componentId, String processId, String user,
                                   String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.deleteProcess(vspId, componentId, processId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testGetFile_negative(String vspId, Version version, String componentId,
                                    String processId, String user, String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.getProcessArtifact(vspId, version, componentId, processId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testUploadFile_negative(String vspId, String componentId, String processId,
                                       String user, String expectedErrorCode) {
    try {
      vendorSoftwareProductManager
          .uploadProcessArtifact(new ByteArrayInputStream("bla bla".getBytes()), "artifact.sh",
              vspId, componentId, processId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

  private void testDeleteFile_negative(String vspId, String componentId, String processId,
                                       String user, String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.deleteProcessArtifact(vspId, componentId, processId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

}