8ad635be601f80a45b6e3c0fa864c4dfbd74e25a
[appc/cdt.git] /
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 ============LICENSE_END============================================
21 */
22
23 /* tslint:disable:no-unused-variable */
24 import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
25 import { By, BrowserModule } from '@angular/platform-browser';
26 import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
27 import { Component, OnInit, ViewChild, Input } from '@angular/core';
28 import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service';
29 import { MappingEditorService } from '../../../../shared/services/mapping-editor.service';
30 import { ArtifactRequest } from '../../../../shared/models/index';
31 import { ActivatedRoute, Router } from "@angular/router";
32 import { saveAs } from "file-saver";
33 import { NotificationService } from '../../../../shared/services/notification.service';
34 import { NotificationsService } from "angular2-notifications"
35 import { ParamShareService } from '../../../../shared/services/paramShare.service';
36 import { DialogService } from "ng2-bootstrap-modal";
37 import { ConfirmComponent } from '../../../../shared/confirmModal/confirm.component';
38 import { BuildDesignComponent } from '../../build-artifacts.component';
39 import { environment } from '../../../../../environments/environment';
40 import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal'
41 import { FormsModule } from '@angular/forms';
42 import { RouterTestingModule } from '@angular/router/testing';
43 import { HomeComponent } from '../../../../home/home/home.component';
44 import { LogoutComponent } from '../../../../shared/components/logout/logout.component';
45 import { HelpComponent } from '../../../../shared/components/help/help/help.component';
46 import { AboutUsComponent } from '../../../../about-us/aboutus.component';
47 import { TestComponent } from '../../../../test/test.component';
48 import { HttpModule } from '@angular/http';
49 import { AceEditorComponent } from 'ng2-ace-editor';
50 import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
51 import { SimpleNotificationsModule } from 'angular2-notifications';
52 import { GoldenConfigurationComponent } from './template-configuration.component';
53 import { NgProgress } from 'ngx-progressbar';
54 import { BaseRequestOptions, Response, ResponseOptions, Http } from '@angular/http';
55 import { MockBackend, MockConnection } from '@angular/http/testing';
56
57 describe('GoldenConfigurationComponent', () => {
58   let component: GoldenConfigurationComponent;
59   let fixture: ComponentFixture<GoldenConfigurationComponent>;
60   let buildDesignComponent: BuildDesignComponent;
61   let paramShareService: ParamShareService;
62   let dialogService: DialogService;
63   let notificationService: NotificationService;
64   let httpUtil: HttpUtilService;
65   let mappingEditorService: MappingEditorService;
66   let activeRoutes: ActivatedRoute;
67   let router: Router;
68   let nService: NotificationsService
69   const routes = [
70     {
71       path: 'home',
72       component: HomeComponent
73     }, {
74       path: 'vnfs',
75       loadChildren: '../../../../vnfs/vnfs.module#VnfsModule'
76     }, {
77       path: 'test',
78       component: TestComponent
79     },
80     {
81       path: 'help',
82       component: HelpComponent
83     }, {
84       path: 'aboutUs',
85       component: AboutUsComponent
86     }, {
87       path: 'logout',
88       component: LogoutComponent
89     }, {
90       path: '',
91       redirectTo: '/home',
92       pathMatch: 'full'
93     }
94   ];
95
96   beforeEach(() => {
97     TestBed.configureTestingModule({
98       imports: [FormsModule, BrowserModule, RouterTestingModule.withRoutes(routes), HttpModule, Ng2Bs3ModalModule, SimpleNotificationsModule.forRoot()],
99       declarations: [GoldenConfigurationComponent, HomeComponent, TestComponent, HelpComponent, AboutUsComponent, LogoutComponent, AceEditorComponent],
100       providers: [BuildDesignComponent, NgProgress, ParamShareService, DialogService, NotificationService, MockBackend,
101         BaseRequestOptions,
102         {
103           provide: Http,
104           useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
105             return new Http(backend, defaultOptions);
106           },
107           deps: [MockBackend, BaseRequestOptions],
108         },
109
110         HttpUtilService, MappingEditorService, NotificationsService],
111       schemas: [NO_ERRORS_SCHEMA],
112     })
113
114   });
115
116   beforeEach(async(() => {
117     TestBed.compileComponents()
118
119   }));
120
121
122   it('validate if uploaded file should be xml or json', () => {
123     fixture = TestBed.createComponent(GoldenConfigurationComponent);
124     component = fixture.componentInstance;
125     expect(component.validateUploadedFile('xls')).toBe(false);
126     expect(component.validateUploadedFile('json')).toBe(true);
127     expect(component.validateUploadedFile('xml')).toBe(true);
128   });
129
130
131   it('validate initialisation of variables in ngOnit() function', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
132     fixture = TestBed.createComponent(GoldenConfigurationComponent);
133     component = fixture.componentInstance;
134     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" }
135
136     expect(component.ngOnInit());
137     expect(component.ngAfterViewInit());
138     expect(component.action).toEqual('Configure');
139     expect(component.vnfType).toEqual('testVnf');
140     expect(component.vnfcType).toEqual('');
141     expect(component.protocol).toEqual('CHEF');
142
143     expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json');
144
145     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" }
146     expect(component.ngOnInit());
147     expect(component.vnfcType).toEqual('testVnfc');
148
149
150   }));
151
152   it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
153     fixture = TestBed.createComponent(GoldenConfigurationComponent);
154     component = fixture.componentInstance;
155     mappingEditorService.latestAction = undefined;
156     expect(component.ngAfterViewInit());
157     expect(component.action).toEqual('');
158     expect(component.vnfType).toEqual('');
159     expect(component.vnfcType).toEqual('');
160     expect(component.protocol).toEqual('');
161     expect(component.artifactName).toEqual('');
162
163   }));
164
165   it('check if correct notification is fired while initialising if reference data object is undefined', () => {
166     fixture = TestBed.createComponent(GoldenConfigurationComponent);
167     component = fixture.componentInstance;
168     expect(component.ngAfterViewInit());
169     expect(component.Actions.length).toBe(0)
170     expect(component.enableBrowse).toBe(false)
171   });
172
173   it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
174     fixture = TestBed.createComponent(GoldenConfigurationComponent);
175     component = fixture.componentInstance;
176     mappingEditorService.fromScreen === 'MappingScreen'
177     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>"
178     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
179
180     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] }];
181     paramShareService.setSessionParamData([pdData]);
182     localStorage["paramsContent"] = {
183       "sync_auto-pop_name1": "10.0.1.34",
184       "sync_auto-pop_address1": "",
185       "node0_tacplus_server_name2": "192.34.45.5"
186     };
187     expect(component.syncTemplate());
188
189
190   }));
191
192   it('test sync template when template data, param data and pd data are not available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService: ParamShareService) => {
193     fixture = TestBed.createComponent(GoldenConfigurationComponent);
194     component = fixture.componentInstance;
195     mappingEditorService.fromScreen === 'MappingScreen'
196     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>"
197     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
198
199     var pdData = [];
200     paramShareService.setSessionParamData([pdData]);
201     localStorage["paramsContent"] = {};
202     expect(component.syncTemplate());
203
204
205   }));
206
207   it('test whether proper param data and template data are getting set in the appDataObject', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
208     fixture = TestBed.createComponent(GoldenConfigurationComponent);
209     component = fixture.componentInstance;
210     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" };
211     component.ngOnInit();
212     component.ngAfterViewInit();
213     component.appDataObject = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
214     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>"
215     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
216     localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" });
217
218     component.userId = "sj108s";
219     component.apiToken = "87264736473";
220     mappingEditorService.identifier = "id1";
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   it('should give the correct template artifact name when multiple template identifiers are provided from reference page', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
447     fixture = TestBed.createComponent(GoldenConfigurationComponent);
448     component = fixture.componentInstance;
449     mappingEditorService.identifier = "id1";
450     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" };
451     component.ngAfterViewInit();
452     expect(component.artifactName).toBe("template_ConfigScaleOut_test_0.0.1V_id1.json");
453   }));
454
455
456 });