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