Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
| 20 | describe('factory: fw/remote/urlfn.js', function () { |
| 21 | var $log, $loc, ufs, fs; |
| 22 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 23 | var protocol, host, port; |
| 24 | |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 25 | beforeEach(module('onosRemote')); |
| 26 | |
| 27 | beforeEach(module(function($provide) { |
| 28 | $provide.factory('$location', function (){ |
| 29 | return { |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 30 | protocol: function () { return protocol; }, |
| 31 | host: function () { return host; }, |
| 32 | port: function () { return port; } |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 33 | }; |
| 34 | }) |
| 35 | })); |
| 36 | |
| 37 | beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) { |
| 38 | $log = _$log_; |
| 39 | $loc = $location; |
| 40 | ufs = UrlFnService; |
| 41 | fs = FnService; |
| 42 | })); |
| 43 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 44 | function setLoc(prot, h, p) { |
| 45 | protocol = prot; |
| 46 | host = h; |
| 47 | port = p; |
| 48 | } |
| 49 | |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 50 | it('should define UrlFnService', function () { |
| 51 | expect(ufs).toBeDefined(); |
| 52 | }); |
| 53 | |
| 54 | it('should define api functions', function () { |
| 55 | expect(fs.areFunctions(ufs, [ |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 56 | 'rsUrl', 'wsUrl' |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 57 | ])).toBeTruthy(); |
| 58 | }); |
| 59 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 60 | it('should return the correct (http) RS url', function () { |
| 61 | setLoc('http', 'foo', '123'); |
| 62 | expect(ufs.rsUrl('path')).toEqual('http://foo:123/onos/ui/rs/path'); |
| 63 | }); |
| 64 | |
| 65 | it('should return the correct (https) RS url', function () { |
| 66 | setLoc('https', 'foo', '123'); |
| 67 | expect(ufs.rsUrl('path')).toEqual('https://foo:123/onos/ui/rs/path'); |
| 68 | }); |
| 69 | |
| 70 | it('should return the correct (ws) WS url', function () { |
| 71 | setLoc('http', 'foo', '123'); |
| 72 | expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/ws/path'); |
| 73 | }); |
| 74 | |
| 75 | it('should return the correct (wss) WS url', function () { |
| 76 | setLoc('https', 'foo', '123'); |
| 77 | expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/ws/path'); |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 78 | }); |
Simon Hunt | bb920fd | 2015-01-22 17:06:32 -0800 | [diff] [blame] | 79 | |
| 80 | it('should allow us to define an alternate WS port', function () { |
| 81 | setLoc('http', 'foo', '123'); |
| 82 | expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/ws/xyyzy'); |
| 83 | }); |
Bri Prebilic Cole | eb28b0b | 2015-01-15 14:20:58 -0800 | [diff] [blame] | 84 | }); |