4c682a4af542b3e92170a9b954406e4f1a60f67c
[appc/cdt.git] /
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
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;
70   let router: Router;
71   let nService: NotificationsService
72   const routes = [
73     {
74       path: 'home',
75       component: HomeComponent
76     }, {
77       path: 'vnfs',
78       loadChildren: '../../../../vnfs/vnfs.module#VnfsModule'
79     }, {
80       path: 'test',
81       component: TestComponent
82     },
83     {
84       path: 'help',
85       component: HelpComponent
86     }, {
87       path: 'aboutUs',
88       component: AboutUsComponent
89     }, {
90       path: 'logout',
91       component: LogoutComponent
92     }, {
93       path: '',
94       redirectTo: '/home',
95       pathMatch: 'full'
96     }
97   ];
98
99   beforeEach(() => {
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,
104         BaseRequestOptions,
105         {
106           provide: Http,
107           useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
108             return new Http(backend, defaultOptions);
109           },
110           deps: [MockBackend, BaseRequestOptions],
111         },
112
113         HttpUtilService, MappingEditorService, NotificationsService],
114       schemas: [NO_ERRORS_SCHEMA],
115     })
116
117   });
118
119   beforeEach(async(() => {
120     TestBed.compileComponents()
121
122   }));
123
124
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);
131   });
132
133
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" }
138
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');
145
146     expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json');
147
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');
151
152
153   }));
154
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('');
165
166   }));
167
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)
174   });
175
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);
182
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"
189     };
190     expect(component.syncTemplate());
191
192
193   }));
194
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);
201
202     var pdData = [];
203     paramShareService.setSessionParamData([pdData]);
204     localStorage["paramsContent"] = {};
205     expect(component.syncTemplate());
206
207
208   }));
209
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" });
220
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"]));
229   }));
230
231
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 = {
239       reference: {},
240       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
241       pd: { pdData: '', pdFileName: '' }
242     };
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" });
244
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"
250     };
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");
253   }));
254
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 = {
262       reference: {},
263       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
264       pd: { pdData: '', pdFileName: '' }
265     };
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');
269
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, '}'));
278   }));
279
280
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 = {
288       reference: {},
289       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
290       pd: { pdData: '', pdFileName: '' }
291     };
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"
298     });
299     component.mergeParams();
300     expect(component.mergeStatus).toBe(true);
301
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);
306
307   }));
308
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();
315
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));
320   }));
321
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();
328
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();
339   }));
340
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;
344     var mockData = {
345       "output": {
346         "data": {
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"
349         },
350         "status": {
351           "code": "400",
352           "message": "success"
353         }
354       }
355     }
356     let response = new ResponseOptions({
357       body: JSON.stringify(mockData)
358     });
359     const baseResponse = new Response(response);
360     mockBackend.connections.subscribe(
361       (c: MockConnection) => c.mockRespond(baseResponse)
362     );
363
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" }
365
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);
375
376   }));
377
378   // fileChange method
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;
384
385     component.fileChange(input);
386
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);
391     });
392   }));
393
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;
399
400     component.fileChange(input);
401
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);
406     });
407   }));
408
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;
414
415     component.fileChange(input);
416
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);
422     });
423   }));
424
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;
430
431     component.fileChange(input);
432
433     expect(spy).toHaveBeenCalled();
434   });
435
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;
441
442     component.fileChange(input);
443
444     expect(spy).toHaveBeenCalled();
445   });
446
447   // End fileChange method
448
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");
456   }));
457
458
459 });