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';
60 describe('GoldenConfigurationComponent', () => {
61 let component: GoldenConfigurationComponent;
62 let fixture: ComponentFixture<GoldenConfigurationComponent>;
63 let buildDesignComponent: BuildDesignComponent;
64 let paramShareService: ParamShareService;
65 let dialogService: DialogService;
66 let notificationService: NotificationService;
67 let httpUtil: HttpUtilService;
68 let mappingEditorService: MappingEditorService;
69 let activeRoutes: ActivatedRoute;
71 let nService: NotificationsService
75 component: HomeComponent
78 loadChildren: '../../../../vnfs/vnfs.module#VnfsModule'
81 component: TestComponent
85 component: HelpComponent
88 component: AboutUsComponent
91 component: LogoutComponent
100 TestBed.configureTestingModule({
101 imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()],
102 declarations: [GoldenConfigurationComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent],
103 providers: [BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, NgxSpinnerService, MockBackend,
107 useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
108 return new Http(backend, defaultOptions);
110 deps: [MockBackend, BaseRequestOptions],
113 HttpUtilService, MappingEditorService, NotificationsService],
114 schemas: [NO_ERRORS_SCHEMA],
119 beforeEach(async(() => {
120 TestBed.compileComponents()
125 it('validate if uploaded file should be xml or json', () => {
126 fixture = TestBed.createComponent(GoldenConfigurationComponent);
127 component = fixture.componentInstance;
128 expect(component.validateUploadedFile('xls')).toBe(false);
129 expect(component.validateUploadedFile('json')).toBe(true);
130 expect(component.validateUploadedFile('xml')).toBe(true);
134 it('validate initialisation of variables in ngOnit() function', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
135 fixture = TestBed.createComponent(GoldenConfigurationComponent);
136 component = fixture.componentInstance;
137 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" }
139 expect(component.ngOnInit());
140 expect(component.ngAfterViewInit());
141 expect(component.action).toEqual('Configure');
142 expect(component.vnfType).toEqual('testVnf');
143 expect(component.vnfcType).toEqual('');
144 expect(component.protocol).toEqual('CHEF');
146 expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json');
148 mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "testVnfc" }, "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" }
149 expect(component.ngOnInit());
150 expect(component.vnfcType).toEqual('testVnfc');
155 it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
156 fixture = TestBed.createComponent(GoldenConfigurationComponent);
157 component = fixture.componentInstance;
158 mappingEditorService.latestAction = undefined;
159 expect(component.ngAfterViewInit());
160 expect(component.action).toEqual('');
161 expect(component.vnfType).toEqual('');
162 expect(component.vnfcType).toEqual('');
163 expect(component.protocol).toEqual('');
164 expect(component.artifactName).toEqual('');
168 it('check if correct notification is fired while initialising if reference data object is undefined', () => {
169 fixture = TestBed.createComponent(GoldenConfigurationComponent);
170 component = fixture.componentInstance;
171 expect(component.ngAfterViewInit());
172 expect(component.Actions.length).toBe(0)
173 expect(component.enableBrowse).toBe(false)
176 it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
177 fixture = TestBed.createComponent(GoldenConfigurationComponent);
178 component = fixture.componentInstance;
179 mappingEditorService.fromScreen === 'MappingScreen'
180 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>"
181 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
183 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] }];
184 paramShareService.setSessionParamData([pdData]);
185 localStorage["paramsContent"] = {
186 "sync_auto-pop_name1": "10.0.1.34",
187 "sync_auto-pop_address1": "",
188 "node0_tacplus_server_name2": "192.34.45.5"
190 expect(component.syncTemplate());
195 it('test sync template when template data, param data and pd data are not 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, component.modal);
203 paramShareService.setSessionParamData([pdData]);
204 localStorage["paramsContent"] = {};
205 expect(component.syncTemplate());
210 it('test whether proper param data and template data are getting set in the appDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
211 fixture = TestBed.createComponent(GoldenConfigurationComponent);
212 component = fixture.componentInstance;
213 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" };
214 component.ngOnInit();
215 component.ngAfterViewInit();
216 component.appDataObject = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
217 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>"
218 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
219 localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" });
221 component.userId = "sj108s";
222 component.apiToken = "87264736473";
223 mappingEditorService.identifier = "id1";
224 component.prepareAppData();
225 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\"}]"}' }) }) };
226 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>"}' }) }) };
227 expect(component.appDataObject.template.nameValueData["payload"]).toBe(JSON.stringify(paramData["payload"]));
228 expect(component.appDataObject.template.templateData["payload"]).toBe(JSON.stringify(templateData["payload"]));
232 it('test whether proper param data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
233 fixture = TestBed.createComponent(GoldenConfigurationComponent);
234 component = fixture.componentInstance;
235 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" };
236 component.ngOnInit();
237 component.ngAfterViewInit();
238 component.downloadDataObject = {
240 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
241 pd: { pdData: '', pdFileName: '' }
243 localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" });
245 component.onDownloadParameter();
246 var nameValueData = {
247 "sync_auto-pop_name1": "10.0.1.34",
248 "sync_auto-pop_address1": "",
249 "node0_tacplus_server_name2": "192.34.45.5"
251 expect(component.downloadDataObject.template.nameValueData).toBe(JSON.stringify(nameValueData, null, "\t"));
252 expect(component.downloadDataObject.template.nameValueFileName).toBe("param_Configure_testVnf_0.0.1V.json");
255 it('test whether proper template data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
256 fixture = TestBed.createComponent(GoldenConfigurationComponent);
257 component = fixture.componentInstance;
258 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" };
259 component.ngOnInit();
260 component.ngAfterViewInit();
261 component.downloadDataObject = {
263 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
264 pd: { pdData: '', pdFileName: '' }
266 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>"
267 component.fileType = "text/xml"
268 component.onDownloadTemplate('Template');
270 component.fileType = "text/plain"
271 component.onDownloadTemplate('Template');
272 component.fileType = "text/json"
273 component.onDownloadTemplate('Template');
274 component.tempretrieveFlag = true;
275 component.fileNameForTempSave = "Configure_testVnf_0.0.1V.json"
276 component.onDownloadTemplate('Template');
277 expect(component.downloadDataObject.template.templateData).toBe(component.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}'));
281 it('test merge status for golden config template and uploaded parameter data', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
282 fixture = TestBed.createComponent(GoldenConfigurationComponent);
283 component = fixture.componentInstance;
284 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" };
285 component.ngOnInit();
286 component.ngAfterViewInit();
287 component.downloadDataObject = {
289 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
290 pd: { pdData: '', pdFileName: '' }
292 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>";
293 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
294 localStorage["paramsContent"] = JSON.stringify({
295 "node0_tacplus_server_name1": "199.37.184.211",
296 "node0_tacplus_server_source_address1": "135.144.3.125",
297 "node0_tacplus_server_name2": "199.37.184.242"
299 component.mergeParams();
300 expect(component.mergeStatus).toBe(true);
302 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>"
303 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
304 component.mergeParams();
305 expect(component.mergeStatus).toBe(false);
309 it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
310 fixture = TestBed.createComponent(GoldenConfigurationComponent);
311 component = fixture.componentInstance;
312 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" };
313 component.ngOnInit();
314 component.ngAfterViewInit();
316 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>";
317 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
318 component.selectedWord = "node0";
319 expect(component.handleAnnotation(component.modal));
322 it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
323 fixture = TestBed.createComponent(GoldenConfigurationComponent);
324 component = fixture.componentInstance;
325 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" };
326 component.ngOnInit();
327 component.ngAfterViewInit();
329 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>";
330 mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
331 component.selectedWord = "node0";
332 component.tempName = "name0";
333 component.submitNameValues()
334 expect(component.replaceWord).toContain("{(node0)=(name0)}");
335 component.selectedWord = "{(node1)=(name1)}";
336 component.submitNameValues();
337 component.tempName = false;
338 component.submitNameValues();
341 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) => {
342 fixture = TestBed.createComponent(GoldenConfigurationComponent);
343 component = fixture.componentInstance;
347 "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>\"}]}",
348 "requestId": "497085412083"
356 let response = new ResponseOptions({
357 body: JSON.stringify(mockData)
359 const baseResponse = new Response(response);
360 mockBackend.connections.subscribe(
361 (c: MockConnection) => c.mockRespond(baseResponse)
364 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" }
366 mappingEditorService.fromScreen = 'MappingScreen';
367 component.action = 'Configure';
368 component.refObj = mappingEditorService.latestAction;
369 component.scopeName = "testVnf";
370 component.vnfType = "testVnf";
371 component.userId = "abc";
372 component.item.action = "Configure";
373 component.retrieveTemplateFromAppc();
374 expect(component.configMappingEditorContent).not.toBe(null);
379 it('Should validatte fileChange method if file type is xml', async(() => {
380 let reader = new FileReader();
381 let file = new File(["testing"], "foo.xml", { type: "text/xml" });
382 let input = { files: [file] };
383 component.refObj = true;
385 component.fileChange(input);
387 component.readFile(input.files[0], reader, (res) => {
388 expect(component.selectedUploadType).toEqual('Generated Template');
389 expect(component.configMappingEditorContent).toEqual(res);
390 expect(component.artifactRequest.templateContent).toEqual(res);
394 it('Should validatte fileChange method if file type is json', async(() => {
395 let reader = new FileReader();
396 let file = new File(["testing"], "foo.json", { type: "text/json" });
397 let input = { files: [file] };
398 component.refObj = true;
400 component.fileChange(input);
402 component.readFile(input.files[0], reader, (res) => {
403 expect(component.selectedUploadType).toEqual('Generated Template');
404 expect(component.configMappingEditorContent).toEqual(res);
405 expect(component.artifactRequest.templateContent).toEqual(res);
409 it('Should validatte fileChange method if file type is none ', async(() => {
410 let reader = new FileReader();
411 let file = new File(["testing"], "foo", { type: "" });
412 let input = { files: [file] };
413 component.refObj = true;
415 component.fileChange(input);
417 component.readFile(input.files[0], reader, (res) => {
418 expect(typeof sessionStorage.getItem('fileType')).toEqual('string')
419 expect(component.selectedUploadType).toEqual('Generated Template');
420 expect(component.configMappingEditorContent).toEqual(res);
421 expect(component.artifactRequest.templateContent).toEqual(res);
425 it('Should validate if files is false', () => {
426 let spy = spyOn(NotificationsService.prototype, 'error');
427 let reader = new FileReader();
428 let input = { files: [] };
429 component.refObj = true;
431 component.fileChange(input);
433 expect(spy).toHaveBeenCalled();
436 it('Should validate if refObj is undefined', () => {
437 let spy = spyOn(NotificationsService.prototype, 'error');
438 let reader = new FileReader();
439 let input = { files: [] };
440 component.refObj = undefined;
442 component.fileChange(input);
444 expect(spy).toHaveBeenCalled();
447 // End fileChange method
449 it('should give the correct template artifact name when multiple template identifiers are provided from reference page', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
450 fixture = TestBed.createComponent(GoldenConfigurationComponent);
451 component = fixture.componentInstance;
452 mappingEditorService.identifier = "id1";
453 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" };
454 component.ngAfterViewInit();
455 expect(component.artifactName).toBe("template_ConfigScaleOut_test_0.0.1V_id1.json");