f26e5fd817cd70cfd87b4a2c7dd56f540f24b52b
[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 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 { ModalComponent } from '../../modal/modal.component';
30 import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service';
31 import { MappingEditorService } from '../../../../shared/services/mapping-editor.service';
32 import { ArtifactRequest } from '../../../../shared/models/index';
33 import { ActivatedRoute, Router } from "@angular/router";
34 import { saveAs } from "file-saver";
35 import { NotificationService } from '../../../../shared/services/notification.service';
36 import { NotificationsService } from "angular2-notifications"
37 import { ParamShareService } from '../../../../shared/services/paramShare.service';
38 import { DialogService } from "ng2-bootstrap-modal";
39 import {ConfirmComponent} from '../../../../shared/confirmModal/confirm.component';
40 import {BuildDesignComponent} from '../../build-artifacts.component';
41 import { environment } from '../../../../../environments/environment';
42 import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal'
43 import { FormsModule } from '@angular/forms';
44 import { RouterTestingModule } from '@angular/router/testing';
45 import { HomeComponent } from '../../../../home/home/home.component';
46 import { LogoutComponent } from '../../../../shared/components/logout/logout.component';
47 import { HelpComponent } from '../../../../shared/components/help/help/help.component';
48 import { AboutUsComponent } from '../../../../about-us/aboutus.component';
49 import { TestComponent } from '../../../../test/test.component';
50 import { HttpModule } from '@angular/http';
51 import { AceEditorComponent } from 'ng2-ace-editor';
52 import { Ng2Bs3ModalModule } from 'ng2-bs3-modal/ng2-bs3-modal';
53 import { SimpleNotificationsModule } from 'angular2-notifications';
54 import { GoldenConfigurationComponent } from './template-configuration.component';
55 import { NgProgress } from 'ngx-progressbar';
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, HttpUtilService, MappingEditorService, NotificationsService],
101       schemas: [NO_ERRORS_SCHEMA],
102     })
103
104   });
105
106   beforeEach(async(() => {
107     TestBed.compileComponents()
108
109   }));
110
111
112   it('validate if uploaded file should be xml or json', () => {
113     fixture = TestBed.createComponent(GoldenConfigurationComponent);
114     component = fixture.componentInstance;
115     expect(component.validateUploadedFile('xls')).toBe(false);
116     expect(component.validateUploadedFile('json')).toBe(true);
117     expect(component.validateUploadedFile('xml')).toBe(true);
118   });
119
120
121   it('validate initialisation of variables in ngOnit() function', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
122     fixture = TestBed.createComponent(GoldenConfigurationComponent);
123     component = fixture.componentInstance;
124     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" }
125
126     expect(component.ngOnInit());
127     expect(component.ngAfterViewInit());
128     expect(component.action).toEqual('Configure');
129     expect(component.vnfType).toEqual('testVnf');
130     expect(component.vnfcType).toEqual('');
131     expect(component.protocol).toEqual('CHEF');
132
133     expect(component.artifactName).toEqual('template_Configure_test_0.0.1V.json');
134
135      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" }
136      expect(component.ngOnInit());
137      expect(component.vnfcType).toEqual('testVnfc');
138       
139
140   }));
141
142   it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => {
143     fixture = TestBed.createComponent(GoldenConfigurationComponent);
144     component = fixture.componentInstance;
145     mappingEditorService.latestAction = { "action": "", "scope": { "vnf-type": "", "vnfc-type": "" }, "vm": [], "protocol": "", "download-dg-reference": "", "user-name": "", "port-number": "", "artifact-list": [], "deviceTemplate": "", "scopeType": "" };
146     
147     expect(component.ngAfterViewInit());
148     expect(component.action).toEqual('');
149     expect(component.vnfType).toEqual('');
150     expect(component.vnfcType).toEqual('');
151     expect(component.protocol).toEqual('');
152     expect(component.artifactName).toEqual('');
153        
154   }));
155
156   it('check if correct notification is fired while initialising if reference data object is undefined',()=>{
157     fixture = TestBed.createComponent(GoldenConfigurationComponent);
158     component = fixture.componentInstance;
159     expect(component.ngAfterViewInit());
160     expect(component.Actions.length).toBe(0)
161     expect(component.enableBrowse).toBe(false)
162   });
163
164    it('test sync template when template data, param data and pd data are available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
165     fixture = TestBed.createComponent(GoldenConfigurationComponent);
166     component = fixture.componentInstance;
167     mappingEditorService.fromScreen === 'MappingScreen'
168     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>"
169     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
170     
171     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]}];
172     paramShareService.setSessionParamData([pdData]);
173     localStorage["paramsContent"]={
174             "sync_auto-pop_name1":"10.0.1.34",
175             "sync_auto-pop_address1":"",
176             "node0_tacplus_server_name2":"192.34.45.5"
177             };       
178     expect(component.syncTemplate());
179    
180        
181   }));
182
183    it('test sync template when template data, param data and pd data are not available', inject([MappingEditorService, ParamShareService], (mappingEditorService: MappingEditorService, paramShareService:ParamShareService) => {
184     fixture = TestBed.createComponent(GoldenConfigurationComponent);
185     component = fixture.componentInstance;
186     mappingEditorService.fromScreen === 'MappingScreen'
187     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>"
188     mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal);
189     
190     var pdData=[];
191     paramShareService.setSessionParamData([pdData]);
192     localStorage["paramsContent"]={};       
193     expect(component.syncTemplate());
194    
195        
196   }));
197
198
199 });