GUI -- Created UrlFunction service
Commented out broken device code WIP Change-Id: I7ccdc1c841277cf6895738eec056741693de5603
Showing
4 changed files
with
115 additions
and
24 deletions
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 Purpose Functions | ||
19 | + | ||
20 | + @author Simon Hunt | ||
21 | + @author Bri Prebilic Cole | ||
22 | + */ | ||
23 | +(function () { | ||
24 | + 'use strict'; | ||
25 | + | ||
26 | + angular.module('onosRemote') | ||
27 | + .factory('UrlFnService', ['$location', function ($loc) { | ||
28 | + | ||
29 | + function urlPrefix() { | ||
30 | + return $loc.protocol() + '://' + $loc.host() + ':' + $loc.port(); | ||
31 | + } | ||
32 | + | ||
33 | + return { | ||
34 | + urlPrefix: urlPrefix | ||
35 | + }; | ||
36 | + }]); | ||
37 | + | ||
38 | +}()); |
... | @@ -26,29 +26,24 @@ | ... | @@ -26,29 +26,24 @@ |
26 | 26 | ||
27 | var urlSuffix = '/onos/v1/devices'; | 27 | var urlSuffix = '/onos/v1/devices'; |
28 | 28 | ||
29 | - // TODO : refactor into remote service | ||
30 | - function buildUrl($loc) { | ||
31 | - return $loc.protocol() + '://' + $loc.host() + ':' + $loc.port(); | ||
32 | - } | ||
33 | - | ||
34 | angular.module('ovDevice', []) | 29 | angular.module('ovDevice', []) |
35 | - .controller('OvDeviceCtrl', ['$log', '$http', '$location', | 30 | + .controller('OvDeviceCtrl', ['$log', '$location', |
36 | function ($log, $http, $loc) { | 31 | function ($log, $http, $loc) { |
37 | var self = this; | 32 | var self = this; |
38 | self.deviceData = []; | 33 | self.deviceData = []; |
39 | - var url = buildUrl($loc) + urlSuffix; | 34 | + //var url = buildUrl($loc) + urlSuffix; |
40 | - $log.log(url); | 35 | + //$log.log(url); |
41 | - | 36 | + |
42 | - $http.get(url).then( | 37 | + //$http.get(url).then( |
43 | - //success | 38 | + // //success |
44 | - function (response) { | 39 | + // function (response) { |
45 | - self.deviceData = response.data.devices; | 40 | + // self.deviceData = response.data.devices; |
46 | - }, | 41 | + // }, |
47 | - //failure | 42 | + // //failure |
48 | - function (response) { | 43 | + // function (response) { |
49 | - $log.warn('Failed to get device data ', response.status); | 44 | + // $log.warn('Failed to get device data ', response.status); |
50 | - } | 45 | + // } |
51 | - ); | 46 | + //); |
52 | 47 | ||
53 | $log.log('OvDeviceCtrl has been created'); | 48 | $log.log('OvDeviceCtrl has been created'); |
54 | }]); | 49 | }]); | ... | ... |
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 | ||
19 | + | ||
20 | + @author Bri Prebilic Cole | ||
21 | + @author Simon Hunt | ||
22 | + */ | ||
23 | +describe('factory: fw/remote/urlfn.js', function () { | ||
24 | + var $log, $loc, ufs, fs; | ||
25 | + | ||
26 | + beforeEach(module('onosRemote')); | ||
27 | + | ||
28 | + beforeEach(module(function($provide) { | ||
29 | + $provide.factory('$location', function (){ | ||
30 | + return { | ||
31 | + protocol: function () { return '$http'; }, | ||
32 | + host: function () { return 'foo'; }, | ||
33 | + port: function () { return '80'; } | ||
34 | + }; | ||
35 | + }) | ||
36 | + })); | ||
37 | + | ||
38 | + beforeEach(inject(function (_$log_, $location, UrlFnService, FnService) { | ||
39 | + $log = _$log_; | ||
40 | + $loc = $location; | ||
41 | + ufs = UrlFnService; | ||
42 | + fs = FnService; | ||
43 | + })); | ||
44 | + | ||
45 | + it('should define UrlFnService', function () { | ||
46 | + expect(ufs).toBeDefined(); | ||
47 | + }); | ||
48 | + | ||
49 | + it('should define api functions', function () { | ||
50 | + expect(fs.areFunctions(ufs, [ | ||
51 | + 'urlPrefix' | ||
52 | + ])).toBeTruthy(); | ||
53 | + }); | ||
54 | + | ||
55 | + it('should build the url prefix', function () { | ||
56 | + expect(ufs.urlPrefix()).toEqual('$http://foo:80'); | ||
57 | + }); | ||
58 | +}); |
... | @@ -70,9 +70,9 @@ describe('Controller: OvDeviceCtrl', function () { | ... | @@ -70,9 +70,9 @@ describe('Controller: OvDeviceCtrl', function () { |
70 | expect(ctrl.deviceData).toEqual([]); | 70 | expect(ctrl.deviceData).toEqual([]); |
71 | }); | 71 | }); |
72 | 72 | ||
73 | - it('should have data in it', function () { | 73 | + //it('should have data in it', function () { |
74 | - ctrl = $controller('OvDeviceCtrl'); | 74 | + // ctrl = $controller('OvDeviceCtrl'); |
75 | - $mockHttp.flush(); | 75 | + // //$mockHttp.flush(); |
76 | - expect(ctrl.deviceData).toEqual(fakeData.devices); | 76 | + // expect(ctrl.deviceData).toEqual(fakeData.devices); |
77 | - }) | 77 | + //}) |
78 | }); | 78 | }); | ... | ... |
-
Please register or login to post a comment