2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
7 ===================================================================
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
14 http://www.apache.org/licenses/LICENSE-2.0
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.
22 ============LICENSE_END============================================
25 /* tslint:disable:no-unused-variable */
26 import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
27 import { By, BrowserModule } from '@angular/platform-browser';
28 import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
29 import { Component, OnInit, ViewChild, Input } from '@angular/core';
30 import { NgxSpinnerService } from 'ngx-spinner';
31 import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service';
32 import { MappingEditorService } from '../../../../shared/services/mapping-editor.service';
33 import { ArtifactRequest } from '../../../../shared/models/index';
34 import { ActivatedRoute, Router } from "@angular/router";
35 import { saveAs } from "file-saver";
36 import { NotificationService } from '../../../../shared/services/notification.service';
37 import { NotificationsService } from "angular2-notifications"
38 import { ParamShareService } from '../../../../shared/services/paramShare.service';
39 import { DialogService } from "ng2-bootstrap-modal";
40 import { ConfirmComponent } from '../../../../shared/confirmModal/confirm.component';
41 import { BuildDesignComponent } from '../../build-artifacts.component';
42 import { environment } from '../../../../../environments/environment';
43 import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal'
44 import { FormsModule } from '@angular/forms';
45 import { RouterTestingModule } from '@angular/router/testing';
46 import { HomeComponent } from '../../../../home/home/home.component';
47 import { LogoutComponent } from '../../../../shared/components/logout/logout.component';
48 import { HelpComponent } from '../../../../shared/components/help/help/help.component';
49 import { AboutUsComponent } from '../../../../about-us/aboutus.component';
50 import { TestComponent } from '../../../../test/test.component';
51 import { HttpModule } from '@angular/http';
52 import { AceEditorComponent } from 'ng2-ace-editor';
53 import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
54 import { SimpleNotificationsModule } from 'angular2-notifications';
55 import { GoldenConfigurationComponent } from './template-configuration.component';
56 import { NgProgress } from 'ngx-progressbar';
57 import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http';
58 import { MockBackend, MockConnection } from '@angular/http/testing';
59 import { UtilityService } from '../../../../shared/services/utilityService/utility.service';
60 import { APIService } from "../../../../shared/services/cdt.apicall";
61 import { ProcOnSrvSideSvc } from "../../../../shared/services/procOnSrvSide.service";
63 describe('GoldenConfigurationComponent', () => {
64 let component: GoldenConfigurationComponent;
65 let fixture: ComponentFixture<GoldenConfigurationComponent>;
66 let buildDesignComponent: BuildDesignComponent;
67 let paramShareService: ParamShareService;
68 let dialogService: DialogService;
69 let notificationService: NotificationService;
70 let httpUtil: HttpUtilService;
71 let mappingEditorService: MappingEditorService;
72 let activeRoutes: ActivatedRoute;
74 let nService: NotificationsService
78 component: HomeComponent
81 loadChildren: '../../../../vnfs/vnfs.module#VnfsModule'
84 component: TestComponent
88 component: HelpComponent
91 component: AboutUsComponent
94 component: LogoutComponent
103 TestBed.configureTestingModule({
104 imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()],
105 declarations: [GoldenConfigurationComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent],
106 providers: [ProcOnSrvSideSvc, APIService, BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, NgxSpinnerService, MockBackend,
107 BaseRequestOptions, UtilityService,
110 useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
111 return new Http(backend, defaultOptions);
113 deps: [MockBackend, BaseRequestOptions],
116 HttpUtilService, MappingEditorService, NotificationsService],
117 schemas: [NO_ERRORS_SCHEMA],
122 beforeEach(async(() => {
123 TestBed.compileComponents()
128 it('validate if uploaded file should be xml or json', () => {
129 fixture = TestBed.createComponent(GoldenConfigurationComponent);
130 component = fixture.componentInstance;
131 expect(component.validateUploadedFile('xls')).toBe(false);
132 expect(component.validateUploadedFile('json')).toBe(true);
133 expect(component.validateUploadedFile('xml')).toBe(true);
137 fit('validate initialisation of variables in ngOnit() function', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
138 fixture = TestBed.createComponent(GoldenConfigurationComponent);
139 component = fixture.componentInstance;
140 mappingEditorService.newObject = {
141 "action": "Configure",
142 "action-level": "vnf",
143 "scope": { "vnf-type": "testVnf", "vnfc-type": "" },
151 "artifact-name": "template_Configure_test_0.0.1V.json",
152 "artifact-type": "config_template"
155 "artifact-name": "pd_Configure_test_0.0.1V.yaml",
156 "artifact-type": "parameter_definitions"
158 "scopeType": "vnf-type",
162 "template_artifact": "template_Configure_test_0.0.1V.json"
165 expect(component.ngOnInit());
166 expect(component.ngAfterViewInit());
167 expect(component.action).toEqual('Configure');
168 expect(component.vnfType).toEqual('testVnf');
169 expect(component.vnfcType).toEqual('');
170 expect(component.protocol).toEqual('CHEF');
171 expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json');
174 it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
175 fixture = TestBed.createComponent(GoldenConfigurationComponent);
176 component = fixture.componentInstance;
177 mappingEditorService.latestAction = undefined;
178 expect(component.ngAfterViewInit());
179 expect(component.action).toEqual('');
180 expect(component.vnfType).toEqual('');
181 expect(component.vnfcType).toEqual('');
182 expect(component.protocol).toEqual('');
183 expect(component.artifactName).toEqual('');
187 it('check if correct notification is fired while initialising if reference data object is undefined', () => {
188 fixture = TestBed.createComponent(GoldenConfigurationComponent);
189 component = fixture.componentInstance;
190 expect(component.ngAfterViewInit());
191 expect(component.Actions.length).toBe(0)
192 expect(component.enableBrowse).toBe(false)
195 it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
196 fixture = TestBed.createComponent(GoldenConfigurationComponent);
197 component = fixture.componentInstance;
198 mappingEditorService.fromScreen === 'MappingScreen'
199 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>"
200 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent);
202 var pdData = [{ "name": "sync_auto-pop_name1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vnfc-oam-ipv4-address-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vnfc" }, { "key-name": "field-key-name", "key-value": "ipaddress-v4-oam-vip" }, { "key-name": null, "key-value": "vm-number" }, { "key-name": null, "key-value": "test" }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "sync_auto-pop_address1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vm-name-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vserver" }, { "key-name": "field-key-name", "key-value": "vserver-name" }, { "key-name": null, "key-value": "vnfc-function-code" }, { "key-name": null, "key-value": null }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "node0_tacplus_server_name2", "type": null, "description": null, "required": null, "default": null, "source": "Manual", "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] }];
203 paramShareService.setSessionParamData([pdData]);
204 localStorage["paramsContent"] = {
205 "sync_auto-pop_name1": "10.0.1.34",
206 "sync_auto-pop_address1": "",
207 "node0_tacplus_server_name2": "192.34.45.5"
209 expect(component.syncTemplate("1"));
214 it('test sync template when template data, param data and pd data are not available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
215 fixture = TestBed.createComponent(GoldenConfigurationComponent);
216 component = fixture.componentInstance;
217 mappingEditorService.fromScreen === 'MappingScreen'
218 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>"
219 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent);
222 paramShareService.setSessionParamData([pdData]);
223 localStorage["paramsContent"] = {};
224 expect(component.syncTemplate("0"));
229 it('test whether proper param data and template data are getting set in the appDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
230 fixture = TestBed.createComponent(GoldenConfigurationComponent);
231 component = fixture.componentInstance;
232 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" };
233 component.ngOnInit();
234 component.ngAfterViewInit();
235 component.appDataObject = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
236 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>"
237 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent);
238 localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" });
240 component.userId = "sj108s";
241 component.apiToken = "87264736473";
242 mappingEditorService.identifier = "id1";
243 component.prepareAppData();
244 var paramData = { "input": ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"sj108s","vnf-type":"testVnf","action":"Configure","artifact-name":"param_Configure_testVnf_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"[{\"sync_auto-pop_name1\":\"10.0.1.34\",\"sync_auto-pop_address1\":\"\",\"node0_tacplus_server_name2\":\"192.34.45.5\"}]"}' }) }) };
245 var templateData = { input: ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"sj108s","vnf-type":"testVnf","action":"Configure","artifact-name":"template_Configure_test_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n<version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>"}' }) }) };
246 expect(component.appDataObject.template.nameValueData["payload"]).toBe(JSON.stringify(paramData["payload"]));
247 expect(component.appDataObject.template.templateData["payload"]).toBe(JSON.stringify(templateData["payload"]));
251 it('test whether proper param data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
252 fixture = TestBed.createComponent(GoldenConfigurationComponent);
253 component = fixture.componentInstance;
254 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" };
255 component.ngOnInit();
256 component.ngAfterViewInit();
257 component.downloadDataObject = {
259 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
260 pd: { pdData: '', pdFileName: '' }
262 localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" });
264 component.onDownloadParameter();
265 var nameValueData = {
266 "sync_auto-pop_name1": "10.0.1.34",
267 "sync_auto-pop_address1": "",
268 "node0_tacplus_server_name2": "192.34.45.5"
270 expect(component.downloadDataObject.template.nameValueData).toBe(JSON.stringify(nameValueData, null, "\t"));
271 expect(component.downloadDataObject.template.nameValueFileName).toBe("param_Configure_testVnf_0.0.1V.json");
274 it('test whether proper template data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
275 fixture = TestBed.createComponent(GoldenConfigurationComponent);
276 component = fixture.componentInstance;
277 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" };
278 component.ngOnInit();
279 component.ngAfterViewInit();
280 component.downloadDataObject = {
282 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
283 pd: { pdData: '', pdFileName: '' }
285 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>"
286 component.fileType = "text/xml"
287 component.onDownloadTemplate('Template');
289 component.fileType = "text/plain"
290 component.onDownloadTemplate('Template');
291 component.fileType = "text/json"
292 component.onDownloadTemplate('Template');
293 component.tempretrieveFlag = true;
294 component.fileNameForTempSave = "Configure_testVnf_0.0.1V.json"
295 component.onDownloadTemplate('Template');
296 expect(component.downloadDataObject.template.templateData).toBe(component.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}'));
300 it('test merge status for golden config template and uploaded parameter data', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
301 fixture = TestBed.createComponent(GoldenConfigurationComponent);
302 component = fixture.componentInstance;
303 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" };
304 component.ngOnInit();
305 component.ngAfterViewInit();
306 component.downloadDataObject = {
308 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
309 pd: { pdData: '', pdFileName: '' }
311 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \r\n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\r\n <version>15.1X49-D50.3</version>\r\n <groups>\r\n <name>node0</name>\r\n <system>\r\n <tacplus-server>\r\n <name>199.37.184.211</name>\r\n <source-address>135.144.3.125</source-address>\r\n </tacplus-server>\r\n <tacplus-server>\r\n <name>199.37.184.242</name>\r\n <source-address>135.144.3.125</source-address>\r\n </tacplus-server>\r\n </system> \r\n </groups>\r\n </configuration>";
312 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent);
313 localStorage["paramsContent"] = JSON.stringify({
314 "node0_tacplus_server_name1": "199.37.184.211",
315 "node0_tacplus_server_source_address1": "135.144.3.125",
316 "node0_tacplus_server_name2": "199.37.184.242"
318 component.mergeParams();
319 expect(component.mergeStatus).toBe(true);
321 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\n <version>15.1X49-D50.3</version>\n <groups>\n <name>node0</name>\n <system>\n <tacplus-server>\n <name>${sync_auto-pop_name1}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n <tacplus-server>\n <name>${node0_tacplus_server_name2}</name>\n <source-address>${sync_auto-pop_address1}</source-address>\n </tacplus-server>\n </system> \n </groups>\n </configuration>"
322 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent);
323 component.mergeParams();
324 expect(component.mergeStatus).toBe(false);
328 it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
329 fixture = TestBed.createComponent(GoldenConfigurationComponent);
330 component = fixture.componentInstance;
331 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" };
332 component.ngOnInit();
333 component.ngAfterViewInit();
335 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \r\n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\r\n <version>15.1X49-D50.3</version>\r\n <groups>\r\n <name>node0</name>\r\n <system>\r\n <tacplus-server>\r\n <name>199.37.184.211</name>\r\n <source-address>135.144.3.125</source-address>\r\n </tacplus-server>\r\n <tacplus-server>\r\n <name>199.37.184.242</name>\r\n <source-address>135.144.3.125</source-address>\r\n </tacplus-server>\r\n </system> \r\n </groups>\r\n </configuration>";
336 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent);
337 component.selectedWord = "node0";
338 expect(component.handleAnnotation(component.modal));
341 it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
342 fixture = TestBed.createComponent(GoldenConfigurationComponent);
343 component = fixture.componentInstance;
344 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" };
345 component.ngOnInit();
346 component.ngAfterViewInit();
348 component.configMappingEditorContent = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" \r\n xmlns:a=\"http://xml.juniper.net/junos/15.1X49/junos\" >\r\n <version>15.1X49-D50.3</version>\r\n <groups>\r\n <name>node0</name>\r\n <system>\r\n <tacplus-server>\r\n <name>{(node1)=(name1)}</name>\r\n <source-address>135.144.3.125</source-address>\r\n </tacplus-server>\r\n <tacplus-server>\r\n <name>199.37.184.242</name>\r\n <source-address>135.144.3.125</source-address>\r\n </tacplus-server>\r\n </system> \r\n </groups>\r\n </configuration>";
349 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent);
350 component.selectedWord = "node0";
351 component.tempName = "name0";
352 component.submitNameValues()
353 expect(component.replaceWord).toContain("{(node0)=(name0)}");
354 component.selectedWord = "{(node1)=(name1)}";
355 component.submitNameValues();
356 component.tempName = false;
357 component.submitNameValues();
360 it('retrieveTemplateFromAppc function should return response on success and set the configMappingEditorContent object', inject([HttpUtilService, NgProgress, MappingEditorService, MockBackend], (httpUtilService: HttpUtilService, mappingEditorService: MappingEditorService, ngProgress: NgProgress, mockBackend: MockBackend) => {
361 fixture = TestBed.createComponent(GoldenConfigurationComponent);
362 component = fixture.componentInstance;
366 "block": "{\"userID\":null,\"designInfo\":null,\"statusInfo\":null,\"artifactInfo\":[{\"artifact-content\":\" <configuration xmlns=\\\"http://xml.juniper.net/xnm/1.1/xnm\\\" \\n xmlns:a=\\\"http://xml.juniper.net/junos/15.1X49/junos\\\" >\\n <version>15.1X49-D50.3</version>\\n <groups>\\n <name>node0</name>\\n <system>\\n <tacplus-server>\\n <name>${sync_auto-pop_name1}</name>\\n <source-address>${sync_auto-pop_address1}</source-address>\\n </tacplus-server>\\n <tacplus-server>\\n <name>${node0_tacplus_server_name2}</name>\\n <source-address>${sync_auto-pop_address1}</source-address>\\n </tacplus-server>\\n </system> \\n </groups>\\n </configuration>\"}]}",
367 "requestId": "497085412083"
375 let response = new ResponseOptions({
376 body: JSON.stringify(mockData)
378 const baseResponse = new Response(response);
379 mockBackend.connections.subscribe(
380 (c: MockConnection) => c.mockRespond(baseResponse)
383 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" }
385 mappingEditorService.fromScreen = 'MappingScreen';
386 component.action = 'Configure';
387 component.refObj = mappingEditorService.latestAction;
388 component.scopeName = "testVnf";
389 component.vnfType = "testVnf";
390 component.userId = "abc";
391 component.item.action = "Configure";
392 component.retrieveTemplateFromAppc();
393 expect(component.configMappingEditorContent).not.toBe(null);
398 it('Should validatte fileChange method if file type is xml', async(() => {
399 fixture = TestBed.createComponent(GoldenConfigurationComponent);
400 component = fixture.componentInstance;
401 let reader = new FileReader();
402 let file = new File(["testing"], "foo.xml", { type: "text/xml" });
403 let input = { files: [file] };
404 component.refObj = true;
406 component.fileChange(input);
408 component.readFile(input.files[0], reader, (res) => {
409 expect(component.selectedUploadType).toEqual('Generated Template');
410 expect(component.configMappingEditorContent).toEqual(res);
411 expect(component.artifactRequest.templateContent).toEqual(res);
415 it('Should validatte fileChange method if file type is json', async(() => {
416 fixture = TestBed.createComponent(GoldenConfigurationComponent);
417 component = fixture.componentInstance;
418 let reader = new FileReader();
419 let file = new File(["testing"], "foo.json", { type: "text/json" });
420 let input = { files: [file] };
421 component.refObj = true;
423 component.fileChange(input);
425 component.readFile(input.files[0], reader, (res) => {
426 expect(component.selectedUploadType).toEqual('Generated Template');
427 expect(component.configMappingEditorContent).toEqual(res);
428 expect(component.artifactRequest.templateContent).toEqual(res);
432 it('Should validatte fileChange method if file type is none ', async(() => {
433 fixture = TestBed.createComponent(GoldenConfigurationComponent);
434 component = fixture.componentInstance;
435 let reader = new FileReader();
436 let file = new File(["testing"], "foo", { type: "" });
437 let input = { files: [file] };
438 component.refObj = true;
440 component.fileChange(input);
442 component.readFile(input.files[0], reader, (res) => {
443 expect(typeof sessionStorage.getItem('fileType')).toEqual('string')
444 expect(component.selectedUploadType).toEqual('Generated Template');
445 expect(component.configMappingEditorContent).toEqual(res);
446 expect(component.artifactRequest.templateContent).toEqual(res);
450 it('Should validate if files is false', () => {
451 fixture = TestBed.createComponent(GoldenConfigurationComponent);
452 component = fixture.componentInstance;
453 let spy = spyOn(NotificationsService.prototype, 'error');
454 let reader = new FileReader();
455 let input = { files: [] };
456 component.refObj = true;
458 component.fileChange(input);
460 expect(spy).toHaveBeenCalled();
463 it('Should validate if refObj is undefined', () => {
464 fixture = TestBed.createComponent(GoldenConfigurationComponent);
465 component = fixture.componentInstance;
466 let spy = spyOn(NotificationsService.prototype, 'error');
467 let reader = new FileReader();
468 let input = { files: [] };
469 component.refObj = undefined;
471 component.fileChange(input);
473 expect(spy).toHaveBeenCalled();
476 // End fileChange method
478 it('should give the correct template artifact name when multiple template identifiers are provided from reference page', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
479 fixture = TestBed.createComponent(GoldenConfigurationComponent);
480 component = fixture.componentInstance;
481 mappingEditorService.identifier = "id1";
482 mappingEditorService.latestAction = { "action": "ConfigScaleOut", "action-level": "vnf", "scope": { "vnf-type": "test", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_ConfigScaleOut_test_0.0.1V_id1.json", "artifact-type": "config_template" }, { "artifact-name": "pd_ConfigScaleOut_test_0.0.1V_id1.yaml", "artifact-type": "parameter_definitions" }, { "artifact-name": "template_ConfigScaleOut_test_0.0.1V_id2.json", "artifact-type": "config_template" }, { "artifact-name": "pd_ConfigScaleOut_test_0.0.1V_id2.yaml", "artifact-type": "parameter_definitions" }], "template-id-list": ["id1", "id2"], "scopeType": "vnf-type" };
483 component.ngAfterViewInit();
484 expect(component.artifactName).toBe("template_ConfigScaleOut_test_0.0.1V_id1.json");