template-configuartion spec- fixed test cases
[appc/cdt.git] / src / app / vnfs / build-artifacts / template-holder / template-configuration / template-configuration.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 ============LICENSE_END============================================
23 */
24
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
61 describe('GoldenConfigurationComponent', () => {
62   let component: GoldenConfigurationComponent;
63   let fixture: ComponentFixture<GoldenConfigurationComponent>;
64   let buildDesignComponent: BuildDesignComponent;
65   let paramShareService: ParamShareService;
66   let dialogService: DialogService;
67   let notificationService: NotificationService;
68   let httpUtil: HttpUtilService;
69   let mappingEditorService: MappingEditorService;
70   let activeRoutes: ActivatedRoute;
71   let router: Router;
72   let nService: NotificationsService
73   const routes = [
74     {
75       path: 'home',
76       component: HomeComponent
77     }, {
78       path: 'vnfs',
79       loadChildren: '../../../../vnfs/vnfs.module#VnfsModule'
80     }, {
81       path: 'test',
82       component: TestComponent
83     },
84     {
85       path: 'help',
86       component: HelpComponent
87     }, {
88       path: 'aboutUs',
89       component: AboutUsComponent
90     }, {
91       path: 'logout',
92       component: LogoutComponent
93     }, {
94       path: '',
95       redirectTo: '/home',
96       pathMatch: 'full'
97     }
98   ];
99
100   beforeEach(() => {
101     TestBed.configureTestingModule({
102       imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()],
103       declarations: [GoldenConfigurationComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent],
104       providers: [BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, NgxSpinnerService, MockBackend,
105         BaseRequestOptions, UtilityService,
106         {
107           provide: Http,
108           useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
109             return new Http(backend, defaultOptions);
110           },
111           deps: [MockBackend, BaseRequestOptions],
112         },
113
114         HttpUtilService, MappingEditorService, NotificationsService],
115       schemas: [NO_ERRORS_SCHEMA],
116     })
117
118   });
119
120   beforeEach(async(() => {
121     TestBed.compileComponents()
122
123   }));
124
125
126   it('validate if uploaded file should be xml or json', () => {
127     fixture = TestBed.createComponent(GoldenConfigurationComponent);
128     component = fixture.componentInstance;
129     expect(component.validateUploadedFile('xls')).toBe(false);
130     expect(component.validateUploadedFile('json')).toBe(true);
131     expect(component.validateUploadedFile('xml')).toBe(true);
132   });
133
134
135   it('validate initialisation of variables in ngOnit() function', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
136     fixture = TestBed.createComponent(GoldenConfigurationComponent);
137     component = fixture.componentInstance;
138     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
140     expect(component.ngOnInit());
141     expect(component.ngAfterViewInit());
142     expect(component.action).toEqual('Configure');
143     expect(component.vnfType).toEqual('testVnf');
144     expect(component.vnfcType).toEqual('');
145     expect(component.protocol).toEqual('CHEF');
146
147     expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json');
148
149     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" }
150     expect(component.ngOnInit());
151     expect(component.vnfcType).toEqual('testVnfc');
152
153
154   }));
155
156   it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
157     fixture = TestBed.createComponent(GoldenConfigurationComponent);
158     component = fixture.componentInstance;
159     mappingEditorService.latestAction = undefined;
160     expect(component.ngAfterViewInit());
161     expect(component.action).toEqual('');
162     expect(component.vnfType).toEqual('');
163     expect(component.vnfcType).toEqual('');
164     expect(component.protocol).toEqual('');
165     expect(component.artifactName).toEqual('');
166
167   }));
168
169   it('check if correct notification is fired while initialising if reference data object is undefined', () => {
170     fixture = TestBed.createComponent(GoldenConfigurationComponent);
171     component = fixture.componentInstance;
172     expect(component.ngAfterViewInit());
173     expect(component.Actions.length).toBe(0)
174     expect(component.enableBrowse).toBe(false)
175   });
176
177   it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
178     fixture = TestBed.createComponent(GoldenConfigurationComponent);
179     component = fixture.componentInstance;
180     mappingEditorService.fromScreen === 'MappingScreen'
181     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>"
182     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
183
184     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] }];
185     paramShareService.setSessionParamData([pdData]);
186     localStorage["paramsContent"] = {
187       "sync_auto-pop_name1": "10.0.1.34",
188       "sync_auto-pop_address1": "",
189       "node0_tacplus_server_name2": "192.34.45.5"
190     };
191     expect(component.syncTemplate());
192
193
194   }));
195
196   it('test sync template when template data, param data and pd data are not available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
197     fixture = TestBed.createComponent(GoldenConfigurationComponent);
198     component = fixture.componentInstance;
199     mappingEditorService.fromScreen === 'MappingScreen'
200     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>"
201     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
202
203     var pdData = [];
204     paramShareService.setSessionParamData([pdData]);
205     localStorage["paramsContent"] = {};
206     expect(component.syncTemplate());
207
208
209   }));
210
211   it('test whether proper param data and template data are getting set in the appDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
212     fixture = TestBed.createComponent(GoldenConfigurationComponent);
213     component = fixture.componentInstance;
214     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" };
215     component.ngOnInit();
216     component.ngAfterViewInit();
217     component.appDataObject = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
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, component.modal);
220     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
222     component.userId = "sj108s";
223     component.apiToken = "87264736473";
224     mappingEditorService.identifier = "id1";
225     component.prepareAppData();
226     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\"}]"}' }) }) };
227     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>"}' }) }) };
228     expect(component.appDataObject.template.nameValueData["payload"]).toBe(JSON.stringify(paramData["payload"]));
229     expect(component.appDataObject.template.templateData["payload"]).toBe(JSON.stringify(templateData["payload"]));
230   }));
231
232
233   it('test whether proper param data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
234     fixture = TestBed.createComponent(GoldenConfigurationComponent);
235     component = fixture.componentInstance;
236     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" };
237     component.ngOnInit();
238     component.ngAfterViewInit();
239     component.downloadDataObject = {
240       reference: {},
241       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
242       pd: { pdData: '', pdFileName: '' }
243     };
244     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
246     component.onDownloadParameter();
247     var nameValueData = {
248       "sync_auto-pop_name1": "10.0.1.34",
249       "sync_auto-pop_address1": "",
250       "node0_tacplus_server_name2": "192.34.45.5"
251     };
252     expect(component.downloadDataObject.template.nameValueData).toBe(JSON.stringify(nameValueData, null, "\t"));
253     expect(component.downloadDataObject.template.nameValueFileName).toBe("param_Configure_testVnf_0.0.1V.json");
254   }));
255
256   it('test whether proper template data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
257     fixture = TestBed.createComponent(GoldenConfigurationComponent);
258     component = fixture.componentInstance;
259     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" };
260     component.ngOnInit();
261     component.ngAfterViewInit();
262     component.downloadDataObject = {
263       reference: {},
264       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
265       pd: { pdData: '', pdFileName: '' }
266     };
267     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>"
268     component.fileType = "text/xml"
269     component.onDownloadTemplate('Template');
270
271     component.fileType = "text/plain"
272     component.onDownloadTemplate('Template');
273     component.fileType = "text/json"
274     component.onDownloadTemplate('Template');
275     component.tempretrieveFlag = true;
276     component.fileNameForTempSave = "Configure_testVnf_0.0.1V.json"
277     component.onDownloadTemplate('Template');
278     expect(component.downloadDataObject.template.templateData).toBe(component.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}'));
279   }));
280
281
282   it('test merge status for golden config template and uploaded parameter data', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
283     fixture = TestBed.createComponent(GoldenConfigurationComponent);
284     component = fixture.componentInstance;
285     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" };
286     component.ngOnInit();
287     component.ngAfterViewInit();
288     component.downloadDataObject = {
289       reference: {},
290       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
291       pd: { pdData: '', pdFileName: '' }
292     };
293     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>";
294     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
295     localStorage["paramsContent"] = JSON.stringify({
296       "node0_tacplus_server_name1": "199.37.184.211",
297       "node0_tacplus_server_source_address1": "135.144.3.125",
298       "node0_tacplus_server_name2": "199.37.184.242"
299     });
300     component.mergeParams();
301     expect(component.mergeStatus).toBe(true);
302
303     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>"
304     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
305     component.mergeParams();
306     expect(component.mergeStatus).toBe(false);
307
308   }));
309
310   it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
311     fixture = TestBed.createComponent(GoldenConfigurationComponent);
312     component = fixture.componentInstance;
313     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" };
314     component.ngOnInit();
315     component.ngAfterViewInit();
316
317     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>";
318     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
319     component.selectedWord = "node0";
320     expect(component.handleAnnotation(component.modal));
321   }));
322
323   it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
324     fixture = TestBed.createComponent(GoldenConfigurationComponent);
325     component = fixture.componentInstance;
326     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" };
327     component.ngOnInit();
328     component.ngAfterViewInit();
329
330     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>";
331     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
332     component.selectedWord = "node0";
333     component.tempName = "name0";
334     component.submitNameValues()
335     expect(component.replaceWord).toContain("{(node0)=(name0)}");
336     component.selectedWord = "{(node1)=(name1)}";
337     component.submitNameValues();
338     component.tempName = false;
339     component.submitNameValues();
340   }));
341
342   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) => {
343     fixture = TestBed.createComponent(GoldenConfigurationComponent);
344     component = fixture.componentInstance;
345     var mockData = {
346       "output": {
347         "data": {
348           "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>\"}]}",
349           "requestId": "497085412083"
350         },
351         "status": {
352           "code": "400",
353           "message": "success"
354         }
355       }
356     }
357     let response = new ResponseOptions({
358       body: JSON.stringify(mockData)
359     });
360     const baseResponse = new Response(response);
361     mockBackend.connections.subscribe(
362       (c: MockConnection) => c.mockRespond(baseResponse)
363     );
364
365     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
367     mappingEditorService.fromScreen = 'MappingScreen';
368     component.action = 'Configure';
369     component.refObj = mappingEditorService.latestAction;
370     component.scopeName = "testVnf";
371     component.vnfType = "testVnf";
372     component.userId = "abc";
373     component.item.action = "Configure";
374     component.retrieveTemplateFromAppc();
375     expect(component.configMappingEditorContent).not.toBe(null);
376
377   }));
378
379   // fileChange method
380   it('Should validatte fileChange method if file type is xml', async(() => {
381     fixture = TestBed.createComponent(GoldenConfigurationComponent);
382     component = fixture.componentInstance;
383     let reader = new FileReader();
384     let file = new File(["testing"], "foo.xml", { type: "text/xml" });
385     let input = { files: [file] };
386     component.refObj = true;
387
388     component.fileChange(input);
389
390     component.readFile(input.files[0], reader, (res) => {
391       expect(component.selectedUploadType).toEqual('Generated Template');
392       expect(component.configMappingEditorContent).toEqual(res);
393       expect(component.artifactRequest.templateContent).toEqual(res);
394     });
395   }));
396
397   it('Should validatte fileChange method if file type is json', async(() => {
398     fixture = TestBed.createComponent(GoldenConfigurationComponent);
399     component = fixture.componentInstance;
400     let reader = new FileReader();
401     let file = new File(["testing"], "foo.json", { type: "text/json" });
402     let input = { files: [file] };
403     component.refObj = true;
404
405     component.fileChange(input);
406
407     component.readFile(input.files[0], reader, (res) => {
408       expect(component.selectedUploadType).toEqual('Generated Template');
409       expect(component.configMappingEditorContent).toEqual(res);
410       expect(component.artifactRequest.templateContent).toEqual(res);
411     });
412   }));
413
414   it('Should validatte fileChange method if file type is none ', async(() => {
415     fixture = TestBed.createComponent(GoldenConfigurationComponent);
416     component = fixture.componentInstance;
417     let reader = new FileReader();
418     let file = new File(["testing"], "foo", { type: "" });
419     let input = { files: [file] };
420     component.refObj = true;
421
422     component.fileChange(input);
423
424     component.readFile(input.files[0], reader, (res) => {
425       expect(typeof sessionStorage.getItem('fileType')).toEqual('string')
426       expect(component.selectedUploadType).toEqual('Generated Template');
427       expect(component.configMappingEditorContent).toEqual(res);
428       expect(component.artifactRequest.templateContent).toEqual(res);
429     });
430   }));
431
432   it('Should validate if files is false', () => {
433    fixture = TestBed.createComponent(GoldenConfigurationComponent);
434    component = fixture.componentInstance;
435     let spy = spyOn(NotificationsService.prototype, 'error');
436     let reader = new FileReader();
437     let input = { files: [] };
438     component.refObj = true;
439
440     component.fileChange(input);
441
442     expect(spy).toHaveBeenCalled();
443   });
444
445   it('Should validate if refObj is undefined', () => {
446     fixture = TestBed.createComponent(GoldenConfigurationComponent);
447     component = fixture.componentInstance;
448     let spy = spyOn(NotificationsService.prototype, 'error');
449     let reader = new FileReader();
450     let input = { files: [] };
451     component.refObj = undefined;
452
453     component.fileChange(input);
454
455     expect(spy).toHaveBeenCalled();
456   });
457
458   // End fileChange method
459
460   it('should give the correct template artifact name when multiple template identifiers are provided from reference page', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
461     fixture = TestBed.createComponent(GoldenConfigurationComponent);
462     component = fixture.componentInstance;
463     mappingEditorService.identifier = "id1";
464     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" };
465     component.ngAfterViewInit();
466     expect(component.artifactName).toBe("template_ConfigScaleOut_test_0.0.1V_id1.json");
467   }));
468
469
470 });