blob: a998e0a3f773e8edc9f40d68de5886befdfe1fd2 [file] [log] [blame]
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -08003 *
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 */
16
17/*
18 ONOS GUI -- Remote -- General Functions - Unit Tests
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080019 */
Matteo Scandolo812aa5a2016-04-19 18:12:45 -070020
Matteo Scandolo231c7542016-05-20 11:13:11 -070021describe('factory: fw/remote/urlfn.js', function () {
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080022 var $log, $loc, ufs, fs;
23
Simon Hunt1e4a0012015-01-21 11:36:08 -080024 var protocol, host, port;
25
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080026 beforeEach(module('onosRemote'));
27
28 beforeEach(module(function($provide) {
29 $provide.factory('$location', function (){
30 return {
Simon Hunt1e4a0012015-01-21 11:36:08 -080031 protocol: function () { return protocol; },
32 host: function () { return host; },
Matteo Scandolo231c7542016-05-20 11:13:11 -070033 port: function () { return port; },
34 search: function() {
35 return {debug: 'true'};
36 }
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080037 };
38 })
39 }));
40
41 beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) {
42 $log = _$log_;
43 $loc = $location;
44 ufs = UrlFnService;
45 fs = FnService;
46 }));
47
Simon Hunt1e4a0012015-01-21 11:36:08 -080048 function setLoc(prot, h, p) {
49 protocol = prot;
50 host = h;
51 port = p;
52 }
53
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080054 it('should define UrlFnService', function () {
55 expect(ufs).toBeDefined();
56 });
57
58 it('should define api functions', function () {
59 expect(fs.areFunctions(ufs, [
Simon Hunt1e4a0012015-01-21 11:36:08 -080060 'rsUrl', 'wsUrl'
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080061 ])).toBeTruthy();
62 });
63
Simon Hunt1e4a0012015-01-21 11:36:08 -080064 it('should return the correct (http) RS url', function () {
65 setLoc('http', 'foo', '123');
66 expect(ufs.rsUrl('path')).toEqual('http://foo:123/onos/ui/rs/path');
67 });
68
69 it('should return the correct (https) RS url', function () {
70 setLoc('https', 'foo', '123');
71 expect(ufs.rsUrl('path')).toEqual('https://foo:123/onos/ui/rs/path');
72 });
73
74 it('should return the correct (ws) WS url', function () {
75 setLoc('http', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070076 expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/websock/path');
Simon Hunt1e4a0012015-01-21 11:36:08 -080077 });
78
79 it('should return the correct (wss) WS url', function () {
80 setLoc('https', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070081 expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/websock/path');
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080082 });
Simon Huntbb920fd2015-01-22 17:06:32 -080083
84 it('should allow us to define an alternate WS port', function () {
85 setLoc('http', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070086 expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/websock/xyyzy');
Simon Huntbb920fd2015-01-22 17:06:32 -080087 });
Simon Hunt8b6d2d42015-03-11 13:04:52 -070088
89 it('should allow us to define an alternate host', function () {
90 setLoc('http', 'foo', '123');
91 expect(ufs.wsUrl('core', 456, 'bar')).toEqual('ws://bar:456/onos/ui/websock/core');
92 });
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080093});