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 {ControlGeneratorUtil} from "../control.generator.util.service";
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";
15 import {SharedControllersService} from "../sharedControlles/shared.controllers.service";
17 class MockAppStore<T> {
22 "type": "UPDATE_DRAWING_BOARD_STATUS",
23 "drawingBoardStatus": "CREATE",
25 "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
26 "FLAG_ADD_MSO_TESTAPI_FIELD": true,
27 "FLAG_SERVICE_MODEL_CACHE": false,
28 "FLAG_SHOW_ASSIGNMENTS": true,
29 "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
30 "FLAG_A_LA_CARTE_AUDIT_INFO": true,
31 "FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST": true,
32 "FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS": true,
33 "FLAG_1902_NEW_VIEW_EDIT": true
38 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
41 "instantiationUI": "serviceWithVnfGrouping",
42 "modelCategory": "other",
43 "viewEditUI": "serviceWithVnfGrouping"
45 "uuid": "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc",
46 "invariantUuid": "7ee41ce4-4827-44b0-a48e-2707a59905d2",
47 "name": "Grouping Service for Test",
49 "toscaModelURL": null,
50 "category": "Network L4+",
51 "serviceType": "INFRASTRUCTURE",
52 "serviceRole": "GROUPING",
54 "serviceEcompNaming": "false",
55 "instantiationType": "A-La-Carte",
60 "collectionResources": {},
62 "fabricConfigurations": {},
64 "vdorothea_svc_vprs_proxy 0": {
65 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
66 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
67 "description": "A Proxy for Service vDOROTHEA_Svc_vPRS",
68 "name": "vDOROTHEA_Svc_vPRS Service Proxy",
70 "customizationUuid": "bdb63d23-e132-4ce7-af2c-a493b4cafac9",
74 "type": "Service Proxy",
75 "sourceModelUuid": "da7827a2-366d-4be6-8c68-a69153c61274",
76 "sourceModelInvariant": "24632e6b-584b-4f45-80d4-fefd75fd9f14",
77 "sourceModelName": "vDOROTHEA_Svc_vPRS"
79 "tsbc0001vm001_svc_proxy 0": {
80 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
81 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
82 "description": "A Proxy for Service tsbc0001vm001_Svc",
83 "name": "tsbc0001vm001_Svc Service Proxy",
85 "customizationUuid": "3d814462-30fb-4c62-b997-9aa360d27ead",
89 "type": "Service Proxy",
90 "sourceModelUuid": "28aeb8f6-5620-4148-8bfb-a5fb406f0309",
91 "sourceModelInvariant": "c989ab9a-33c7-46ec-b521-1b2daef5f047",
92 "sourceModelName": "tsbc0001vm001_Svc"
99 "groupingservicefortest..ResourceInstanceGroup..0": {
101 "invariantUuid": "4bb2e27e-ddab-4790-9c6d-1f731bc14a45",
102 "uuid": "daeb6568-cef8-417f-9075-ed259ce59f48",
104 "name": "groupingservicefortest..ResourceInstanceGroup..0",
105 "modelCustomizationName": "groupingservicefortest..ResourceInstanceGroup..0",
107 "ecomp_generated_naming": "false",
108 "contained_resource_type": "VF",
109 "role": "SERVICE-ACCESS",
111 "description": "DDD0",
115 "vdorothea_svc_vprs_proxy 0": {
116 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
117 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
118 "description": "A Proxy for Service vDOROTHEA_Svc_vPRS",
119 "name": "vDOROTHEA_Svc_vPRS Service Proxy",
121 "customizationUuid": "bdb63d23-e132-4ce7-af2c-a493b4cafac9",
125 "type": "Service Proxy",
126 "sourceModelUuid": "da7827a2-366d-4be6-8c68-a69153c61274",
127 "sourceModelInvariant": "24632e6b-584b-4f45-80d4-fefd75fd9f14",
128 "sourceModelName": "vDOROTHEA_Svc_vPRS"
132 "groupingservicefortest..ResourceInstanceGroup..1": {
134 "invariantUuid": "a704112d-dbc6-4e56-8d4e-aec57e95ef9a",
135 "uuid": "c2b300e6-45de-4e5e-abda-3032bee2de56",
137 "name": "groupingservicefortest..ResourceInstanceGroup..1",
138 "modelCustomizationName": "groupingservicefortest..ResourceInstanceGroup..1",
140 "ecomp_generated_naming": "true",
141 "contained_resource_type": "VF",
142 "role": "SERVICE-ACCESS",
143 "function": "SIGNALING",
144 "description": "DDD1",
148 "tsbc0001vm001_svc_proxy 0": {
149 "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
150 "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
151 "description": "A Proxy for Service tsbc0001vm001_Svc",
152 "name": "tsbc0001vm001_Svc Service Proxy",
154 "customizationUuid": "3d814462-30fb-4c62-b997-9aa360d27ead",
158 "type": "Service Proxy",
159 "sourceModelUuid": "28aeb8f6-5620-4148-8bfb-a5fb406f0309",
160 "sourceModelInvariant": "c989ab9a-33c7-46ec-b521-1b2daef5f047",
161 "sourceModelName": "tsbc0001vm001_Svc"
169 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc": {
170 "existingVNFCounterMap": {},
171 "existingVnfGroupCounterMap": {
172 "daeb6568-cef8-417f-9075-ed259ce59f48": 1,
173 "c2b300e6-45de-4e5e-abda-3032bee2de56": 0
175 "existingNetworksCounterMap": {},
178 "groupingservicefortest..ResourceInstanceGroup..0": {
180 "rollbackOnFailure": "true",
181 "originalName": "groupingservicefortest..ResourceInstanceGroup..0",
182 "isMissingData": false,
183 "trackById": "johjmxpmrlk",
184 "vnfGroupStoreKey": "groupingservicefortest..ResourceInstanceGroup..0",
185 "instanceName": "groupingservicefortestResourceInstanceGroup0",
190 "modelInvariantId": "4bb2e27e-ddab-4790-9c6d-1f731bc14a45",
191 "modelVersionId": "daeb6568-cef8-417f-9075-ed259ce59f48",
192 "modelName": "groupingservicefortest..ResourceInstanceGroup..0",
194 "modelCustomizationName": "groupingservicefortest..ResourceInstanceGroup..0",
195 "uuid": "daeb6568-cef8-417f-9075-ed259ce59f48"
197 "uuid": "daeb6568-cef8-417f-9075-ed259ce59f48"
200 "isEcompGeneratedNaming": false,
209 class MockFeatureFlagsService {}
211 describe('VNF Group Control Generator', () => {
213 let service: VnfGroupControlGenerator;
214 let httpMock: HttpTestingController;
216 beforeAll(done => (async () => {
217 TestBed.configureTestingModule({
218 imports: [HttpClientTestingModule],
219 providers: [VnfGroupControlGenerator,
221 ControlGeneratorUtil,
222 SharedControllersService,
226 {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
227 {provide: NgRedux, useClass: MockAppStore}]
229 await TestBed.compileComponents();
231 injector = getTestBed();
232 service = injector.get(VnfGroupControlGenerator);
233 httpMock = injector.get(HttpTestingController);
235 })().then(done).catch(done.fail));
239 test('getMacroFormControls check for mandatory controls', () => {
240 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
241 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..0";
242 const vnfGroupStoreKey : string = "groupingservicefortest..ResourceInstanceGroup..0";
243 const controls :FormControlModel[] = service.getMacroFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);
245 const mandatoryControls : string[] = [
246 FormControlNames.INSTANCE_NAME
249 for(let i = 0 ; i < mandatoryControls.length ; i++){
250 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
251 expect(requiredExist).toBeDefined();
255 test('getMacroFormControls should return the correct order of controls', () => {
256 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
257 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..0";
258 const vnfGroupStoreKey : string = "groupingservicefortest..ResourceInstanceGroup..0";
259 const controls :FormControlModel[] = service.getMacroFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);
261 const controlsOrderNames = [
262 FormControlNames.INSTANCE_NAME,
263 'rollbackOnFailure'];
265 expect(controls.length).toEqual(1);
266 for(let i = 0 ; i < controls.length ; i++){
267 expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
271 test('getMacroFormControls check for mandatory controls when ecomp naming = true', () => {
272 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
273 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..1";
274 const vnfGroupStoreKey : string = "groupingservicefortest..ResourceInstanceGroup..1";
275 const controls :FormControlModel[] = service.getMacroFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);
277 let isOptional = controls.find(ctrl => ctrl.controlName === 'instanceName').validations.find(item => item.validatorName !== 'required');
278 expect(isOptional).toBeTruthy();
281 test('getAlacartFormControls should return the correct order of controls', () => {
282 const controls:FormControlModel[] = getALaCarteFormControls();
284 const controlsOrderNames = [
285 FormControlNames.INSTANCE_NAME,
286 'rollbackOnFailure'];
287 expect(controls.length).toEqual(2);
288 for(let i = 0 ; i < controls.length ; i++) {
289 expect(controls[i].controlName).toEqual(controlsOrderNames[i]);
294 test('getAlacartFormControls check for mandatory controls', () => {
295 const controls:FormControlModel[] = getALaCarteFormControls();
297 const mandatoryControls : string[] = [
298 FormControlNames.INSTANCE_NAME,
301 for(let i = 0 ; i < mandatoryControls.length ; i++){
302 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
303 expect(requiredExist).toBeDefined();
307 test('getAlacartFormControls with ecomp_naming true check for mandatory controls', () => {
308 const controls:FormControlModel[] = getALaCarteFormControls();
310 const mandatoryControls : string[] = [
313 for(let i = 0 ; i < mandatoryControls.length ; i++){
314 let requiredExist = controls.find(ctrl => ctrl.controlName === mandatoryControls[i]).validations.find(item => item.validatorName === 'required');
315 expect(requiredExist).toBeDefined();
319 test('default instanceName', () => {
320 const serviceId : string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
321 const vnfGroupName : string = "groupingservicefortest..ResourceInstanceGroup..0";
322 let result:FormControlModel = service.getInstanceName(null, serviceId, vnfGroupName, false);
323 expect(result.value).toEqual("groupingservicefortest..ResourceInstanceGroup..0");
326 test('rollbackOnFailure', () => {
327 let result : Observable<SelectOption[]> = service.getRollBackOnFailureOptions();
328 result.subscribe((val)=>{
329 expect(val).toEqual([
330 new SelectOption({id: 'true', name: 'Rollback'}),
331 new SelectOption({id: 'false', name: 'Don\'t Rollback'})
336 test('getAlacartFormControls instance name control validator shall have the expected regex', () => {
337 const controls:FormControlModel[] = getALaCarteFormControls();
339 const instanceNameControl: FormControlModel = <FormControlModel>controls.find(item => item.controlName === FormControlNames.INSTANCE_NAME);
340 const instanceNameValidator: ValidatorModel = instanceNameControl.validations.find(val => val.validatorName === ValidatorOptions.pattern);
341 expect(instanceNameValidator.validatorArg).toEqual(/^[a-zA-Z0-9._-]*$/);
344 function getALaCarteFormControls():FormControlModel[] {
345 const serviceId: string = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
346 const vnfGroupName: string = "groupingservicefortest..ResourceInstanceGroup..0";
347 const vnfGroupStoreKey: string = "groupingservicefortest..ResourceInstanceGroup..0";
348 const controls: FormControlModel[] = service.getAlaCarteFormControls(serviceId, vnfGroupStoreKey, vnfGroupName, []);