blob: ebcfba5c7cca5f1f27d4ab6116be7d8fbcd8ee7d [file] [log] [blame]
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -08001/*
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 Coleeb28b0b2015-01-15 14:20:58 -080019 */
20describe('factory: fw/remote/urlfn.js', function () {
21 var $log, $loc, ufs, fs;
22
Simon Hunt1e4a0012015-01-21 11:36:08 -080023 var protocol, host, port;
24
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080025 beforeEach(module('onosRemote'));
26
27 beforeEach(module(function($provide) {
28 $provide.factory('$location', function (){
29 return {
Simon Hunt1e4a0012015-01-21 11:36:08 -080030 protocol: function () { return protocol; },
31 host: function () { return host; },
32 port: function () { return port; }
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080033 };
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 Hunt1e4a0012015-01-21 11:36:08 -080044 function setLoc(prot, h, p) {
45 protocol = prot;
46 host = h;
47 port = p;
48 }
49
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080050 it('should define UrlFnService', function () {
51 expect(ufs).toBeDefined();
52 });
53
54 it('should define api functions', function () {
55 expect(fs.areFunctions(ufs, [
Simon Hunt1e4a0012015-01-21 11:36:08 -080056 'rsUrl', 'wsUrl'
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080057 ])).toBeTruthy();
58 });
59
Simon Hunt1e4a0012015-01-21 11:36:08 -080060 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');
Simon Hunt2d16fc82015-03-10 20:19:52 -070072 expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/websock/path');
Simon Hunt1e4a0012015-01-21 11:36:08 -080073 });
74
75 it('should return the correct (wss) WS url', function () {
76 setLoc('https', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070077 expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/websock/path');
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080078 });
Simon Huntbb920fd2015-01-22 17:06:32 -080079
80 it('should allow us to define an alternate WS port', function () {
81 setLoc('http', 'foo', '123');
Simon Hunt2d16fc82015-03-10 20:19:52 -070082 expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/websock/xyyzy');
Simon Huntbb920fd2015-01-22 17:06:32 -080083 });
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080084});