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
|
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.so.asdc.client;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import javax.persistence.EntityNotFoundException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.onap.so.asdc.BaseTest;
import org.onap.so.asdc.client.exceptions.ASDCControllerException;
import org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl;
import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator;
import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
import org.onap.so.asdc.client.test.emulators.ResourceInfoImpl;
import org.onap.so.db.catalog.beans.PnfResource;
import org.onap.so.db.catalog.beans.PnfResourceCustomization;
import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.ToscaCsar;
import org.onap.so.db.catalog.beans.VnfResource;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.catalog.data.repository.PnfCustomizationRepository;
import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
import org.onap.so.db.catalog.data.repository.ServiceRepository;
import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
/**
* This is used to run some basic integration test(BIT) for ASDC controller. It will test the csar install and all the
* testing csar files are located underneath src/main/resources/download folder,
*
* PNF csar: service-Testservice140-csar.csar VNF csar: service-Svc140-VF-csar.csar
*/
@Transactional
public class ASDCControllerITTest extends BaseTest {
private Logger logger = LoggerFactory.getLogger(ASDCControllerITTest.class);
@Rule
public TestName testName = new TestName();
private String serviceUuid;
private String serviceInvariantUuid;
/**
* Random UUID served as distribution UUID.
*/
private String distributionId;
private String artifactUuid;
@Autowired
private ASDCController asdcController;
@Autowired
private PnfResourceRepository pnfResourceRepository;
@Autowired
private PnfCustomizationRepository pnfCustomizationRepository;
@Autowired
private VnfResourceRepository vnfResourceRepository;
@Autowired
private VnfCustomizationRepository vnfCustomizationRepository;
@Autowired
private ToscaCsarRepository toscaCsarRepository;
@Autowired
private ServiceRepository serviceRepository;
private DistributionClientEmulator distributionClient;
@Before
public void setUp() {
distributionId = UUID.randomUUID().toString();
artifactUuid = UUID.randomUUID().toString();
logger.info("Using distributionId: {}, artifactUUID: {} for testcase: {}", distributionId, artifactUuid,
testName.getMethodName());
distributionClient = new DistributionClientEmulator();
distributionClient.setResourcePath("src/test/resources");
asdcController.setDistributionClient(distributionClient);
try {
asdcController.initASDC();
} catch (ASDCControllerException e) {
logger.error(e.getMessage(), e);
fail(e.getMessage());
}
}
@After
public void shutDown() {
try {
asdcController.closeASDC();
} catch (ASDCControllerException e) {
logger.error(e.getMessage(), e);
fail(e.getMessage());
}
}
/**
* Mock the AAI using wireshark.
*/
private void initMockAaiServer(final String serviceUuid, final String serviceInvariantUuid) {
String modelEndpoint = "/aai/v15/service-design-and-creation/models/model/" + serviceInvariantUuid
+ "/model-vers/model-ver/" + serviceUuid + "?depth=0";
stubFor(post(urlEqualTo(modelEndpoint)).willReturn(ok()));
}
/**
* Test with service-Testservice140-csar.csar.
*/
@Test
public void treatNotification_ValidPnfResource_ExpectedOutput() {
/**
* service UUID/invariantUUID from global metadata in service-Testservice140-template.yml.
*/
String serviceUuid = "efaea486-561f-4159-9191-a8d3cb346728";
String serviceInvariantUuid = "f2edfbf4-bb0a-4fe7-a57a-71362d4b0b23";
initMockAaiServer(serviceUuid, serviceInvariantUuid);
NotificationDataImpl notificationData = new NotificationDataImpl();
notificationData.setServiceUUID(serviceUuid);
notificationData.setDistributionID(distributionId);
notificationData.setServiceInvariantUUID(serviceInvariantUuid);
notificationData.setServiceVersion("1.0");
ResourceInfoImpl resourceInfo = constructPnfResourceInfo();
List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
resourceInfoList.add(resourceInfo);
notificationData.setResources(resourceInfoList);
ArtifactInfoImpl artifactInfo = constructPnfServiceArtifact();
List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
artifactInfoList.add(artifactInfo);
notificationData.setServiceArtifacts(artifactInfoList);
try {
asdcController.treatNotification(notificationData);
logger.info("Checking the database for PNF ingestion");
/**
* Check the tosca csar entity, it should be the same as provided from NotficationData.
*/
ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid)
.orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
assertEquals("tosca csar name", "service-Testservice140-csar.csar", toscaCsar.getName());
assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
assertNull("tosca csar descrption", toscaCsar.getDescription());
assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
assertEquals("toscar csar URL", "/download/service-Testservice140-csar.csar", toscaCsar.getUrl());
/**
* Check the service entity, it should be the same as global metadata information in service-Testservice140-template.yml inside csar.
*/
Service service = serviceRepository.findById(serviceUuid)
.orElseThrow(() -> new EntityNotFoundException("Service: " + serviceUuid + " not found"));
assertEquals("model UUID", "efaea486-561f-4159-9191-a8d3cb346728", service.getModelUUID());
assertEquals("model name", "TestService140", service.getModelName());
assertEquals("model invariantUUID", "f2edfbf4-bb0a-4fe7-a57a-71362d4b0b23",
service.getModelInvariantUUID());
assertEquals("model version", "1.0", service.getModelVersion());
assertEquals("description", "Test Service for extended attributes of PNF resource",
service.getDescription().trim());
assertEquals("tosca csar artifact UUID", artifactUuid, service.getCsar().getArtifactUUID());
assertEquals("service type", "Network", service.getServiceType());
assertEquals("service role", "nfv", service.getServiceRole());
assertEquals("environment context", "General_Revenue-Bearing", service.getEnvironmentContext());
assertEquals("service category", "Network Service", service.getCategory());
assertNull("workload context", service.getWorkloadContext());
assertEquals("resource order", "Test140PNF", service.getResourceOrder());
/**
* Check PNF resource, it should be the same as metadata in the topology template in service-Testservice140-template.yml
* OR
* global metadata in the resource-Test140pnf-template.yml
*/
String pnfResourceKey = "9c54e269-122b-4e8a-8b2a-6eac849b441a";
PnfResource pnfResource = pnfResourceRepository.findById(pnfResourceKey)
.orElseThrow(() -> new EntityNotFoundException("PNF resource:" + pnfResourceKey + " not found"));
assertNull("orchestration mode", pnfResource.getOrchestrationMode());
assertEquals("Description", "Oracle", pnfResource.getDescription().trim());
assertEquals("model UUID", pnfResourceKey, pnfResource.getModelUUID());
assertEquals("model invariant UUID", "d832a027-75f3-455d-9de4-f02fcdee7e7e",
pnfResource.getModelInvariantUUID());
assertEquals("model version", "1.0", pnfResource.getModelVersion());
assertEquals("model name", "Test140PNF", pnfResource.getModelName());
assertEquals("tosca node type", "org.openecomp.resource.pnf.Test140pnf", pnfResource.getToscaNodeType());
assertEquals("resource category", "Application L4+", pnfResource.getCategory());
assertEquals("resource sub category", "Call Control", pnfResource.getSubCategory());
/**
* Check PNF resource customization, it should be the same as metadata in the topology template in service-Testservice140-template.yml
* OR
* global metadata in the resource-Test140pnf-template.yml
*/
String pnfCustomizationKey = "428a3d73-f962-4cc2-ba62-2483c45d6b12";
PnfResourceCustomization pnfCustomization = pnfCustomizationRepository
.findById(pnfCustomizationKey).orElseThrow(
() -> new EntityNotFoundException(
"PNF resource customization: " + pnfCustomizationKey + " not found"));
assertEquals("model customizationUUID", pnfCustomizationKey, pnfCustomization.getModelCustomizationUUID());
assertEquals("model instance name", "Test140PNF 0", pnfCustomization.getModelInstanceName());
assertEquals("NF type", "", pnfCustomization.getNfType());
assertEquals("NF Role", "nf", pnfCustomization.getNfRole());
assertEquals("NF function", "nf", pnfCustomization.getNfFunction());
assertEquals("NF naming code", "", pnfCustomization.getNfNamingCode());
assertEquals("PNF resource model UUID", pnfResourceKey, pnfCustomization.getPnfResources().getModelUUID());
assertEquals("Multi stage design", "", pnfCustomization.getMultiStageDesign());
assertNull("resource input", pnfCustomization.getResourceInput());
assertEquals("cds blueprint name(sdnc_model_name property)", pnfCustomization.getBlueprintName(),
pnfCustomization.getBlueprintName());
assertEquals("cds blueprint version(sdnc_model_version property)", pnfCustomization.getBlueprintVersion(),
pnfCustomization.getBlueprintVersion());
/**
* Check the pnf resource customization with service mapping
*/
List<PnfResourceCustomization> pnfCustList = service.getPnfCustomizations();
assertEquals("PNF resource customization entity", 1, pnfCustList.size());
assertEquals(pnfCustomizationKey, pnfCustList.get(0).getModelCustomizationUUID());
} catch (Exception e) {
logger.info(e.getMessage(), e);
fail(e.getMessage());
}
}
private ArtifactInfoImpl constructPnfServiceArtifact() {
ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
artifactInfo.setArtifactType(ASDCConfiguration.TOSCA_CSAR);
artifactInfo.setArtifactURL("/download/service-Testservice140-csar.csar");
artifactInfo.setArtifactName("service-Testservice140-csar.csar");
artifactInfo.setArtifactVersion("1.0");
artifactInfo.setArtifactUUID(artifactUuid);
return artifactInfo;
}
/**
* Construct the PnfResourceInfo based on the resource-Test140Pnf-template.yml from
* service-Testservice140-csar.csar.
*/
private ResourceInfoImpl constructPnfResourceInfo() {
ResourceInfoImpl resourceInfo = new ResourceInfoImpl();
resourceInfo.setResourceInstanceName("Test140PNF");
resourceInfo.setResourceInvariantUUID("d832a027-75f3-455d-9de4-f02fcdee7e7e");
resourceInfo.setResoucreType("PNF");
resourceInfo.setCategory("Application L4+");
resourceInfo.setSubcategory("Call Control");
resourceInfo.setResourceUUID("9c54e269-122b-4e8a-8b2a-6eac849b441a");
resourceInfo.setResourceCustomizationUUID("428a3d73-f962-4cc2-ba62-2483c45d6b12");
resourceInfo.setResourceVersion("1.0");
return resourceInfo;
}
/**
* Testing with the service-Svc140-VF-csar.csar.
*/
@Test
@Ignore
public void treatNotification_ValidVnfResource_ExpectedOutput() {
/**
* service UUID/invariantUUID from global metadata in resource-Testvf140-template.yml.
*/
String serviceUuid = "28944a37-de3f-46ec-9c60-b57036fbd26d";
String serviceInvariantUuid = "9e900d3e-1e2e-4124-a5c2-4345734dc9de";
initMockAaiServer(serviceUuid, serviceInvariantUuid);
NotificationDataImpl notificationData = new NotificationDataImpl();
notificationData.setServiceUUID(serviceUuid);
notificationData.setDistributionID(distributionId);
notificationData.setServiceInvariantUUID(serviceInvariantUuid);
notificationData.setServiceVersion("1.0");
ResourceInfoImpl resourceInfo = constructVnfResourceInfo();
List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
resourceInfoList.add(resourceInfo);
notificationData.setResources(resourceInfoList);
ArtifactInfoImpl artifactInfo = constructVnfServiceArtifact();
List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
artifactInfoList.add(artifactInfo);
notificationData.setServiceArtifacts(artifactInfoList);
try {
asdcController.treatNotification(notificationData);
logger.info("Checking the database for VNF ingestion");
/**
* Check the tosca csar entity, it should be the same as provided from NotficationData.
*/
ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid)
.orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
assertEquals("tosca csar name", "service-Svc140-VF-csar.csar", toscaCsar.getName());
assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
assertNull("tosca csar descrption", toscaCsar.getDescription());
assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
assertEquals("toscar csar URL", "/download/service-Svc140-VF-csar.csar", toscaCsar.getUrl());
/**
* Check the service entity, it should be the same as global metadata information in service-Testservice140-template.yml inside csar.
*/
Service service = serviceRepository.findById(serviceUuid)
.orElseThrow(() -> new EntityNotFoundException("Service: " + serviceUuid + " not found"));
assertEquals("model UUID", serviceUuid, service.getModelUUID());
assertEquals("model name", "SVC140", service.getModelName());
assertEquals("model invariantUUID", serviceInvariantUuid,
service.getModelInvariantUUID());
assertEquals("model version", "1.0", service.getModelVersion());
assertEquals("description", "SVC140",
service.getDescription().trim());
assertEquals("tosca csar artifact UUID", artifactUuid, service.getCsar().getArtifactUUID());
assertEquals("service type", "ST", service.getServiceType());
assertEquals("service role", "Sr", service.getServiceRole());
assertEquals("environment context", "General_Revenue-Bearing", service.getEnvironmentContext());
assertEquals("service category", "Network Service", service.getCategory());
assertNull("workload context", service.getWorkloadContext());
assertEquals("resource order", "TestVF140", service.getResourceOrder());
/**
* Check VNF resource, it should be the same as metadata in the topology template in service-Testservice140-template.yml
* OR
* global metadata in the resource-Testservice140-template.yml
*/
String vnfResourceKey = "d20d3ea9-2f54-4071-8b5c-fd746dde245e";
VnfResource vnfResource = vnfResourceRepository.findById(vnfResourceKey)
.orElseThrow(() -> new EntityNotFoundException("VNF resource:" + vnfResourceKey + " not found"));
assertEquals("orchestration mode", "HEAT", vnfResource.getOrchestrationMode());
assertEquals("Description", "TestPNF140", vnfResource.getDescription().trim());
assertEquals("model UUID", vnfResourceKey, vnfResource.getModelUUID());
assertEquals("model invariant UUID", "7a4bffa2-fac5-4b8b-b348-0bdf313a1aeb",
vnfResource.getModelInvariantUUID());
assertEquals("model version", "1.0", vnfResource.getModelVersion());
assertEquals("model name", "TestVF140", vnfResource.getModelName());
assertEquals("tosca node type", "org.openecomp.resource.vf.Testvf140", vnfResource.getToscaNodeType());
assertEquals("resource category", "Application L4+", vnfResource.getCategory());
assertEquals("resource sub category", "Database", vnfResource.getSubCategory());
/**
* Check VNF resource customization, it should be the same as metadata in the topology template in service-Testservice140-template.yml
* OR
* global metadata in the resource-Testservice140-template.yml
*/
String vnfCustomizationKey = "ca1c8455-8ce2-4a76-a037-3f4cf01cffa0";
VnfResourceCustomization vnfCustomization = vnfCustomizationRepository
.findById(vnfCustomizationKey).orElseThrow(
() -> new EntityNotFoundException(
"VNF resource customization: " + vnfCustomizationKey + " not found"));
assertEquals("model customizationUUID", vnfCustomizationKey, vnfCustomization.getModelCustomizationUUID());
assertEquals("model instance name", "TestVF140 0", vnfCustomization.getModelInstanceName());
assertNull("NF type", vnfCustomization.getNfType());
assertNull("NF Role", vnfCustomization.getNfRole());
assertNull("NF function", vnfCustomization.getNfFunction());
assertNull("NF naming code", vnfCustomization.getNfNamingCode());
assertEquals("VNF resource model UUID", vnfResourceKey, vnfCustomization.getVnfResources().getModelUUID());
assertEquals("Multi stage design", "false", vnfCustomization.getMultiStageDesign());
assertNull("resource input", vnfCustomization.getResourceInput());
assertEquals("cds blueprint name(sdnc_model_name property)", vnfCustomization.getBlueprintName(),
vnfCustomization.getBlueprintName());
assertEquals("cds blueprint version(sdnc_model_version property)", vnfCustomization.getBlueprintVersion(),
vnfCustomization.getBlueprintVersion());
/**
* Check the vnf resource customization with service mapping
*/
List<VnfResourceCustomization> vnfCustList = service.getVnfCustomizations();
assertEquals("VNF resource customization entity", 1, vnfCustList.size());
assertEquals(vnfCustomizationKey, vnfCustList.get(0).getModelCustomizationUUID());
} catch (Exception e) {
logger.info(e.getMessage(), e);
fail(e.getMessage());
}
}
private ArtifactInfoImpl constructVnfServiceArtifact() {
ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
artifactInfo.setArtifactType(ASDCConfiguration.TOSCA_CSAR);
artifactInfo.setArtifactURL("/download/service-Svc140-VF-csar.csar");
artifactInfo.setArtifactName("service-Svc140-VF-csar.csar");
artifactInfo.setArtifactVersion("1.0");
artifactInfo.setArtifactUUID(artifactUuid);
return artifactInfo;
}
/**
* Construct the PnfResourceInfo based on the resource-Testvf140-template.yml from service-Svc140-VF-csar.csar.
*/
private ResourceInfoImpl constructVnfResourceInfo() {
ResourceInfoImpl resourceInfo = new ResourceInfoImpl();
resourceInfo.setResourceInstanceName("TestVF140");
resourceInfo.setResourceInvariantUUID("7a4bffa2-fac5-4b8b-b348-0bdf313a1aeb");
resourceInfo.setResoucreType("VF");
resourceInfo.setCategory("Application L4+");
resourceInfo.setSubcategory("Database");
resourceInfo.setResourceUUID("d20d3ea9-2f54-4071-8b5c-fd746dde245e");
resourceInfo.setResourceCustomizationUUID("ca1c8455-8ce2-4a76-a037-3f4cf01cffa0");
resourceInfo.setResourceVersion("1.0");
resourceInfo.setArtifacts(Collections.EMPTY_LIST);
return resourceInfo;
}
}
|