Removing INSTAR functionality from CDT for ONAP.
[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
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 ============LICENSE_END============================================
22 */
23
24 /* tslint:disable:no-unused-variable */
25 import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
26 import { By, BrowserModule } from '@angular/platform-browser';
27 import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
28 import { Component, OnInit, ViewChild, Input } from '@angular/core';
29 import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service';
30 import { MappingEditorService } from '../../../../shared/services/mapping-editor.service';
31 import { ArtifactRequest } from '../../../../shared/models/index';
32 import { ActivatedRoute, Router } from "@angular/router";
33 import { saveAs } from "file-saver";
34 import { NotificationService } from '../../../../shared/services/notification.service';
35 import { NotificationsService } from "angular2-notifications"
36 import { ParamShareService } from '../../../../shared/services/paramShare.service';
37 import { DialogService } from "ng2-bootstrap-modal";
38 import { ConfirmComponent } from '../../../../shared/confirmModal/confirm.component';
39 import { BuildDesignComponent } from '../../build-artifacts.component';
40 import { environment } from '../../../../../environments/environment';
41 import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal'
42 import { FormsModule } from '@angular/forms';
43 import { RouterTestingModule } from '@angular/router/testing';
44 import { HomeComponent } from '../../../../home/home/home.component';
45 import { LogoutComponent } from '../../../../shared/components/logout/logout.component';
46 import { HelpComponent } from '../../../../shared/components/help/help/help.component';
47 import { AboutUsComponent } from '../../../../about-us/aboutus.component';
48 import { TestComponent } from '../../../../test/test.component';
49 import { HttpModule } from '@angular/http';
50 import { AceEditorComponent } from 'ng2-ace-editor';
51 import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
52 import { SimpleNotificationsModule } from 'angular2-notifications';
53 import { GoldenConfigurationComponent } from './template-configuration.component';
54 import { NgProgress } from 'ngx-progressbar';
55 import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http';
56 import { MockBackend, MockConnection } from '@angular/http/testing';
57
58 describe('GoldenConfigurationComponent', () => {
59   let component: GoldenConfigurationComponent;
60   let fixture: ComponentFixture<GoldenConfigurationComponent>;
61   let buildDesignComponent: BuildDesignComponent;
62   let paramShareService: ParamShareService;
63   let dialogService: DialogService;
64   let notificationService: NotificationService;
65   let httpUtil: HttpUtilService;
66   let mappingEditorService: MappingEditorService;
67   let activeRoutes: ActivatedRoute;
68   let router: Router;
69   let nService: NotificationsService
70   const routes = [
71     {
72       path: 'home',
73       component: HomeComponent
74     }, {
75       path: 'vnfs',
76       loadChildren: '../../../../vnfs/vnfs.module#VnfsModule'
77     }, {
78       path: 'test',
79       component: TestComponent
80     },
81     {
82       path: 'help',
83       component: HelpComponent
84     }, {
85       path: 'aboutUs',
86       component: AboutUsComponent
87     }, {
88       path: 'logout',
89       component: LogoutComponent
90     }, {
91       path: '',
92       redirectTo: '/home',
93       pathMatch: 'full'
94     }
95   ];
96
97   beforeEach(() => {
98     TestBed.configureTestingModule({
99       imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()],
100       declarations: [GoldenConfigurationComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent],
101       providers: [BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, MockBackend,
102         BaseRequestOptions,
103         {
104           provide: Http,
105           useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
106             return new Http(backend, defaultOptions);
107           },
108           deps: [MockBackend, BaseRequestOptions],
109         },
110
111         HttpUtilService, MappingEditorService, NotificationsService],
112       schemas: [NO_ERRORS_SCHEMA],
113     })
114
115   });
116
117   beforeEach(async(() => {
118     TestBed.compileComponents()
119
120   }));
121
122
123   it('validate if uploaded file should be xml or json', () => {
124     fixture = TestBed.createComponent(GoldenConfigurationComponent);
125     component = fixture.componentInstance;
126     expect(component.validateUploadedFile('xls')).toBe(false);
127     expect(component.validateUploadedFile('json')).toBe(true);
128     expect(component.validateUploadedFile('xml')).toBe(true);
129   });
130
131
132   it('validate initialisation of variables in ngOnit() function', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
133     fixture = TestBed.createComponent(GoldenConfigurationComponent);
134     component = fixture.componentInstance;
135     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" }
136
137     expect(component.ngOnInit());
138     expect(component.ngAfterViewInit());
139     expect(component.action).toEqual('Configure');
140     expect(component.vnfType).toEqual('testVnf');
141     expect(component.vnfcType).toEqual('');
142     expect(component.protocol).toEqual('CHEF');
143
144     expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json');
145
146     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" }
147     expect(component.ngOnInit());
148     expect(component.vnfcType).toEqual('testVnfc');
149
150
151   }));
152
153   it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
154     fixture = TestBed.createComponent(GoldenConfigurationComponent);
155     component = fixture.componentInstance;
156     mappingEditorService.latestAction = undefined;
157     expect(component.ngAfterViewInit());
158     expect(component.action).toEqual('');
159     expect(component.vnfType).toEqual('');
160     expect(component.vnfcType).toEqual('');
161     expect(component.protocol).toEqual('');
162     expect(component.artifactName).toEqual('');
163
164   }));
165
166   it('check if correct notification is fired while initialising if reference data object is undefined', () => {
167     fixture = TestBed.createComponent(GoldenConfigurationComponent);
168     component = fixture.componentInstance;
169     expect(component.ngAfterViewInit());
170     expect(component.Actions.length).toBe(0)
171     expect(component.enableBrowse).toBe(false)
172   });
173
174   it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
175     fixture = TestBed.createComponent(GoldenConfigurationComponent);
176     component = fixture.componentInstance;
177     mappingEditorService.fromScreen === 'MappingScreen'
178     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>"
179     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
180
181     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] }];
182     paramShareService.setSessionParamData([pdData]);
183     localStorage["paramsContent"] = {
184       "sync_auto-pop_name1": "10.0.1.34",
185       "sync_auto-pop_address1": "",
186       "node0_tacplus_server_name2": "192.34.45.5"
187     };
188     expect(component.syncTemplate());
189
190
191   }));
192
193   it('test sync template when template data, param data and pd data are not available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
194     fixture = TestBed.createComponent(GoldenConfigurationComponent);
195     component = fixture.componentInstance;
196     mappingEditorService.fromScreen === 'MappingScreen'
197     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>"
198     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
199
200     var pdData = [];
201     paramShareService.setSessionParamData([pdData]);
202     localStorage["paramsContent"] = {};
203     expect(component.syncTemplate());
204
205
206   }));
207
208   it('test whether proper param data and template data are getting set in the appDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
209     fixture = TestBed.createComponent(GoldenConfigurationComponent);
210     component = fixture.componentInstance;
211     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" };
212     component.ngOnInit();
213     component.ngAfterViewInit();
214     component.appDataObject = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
215     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>"
216     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
217     localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" });
218
219     component.userId = "sj108s";
220     component.apiToken = "87264736473";
221     component.prepareAppData();
222     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\"}]"}' }) }) };
223     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>"}' }) }) };
224     expect(component.appDataObject.template.nameValueData["payload"]).toBe(JSON.stringify(paramData["payload"]));
225     expect(component.appDataObject.template.templateData["payload"]).toBe(JSON.stringify(templateData["payload"]));
226   }));
227
228
229   it('test whether proper param data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
230     fixture = TestBed.createComponent(GoldenConfigurationComponent);
231     component = fixture.componentInstance;
232     mappingEditorService.latestAction = { "action": "Configure", "action-level": "vnf", "scope": { "vnf-type": "testVnf", "vnfc-type": "" }, "template": "Y", "vm": [], "device-protocol": "CHEF", "user-name": "", "port-number": "", "artifact-list": [{ "artifact-name": "template_Configure_test_0.0.1V.json", "artifact-type": "config_template" }, { "artifact-name": "pd_Configure_test_0.0.1V.yaml", "artifact-type": "parameter_definitions" }], "scopeType": "vnf-type" };
233     component.ngOnInit();
234     component.ngAfterViewInit();
235     component.downloadDataObject = {
236       reference: {},
237       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
238       pd: { pdData: '', pdFileName: '' }
239     };
240     localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" });
241
242     component.onDownloadParameter();
243     var nameValueData = {
244       "sync_auto-pop_name1": "10.0.1.34",
245       "sync_auto-pop_address1": "",
246       "node0_tacplus_server_name2": "192.34.45.5"
247     };
248     expect(component.downloadDataObject.template.nameValueData).toBe(JSON.stringify(nameValueData, null, "\t"));
249     expect(component.downloadDataObject.template.nameValueFileName).toBe("param_Configure_testVnf_0.0.1V.json");
250   }));
251
252   it('test whether proper template data is getting set in the downloadDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
253     fixture = TestBed.createComponent(GoldenConfigurationComponent);
254     component = fixture.componentInstance;
255     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" };
256     component.ngOnInit();
257     component.ngAfterViewInit();
258     component.downloadDataObject = {
259       reference: {},
260       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
261       pd: { pdData: '', pdFileName: '' }
262     };
263     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>"
264     component.fileType = "text/xml"
265     component.onDownloadTemplate('Template');
266
267     component.fileType = "text/plain"
268     component.onDownloadTemplate('Template');
269     component.fileType = "text/json"
270     component.onDownloadTemplate('Template');
271     component.tempretrieveFlag = true;
272     component.fileNameForTempSave = "Configure_testVnf_0.0.1V.json"
273     component.onDownloadTemplate('Template');
274     expect(component.downloadDataObject.template.templateData).toBe(component.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}'));
275   }));
276
277
278   it('test merge status for golden config template and uploaded parameter data', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
279     fixture = TestBed.createComponent(GoldenConfigurationComponent);
280     component = fixture.componentInstance;
281     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" };
282     component.ngOnInit();
283     component.ngAfterViewInit();
284     component.downloadDataObject = {
285       reference: {},
286       template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
287       pd: { pdData: '', pdFileName: '' }
288     };
289     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>";
290     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
291     localStorage["paramsContent"] = JSON.stringify({
292       "node0_tacplus_server_name1": "199.37.184.211",
293       "node0_tacplus_server_source_address1": "135.144.3.125",
294       "node0_tacplus_server_name2": "199.37.184.242"
295     });
296     component.mergeParams();
297     expect(component.mergeStatus).toBe(true);
298
299     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>"
300     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
301     component.mergeParams();
302     expect(component.mergeStatus).toBe(false);
303
304   }));
305
306   it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
307     fixture = TestBed.createComponent(GoldenConfigurationComponent);
308     component = fixture.componentInstance;
309     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" };
310     component.ngOnInit();
311     component.ngAfterViewInit();
312
313     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>";
314     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
315     component.selectedWord = "node0";
316     expect(component.handleAnnotation(component.modal));
317   }));
318
319   it('test handleAnnotation method', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
320     fixture = TestBed.createComponent(GoldenConfigurationComponent);
321     component = fixture.componentInstance;
322     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" };
323     component.ngOnInit();
324     component.ngAfterViewInit();
325
326     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>";
327     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
328     component.selectedWord = "node0";
329     component.tempName = "name0";
330     component.submitNameValues()
331     expect(component.replaceWord).toContain("{(node0)=(name0)}");
332     component.selectedWord = "{(node1)=(name1)}";
333     component.submitNameValues();
334     component.tempName = false;
335     component.submitNameValues();
336   }));
337
338   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) => {
339     fixture = TestBed.createComponent(GoldenConfigurationComponent);
340     component = fixture.componentInstance;
341     var mockData = {
342       "output": {
343         "data": {
344           "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>\"}]}",
345           "requestId": "497085412083"
346         },
347         "status": {
348           "code": "400",
349           "message": "success"
350         }
351       }
352     }
353     let response = new ResponseOptions({
354       body: JSON.stringify(mockData)
355     });
356     const baseResponse = new Response(response);
357     mockBackend.connections.subscribe(
358       (c: MockConnection) => c.mockRespond(baseResponse)
359     );
360
361     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" }
362
363     mappingEditorService.fromScreen = 'MappingScreen';
364     component.action = 'Configure';
365     component.refObj = mappingEditorService.latestAction;
366     component.scopeName = "testVnf";
367     component.vnfType = "testVnf";
368     component.userId = "abc";
369     component.item.action = "Configure";
370     component.retrieveTemplateFromAppc();
371     expect(component.configMappingEditorContent).not.toBe(null);
372
373   }));
374
375   // fileChange method
376   it('Should validatte fileChange method if file type is xml', async(() => {
377     let reader = new FileReader();
378     let file = new File(["testing"], "foo.xml", {type: "text/xml"});
379     let input = {files: [file]};
380     component.refObj = true;
381
382     component.fileChange(input);
383
384     component.readFile(input.files[0], reader,(res) => {
385       expect(component.selectedUploadType).toEqual('Generated Template');
386       expect(component.configMappingEditorContent).toEqual(res);
387       expect(component.artifactRequest.templateContent).toEqual(res);
388     });    
389   }));
390
391   it('Should validatte fileChange method if file type is json', async(() => {
392     let reader = new FileReader();
393     let file = new File(["testing"], "foo.json", {type: "text/json"});
394     let input = {files: [file]};
395     component.refObj = true;
396
397     component.fileChange(input);
398
399     component.readFile(input.files[0], reader,(res) => {
400       expect(component.selectedUploadType).toEqual('Generated Template');
401       expect(component.configMappingEditorContent).toEqual(res);
402       expect(component.artifactRequest.templateContent).toEqual(res);
403     });    
404   }));
405
406   it('Should validatte fileChange method if file type is none ', async(() => {
407     let reader = new FileReader();
408     let file = new File(["testing"], "foo", {type: ""});
409     let input = {files: [file]};
410     component.refObj = true;
411
412     component.fileChange(input);
413
414     component.readFile(input.files[0], reader,(res) => {
415       expect(typeof sessionStorage.getItem('fileType')).toEqual('string')
416       expect(component.selectedUploadType).toEqual('Generated Template');
417       expect(component.configMappingEditorContent).toEqual(res);
418       expect(component.artifactRequest.templateContent).toEqual(res);
419     });    
420   }));
421
422   it('Should validate if files is false', () => {
423     let spy = spyOn(NotificationsService.prototype, 'error');
424     let reader = new FileReader();
425     let input = {files: []};
426     component.refObj = true;
427
428     component.fileChange(input);
429
430     expect(spy).toHaveBeenCalled();
431   });
432
433   it('Should validate if refObj is undefined', () => {
434     let spy = spyOn(NotificationsService.prototype, 'error');
435     let reader = new FileReader();
436     let input = {files: []};
437     component.refObj = undefined;
438
439     component.fileChange(input);
440
441     expect(spy).toHaveBeenCalled();
442   });
443
444   // End fileChange method
445
446 });