Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Remote -- General Functions - Unit Tests |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 19 | */ |
Matteo Scandolo | 812aa5a | 2016-04-19 18:12:45 -0700 | [diff] [blame] | 20 | |
| 21 | // FIXME TypeError: $loc.search is not a function |
| 22 | |
| 23 | xdescribe('factory: fw/remote/urlfn.js', function () { |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 24 | var $log, $loc, ufs, fs; |
| 25 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 26 | var protocol, host, port; |
| 27 | |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 28 | beforeEach(module('onosRemote')); |
| 29 | |
| 30 | beforeEach(module(function($provide) { |
| 31 | $provide.factory('$location', function (){ |
| 32 | return { |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 33 | protocol: function () { return protocol; }, |
| 34 | host: function () { return host; }, |
| 35 | port: function () { return port; } |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 36 | }; |
| 37 | }) |
| 38 | })); |
| 39 | |
| 40 | beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) { |
| 41 | $log = _$log_; |
| 42 | $loc = $location; |
| 43 | ufs = UrlFnService; |
| 44 | fs = FnService; |
| 45 | })); |
| 46 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 47 | function setLoc(prot, h, p) { |
| 48 | protocol = prot; |
| 49 | host = h; |
| 50 | port = p; |
| 51 | } |
| 52 | |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 53 | it('should define UrlFnService', function () { |
| 54 | expect(ufs).toBeDefined(); |
| 55 | }); |
| 56 | |
| 57 | it('should define api functions', function () { |
| 58 | expect(fs.areFunctions(ufs, [ |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 59 | 'rsUrl', 'wsUrl' |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 60 | ])).toBeTruthy(); |
| 61 | }); |
| 62 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 63 | it('should return the correct (http) RS url', function () { |
| 64 | setLoc('http', 'foo', '123'); |
| 65 | expect(ufs.rsUrl('path')).toEqual('http://foo:123/onos/ui/rs/path'); |
| 66 | }); |
| 67 | |
| 68 | it('should return the correct (https) RS url', function () { |
| 69 | setLoc('https', 'foo', '123'); |
| 70 | expect(ufs.rsUrl('path')).toEqual('https://foo:123/onos/ui/rs/path'); |
| 71 | }); |
| 72 | |
| 73 | it('should return the correct (ws) WS url', function () { |
| 74 | setLoc('http', 'foo', '123'); |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 75 | expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/websock/path'); |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 76 | }); |
| 77 | |
| 78 | it('should return the correct (wss) WS url', function () { |
| 79 | setLoc('https', 'foo', '123'); |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 80 | expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/websock/path'); |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 81 | }); |
Simon Hunt | bb920fd | 2015-01-22 17:06:32 -0800 | [diff] [blame] | 82 | |
| 83 | it('should allow us to define an alternate WS port', function () { |
| 84 | setLoc('http', 'foo', '123'); |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 85 | expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/websock/xyyzy'); |
Simon Hunt | bb920fd | 2015-01-22 17:06:32 -0800 | [diff] [blame] | 86 | }); |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 87 | |
| 88 | it('should allow us to define an alternate host', function () { |
| 89 | setLoc('http', 'foo', '123'); |
| 90 | expect(ufs.wsUrl('core', 456, 'bar')).toEqual('ws://bar:456/onos/ui/websock/core'); |
| 91 | }); |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 92 | }); |