aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/NicsTest.java
blob: 10ea7f7eaf052f69b9f608c2d5849683b4a67139 (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
package org.openecomp.sdc.vendorsoftwareproduct;

import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
import org.openecomp.core.utilities.CommonMethods;

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

import java.util.Collection;

public class NicsTest {

  private static final String USER1 = "nicsTestUser1";
  private static final String USER2 = "nicsTestUser2";
  private static final org.openecomp.sdc.versioning.dao.types.Version
      VERSION01 = new org.openecomp.sdc.versioning.dao.types.Version(0, 1);
  private static final VendorSoftwareProductManager vendorSoftwareProductManager =
      new VendorSoftwareProductManagerImpl();
  private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao
      vendorSoftwareProductDao =
      org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory.getInstance().createInterface();

  private static String vsp1Id;
  private static String vsp2Id;
  private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity network1;
  private static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity network2;
  private static String component11Id;
  private static String component21Id;
  private static String nic1Id = "nic1";

  static org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity createNic(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String compId, String nicId,
                                                                              String networkId) {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
        nicEntity = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, version, compId, nicId);
    org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
        nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
    nicData.setName(nicId + " name");
    nicData.setDescription(nicId + " desc");
    nicData.setNetworkId(networkId);
    nicEntity.setNicCompositionData(nicData);
    vendorSoftwareProductDao.createNic(nicEntity);
    return nicEntity;
  }

  @BeforeClass
  private void init() {
    vsp1Id = vendorSoftwareProductManager.createNewVsp(VSPCommon
        .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName1",
            "vlm1Id", "icon", "category", "subCategory", "123", null), USER1).getId();
    network1 = NetworksTest.createNetwork(vsp1Id, VERSION01, "network1");
    component11Id = ComponentsTest.createComponent(vsp1Id, VERSION01, "component11").getId();

    vsp2Id = vendorSoftwareProductManager.createNewVsp(VSPCommon
        .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp2", "vendorName1",
            "vlm1Id", "icon", "category", "subCategory", "123", null), USER1).getId();
    network2 = NetworksTest.createNetwork(vsp2Id, VERSION01, "network2");
    component21Id = ComponentsTest.createComponent(vsp2Id, VERSION01, "component21").getId();
  }

/*    @Test
    public void testCreateNonExistingComponentId_negative() {
        testCreate_negative(new NicEntity(vsp1Id, null, "non existing component id", null), USER1, VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
    }*/

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

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

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

//    @Test(dependsOnMethods = "testListWhenNone")
//    public void testCreate() {
//        nic1Id = testCreate(vsp1Id, component11Id, network1.getId(), network1.getNetworkCompositionData().getName());
//    }

/*    @Test(dependsOnMethods = {"testCreate"})
    public void testCreateWithExistingName_negative() {
        NicEntity nic = new NicEntity(vsp1Id, null, component11Id, null);
        Nic nicData = new Nic();
        nicData.setName("nic1 name");
        nic.setNicCompositionData(nicData);
        testCreate_negative(nic, USER1, UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
    }*/

//    @Test(dependsOnMethods = {"testCreate"})
//    public void testCreateWithExistingNameUnderOtherComponent() {
//        ComponentEntity component12 = new ComponentEntity(vsp1Id, null, null);
//        ComponentData compData12 = new ComponentData();
//        compData12.setName("comp12 name");
//        compData12.setDescription("comp12 desc");
//        component12.setComponentCompositionData(compData12);
//
//        String component12Id = vendorSoftwareProductManager.createComponent(component12, USER1).getId();
//        testCreate(vsp1Id, component12Id, network1.getId(), network1.getNetworkCompositionData().getName());
//    }

