aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote')
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js97
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js89
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js268
-rw-r--r--framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js78
4 files changed, 0 insertions, 532 deletions
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js
deleted file mode 100644
index 55e22782..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/rest-spec.js
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Remote -- REST Service - Unit Tests
- */
-describe('factory: fw/remote/rest.js', function() {
- var $log, $httpBackend, fs, rs, promise;
-
- beforeEach(module('onosUtil', 'onosRemote'));
-
- beforeEach(module(function($provide) {
- $provide.factory('$location', function (){
- return {
- protocol: function () { return 'http'; },
- host: function () { return 'foo'; },
- port: function () { return '80'; }
- };
- })
- }));
-
- beforeEach(inject(function (_$log_, _$httpBackend_, FnService, RestService) {
- $log = _$log_;
- $httpBackend = _$httpBackend_;
- fs = FnService;
- rs = RestService;
- }));
-
- it('should define RestService', function () {
- expect(rs).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(rs, [
- 'get'
- ])).toBeTruthy();
- });
-
- var mockData = {
- id: 1,
- prop: 'abc'
- };
-
- it('should fetch remote data', function () {
- var called = 0,
- capture = null;
- $httpBackend.whenGET(/.*/).respond(mockData);
- spyOn($log, 'warn');
-
- rs.get('bar', function (data) {
- called++;
- capture = data;
- });
-
- expect(called).toEqual(0);
- expect(capture).toBeNull();
- $httpBackend.flush();
- expect(called).toEqual(1);
- expect(capture).toEqual(mockData);
- expect($log.warn).not.toHaveBeenCalled();
- });
-
- it('should fail to fetch remote data', function () {
- var called = 0,
- capture = null;
- $httpBackend.whenGET(/.*/).respond(404, 'Not Found');
- spyOn($log, 'warn');
-
- rs.get('bar', function (data) {
- called++;
- capture = data;
- });
-
- expect(called).toEqual(0);
- expect(capture).toBeNull();
- $httpBackend.flush();
- expect(called).toEqual(0);
- expect(capture).toBeNull();
- expect($log.warn).toHaveBeenCalledWith(
- 'Failed to retrieve JSON data: http://foo:80/onos/ui/rs/bar',
- 404, 'Not Found');
- });
-
-});
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js
deleted file mode 100644
index eddbf8b2..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/urlfn-spec.js
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Remote -- General Functions - Unit Tests
- */
-describe('factory: fw/remote/urlfn.js', function () {
- var $log, $loc, ufs, fs;
-
- var protocol, host, port;
-
- beforeEach(module('onosRemote'));
-
- beforeEach(module(function($provide) {
- $provide.factory('$location', function (){
- return {
- protocol: function () { return protocol; },
- host: function () { return host; },
- port: function () { return port; }
- };
- })
- }));
-
- beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) {
- $log = _$log_;
- $loc = $location;
- ufs = UrlFnService;
- fs = FnService;
- }));
-
- function setLoc(prot, h, p) {
- protocol = prot;
- host = h;
- port = p;
- }
-
- it('should define UrlFnService', function () {
- expect(ufs).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(ufs, [
- 'rsUrl', 'wsUrl'
- ])).toBeTruthy();
- });
-
- it('should return the correct (http) RS url', function () {
- setLoc('http', 'foo', '123');
- expect(ufs.rsUrl('path')).toEqual('http://foo:123/onos/ui/rs/path');
- });
-
- it('should return the correct (https) RS url', function () {
- setLoc('https', 'foo', '123');
- expect(ufs.rsUrl('path')).toEqual('https://foo:123/onos/ui/rs/path');
- });
-
- it('should return the correct (ws) WS url', function () {
- setLoc('http', 'foo', '123');
- expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/websock/path');
- });
-
- it('should return the correct (wss) WS url', function () {
- setLoc('https', 'foo', '123');
- expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/websock/path');
- });
-
- it('should allow us to define an alternate WS port', function () {
- setLoc('http', 'foo', '123');
- expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/websock/xyyzy');
- });
-
- it('should allow us to define an alternate host', function () {
- setLoc('http', 'foo', '123');
- expect(ufs.wsUrl('core', 456, 'bar')).toEqual('ws://bar:456/onos/ui/websock/core');
- });
-});
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js
deleted file mode 100644
index 9673f16e..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/websocket-spec.js
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Remote -- Web Socket Service - Unit Tests
- */
-describe('factory: fw/remote/websocket.js', function () {
- var $log, fs, wss;
-
- var noop = function () {},
- send = jasmine.createSpy('send').and.callFake(function (ev) {
- return ev;
- }),
- mockWebSocket = {
- send: send
- };
-
- beforeEach(module('onosRemote', 'onosLayer', 'ngRoute', 'onosNav', 'onosSvg'));
-
- beforeEach(function () {
- mockWebSocket = {
- send: send
- };
- });
-
- beforeEach(function () {
- module(function ($provide) {
- $provide.factory('WSock', function () {
- return {
- newWebSocket: function () {
- return mockWebSocket;
- }
- };
- });
- });
- });
-
- beforeEach(module(function($provide) {
- $provide.factory('$location', function () {
- return {
- protocol: function () { return 'http'; },
- host: function () { return 'foo'; },
- port: function () { return '80'; }
- };
- })
- }));
-
- beforeEach(inject(function (_$log_, FnService, WebSocketService) {
- $log = _$log_;
- fs = FnService;
- wss = WebSocketService;
- wss.resetState();
- }));
-
-
- it('should define WebSocketService', function () {
- expect(wss).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(wss, [
- 'resetSid', 'resetState',
- 'createWebSocket', 'bindHandlers', 'unbindHandlers',
- 'addOpenListener', 'removeOpenListener', 'sendEvent'
- ])).toBeTruthy();
- });
-
- it('should use the appropriate URL, createWebsocket', function () {
- var url = wss.createWebSocket();
- expect(url).toEqual('ws://foo:80/onos/ui/websock/core');
- });
-
- it('should use the appropriate URL with modified port, createWebsocket',
- function () {
- var url = wss.createWebSocket({ wsport: 1243 });
- expect(url).toEqual('ws://foo:1243/onos/ui/websock/core');
- });
-
- it('should verify websocket event handlers, createWebsocket', function () {
- wss.createWebSocket({ wsport: 1234 });
- expect(fs.isF(mockWebSocket.onopen)).toBeTruthy();
- expect(fs.isF(mockWebSocket.onmessage)).toBeTruthy();
- expect(fs.isF(mockWebSocket.onclose)).toBeTruthy();
- });
-
- it('should invoke listener callbacks when websocket is up, handleOpen',
- function () {
- var num = 0;
- function incrementNum() { num++; }
- wss.addOpenListener(incrementNum);
- wss.createWebSocket({ wsport: 1234 });
- mockWebSocket.onopen();
- expect(num).toBe(1);
- });
-
- it('should send pending events, handleOpen', function () {
- var fakeEvent = {
- event: 'mockEv',
- sid: 1,
- payload: { mock: 'thing' }
- };
- wss.sendEvent(fakeEvent.event, fakeEvent.payload);
- expect(mockWebSocket.send).not.toHaveBeenCalled();
- wss.createWebSocket({ wsport: 1234 });
- mockWebSocket.onopen();
- expect(mockWebSocket.send).toHaveBeenCalledWith(JSON.stringify(fakeEvent));
- });
-
- it('should handle an incoming bad JSON message, handleMessage', function () {
- spyOn($log, 'error');
- var badMsg = {
- data: 'bad message'
- };
- wss.createWebSocket({ wsport: 1234 });
- expect(mockWebSocket.onmessage(badMsg)).toBeNull();
- expect($log.error).toHaveBeenCalled();
- });
-
- it('should verify message was handled, handleMessage', function () {
- var num = 0,
- fakeHandler = {
- mockEvResp: function () { num++; }
- },
- data = JSON.stringify({
- event: 'mockEvResp',
- payload: {}
- }),
- event = {
- data: data
- };
- wss.createWebSocket({ wsport: 1234 });
- wss.bindHandlers(fakeHandler);
- expect(mockWebSocket.onmessage(event)).toBe(undefined);
- expect(num).toBe(1);
- });
-
- it('should warn if there is an unhandled event, handleMessage', function () {
- spyOn($log, 'warn');
- var data = { foo: 'bar', bar: 'baz'},
- dataString = JSON.stringify(data),
- badEv = {
- data: dataString
- };
- wss.createWebSocket({ wsport: 1234 });
- mockWebSocket.onmessage(badEv);
- expect($log.warn).toHaveBeenCalledWith('Unhandled event:', data);
- });
-
- it('should not warn if valid input, bindHandlers', function () {
- spyOn($log, 'warn');
- expect(wss.bindHandlers({
- foo: noop,
- bar: noop
- })).toBe(undefined);
- expect($log.warn).not.toHaveBeenCalled();
- });
-
- it('should warn if no arguments, bindHandlers', function () {
- spyOn($log, 'warn');
- expect(wss.bindHandlers()).toBeNull();
- expect($log.warn).toHaveBeenCalledWith(
- 'WSS.bindHandlers(): no event handlers'
- );
- expect(wss.bindHandlers({})).toBeNull();
- expect($log.warn).toHaveBeenCalledWith(
- 'WSS.bindHandlers(): no event handlers'
- );
- });
-
- it('should warn if handler is not a function, bindHandlers', function () {
- spyOn($log, 'warn');
- expect(wss.bindHandlers({
- foo: 'handler1',
- bar: 3,
- baz: noop
- })).toBe(undefined);
- expect($log.warn).toHaveBeenCalledWith('foo handler not a function');
- expect($log.warn).toHaveBeenCalledWith('bar handler not a function');
- });
-
- it('should warn if duplicate handlers were given, bindHandlers',
- function () {
- spyOn($log, 'warn');
- wss.bindHandlers({
- foo: noop
- });
- expect(wss.bindHandlers({
- foo: noop
- })).toBe(undefined);
- expect($log.warn).toHaveBeenCalledWith('duplicate bindings ignored:',
- ['foo']);
- });
-
- it('should warn if no arguments, unbindHandlers', function () {
- spyOn($log, 'warn');
- expect(wss.unbindHandlers()).toBeNull();
- expect($log.warn).toHaveBeenCalledWith(
- 'WSS.unbindHandlers(): no event handlers'
- );
- expect(wss.unbindHandlers({})).toBeNull();
- expect($log.warn).toHaveBeenCalledWith(
- 'WSS.unbindHandlers(): no event handlers'
- );
- });
- // Note: cannot test unbindHandlers' forEach due to it using closure variable
-
- it('should not warn if valid argument, addOpenListener', function () {
- spyOn($log, 'warn');
- var o = wss.addOpenListener(noop);
- expect(o.id === 1);
- expect(o.cb === noop);
- expect($log.warn).not.toHaveBeenCalled();
- o = wss.addOpenListener(noop);
- expect(o.id === 2);
- expect(o.cb === noop);
- expect($log.warn).not.toHaveBeenCalled();
- });
-
- it('should log error if callback not a function, addOpenListener',
- function () {
- spyOn($log, 'error');
- var o = wss.addOpenListener('foo');
- expect(o.id === 1);
- expect(o.cb === 'foo');
- expect(o.error === 'No callback defined');
- expect($log.error).toHaveBeenCalledWith(
- 'WSS.addOpenListener(): callback not a function'
- );
- });
-
- it('should not warn if valid listener object, removeOpenListener', function () {
- spyOn($log, 'warn');
- expect(wss.removeOpenListener({
- id: 1,
- cb: noop
- })).toBe(undefined);
- expect($log.warn).not.toHaveBeenCalled();
- });
-
- it('should warn if listener is invalid, removeOpenListener', function () {
- spyOn($log, 'warn');
- expect(wss.removeOpenListener({})).toBeNull();
- expect($log.warn).toHaveBeenCalledWith(
- 'WSS.removeOpenListener(): invalid listener', {}
- );
- expect(wss.removeOpenListener('listener')).toBeNull();
- expect($log.warn).toHaveBeenCalledWith(
- 'WSS.removeOpenListener(): invalid listener', 'listener'
- );
- });
-
- // Note: handleClose is not currently tested due to all work it does relies
- // on closure variables that cannot be mocked
-
-});
diff --git a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js b/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js
deleted file mode 100644
index 23d3153f..00000000
--- a/framework/src/onos/web/gui/src/main/webapp/tests/app/fw/remote/wsevent-spec.js
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- ONOS GUI -- Remote -- Web Socket Event Service - Unit Tests
- */
-describe('factory: fw/remote/wsevent.js', function () {
- var $log, fs, wse;
-
- beforeEach(module('onosRemote'));
-
- beforeEach(inject(function (_$log_, FnService, WsEventService) {
- $log = _$log_;
- fs = FnService;
- wse = WsEventService;
- wse.resetSid();
- }));
-
-
- it('should define WsEventService', function () {
- expect(wse).toBeDefined();
- });
-
- it('should define api functions', function () {
- expect(fs.areFunctions(wse, [
- 'sendEvent', 'resetSid'
- ])).toBeTruthy();
- });
-
- var event,
- fakeWs = {
- send: function (ev) {
- event = ev;
- }
- };
-
- it('should construct an event object with no payload', function () {
- wse.sendEvent(fakeWs, 'foo');
- expect(event.event).toEqual('foo');
- expect(event.sid).toEqual(1);
- expect(event.payload).toEqual({});
- });
-
- it('should construct an event object with some payload', function () {
- wse.sendEvent(fakeWs, 'bar', { val: 42 });
- expect(event.event).toEqual('bar');
- expect(event.sid).toEqual(1);
- expect(event.payload).toEqual({ val: 42 });
- });
-
- it('should increment the sid', function () {
- wse.sendEvent(fakeWs, 'one');
- expect(event.event).toEqual('one');
- expect(event.sid).toEqual(1);
-
- wse.sendEvent(fakeWs, 'dos');
- expect(event.event).toEqual('dos');
- expect(event.sid).toEqual(2);
-
- wse.sendEvent(fakeWs, 'tres');
- expect(event.event).toEqual('tres');
- expect(event.sid).toEqual(3);
- });
-
-});