2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 require('./new-change-management.controller');
23 const jestMock = require('jest-mock');
25 describe('Testing workFlows from SO', () => {
28 let $changeManagementService;
32 angular.mock.module('app')
35 beforeEach(inject(function (_$controller_) {
36 $notNeeded = jestMock.fn();
37 let lodash = require('lodash')
39 // mock ChangeManagementService
40 $changeManagementService = jestMock.fn();
41 $changeManagementService.getAllSDCServices = jestMock.fn(() => Promise.resolve([]));
45 $defer = jestMock.fn();
46 $flags = jestMock.fn();
47 $flags.FEATURE_FLAGS = {FLAG_HANDLE_SO_WORKFLOWS: ''};
48 $featureFlags = jestMock.fn();
49 $featureFlags.isOn = jestMock.fn(() => true);
50 $q.defer = jestMock.fn(() => $defer);
51 $defer.promise = Promise.resolve({});
53 $aaiService = jestMock.fn();
54 $aaiService.getLoggedInUserID = jestMock.fn();
55 $aaiService.getSubscribers = jestMock.fn();
56 $controller = _$controller_('newChangeManagementModalController', {
57 $uibModalInstance: $notNeeded,
58 $uibModal: $notNeeded,
60 AaiService: $aaiService,
61 changeManagementService: $changeManagementService,
66 VIDCONFIGURATION: $notNeeded,
67 DataService: $notNeeded,
68 featureFlags: $featureFlags,
73 test('Verify load workflows from SO will call getSOWorkflow and return only names of workflows', () => {
75 $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
76 let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
77 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
78 $controller.workflows = [];
80 return $controller.loadRemoteWorkFlows()
82 remoteWorkflows = $controller.remoteWorkflows.map(item => item.name);
83 expect(remoteWorkflows).toContain('workflow 1');
84 expect(remoteWorkflows).toContain('workflow 2');
89 test('Verify load workflows wont load parameters from local service', () => {
91 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
92 let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
93 "parameterDefinitions": [
96 "name": "Configuration Parameters",
100 "msgOnPatternError": null,
101 "msgOnContentError": null,
102 "acceptableFileType": null
106 let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{
108 "id": "ab6478e4-ea33-3346-ac12-ab121484a333",
109 "workflowName": "inPlaceSoftwareUpdate",
110 "name": "inPlaceSoftwareUpdate",
112 "workflowInputParameters": [
114 "label": "New Software Version",
117 "soFieldName": "new_software_version",
118 "soPayloadLocation": "userParams",
125 $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}];
126 $changeManagementService.getWorkflows = () => getWorkflowsStub;
127 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
128 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
130 return $controller.loadWorkFlows().then(() => {
131 expect($controller.workflows).toContain('inPlaceSoftwareUpdate');
132 expect($controller.localWorkflowsParameters).toEqual(new Map());
136 test('Verify load workflows will set workflows and parameters', () => {
138 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
139 let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}});
140 let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{
142 "id": "ab6478e4-ea33-3346-ac12-ab121484a333",
143 "workflowName": "inPlaceSoftwareUpdate",
144 "name": "inPlaceSoftwareUpdate",
146 "workflowInputParameters": [
148 "label": "New Software Version",
151 "soFieldName": "new_software_version",
152 "soPayloadLocation": "userParams",
158 $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}];
159 $changeManagementService.getWorkflows = () => getWorkflowsStub;
160 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
161 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
162 $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub;
164 return $controller.loadWorkFlows()
166 expect($controller.workflows).toEqual(["inPlaceSoftwareUpdate"]);
167 expect($controller.remoteWorkflowsParameters).toEqual(new Map([["inPlaceSoftwareUpdate",
169 "name": "New Software Version",
171 "id": "new_software_version",
172 "soFieldName": "new_software_version",
181 test('Verify load workflows wont load workflows parameters from SO if feature flag is disabled', () => {
183 $featureFlags.isOn = jestMock.fn(() => false);
184 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
185 let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}});
186 let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 0"}]});
187 let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": [
188 {"id": 1, "name": "parameter 1", "required": true, "type": "text", "pattern": "[0-9]*"},
189 {"id": 2, "name": "parameter 2", "required": true, "type": "text", "pattern": ".*"},
190 {"id": 3, "name": "parameter 3", "required": false, "type": "text", "pattern": "[0-9]*"}]}});
192 $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
193 $changeManagementService.getWorkflows = () => getWorkflowsStub;
194 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
195 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
196 $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub;
198 return $controller.loadWorkFlows()
200 expect($controller.workflows).toEqual(["workflow 0"]);
201 expect($controller.remoteWorkflowsParameters).toEqual(new Map());
205 test('Verify load workflows will call load workflows parameters from local service', () => {
207 $featureFlags.isOn = jestMock.fn(() => false);
208 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
209 let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
210 "parameterDefinitions": [
213 "name": "Configuration Parameters",
217 "msgOnPatternError": null,
218 "msgOnContentError": null,
219 "acceptableFileType": null
224 $controller.changeManagement.vnfNames = [{name: 'test1'}];
225 $changeManagementService.getWorkflows = () => getWorkflowsStub;
226 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
229 let result = new Map();
230 const scaleOutResult = [
232 "acceptableFileType": null,
234 "msgOnContentError": null,
235 "msgOnPatternError": null,
236 "name": "Configuration Parameters",
242 result.set("VNF Scale Out", scaleOutResult);
244 return $controller.loadWorkFlows()
246 expect($controller.localWorkflowsParameters).toEqual(result);
250 test('Verify broken SO workflows will return empty list of workflows', () => {
252 let getSOWorkflowsPromiseStub = Promise.reject(new Error("Broken SO workflows service."));
254 $controller.changeManagement.vnfNames = [{name:"any"}];
255 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
257 $controller.loadWorkFlows()
259 expect($controller.workflows).toEqual([]);
263 test('Verify get internal workflow parameters should return an empty list if not such workflow exist', () => {
265 $featureFlags.isOn = jestMock.fn(() => false);
266 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
267 let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
268 "parameterDefinitions": [
271 "name": "Configuration Parameters",
275 "msgOnPatternError": null,
276 "msgOnContentError": null,
277 "acceptableFileType": null
282 $controller.changeManagement.vnfNames = [{name: 'test1'}];
283 $changeManagementService.getWorkflows = () => getWorkflowsStub;
284 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
286 return $controller.loadWorkFlows()
288 let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("NON-EXISTENT WF", "text");
289 expect(internalWorkFlowParameters).toEqual([]);
293 test('Verify get internal workflow parameters should return an empty list if not such type exist', () => {
295 $featureFlags.isOn = jestMock.fn(() => false);
296 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
297 let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
298 "parameterDefinitions": [
301 "name": "Configuration Parameters",
305 "msgOnPatternError": null,
306 "msgOnContentError": null,
307 "acceptableFileType": null
312 $controller.changeManagement.vnfNames = [{name: 'test1'}];
313 $changeManagementService.getWorkflows = () => getWorkflowsStub;
314 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
316 return $controller.loadWorkFlows()
318 let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "FILE");
319 expect(internalWorkFlowParameters).toEqual([]);
323 test('Verify get internal workflow parameters should return an empty list if type exist but mapped to undefined', () => {
325 $featureFlags.isOn = jestMock.fn(() => false);
326 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
327 let getLocalWorkflowsParametersStub = Promise.resolve({"data": undefined});
329 $controller.changeManagement.vnfNames = [{name: 'test1'}];
330 $changeManagementService.getWorkflows = () => getWorkflowsStub;
331 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
333 return $controller.loadWorkFlows()
335 let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "FILE");
336 expect(internalWorkFlowParameters).toEqual([]);
340 test('Verify get internal workflow parameters should return a list if such workflow and type exist', () => {
342 $featureFlags.isOn = jestMock.fn(() => false);
343 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
344 let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
345 "parameterDefinitions": [
348 "name": "Configuration Parameters",
352 "msgOnPatternError": null,
353 "msgOnContentError": null,
354 "acceptableFileType": null
358 $controller.changeManagement.vnfNames = [{name: 'test1'}];
359 $changeManagementService.getWorkflows = () => getWorkflowsStub;
360 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
363 "acceptableFileType": null,
365 "msgOnContentError": null,
366 "msgOnPatternError": null,
367 "name": "Configuration Parameters",
373 return $controller.loadWorkFlows()
375 let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "text");
376 expect(internalWorkFlowParameters).toEqual(result);
380 test('Verify get remote workflow should call internal service for params when workflow is native', () =>{
381 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
382 let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
383 "parameterDefinitions": [
386 "name": "Configuration Parameters",
390 "msgOnPatternError": null,
391 "msgOnContentError": null,
392 "acceptableFileType": null
396 let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{
398 "id": "ab6478e4-ea33-3346-ac12-ab121484a333",
399 "workflowName": "inPlaceSoftwareUpdate",
400 "name": "inPlaceSoftwareUpdate",
402 "workflowInputParameters": [
407 $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}];
408 $changeManagementService.getWorkflows = () => getWorkflowsStub;
409 $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
410 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
412 return $controller.loadWorkFlows().then(() => {
413 expect($controller.workflows).toContain('inPlaceSoftwareUpdate');
414 expect($controller.localWorkflowsParameters.get('inPlaceSoftwareUpdate')).toEqual([{
416 "name": "Configuration Parameters",
420 "msgOnPatternError": null,
421 "msgOnContentError": null,
422 "acceptableFileType": null
427 test('Verify that vm.searchVNFs return only generic-vnfs with relation to vserver', () => {
429 $controller.changeManagement.serviceType = [];
430 let getVnfsByCustomerIdAndServiceType = Promise.resolve({"data":
433 "node-type": "generic-vnf",
439 "node-type": "vf-module"
442 "node-type": "tenant"
447 "node-type": "generic-vnf",
453 "node-type": "tenant"
458 "node-type": "generic-vnf",
464 "node-type": "vf-module"
467 "node-type": "tenant"
470 "node-type": "vserver"
475 "node-type": "vf-module",
478 "node-type": "vserver"
483 "node-type": "vf-module",
486 "node-type": "vserver"
496 "node-type": "generic-vnf",
497 "properties": {"nf-role": "vLB"},
499 {"id": "11", "node-type": "vf-module"},
500 {"id": "12", "node-type": "tenant"}]},
503 "node-type": "generic-vnf",
504 "properties": {"nf-role": "vLB"},
506 {"id": "31", "node-type": "vf-module"},
507 {"id": "32", "node-type": "tenant"},
508 {"id": "33", "node-type": "vserver"}
510 $aaiService.getVnfsByCustomerIdAndServiceType = () => getVnfsByCustomerIdAndServiceType;
513 $controller.searchVNFs().then(() => {
514 expect($controller.vnfs).toHaveLength(2);
515 expect($controller.vnfs).toEqual(expectedVnfs);