blob: 78c937e0271988c5f7b57dc34153ce8fb57fd248 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080019'use strict';
20
Matteo Scandoloff7df762016-01-22 16:36:34 -080021describe('The Service Relation Service', () => {
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080022
Matteo Scandoloff7df762016-01-22 16:36:34 -080023 var Service;
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080024
Matteo Scandolo930e4fd2016-03-07 16:41:25 -080025 beforeEach(module('xos.diagnostic'));
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080026 beforeEach(module('templates'));
27
Matteo Scandoloff7df762016-01-22 16:36:34 -080028 // inject the cartService
29 beforeEach(inject(function (_ServiceRelation_) {
30 // The injector unwraps the underscores (_) from around the parameter names when matching
31 Service = _ServiceRelation_;
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080032 }));
33
Matteo Scandoloff7df762016-01-22 16:36:34 -080034 describe('given a service', () => {
35
36 const levelRelations = [
37 {
38 subscriber_service: 1
39 },
40 {
41 subscriber_service: 1
42 },
43 {
44 subscriber_service: 2
45 }
46 ];
47
48 it('should find all involved relations', () => {
49 expect(typeof Service.findLevelRelation).toBe('function');
50 let levelRelation = Service.findLevelRelation(levelRelations, 1);
51 expect(levelRelation.length).toBe(2);
52 });
Matteo Scandolo8a64fa42016-01-21 11:21:03 -080053 });
54
Matteo Scandoloff7df762016-01-22 16:36:34 -080055 describe('given a set of relation', () => {
56
57 const levelRelations = [
58 {
Matteo Scandoloc9ebd922016-01-28 12:02:57 -080059 provider_service: 1,
60 service_specific_attribute: '{"instance_id": "instance1"}',
61 subscriber_tenant: 2
Matteo Scandoloff7df762016-01-22 16:36:34 -080062 },
63 {
64 provider_service: 2
65 }
66 ];
67
68 const services = [
69 {
70 id: 1
71 },
72 {
73 id: 2
74 },
75 {
76 id: 3
77 }
78 ];
79
80 it('should find all the provider service', () => {
81 expect(typeof Service.findLevelServices).toBe('function');
82 let levelServices = Service.findLevelServices(levelRelations, services);
83 expect(levelServices.length).toBe(2);
84 });
Matteo Scandoloc9ebd922016-01-28 12:02:57 -080085
86 it('should retrieve all service specific information', () => {
87 let info = Service.findSpecificInformation(levelRelations, 1);
88 expect(info.instance_id).toBe('instance1');
89 });
Matteo Scandoloff7df762016-01-22 16:36:34 -080090 });
91
Matteo Scandoloc9ebd922016-01-28 12:02:57 -080092
93
Matteo Scandoloff7df762016-01-22 16:36:34 -080094 describe('given a list of services and a list of relations', () => {
95
96 const services = [
97 {
98 id: 1,
99 humanReadableName: 'service-1'
100 },
101 {
102 id: 2,
103 humanReadableName: 'service-2'
104 },
105 {
106 id: 3,
107 humanReadableName: 'service-3'
108 },
109 {
110 id: 4,
111 humanReadableName: 'service-4'
112 }
113 ];
114
Matteo Scandolo012dddb2016-02-22 16:53:22 -0800115 const tenants = [
Matteo Scandoloff7df762016-01-22 16:36:34 -0800116 {
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800117 id: 1,
Matteo Scandoloff7df762016-01-22 16:36:34 -0800118 provider_service: 2,
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800119 subscriber_tenant: 4,
Matteo Scandoloff7df762016-01-22 16:36:34 -0800120 subscriber_service: 1,
121 },
122 {
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800123 id: 2,
Matteo Scandoloff7df762016-01-22 16:36:34 -0800124 provider_service: 3,
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800125 subscriber_tenant: 1,
Matteo Scandoloff7df762016-01-22 16:36:34 -0800126 subscriber_service: 2
127 },
128 {
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800129 id: 3,
Matteo Scandoloff7df762016-01-22 16:36:34 -0800130 provider_service: 4,
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800131 subscriber_tenant: 4,
Matteo Scandoloff7df762016-01-22 16:36:34 -0800132 subscriber_service: 1
133 },
134 {
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800135 id: 4,
Matteo Scandoloff7df762016-01-22 16:36:34 -0800136 subscriber_root: 1,
137 provider_service: 1
138 }
139 ];
140
Matteo Scandolo012dddb2016-02-22 16:53:22 -0800141 it('should return a tree ordered by tenants', () => {
142 let tree = Service.buildSubscriberServiceTree(services, tenants);
Matteo Scandoloff7df762016-01-22 16:36:34 -0800143
144 expect(tree.name).toBe('fakeSubs');
145 expect(tree.parent).toBeNull();
146 expect(tree.children.length).toBe(1);
147
148 expect(tree.children[0].name).toBe('service-1');
149 expect(tree.children[0].parent).toBeNull();
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800150 expect(tree.children[0].tenant).toEqual({id: 4, subscriber_root: 1, provider_service: 1});
Matteo Scandoloff7df762016-01-22 16:36:34 -0800151 expect(tree.children[0].children.length).toBe(2);
152
153 expect(tree.children[0].children[0].name).toBe('service-2');
Matteo Scandolo50eeec62016-02-23 10:04:36 -0800154 expect(tree.children[0].children[0].tenant).toEqual({ id: 1, provider_service: 2, subscriber_tenant: 4, subscriber_service: 1 });;
Matteo Scandoloff7df762016-01-22 16:36:34 -0800155 expect(tree.children[0].children[0].children[0].name).toBe('service-3');
Matteo Scandolo012dddb2016-02-22 16:53:22 -0800156
Matteo Scandolo930e4fd2016-03-07 16:41:25 -0800157 // expect(tree.children[0].children[0].children[0].children[0].name).toBe('Router');
Matteo Scandoloff7df762016-01-22 16:36:34 -0800158
159 expect(tree.children[0].children[1].name).toBe('service-4');
Matteo Scandolo930e4fd2016-03-07 16:41:25 -0800160 // expect(tree.children[0].children[1].children[0].name).toBe('Router');
Matteo Scandolof2c99012016-01-25 10:10:38 -0800161 });
162 });
163
164 describe('given an object', () => {
165
166 const sample = {
167 name: '1',
168 children: [
169 {
170 name: '2',
171 children: [
172 {
173 name: '3'
174 }
175 ]
176 }
177 ]
178 };
179
180 it('should return the depth', () => {
181 expect(Service.depthOf(sample)).toBe(3);
Matteo Scandoloff7df762016-01-22 16:36:34 -0800182 });
183 });
184
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800185 describe('Given a list of services and COARSE tenant', () => {
186
187 const coarseTenants = [
188 {
189 humanReadableName: 'coarse-1',
190 provider_service: 1,
191 subscriber_service: 2
192 },
193 {
194 humanReadableName: 'coarse-2',
195 provider_service: 2,
196 subscriber_service: 3
197 }
198 ];
199
200 const services = [
201 {
202 id: 1,
Matteo Scandolo45fba732016-02-22 14:53:44 -0800203 name: 'vbng',
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800204 humanReadableName: 'vbng'
205 },
206 {
207 id: 2,
Matteo Scandolo45fba732016-02-22 14:53:44 -0800208 name: 'vsg',
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800209 humanReadableName: 'vsg'
210 },
211 {
212 id: 3,
Matteo Scandolo45fba732016-02-22 14:53:44 -0800213 name: 'volt',
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800214 humanReadableName: 'volt'
215 }
216 ];
217
218 it('should build the tenancy graph', () => {
219 let tree = Service.buildServiceTree(services, coarseTenants);
220
221 expect(tree.type).toBe('subscriber');
Matteo Scandolo45fba732016-02-22 14:53:44 -0800222 expect(tree.children[0].name).toBe('volt');
223 expect(tree.children[0].service).toBeDefined();
224 expect(tree.children[0].children[0].name).toBe('vsg');
225 expect(tree.children[0].children[0].children[0].name).toBe('vbng');
Matteo Scandolo77d8fa02016-02-16 17:43:00 -0800226 });
227 });
228
Matteo Scandolo8a64fa42016-01-21 11:21:03 -0800229});