blob: aa9ce64c4c689de83f3322a87b971e4144a50c5c [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Sean Condonc13d9562019-04-18 13:24:42 +010016import {async, ComponentFixture, TestBed} from '@angular/core/testing';
Sean Condonf4f54a12018-10-10 23:25:46 +010017
Sean Condonc13d9562019-04-18 13:24:42 +010018import {ForceSvgComponent} from './forcesvg.component';
Sean Condon71910542019-02-16 18:16:42 +000019import {FnService, LogService} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000020import {DraggableDirective} from './draggable/draggable.directive';
21import {ActivatedRoute, Params} from '@angular/router';
22import {of} from 'rxjs';
Sean Condon71910542019-02-16 18:16:42 +000023import {MapSvgComponent} from '../mapsvg/mapsvg.component';
Sean Condonff85fbe2019-03-16 14:28:46 +000024import {DeviceNodeSvgComponent} from './visuals/devicenodesvg/devicenodesvg.component';
25import {SubRegionNodeSvgComponent} from './visuals/subregionnodesvg/subregionnodesvg.component';
26import {HostNodeSvgComponent} from './visuals/hostnodesvg/hostnodesvg.component';
27import {LinkSvgComponent} from './visuals/linksvg/linksvg.component';
Sean Condonc13d9562019-04-18 13:24:42 +010028import {Device, Host, Link, LinkType, Region} from './models';
29import {SimpleChange} from '@angular/core';
Sean Condon0c577f62018-11-18 22:40:05 +000030
31class MockActivatedRoute extends ActivatedRoute {
32 constructor(params: Params) {
33 super();
34 this.queryParams = of(params);
35 }
36}
37
Sean Condonf4f54a12018-10-10 23:25:46 +010038describe('ForceSvgComponent', () => {
Sean Condon71910542019-02-16 18:16:42 +000039 let fs: FnService;
Sean Condon0c577f62018-11-18 22:40:05 +000040 let ar: MockActivatedRoute;
41 let windowMock: Window;
42 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condonf4f54a12018-10-10 23:25:46 +010043 let component: ForceSvgComponent;
44 let fixture: ComponentFixture<ForceSvgComponent>;
Sean Condonc13d9562019-04-18 13:24:42 +010045 const sampledata = require('./tests/test-module-topo2CurrentRegion.json');
46 const regionData: Region = <Region><unknown>(sampledata.payload);
47 const emptyRegion: Region = <Region>{devices: [ [], [], [] ], hosts: [ [], [], [] ], links: []};
Sean Condonf4f54a12018-10-10 23:25:46 +010048
49 beforeEach(async(() => {
Sean Condon0c577f62018-11-18 22:40:05 +000050 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
51 ar = new MockActivatedRoute({ 'debug': 'txrx' });
52
53 windowMock = <any>{
54 location: <any>{
55 hostname: 'foo',
56 host: 'foo',
57 port: '80',
58 protocol: 'http',
59 search: { debug: 'true' },
60 href: 'ws://foo:123/onos/ui/websock/path',
61 absUrl: 'ws://foo:123/onos/ui/websock/path'
62 }
63 };
64
Sean Condon71910542019-02-16 18:16:42 +000065 fs = new FnService(ar, logSpy, windowMock);
66
Sean Condonf4f54a12018-10-10 23:25:46 +010067 TestBed.configureTestingModule({
Sean Condon0c577f62018-11-18 22:40:05 +000068 declarations: [
69 ForceSvgComponent,
70 DeviceNodeSvgComponent,
71 HostNodeSvgComponent,
72 SubRegionNodeSvgComponent,
Sean Condon50855cf2018-12-23 15:37:42 +000073 LinkSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +000074 DraggableDirective,
75 MapSvgComponent
Sean Condon0c577f62018-11-18 22:40:05 +000076 ],
77 providers: [
Sean Condon71910542019-02-16 18:16:42 +000078 { provide: FnService, useValue: fs },
Sean Condon0c577f62018-11-18 22:40:05 +000079 { provide: LogService, useValue: logSpy },
Sean Condon71910542019-02-16 18:16:42 +000080 { provide: 'Window', useValue: windowMock },
Sean Condon0c577f62018-11-18 22:40:05 +000081 ]
Sean Condonf4f54a12018-10-10 23:25:46 +010082 })
83 .compileComponents();
Sean Condon0c577f62018-11-18 22:40:05 +000084 logServiceSpy = TestBed.get(LogService);
Sean Condonf4f54a12018-10-10 23:25:46 +010085 }));
86
87 beforeEach(() => {
88 fixture = TestBed.createComponent(ForceSvgComponent);
Sean Condon0c577f62018-11-18 22:40:05 +000089 component = fixture.debugElement.componentInstance;
Sean Condonf4f54a12018-10-10 23:25:46 +010090 fixture.detectChanges();
91 });
92
93 it('should create', () => {
94 expect(component).toBeTruthy();
95 });
Sean Condonc13d9562019-04-18 13:24:42 +010096
97 it('load sample file', () => {
98 expect(sampledata).toBeTruthy();
99 expect(sampledata.payload).toBeTruthy();
100 expect(sampledata.payload.id).toBe('(root)');
101 });
102
103 it('should read sample data payload as Region', () => {
104 expect(regionData).toBeTruthy();
105 // console.log(regionData);
106 expect(regionData.id).toBe('(root)');
107 expect(regionData.devices).toBeTruthy();
108 expect(regionData.devices.length).toBe(3);
109 expect(regionData.devices[2].length).toBe(10);
110 expect(regionData.hosts.length).toBe(3);
111 expect(regionData.hosts[2].length).toBe(20);
112 expect(regionData.links.length).toBe(44);
113 });
114
115 it('should read device246 correctly', () => {
116 const device246: Device = regionData.devices[2][0];
117 expect(device246.id).toBe('of:0000000000000246');
118 expect(device246.nodeType).toBe('device');
119 expect(device246.type).toBe('switch');
120 expect(device246.online).toBe(true);
121 expect(device246.master).toBe('10.192.19.68');
122 expect(device246.layer).toBe('def');
123
124 expect(device246.props.managementAddress).toBe('10.192.19.69');
125 expect(device246.props.protocol).toBe('OF_13');
126 expect(device246.props.driver).toBe('ofdpa-ovs');
127 expect(device246.props.latitude).toBe('40.15');
128 expect(device246.props.name).toBe('s246');
129 expect(device246.props.locType).toBe('geo');
130 expect(device246.props.channelId).toBe('10.192.19.69:59980');
131 expect(device246.props.longitude).toBe('-121.679');
132
133 expect(device246.location.locType).toBe('geo');
134 expect(device246.location.latOrY).toBe(40.15);
135 expect(device246.location.longOrX).toBe(-121.679);
136 });
137
138 it('should read host 3 correctly', () => {
139 const host3: Host = regionData.hosts[2][0];
140 expect(host3.id).toBe('00:88:00:00:00:03/110');
141 expect(host3.nodeType).toBe('host');
142 expect(host3.layer).toBe('def');
143 expect(host3.configured).toBe(false);
144 expect(host3.ips.length).toBe(3);
145 expect(host3.ips[0]).toBe('fe80::288:ff:fe00:3');
146 expect(host3.ips[1]).toBe('2000::102');
147 expect(host3.ips[2]).toBe('10.0.1.2');
148 });
149
150 it('should read link 3-205 correctly', () => {
151 const link3_205: Link = regionData.links[0];
152 expect(link3_205.id).toBe('00:AA:00:00:00:03/None~of:0000000000000205/6');
153 expect(link3_205.epA).toBe('00:AA:00:00:00:03/None');
154 expect(link3_205.epB).toBe('of:0000000000000205');
155 expect(String(LinkType[link3_205.type])).toBe('2');
156 expect(link3_205.portA).toBe(undefined);
157 expect(link3_205.portB).toBe('6');
158
159 expect(link3_205.rollup).toBeTruthy();
160 expect(link3_205.rollup.length).toBe(1);
161 expect(link3_205.rollup[0].id).toBe('00:AA:00:00:00:03/None~of:0000000000000205/6');
162 expect(link3_205.rollup[0].epA).toBe('00:AA:00:00:00:03/None');
163 expect(link3_205.rollup[0].epB).toBe('of:0000000000000205');
164 expect(String(LinkType[link3_205.rollup[0].type])).toBe('2');
165 expect(link3_205.rollup[0].portA).toBe(undefined);
166 expect(link3_205.rollup[0].portB).toBe('6');
167
168 });
169
170 it('should handle regionData change - empty Region', () => {
171 component.ngOnChanges(
172 {'regionData' : new SimpleChange(<Region>{}, emptyRegion, true)});
173
174 expect(component.graph.nodes.length).toBe(0);
175 });
176
177 it('should know hwo to format names', () => {
178 expect(ForceSvgComponent.extractNodeName('00:AA:00:00:00:03/None'))
179 .toEqual('00:AA:00:00:00:03/None');
180
181 expect(ForceSvgComponent.extractNodeName('00:AA:00:00:00:03/161'))
182 .toEqual('00:AA:00:00:00:03/161');
183
184 expect(ForceSvgComponent.extractNodeName('of:0000000000000206/6'))
185 .toEqual('of:0000000000000206');
186 });
187
188 it('should handle regionData change - sample Region', () => {
189 component.regionData = regionData;
190 component.ngOnChanges(
191 {'regionData' : new SimpleChange(<Region>{}, regionData, true)});
192
193 expect(component.graph.nodes.length).toBe(30);
194
195 expect(component.graph.links.length).toBe(44);
196
197 });
Sean Condonf4f54a12018-10-10 23:25:46 +0100198});