8d0d617d2c1f265cadd1599c7ffae35ade1dc55a
[appc/cdt.git] / src / app / vnfs / build-artifacts / parameter-definitions / parameter.component.spec.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5
6 Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
7 ===================================================================
8
9 Unless otherwise specified, all software contained herein is licensed
10 under the Apache License, Version 2.0 (the License);
11 you may not use this software except in compliance with the License.
12 You may obtain a copy of the License at
13
14     http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21
22 ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 ============LICENSE_END============================================
24 */
25
26 /* tslint:disable:no-unused-variable */
27 import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing';
28 import {NO_ERRORS_SCHEMA} from '@angular/core';
29 import {FormsModule} from '@angular/forms';
30 import { NgxSpinnerService } from 'ngx-spinner';
31 import {NotificationService} from '../../../shared/services/notification.service';
32 import {ParamShareService} from '../../../shared/services/paramShare.service';
33 import {MappingEditorService} from '../../../shared/services/mapping-editor.service';
34 import {ModalComponent} from '../../../shared/modal/modal.component';
35 import {DialogService} from 'ng2-bootstrap-modal';
36 import {ConfirmComponent} from '../../../shared/confirmModal/confirm.component';
37 import {RouterTestingModule} from '@angular/router/testing';
38 import {HttpUtilService} from '../../../shared/services/httpUtil/http-util.service';
39 import {UtilityService} from '../../../shared/services/utilityService/utility.service';
40
41 import {BuildDesignComponent} from '../build-artifacts.component';
42 import {NotificationsService} from 'angular2-notifications';
43 import {HomeComponent} from '../../../home/home/home.component';
44 import {LogoutComponent} from '../../../shared/components/logout/logout.component';
45 import {HelpComponent} from '../../../shared/components/help/help/help.component';
46 import {AboutUsComponent} from '../../../about-us/aboutus.component';
47 import {TestComponent} from '../../../test/test.component';
48 import {ParameterComponent} from './parameter.component';
49 import {HttpModule} from '@angular/http';
50 import { NgProgress } from 'ngx-progressbar';
51
52
53
54 describe('ParameterComponent', () => {
55     let component: ParameterComponent;
56     let fixture: ComponentFixture<ParameterComponent>;
57     const routes = [
58         {
59             path: 'home',
60             component: HomeComponent
61         }, {
62             path: 'vnfs',
63             loadChildren: './vnfs/vnfs.module#VnfsModule'
64         }, {
65             path: 'test',
66             component: TestComponent
67         },
68         {
69             path: 'help',
70             component: HelpComponent
71         }, {
72             path: 'aboutUs',
73             component: AboutUsComponent
74         }, {
75             path: 'logout',
76             component: LogoutComponent
77         }, {
78             path: '',
79             redirectTo: '/home',
80             pathMatch: 'full'
81         }
82     ];
83     beforeEach(async(() => {
84         TestBed.configureTestingModule({
85             declarations: [ParameterComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent],
86             schemas: [NO_ERRORS_SCHEMA],
87             imports: [HttpModule, FormsModule, RouterTestingModule.withRoutes(routes)],
88             providers: [UtilityService, NgProgress, BuildDesignComponent, ParamShareService, DialogService, NotificationService, HttpUtilService, MappingEditorService, NotificationsService, NgxSpinnerService]
89         })
90             .compileComponents();
91     }));
92
93     beforeEach(() => {
94         fixture = TestBed.createComponent(ParameterComponent);
95         component = fixture.componentInstance;
96         fixture.detectChanges();
97     });
98
99     it('should create', () => {
100         expect(component).toBeTruthy();
101     });
102
103     it('should call ngOnInit...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
104     
105         mappingEditorService.latestAction = {"action":"Configure","action-level":"vnf","scope":{"vnf-type":"ticktack","vnfc-type":""},"template":"Y","vm":[],"device-protocol":"CHEF","user-name":"","port-number":"","artifact-list":[{"artifact-name":"template_Configure_ticktack_0.0.1V.json","artifact-type":"config_template"},{"artifact-name":"pd_Configure_ticktack_0.0.1V.yaml","artifact-type":"parameter_definitions"}],"scopeType":"vnf-type"};
106         mappingEditorService.appDataObject = {"value" : ''};
107         mappingEditorService.downloadDataObject = {"value": ''};
108         mappingEditorService.identifier = "identifier";
109         component.ngOnInit();
110     
111     }));
112
113     it('should test selectedNavItem method...', () => {
114             component.selectedNavItem('item');
115             expect(component.item).toEqual('item');
116         });
117
118     it('should set the selectedUploadType value', ()=>{
119         let obj = {value : 'type1', display : 'display1'};
120         component.uploadTypes = [obj];
121         component.showUpload();
122         expect(component.selectedUploadType.toString()).toEqual("type1");
123     });
124
125
126      it('should retrieve PD from APPC...', () => {
127     expect(component.getPD());
128   });
129
130   it('should infer some information from reference object...', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
131     mappingEditorService.latestAction = {"action":"Configure","action-level":"vnf","scope":{"vnf-type":"ticktack","vnfc-type":""},"template":"Y","vm":[],"device-protocol":"CHEF","user-name":"","port-number":"","artifact-list":[{"artifact-name":"template_Configure_ticktack_0.0.1V.json","artifact-type":"config_template"},{"artifact-name":"pd_Configure_ticktack_0.0.1V.yaml","artifact-type":"parameter_definitions"}],"scopeType":"vnf-type"};
132     expect(component.ngOnInit());
133     expect(component.vnfType).toEqual('ticktack');
134     expect(component.vnfcType).toEqual('');
135     expect(component.protocol).toEqual('CHEF');
136     expect(component.action).toEqual('Configure');
137     expect(component.artifact_fileName).toEqual('pd_Configure_ticktack_0.0.1V.yaml');
138   }));
139
140
141   it('should retrieve the PD from cache...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
142     mappingEditorService.latestAction = {"action":"Configure","action-level":"vnf","scope":{"vnf-type":"ticktack","vnfc-type":""},"template":"Y","vm":[],"device-protocol":"CHEF","user-name":"","port-number":"","artifact-list":[{"artifact-name":"template_Configure_ticktack_0.0.1V.json","artifact-type":"config_template"},{"artifact-name":"pd_Configure_ticktack_0.0.1V.yaml","artifact-type":"parameter_definitions"}],"scopeType":"vnf-type"};
143     paramShareService.setSessionParamData("TEST PD INFORMATION");
144     expect(component.ngAfterViewInit()).toEqual([]);
145   }));
146
147
148   it('should set the ruletypes for source A&AI...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
149     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
150     let data = "A&AI";
151     expect(component.sourceChanged(data, obj));
152     expect(obj.ruleTypeValues).toEqual([null, 'vnf-name', 'vm-name-list', 'vnfc-name-list', 'vnf-oam-ipv4-address', 'vnfc-oam-ipv4-address-list']);
153   }));
154
155   it('should set the ruletypes for source Manual...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
156     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
157     let data = "Manual";
158     expect(component.sourceChanged(data, obj));
159     expect(obj.ruleTypeValues).toEqual([null]);
160     expect(obj['rule-type']).toBeNull();
161   }));
162
163   it('should set the ruletypes for source INSTAR...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
164     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
165     let data = "INSTAR";
166     expect(component.sourceChanged(data, obj));
167     expect(obj.ruleTypeValues).toEqual([null]);
168   }));
169
170   it('should set the ruletypes for ruletype null...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
171     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
172     let data = null
173     expect(component.ruleTypeChanged(data, obj));
174     expect(obj['showFilterFields']).toBeFalsy();
175     expect(obj['rule-type']).toBeNull();
176   }));
177
178   it('should set the ruletypes for ruletype vm-name-list...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
179     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
180     let data = 'vm-name-list';
181     let sourceObject = component.ruleTypeConfiguaration[data];
182
183     expect(component.ruleTypeChanged(data, obj));
184     expect(obj['showFilterFields']).toBeTruthy();
185     expect(obj['rule-type']).toBeNull();
186
187     for (let x = 0; x < sourceObject.length; x++) {
188         expect(obj['response-keys'][x]['key-name']).toEqual(sourceObject[x]['key-name']);
189         expect(obj['response-keys'][x]['key-value']).toEqual(sourceObject[x]['key-value']);
190     }
191   }));
192
193
194   it('should set the ruletypes for ruletype vnf-name...', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
195     let obj = {"name":"name1","type":"ipv4-address","description":"xxx","required":"true","default":null,"source":"A&AI","rule-type":null,"request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}
196     let data = "vnf-name";
197     expect(component.ruleTypeChanged(data, obj));
198     expect(obj['showFilterFields']).toBeFalsy();
199     expect(obj['response-keys'][3]['key-name']).toBeNull;
200     expect(obj['response-keys'][3]['key-value']).toBeNull;
201     expect(obj['response-keys'][4]['key-name']).toBeNull;
202     expect(obj['response-keys'][4]['key-value']).toBeNull;
203   }));
204    
205   it('should read file key file content...', () => {
206       let file = new File(["testing"], "foo.XLS", {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
207       let uploadType = 'keyfile';
208       let input = {files: [file]};
209
210       component.fileChange(input, uploadType);
211   });
212
213
214   it('should read file key file content...', () => {
215       let file = new File(["testing"], "foo.XLS", {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
216       let uploadType = 'pdfile';
217       let input = {files: [file]};
218
219       component.fileChange(input, uploadType);
220   }); 
221
222
223 });