3 * Copyright 2016 RIFT.IO Inc
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * Created by onvelocity on 2/8/16.
21 /*global describe, beforeEach, it, expect, xit, xdescribe */
24 import _
from 'lodash'
25 import DescriptorModelSerializer
from '../../../src/libraries/model/DescriptorModelSerializer'
26 import DescriptorModelFactory
from '../../../src/libraries/model/DescriptorModelFactory'
27 import SampleCatalogs
from 'json!../../../src/assets/ping-pong-catalog.json'
28 import TestCatalogs
from 'json!../../helpers/test-clean-input-output-model.json'
30 describe('DescriptorModelFactory', () => {
32 expect(DescriptorModelFactory
).toBeDefined();
34 describe('buildCatalogItemFactory', () => {
37 const nsdJson
= _
.cloneDeep(SampleCatalogs
[0].descriptors
[0]);
38 // the CatalogItemsStore adds the type to the uiState field when the catalog is loaded
39 nsdJson
.uiState
= {type
: 'nsd'};
40 // the user will open a catalog item by dbl clicking on it in the ui that is when we
41 // parse the item into a DescriptorModel class instance as follows....
42 const factory
= DescriptorModelFactory
.buildCatalogItemFactory(SampleCatalogs
);
43 // the result is a list of all the containers defined with then NSD JSON data
44 containers
= [nsdJson
].reduce(factory
, []);
46 it('ignores an empty object', () => {
47 const factory
= DescriptorModelFactory
.buildCatalogItemFactory([]);
48 const result
= [{}].reduce(factory
, []);
49 expect(result
).toEqual([]);
51 it('parses an NSD object', () => {
52 const nsdJson
= _
.cloneDeep(SampleCatalogs
[0].descriptors
[0]);
53 nsdJson
.uiState
= {type
: 'nsd'};
54 const factory
= DescriptorModelFactory
.buildCatalogItemFactory(SampleCatalogs
);
55 const result
= [nsdJson
].reduce(factory
, [])[0];
56 expect(result
.id
).toEqual('ba1dfbcc-626b-11e5-998d-6cb3113b406f');
58 it('parses the constituent-vnfd classes', () => {
59 const nsd
= containers
[0];
60 const cvnfd
= containers
.filter(d
=> DescriptorModelFactory
.isConstituentVnfd(d
));
61 expect(nsd
.constituentVnfd
).toEqual(cvnfd
);
63 describe('ConstituentVnfd', () => {
64 it('connection-points derive from referenced VNFD', () => {
65 const constituentVNFDs
= containers
.filter(d
=> DescriptorModelFactory
.isConstituentVnfd(d
)).map(d
=> d
.vnfdId
);
66 expect(constituentVNFDs
).toEqual(['ba145e82-626b-11e5-998d-6cb3113b406f', 'ba1947da-626b-11e5-998d-6cb3113b406f']);
69 describe('DescriptorModelSerializer', () => {
70 it('outputs the same JSON that was parsed by the .buildCatalogItemFactory method', () => {
71 const inputJSON
= _
.cloneDeep(TestCatalogs
[0].descriptors
[0]);
72 inputJSON
.uiState
= {type
: 'nsd'};
73 const factory
= DescriptorModelFactory
.buildCatalogItemFactory(TestCatalogs
);
74 const parsedModel
= [inputJSON
].reduce(factory
, []);
75 const serialized
= DescriptorModelSerializer
.serialize(parsedModel
[0].model
);
76 const expectedSerializedString
= '{"id":"ba1dfbcc-626b-11e5-998d-6cb3113b406f","name":"ping-pong-nsd","short-name":"ping-pong-nsd","vendor":"RIFT.io","logo":"rift.png","description":"Toy NS","version":"1.0","connection-point":[{"name":"ping-pong-nsd/cp0"},{"name":"ping-pong-nsd/cp1"}],"vld":[{"id":"ba1c03a8-626b-11e5-998d-6cb3113b406f","name":"ping-pong-vld","short-name":"ping-pong-vld","vendor":"RIFT.io","description":"Toy VL","version":"1.0","type":"ELAN","vnfd-connection-point-ref":[{"member-vnf-index-ref":1,"vnfd-id-ref":"ba145e82-626b-11e5-998d-6cb3113b406f","vnfd-connection-point-ref":"ping-vnfd/cp1"},{"member-vnf-index-ref":2,"vnfd-id-ref":"ba1947da-626b-11e5-998d-6cb3113b406f","vnfd-connection-point-ref":"pong-vnfd/cp1"}],"provider-network":{"name":"physnet1","overlay-type":"VLAN"}}],"constituent-vnfd":[{"member-vnf-index":1,"vnfd-id-ref":"ba145e82-626b-11e5-998d-6cb3113b406f"},{"member-vnf-index":2,"vnfd-id-ref":"ba1947da-626b-11e5-998d-6cb3113b406f"}],"vnffgd":[{"id":"1d6382bb-52fa-43b6-9489-d764a0a27da9","name":"vnffgd-5","short-name":"FG-1","rsp":[{"id":"a10b372d-19a1-4d84-a246-82bfceddae12","name":"rsp-6","vnfd-connection-point-ref":[{"vnfd-id-ref":"ba145e82-626b-11e5-998d-6cb3113b406f","member-vnf-index-ref":1,"vnfd-connection-point-ref":"ping-vnfd/cp1"},{"vnfd-id-ref":"ba1947da-626b-11e5-998d-6cb3113b406f","member-vnf-index-ref":2,"vnfd-connection-point-ref":"pong-vnfd/cp0"}]}],"classifier":[{"id":"1-a5b8-45b5-8163-f2577555d561","name":"classifier-1","rsp-id-ref":"a10b372d-19a1-4d84-a246-82bfceddae12","match-attributes":[{"id":"1","ip-proto":"123.0.0.1","source-ip-address":"10.4.0.1","destination-ip-address":"10.4.0.2","source-port":"1234","destination-port":"4321"}]},{"id":"2-a5b8-45b5-8163-f2577555d561","name":"classifier-2","rsp-id-ref":"a10b372d-19a1-4d84-a246-82bfceddae12","match-attributes":[{"id":"1","ip-proto":"123.0.0.1","source-ip-address":"10.4.0.1","destination-ip-address":"10.4.0.2","source-port":"1234","destination-port":"4321"}]},{"id":"3-a5b8-45b5-8163-f2577555d561","name":"classifier-3","rsp-id-ref":"a10b372d-19a1-4d84-a246-82bfceddae12","match-attributes":[{"id":"1","ip-proto":"123.0.0.1","source-ip-address":"10.4.0.1","destination-ip-address":"10.4.0.2","source-port":"1234","destination-port":"4321"}]},{"id":"4-a5b8-45b5-8163-f2577555d561","name":"classifier-4","rsp-id-ref":"a10b372d-19a1-4d84-a246-82bfceddae12","match-attributes":[{"id":"1","ip-proto":"123.0.0.1","source-ip-address":"10.4.0.1","destination-ip-address":"10.4.0.2","source-port":"1234","destination-port":"4321"}]}]}]}';
77 const result
= JSON
.stringify(serialized
);
78 expect(expectedSerializedString
).toEqual(result
);