//    @Test(dependsOnMethods = {"testCreate"})
//    public void testCreateWithExistingNameUnderOtherVsp() {
//        testCreate(vsp2Id, component21Id, network2.getId(), network2.getNetworkCompositionData().getName());
//    }

  @Test
  public void testCreateOnUploadVsp_negative() {
    testCreate_negative(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, null), USER1,
        VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
  }

  @Test
  public void testGetNonExistingNicId_negative() {
    testGet_negative(vsp1Id, null, component11Id, "non existing nic id", USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
  public void testGetNonExistingComponentId_negative() {
    testGet_negative(vsp1Id, null, "non existing component id", nic1Id, USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
  public void testGetNonExistingVspId_negative() {
    testGet_negative("non existing vsp id", null, component11Id, nic1Id, USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
  public void testGet() {
    createNic(vsp1Id, VERSION01, component11Id, nic1Id, network1.getId());
    testGet(vsp1Id, VERSION01, component11Id, nic1Id, USER1);
  }

  @Test
  public void testUpdateNonExistingNicId_negative() {
    testUpdate_negative(vsp1Id, component11Id, "non existing nic id", USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
  public void testUpdateNonExistingComponentId_negative() {
    testUpdate_negative(vsp1Id, "non existing component id", nic1Id, USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testListWhenNone")//"testCreate")
  public void testUpdateNonExistingVspId_negative() {
    testUpdate_negative("non existing vsp id", component11Id, nic1Id, USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test(dependsOnMethods = {"testGet"})
  public void testUpdateOnUploadVsp() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
        expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, nic1Id);
    org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
        nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
    nicData.setName(nic1Id + " name");
    nicData.setDescription(nic1Id + " desc updated");
    nicData.setNetworkId(network1.getId());
    expected.setNicCompositionData(nicData);

    CompositionEntityValidationData validationData =
        vendorSoftwareProductManager.updateNic(expected, USER1);
    Assert.assertTrue(validationData == null || validationData.getErrors() == null);
    expected.setVersion(VERSION01);

    org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
        actual = vendorSoftwareProductDao.getNic(vsp1Id, VERSION01, component11Id, nic1Id);
    Assert.assertEquals(actual, expected);
  }

  @Test(dependsOnMethods = {"testGet"})
  public void testIllegalUpdateOnUploadVsp() {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
        expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vsp1Id, null, component11Id, nic1Id);
    org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
        nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
    nicData.setName(nic1Id + " name updated");
    nicData.setDescription(nic1Id + " desc updated");
    nicData.setNetworkId(network1.getId());
    expected.setNicCompositionData(nicData);

    CompositionEntityValidationData validationData =
        vendorSoftwareProductManager.updateNic(expected, USER1);
    Assert.assertNotNull(validationData);
    Assert.assertTrue(validationData.getErrors().size() > 0);
  }

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

  @Test
  public void testListNonExistingVspId_negative() {
    testList_negative("non existing vsp id", null, component11Id, USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }
/*
    @Test(dependsOnMethods = {"testUpdateOnUploadVsp", "testList"})
    public void testCreateWithRemovedName() {
        testCreate(vsp1Id, component11Id);
    }

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

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

  @Test(dependsOnMethods = {"testGet"})
  public void testList() {
    createNic(vsp1Id, VERSION01, component11Id, "nic2", network1.getId());

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

  @Test(dependsOnMethods = "testList")
  public void testDeleteNonExistingVspId_negative() {
    testDelete_negative("non existing vsp id", component11Id, nic1Id, USER1,
        org.openecomp.sdc.versioning.errors.VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }
/*
    @Test(dependsOnMethods = "testList")
    public void testDelete() {
        vendorSoftwareProductManager.deleteNic(vsp1Id, component11Id, nic1Id, USER1);
        NicEntity actual = vendorSoftwareProductDao.getNic(vsp1Id, VERSION01, component11Id, nic1Id);
        Assert.assertNull(actual);
    }*/

  @Test(dependsOnMethods = "testList")
  public void testDeleteOnUploadVsp_negative() {
    testDelete_negative(vsp1Id, component11Id, nic1Id, USER1,
        VendorSoftwareProductErrorCodes.VSP_COMPOSITION_EDIT_NOT_ALLOWED);
  }

  private String testCreate(String vspId, String componentId, String networkId,
                            String networkName) {
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
        expected = new org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity(vspId, null, componentId, null);

    org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic
        nicData = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic();
    nicData.setName("nic1 name");
    nicData.setNetworkId(networkId);
    //nicData.setNetworkName(networkName);
    nicData.setNetworkType(org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType.External);
    expected.setNicCompositionData(nicData);

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

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

    Assert.assertEquals(actual, expected);

    return created.getId();
  }

  private void testGet(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId,
                       String user) {
    CompositionEntityResponse<org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic> response =
        vendorSoftwareProductManager.getNic(vspId, null, componentId, nicId, user);
    org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity
        expected = vendorSoftwareProductDao.getNic(vspId, version, componentId, nicId);
    Assert.assertEquals(response.getId(), expected.getId());
    Assert.assertEquals(response.getData(), expected.getNicCompositionData());
    Assert.assertNotNull(response.getSchema());
  }

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

  private void testGet_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String nicId,
                                String user, String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.getNic(vspId, version, componentId, nicId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

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

  private void testList_negative(String vspId, org.openecomp.sdc.versioning.dao.types.Version version, String componentId, String user,
                                 String expectedErrorCode) {
    try {
      vendorSoftwareProductManager.listNics(vspId, version, componentId, user);
      Assert.fail();
    } catch (CoreException e) {
      Assert.assertEquals(e.code().id(), expectedErrorCode);
    }
  }

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