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

import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING;
import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_COMPUTE_NAME_NOT_ALLOWED;

import org.openecomp.core.utilities.CommonMethods;
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.ComponentEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.ListComputeResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentComputeAssociation;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ComputeTest {

  /*private static final String USER1 = "componentsTestUser1";
  private static final String USER2 = "componentsTestUser2";
  private static final Version VERSION01 = new Version(0, 1);
  private static final VendorSoftwareProductManager vendorSoftwareProductManager =
      new VendorSoftwareProductManagerImpl();
  private static final VendorSoftwareProductDao vendorSoftwareProductDao =
      VendorSoftwareProductDaoFactory
          .getInstance().createInterface();

  private static String vsp1Id;
  private static String vsp2Id;
  private static String comp1 = "{\"displayName\": \"VFC_Manual\", " +
      "\"description\": \"desc manual\"}";
  private static String compute1 = "{\"name\": \"Compute_A\", " +
      "\"description\": \"desc manual compute\"}";
  private static String computeDelete = "{\"name\": \"Compute_Delete\", " +
      "\"description\": \"desc manual compute delete\"}";

  private static String comp1Id;
  private static String compute1Id;
  private ComputeEntity createdCompute;

  static ComponentEntity createComponent(String vspId, Version version, String compId) {
    ComponentEntity componentEntity = new ComponentEntity(vspId, version, compId);
    ComponentData compData = new ComponentData();
    compData.setName(compId + " name");
    compData.setDisplayName(compId + " display name");
    compData.setDescription(compId + " desc");
    componentEntity.setComponentCompositionData(compData);
    vendorSoftwareProductDao.createComponent(componentEntity);
    return componentEntity;
  }

  static ComputeEntity createComputeEntity(String vspId, String componentId, String data ){
    ComputeEntity comp = new ComputeEntity();
    comp.setVspId(vspId);
    comp.setComponentId(componentId);
    comp.setCompositionData(data);
    return comp;
  }

  @BeforeClass
  private void init() {
    VspDetails
        vsp1 = vendorSoftwareProductManager.createNewVsp(VSPCommon
        .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp1", "vendorName",
            "vlm1Id", "icon", "category", "subCategory", "123", null,
            VSPCommon.OnboardingMethod.HEAT.name()), USER1
    );
    vsp1Id = vsp1.getId(); //HEAT onboarded

    VspDetails vsp2 = vendorSoftwareProductManager.createNewVsp(VSPCommon
        .createVspDetails(null, null, "VSP_" + CommonMethods.nextUuId(), "Test-vsp3",
            "vendorName",
            "vlm1Id", "icon", "category", "subCategory", "123", null, VSPCommon
                .OnboardingMethod.Manual.name()), USER1);
    vsp2Id = vsp2.getId(); //MANUAL onboarded

    ComponentEntity component = new ComponentEntity();
    component.setVspId(vsp2Id);
    component.setCompositionData(comp1);
    ComponentEntity createdComp = vendorSoftwareProductManager.createComponent(component, USER1);
    comp1Id = createdComp.getId();
  }

  @Test
  public void testListWhenNone() {

    final Collection<ListComputeResponse> listComputeResponses =
        vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
    Assert.assertEquals(listComputeResponses.size(), 0);
  }

  @Test
  public void testCreateComputeInHeatOnboardedVsp_negative() {
    ComputeEntity comp = createComputeEntity(vsp1Id,comp1Id,compute1);
    try {
      createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
      Assert.fail();
    }
    catch(CoreException exception){
      Assert.assertEquals(exception.code().id(),ADD_COMPUTE_NOT_ALLOWED_IN_HEAT_ONBOARDING);
    }
  }

  @Test(dependsOnMethods = "testListWhenNone")
  public void testCreateCompute() {
    ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);

    createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
    compute1Id = createdCompute.getId();
    Assert.assertNotNull(compute1Id);
    Assert.assertNotNull(createdCompute.getCompositionData());
    Assert.assertNotNull(
        vendorSoftwareProductManager.getCompute(vsp2Id, VERSION01, comp1Id,compute1Id,
            USER1).getData());
  }

  @Test(dependsOnMethods = "testCreateCompute")
  public void testCreateComputeNegative() {
    ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,compute1);

    try {
      ComputeEntity createdCompute = vendorSoftwareProductManager.createCompute(comp, USER1);
      Assert.fail();
    }
    catch (CoreException exception) {
      Assert.assertEquals(exception.code().id(),DUPLICATE_COMPUTE_NAME_NOT_ALLOWED);
    }
  }

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

  @Test
  public void testGetNonExistingVspId_negative() {
    testGet_negative("non existing vsp id", null, comp1Id, compute1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test
  public void testGetNonExistingComputeId_negative() {
    testGet_negative(vsp1Id, null, comp1Id, "non existing compute id", USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test(dependsOnMethods = "testCreateCompute")
  public void testGetCompute() {
    testGet(vsp2Id, VERSION01, comp1Id, compute1Id, USER1, createdCompute);
  }


  @Test(dependsOnMethods = "testCreateCompute")
  public void testListCompute() {

    final Collection<ListComputeResponse> actual =
        vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
    Assert.assertEquals(actual.size(), 1);
    actual.forEach(listComputeResponse -> {
      Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), false);
    } );
  }


  @Test(dependsOnMethods = "testListCompute")
  public void testListComputeAssociatedWithDeployment() {

    //Create DF and associate compute1Id CF to it
    String deployment1Id = null;
    DeploymentFlavorEntity deploymentFlavorEntity = new DeploymentFlavorEntity(vsp2Id,
        VERSION01, deployment1Id);
    DeploymentFlavor deploymentFlavor = new DeploymentFlavor();
    deploymentFlavor.setModel("DF_testListComputeAssociatedWithDeployment");
    deploymentFlavor.setDescription("creating a deployment flavor with compute flavor association");
    ComponentComputeAssociation association = new ComponentComputeAssociation();
    association.setComponentId(comp1Id);
    association.setComputeFlavorId(compute1Id);
    List<ComponentComputeAssociation> associations = new ArrayList<ComponentComputeAssociation>();
    associations.add(association);
    deploymentFlavor.setComponentComputeAssociations(associations);
    deploymentFlavorEntity.setDeploymentFlavorCompositionData(deploymentFlavor);

    DeploymentFlavorEntity createddeployment = vendorSoftwareProductManager.createDeploymentFlavor
        (deploymentFlavorEntity, USER1);
    Assert.assertEquals((createddeployment.getId() != null), true);
    deployment1Id = createddeployment.getId();

    final Collection<ListComputeResponse> actual =
        vendorSoftwareProductManager.listCompute(vsp2Id, null, comp1Id, USER1);
    Assert.assertEquals(actual.size(), 1);
    actual.forEach(listComputeResponse -> {
      Assert.assertEquals(listComputeResponse.isAssociatedWithDeploymentFlavor(), true);
    } );
  }

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

  @Test
  public void testUpdateNonExistingVspId_negative() {
    testUpdate_negative("non existing vsp id", comp1Id, USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  @Test
  public void testDelete() {
    ComputeEntity comp = createComputeEntity(vsp2Id,comp1Id,computeDelete);

    ComputeEntity created = vendorSoftwareProductManager.createCompute(comp, USER1);

    vendorSoftwareProductManager.deleteCompute(vsp2Id,comp1Id,created.getId(),USER1);
    testGet_negative(vsp2Id,null, comp1Id, created.getId(),USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test
  public void testDeleteNonExistingComputeId_negative() {
    testDelete_negative(vsp2Id,comp1Id,"InvalidComputeId",USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test
  public void testDeleteNonExistingComponentId_negative() {
    testDelete_negative(vsp2Id,"InvalidComponentId",compute1Id,USER1,
        VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
  }

  @Test
  public void testDeleteNonExistingVspId_negative() {
    testDelete_negative("InvalidVspId",comp1Id,compute1Id,USER1,
        VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
  }

  private void testGet(String vspId, Version version, String componentId, String computeId, String
      user, ComputeEntity expected) {
    CompositionEntityResponse<ComputeData>
        response = vendorSoftwareProductManager.getCompute(vspId, null, componentId, computeId,
        user);
    Assert.assertEquals(response.getId(), expected.getId());
    Assert.assertEquals(response.getData(), expected.getComputeCompositionData());
    Assert.assertNotNull(response.getSchema());
  }

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

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

  private void testUpdate_negative(String vspId, String componentId, String user,
                                   String expectedErrorCode) {
    try {
      vendorSoftwareProductManager
          .updateComponent(new ComponentEntity(vspId, null, componentId), user);
      Assert.fail();
    } catch (CoreException exception) {
      Assert.assertEquals(exception.code().id(), expectedErrorCode);
    }
  }*/
}