blob: 7b9c11413a101bce99a619ff672d51086de21571 [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 Huntfa875bb2016-08-24 11:41:02 -070024 var protocol, host, port, context;
Simon Hunt1e4a0012015-01-21 11:36:08 -080025
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080026 beforeEach(module('onosRemote'));
27
28 beforeEach(module(function($provide) {
Simon Huntfa875bb2016-08-24 11:41:02 -070029 $provide.factory('$location', function () {
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080030 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'};
Simon Huntfa875bb2016-08-24 11:41:02 -070036 },
37 absUrl: function () {
38 return protocol + '://' + host + ':' + port +
39 context + '/onos/ui/';
Matteo Scandolo231c7542016-05-20 11:13:11 -070040 }
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080041 };
Simon Huntfa875bb2016-08-24 11:41:02 -070042 });
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080043 }));
44
45 beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) {
46 $log = _$log_;
47 $loc = $location;
48 ufs = UrlFnService;
49 fs = FnService;
50 }));
51
Simon Huntfa875bb2016-08-24 11:41:02 -070052 function setLoc(prot, h, p, ctx) {
Simon Hunt1e4a0012015-01-21 11:36:08 -080053 protocol = prot;
54 host = h;
55 port = p;
Simon Huntfa875bb2016-08-24 11:41:02 -070056 context = ctx || '';
Simon Hunt1e4a0012015-01-21 11:36:08 -080057 }
58
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080059 it('should define UrlFnService', function () {
60 expect(ufs).toBeDefined();
61 });
62
63 it('should define api functions', function () {
64 expect(fs.areFunctions(ufs, [
Simon Hunt1e4a0012015-01-21 11:36:08 -080065 'rsUrl', 'wsUrl'
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080066 ])).toBeTruthy();
67 });
68
Simon Hunt1e4a0012015-01-21 11:36:08 -080069 it('should return the correct (http) RS url', function () {
70 setLoc('http', 'foo', '123');
71 expect(ufs.rsUrl('path')).toEqual('http://foo:123/onos/ui/rs/path');
72 });
73
74 it('should return the correct (https) RS url', function () {
75 setLoc('https', 'foo', '123');
76 expect(ufs.rsUrl('path')).toEqual('https://foo:123/onos/ui/rs/path');
77 });
78
79 it('should return the correct (ws) WS url', function () {
80 setLoc('http', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070081 expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/websock/path');
Simon Hunt1e4a0012015-01-21 11:36:08 -080082 });
83
84 it('should return the correct (wss) WS url', function () {
85 setLoc('https', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070086 expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/websock/path');
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080087 });
Simon Huntbb920fd2015-01-22 17:06:32 -080088
89 it('should allow us to define an alternate WS port', function () {
90 setLoc('http', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070091 expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/websock/xyyzy');
Simon Huntbb920fd2015-01-22 17:06:32 -080092 });
Simon Hunt8b6d2d42015-03-11 13:04:52 -070093
94 it('should allow us to define an alternate host', function () {
95 setLoc('http', 'foo', '123');
96 expect(ufs.wsUrl('core', 456, 'bar')).toEqual('ws://bar:456/onos/ui/websock/core');
97 });
Simon Huntfa875bb2016-08-24 11:41:02 -070098
99 it('should allow us to inject an app context', function () {
100 setLoc('http', 'foo', '123', '/my/app');
101 expect(ufs.wsUrl('path')).toEqual('ws://foo:123/my/app/onos/ui/websock/path');
102 });
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -0800103});