1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3 import {NgRedux} from '@angular-redux/store';
4 import {FormControlNames} from "../service.control.generator";
5 import {BasicControlGenerator} from "../basic.control.generator";
6 import {AaiService} from "../../../../services/aaiService/aai.service";
7 import {GenericFormService} from "../../generic-form.service";
8 import {FormBuilder} from "@angular/forms";
9 import {FormControlModel, ValidatorModel, ValidatorOptions} from "../../../../models/formControlModels/formControl.model";
10 import {LogService} from "../../../../utils/log/log.service";
11 import {VnfGroupControlGenerator} from "./vnfGroup.control.generator";
12 import {Observable} from "rxjs";
13 import {SelectOption} from "../../../../models/selectOption";
14 import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service";
16 class MockAppStore<T> {
21 "type": "UPDATE_DRAWING_BOARD_STATUS",
22 "drawingBoardStatus": "CREATE",
24 "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
25 "FLAG_ADD_MSO_TESTAPI_FIELD": true,
26 "FLAG_SERVICE_MODEL_CACHE": false,
27 "FLAG_SHOW_ASSIGNMENTS": true,
28 "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
29 "FLAG_A_LA_CARTE_AUDIT_INFO": true,
30 "FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST": true,
31 "FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS": true,
32 "FLAG_1902_NEW_VIEW_EDIT": true
37 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
40 "instantiationUI": "serviceWithVnfGrouping",
41 "modelCategory": "other",
42 "viewEditUI": "serviceWithVnfGrouping"
44 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
45 "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
46 "name": "Grouping Service for Test",
48 "toscaModelURL": null,
49 "category": "Network L4+",
50 "serviceType": "INFRASTRUCTURE",
51 "serviceRole": "GROUPING",
53 "serviceEcompNaming": "false",
54 "instantiationType": "A-La-Carte",
59 "collectionResources": {},
61 "fabricConfigurations": {},
63 "vdorothea_svc_vprs_proxy 0": {
64 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
65 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
66 "description": "A Proxy for Service vDOROTHEA_Svc_vPRS",
67 "name": "vDOROTHEA_Svc_vPRS Service Proxy",
69 "customizationUuid": "bdb63d23-e132-4ce7-af2c-a493b4cafac9",
73 "type": "Service Proxy",
74 "sourceModelUuid": "da7827a2-366d-4be6-8c68-a69153c61274",
75 "sourceModelInvariant": "24632e6b-584b-4f45-80d4-fefd75fd9f14",
76 "sourceModelName": "vDOROTHEA_Svc_vPRS"
78 "tsbc0001vm001_svc_proxy 0": {
79 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
80 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
81 "description": "A Proxy for Service tsbc0001vm001_Svc",
82 "name": "tsbc0001vm001_Svc Service Proxy",
84 "customizationUuid": "3d814462-30fb-4c62-b997-9aa360d27ead",
88 "type": "Service Proxy",
89 "sourceModelUuid": "28aeb8f6-5620-4148-8bfb-a5fb406f0309",
90 "sourceModelInvariant": "c989ab9a-33c7-46ec-b521-1b2daef5f047",
91 "sourceModelName": "tsbc0001vm001_Svc"
98 "groupingservicefortest..ResourceInstanceGroup..0": {
100 "invariantUuid": "4bb2e27e-ddab-4790-9c6d-1f731bc14a45",
101 "uuid": "daeb6568-cef8-417f-9075-ed259ce59f48",
103 "name": "groupingservicefortest..ResourceInstanceGroup..0",
104 "modelCustomizationName": "groupingservicefortest..ResourceInstanceGroup..0",
106 "ecomp_generated_naming": "false",
107 "contained_resource_type": "VF",
108 "role": "SERVICE-ACCESS",
110 "description": "DDD0",
114 "vdorothea_svc_vprs_proxy 0": {
115 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
116 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
117 "description": "A Proxy for Service vDOROTHEA_Svc_vPRS",
118 "name": "vDOROTHEA_Svc_vPRS Service Proxy",
120 "customizationUuid": "bdb63d23-e132-4ce7-af2c-a493b4cafac9",
124 "type": "Service Proxy",
125 "sourceModelUuid": "da7827a2-366d-4be6-8c68-a69153c61274",
126 "sourceModelInvariant": "24632e6b-584b-4f45-80d4-fefd75fd9f14",
127 "sourceModelName": "vDOROTHEA_Svc_vPRS"
131 "groupingservicefortest..ResourceInstanceGroup..1": {
133 "invariantUuid": "a704112d-dbc6-4e56-8d4e-aec57e95ef9a",
134 "uuid": "c2b300e6-45de-4e5e-abda-3032bee2de56",
136 "name": "groupingservicefortest..ResourceInstanceGroup..1",
137 "modelCustomizationName": "groupingservicefortest..ResourceInstanceGroup..1",
139 "ecomp_generated_naming": "true",
140 "contained_resource_type": "VF",
141 "role": "SERVICE-ACCESS",
142 "function": "SIGNALING",
143 "description": "DDD1",
147 "tsbc0001vm001_svc_proxy 0": {
148 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
149 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
150 "description": "A Proxy for Service tsbc0001vm001_Svc",
151 "name": "tsbc0001vm001_Svc Service Proxy",
153 "customizationUuid": "3d814462-30fb-4c62-b997-9aa360d27ead",
157 "type": "Service Proxy",
158 "sourceModelUuid": "28aeb8f6-5620-4148-8bfb-a5fb406f0309",
159 "sourceModelInvariant": "c989ab9a-33c7-46ec-b521-1b2daef5f047",
160 "sourceModelName": "tsbc0001vm001_Svc"
168 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
169 "existingVNFCounterMap": {},
170 "existingVnfGroupCounterMap": {
171 "daeb6568-cef8-417f-9075-ed259ce59f48": 1,
172 "c2b300e6-45de-4e5e-abda-3032bee2de56": 0
174 "existingNetworksCounterMap": {},
177 "groupingservicefortest..ResourceInstanceGroup..0": {
179 "rollbackOnFailure": "true",
180 "originalName": "groupingservicefortest..ResourceInstanceGroup..0",
181 "isMissingData": false,
182 "trackById": "johjmxpmrlk",
183 "vnfGroupStoreKey": "groupingservicefortest..ResourceInstanceGroup..0",
184 "instanceName": "groupingservicefortestResourceInstanceGroup0",
189 "modelInvariantId": "4bb2e27e-ddab-4790-9c6d-1f731bc14a45",
190 "modelVersionId": "daeb6568-cef8-417f-9075-ed259ce59f48",
191 "modelName": "groupingservicefortest..ResourceInstanceGroup..0",
193 "modelCustomizationName": "groupingservicefortest..ResourceInstanceGroup..0",
194 "uuid": "daeb6568-cef8-417f-9075-ed259ce59f48"
196 "uuid": "daeb6568-cef8-417f-9075-ed259ce59f48"
199 "isEcompGeneratedNaming": false,
208 class MockFeatureFlagsService {}
210 describe('VNF Group Control Generator', () => {
212 let service: VnfGroupControlGenerator;
213 let httpMock: HttpTestingController;
215 beforeAll(done => (async () => {
216 TestBed.configureTestingModule({
217 imports: [HttpClientTestingModule],
218 providers: [VnfGroupControlGenerator,
220 BasicControlGenerator,
224 {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
225 {provide: NgRedux, useClass: MockAppStore}]
227 await TestBed.compileComponents();
229 injector = getTestBed();
230 service = injector.get(VnfGroupControlGenerator);
231 httpMock = injector.get(HttpTestingController);
233 })().then(done).catch(done.fail));
237 test('getMacroFormControls check for mandatory controls', () => {
238 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
239 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..0";
240 const vnfGroupStoreKey : string = "groupingservicefortest..ResourceInstanceGroup..0";
241 const controls :FormControlModel[] = service.getMacroFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);
243 const mandatoryControls : string[] = [
244 FormControlNames.INSTANCE_NAME
247 for(let i = 0 ; i < mandatoryControls.length ; i++){
248 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
249 expect(requiredExist).toBeDefined();
253 test('getMacroFormControls should return the correct order of controls', () => {
254 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
255 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..0";
256 const vnfGroupStoreKey : string = "groupingservicefortest..ResourceInstanceGroup..0";
257 const controls :FormControlModel[] = service.getMacroFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);
259 const controlsOrderNames = [
260 FormControlNames.INSTANCE_NAME,
261 'rollbackOnFailure'];
263 expect(controls.length).toEqual(1);
264 for(let i = 0 ; i < controls.length ; i++){
265 expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
269 test('getMacroFormControls check for mandatory controls when ecomp naming = true', () => {
270 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
271 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..1";
272 const vnfGroupStoreKey : string = "groupingservicefortest..ResourceInstanceGroup..1";
273 const controls :FormControlModel[] = service.getMacroFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);
275 let isOptional = controls.find(ctrl => ctrl.controlName === 'instanceName').validations.find(item => item.validatorName !== 'required');
276 expect(isOptional).toBeTruthy();
279 test('getAlacartFormControls should return the correct order of controls', () => {
280 const controls:FormControlModel[] = getALaCarteFormControls();
282 const controlsOrderNames = [
283 FormControlNames.INSTANCE_NAME,
284 'rollbackOnFailure'];
285 expect(controls.length).toEqual(2);
286 for(let i = 0 ; i < controls.length ; i++) {
287 expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
292 test('getAlacartFormControls check for mandatory controls', () => {
293 const controls:FormControlModel[] = getALaCarteFormControls();
295 const mandatoryControls : string[] = [
296 FormControlNames.INSTANCE_NAME,
299 for(let i = 0 ; i < mandatoryControls.length ; i++){
300 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
301 expect(requiredExist).toBeDefined();
305 test('getAlacartFormControls with ecomp_naming true check for mandatory controls', () => {
306 const controls:FormControlModel[] = getALaCarteFormControls();
308 const mandatoryControls : string[] = [
311 for(let i = 0 ; i < mandatoryControls.length ; i++){
312 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
313 expect(requiredExist).toBeDefined();
317 test('default instanceName', () => {
318 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
319 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..0";
320 let result:FormControlModel = service.getInstanceName(null, serviceId, vnfGroupName, false);
321 expect(result.value).toEqual("groupingservicefortest..ResourceInstanceGroup..0");
324 test('rollbackOnFailure', () => {
325 let result : Observable<SelectOption[]> = service.getRollBackOnFailureOptions();
326 result.subscribe((val)=>{
327 expect(val).toEqual([
328 new SelectOption({id: 'true', name: 'Rollback'}),
329 new SelectOption({id: 'false', name: 'Don\'t Rollback'})
334 test('getAlacartFormControls instance name control validator shall have the expected regex', () => {
335 const controls:FormControlModel[] = getALaCarteFormControls();
337 const instanceNameControl: FormControlModel = <FormControlModel>controls.find(item => item.controlName === FormControlNames.INSTANCE_NAME);
338 const instanceNameValidator: ValidatorModel = instanceNameControl.validations.find(val => val.validatorName === ValidatorOptions.pattern);
339 expect(instanceNameValidator.validatorArg).toEqual(/^[a-zA-Z0-9._-]*$/);
342 function getALaCarteFormControls():FormControlModel[] {
343 const serviceId: string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
344 const vnfGroupName: string = "groupingservicefortest..ResourceInstanceGroup..0";
345 const vnfGroupStoreKey: string = "groupingservicefortest..ResourceInstanceGroup..0";
346 const controls: FormControlModel[] = service.getAlaCarteFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);