Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Foundation |
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 | |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 21 | describe('factory: fw/remote/urlfn.js', function () { |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 22 | var $log, $loc, ufs, fs; |
| 23 | |
Simon Hunt | fa875bb | 2016-08-24 11:41:02 -0700 | [diff] [blame] | 24 | var protocol, host, port, context; |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 25 | |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 26 | beforeEach(module('onosRemote')); |
| 27 | |
| 28 | beforeEach(module(function($provide) { |
Simon Hunt | fa875bb | 2016-08-24 11:41:02 -0700 | [diff] [blame] | 29 | $provide.factory('$location', function () { |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 30 | return { |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 31 | protocol: function () { return protocol; }, |
| 32 | host: function () { return host; }, |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 33 | port: function () { return port; }, |
| 34 | search: function() { |
| 35 | return {debug: 'true'}; |
Simon Hunt | fa875bb | 2016-08-24 11:41:02 -0700 | [diff] [blame] | 36 | }, |
| 37 | absUrl: function () { |
| 38 | return protocol + '://' + host + ':' + port + |
| 39 | context + '/onos/ui/'; |
Matteo Scandolo | 231c754 | 2016-05-20 11:13:11 -0700 | [diff] [blame] | 40 | } |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 41 | }; |
Simon Hunt | fa875bb | 2016-08-24 11:41:02 -0700 | [diff] [blame] | 42 | }); |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 43 | })); |
| 44 | |
| 45 | beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) { |
| 46 | $log = _$log_; |
| 47 | $loc = $location; |
| 48 | ufs = UrlFnService; |
| 49 | fs = FnService; |
| 50 | })); |
| 51 | |
Simon Hunt | fa875bb | 2016-08-24 11:41:02 -0700 | [diff] [blame] | 52 | function setLoc(prot, h, p, ctx) { |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 53 | protocol = prot; |
| 54 | host = h; |
| 55 | port = p; |
Simon Hunt | fa875bb | 2016-08-24 11:41:02 -0700 | [diff] [blame] | 56 | context = ctx || ''; |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 59 | it('should define UrlFnService', function () { |
| 60 | expect(ufs).toBeDefined(); |
| 61 | }); |
| 62 | |
| 63 | it('should define api functions', function () { |
| 64 | expect(fs.areFunctions(ufs, [ |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 65 | 'rsUrl', 'wsUrl' |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 66 | ])).toBeTruthy(); |
| 67 | }); |
| 68 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 69 | 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 Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 81 | expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/websock/path'); |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 82 | }); |
| 83 | |
| 84 | it('should return the correct (wss) WS url', function () { |
| 85 | setLoc('https', 'foo', '123'); |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 86 | 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] | 87 | }); |
Simon Hunt | bb920fd | 2015-01-22 17:06:32 -0800 | [diff] [blame] | 88 | |
| 89 | it('should allow us to define an alternate WS port', function () { |
| 90 | setLoc('http', 'foo', '123'); |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 91 | 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] | 92 | }); |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 93 | |
| 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 Hunt | fa875bb | 2016-08-24 11:41:02 -0700 | [diff] [blame] | 98 | |
| 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 Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 103 | }); |