Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | ba678a9 | 2016-06-20 17:16:15 -0700 | [diff] [blame] | 19 | /** |
| 20 | * © OpenCORD |
| 21 | * |
| 22 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 23 | * |
| 24 | * Created by teone on 6/22/16. |
| 25 | */ |
| 26 | |
| 27 | (function () { |
| 28 | 'use strict'; |
| 29 | |
| 30 | describe('The Slices Encoder service', () => { |
| 31 | |
| 32 | let service, toscaBase, sliceQueryPromise, SliceSpy, rootScope; |
| 33 | |
| 34 | const toscaBaseDefault = { |
| 35 | topology_template: { |
| 36 | node_templates: {} |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | const slicesArray = [ |
| 41 | { |
| 42 | name: 'Slice1', |
| 43 | description: 'Description1', |
| 44 | network: 'noauto' |
| 45 | }, |
| 46 | { |
| 47 | name: 'Slice2', |
| 48 | description: 'Description2', |
| 49 | network: 'noauto' |
| 50 | } |
| 51 | ]; |
| 52 | |
| 53 | const expected = { |
| 54 | topology_template: { |
| 55 | node_templates: { |
| 56 | Slice1: { |
| 57 | description: 'Description1', |
| 58 | type: 'tosca.nodes.Slice', |
| 59 | properties: { |
| 60 | network: 'noauto' |
| 61 | }, |
| 62 | requirements: [ |
| 63 | {management: {node: 'management', relationship: 'tosca.relationships.ConnectsToNetwork'}}, |
| 64 | {test_service: {node: 'service#test', relationship: 'tosca.relationships.MemberOfService'}} |
| 65 | ] |
| 66 | }, |
| 67 | Slice2: { |
| 68 | description: 'Description2', |
| 69 | type: 'tosca.nodes.Slice', |
| 70 | properties: { |
| 71 | network: 'noauto' |
| 72 | }, |
| 73 | requirements: [ |
| 74 | {management: {node: 'management', relationship: 'tosca.relationships.ConnectsToNetwork'}}, |
| 75 | {test_service: {node: 'service#test', relationship: 'tosca.relationships.MemberOfService'}} |
| 76 | ] |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | beforeEach(module('xos.serviceGrid')); |
| 83 | beforeEach(module('templates')); |
| 84 | |
| 85 | beforeEach(inject((SlicesEncoder, Slices, $q, $rootScope) => { |
| 86 | toscaBase = angular.copy(toscaBaseDefault); |
| 87 | service = SlicesEncoder; |
| 88 | rootScope = $rootScope; |
| 89 | |
| 90 | sliceQueryPromise= $q.defer(); |
| 91 | SliceSpy = Slices; |
| 92 | spyOn(SliceSpy, 'query').and.callFake(function(){ |
| 93 | return {$promise: sliceQueryPromise.promise}; |
| 94 | }); |
| 95 | })); |
| 96 | |
| 97 | describe('given a Slices array ', () => { |
| 98 | it('should return the correct JSON structure', (done) => { |
| 99 | service.buildTosca(slicesArray, toscaBase, 'test') |
| 100 | .then(res => { |
| 101 | expect(res).toEqual(expected); |
| 102 | done(); |
| 103 | }); |
| 104 | rootScope.$apply(); |
| 105 | }); |
| 106 | }); |
| 107 | |
| 108 | describe('given a service', () => { |
| 109 | it('should return the JSON structure for all related slices', (done) => { |
| 110 | service.getServiceSlices({id : 1, name: 'test'}, toscaBase) |
| 111 | .then(res => { |
| 112 | expect(res).toEqual(expected); |
| 113 | done(); |
| 114 | }); |
| 115 | sliceQueryPromise.resolve(slicesArray); |
| 116 | rootScope.$apply(); |
| 117 | }); |
| 118 | }); |
| 119 | }); |
| 120 | })(); |
| 121 | |