summaryrefslogtreecommitdiffstats
path: root/src/app/vnfs/build-artifacts/parameter-definitions/parameter-definition.service.spec.ts
blob: 8a9c1126f9b5d200a17266de9bf72b47a400c6ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
============LICENSE_START==========================================
===================================================================
Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
===================================================================

Unless otherwise specified, all software contained herein is licensed
under the Apache License, Version 2.0 (the License);
you may not use this software except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

ECOMP is a trademark and service mark of AT&T Intellectual Property.
============LICENSE_END============================================
*/


/* tslint:disable:no-unused-variable */

import {inject, TestBed} from '@angular/core/testing';
import {ParameterDefinitionService} from './parameter-definition.service';
import {NotificationsService} from 'angular2-notifications';
import {MappingEditorService} from '../../../shared/services/mapping-editor.service';
import {HttpUtilService} from '../../../shared/services/httpUtil/http-util.service';
import {UtilityService} from '../../../shared/services/utilityService/utility.service';
import {ParamShareService} from '../../../shared/services/paramShare.service';


class MockService {
    doStuff() {
        return this;
    }
}

describe('ParameterDefinitionService', () => {
    beforeEach(() => {
        let httpUtilService = new MockService();
        TestBed.configureTestingModule({
            providers: [ParameterDefinitionService, NotificationsService, MappingEditorService, ParamShareService, HttpUtilService, UtilityService,
                {provide: HttpUtilService, useValue: httpUtilService}]
        });
    });

    it('should create a service...', inject([ParameterDefinitionService], (service: ParameterDefinitionService) => {
        expect(service).toBeTruthy();
    }));

    it('should remove unwanted values from PD object...', inject([ParameterDefinitionService], (service: ParameterDefinitionService) => {
        let obj = {
            'vnf-parameter-list': [{
                'ruleTypeValues': 'ruleTypeValues',
                'showFilterFields': 'showFilterFields',
                'enableFilterByValue': 'enableFilterByValue'
            }]
        };

        expect(service.removeUnwantedvalues(obj)).toEqual({'vnf-parameter-list': [{}]});
    }));


    it('populateDataUponSource...', inject([ParameterDefinitionService], (service: ParameterDefinitionService) => {
        let obj = [{'source': 'A&AI', 'ruleType': 'vm-name-list'}];

        expect(service.populateDataUponSource(obj));
    }));

    it('populateDataUponSource...', inject([ParameterDefinitionService], (service: ParameterDefinitionService) => {
        let obj = [{'source': 'Manual', 'ruleType': 'vm-name-list'}];

        expect(service.populateDataUponSource(obj));
    }));

    it('populateDataUponSource...', inject([ParameterDefinitionService], (service: ParameterDefinitionService) => {
        let obj = [{'source': 'Something', 'ruleType': 'vm-name-list'}];

        expect(service.populateDataUponSource(obj));
    }));


    it('populateDataUponSource...', inject([ParameterDefinitionService], (service: ParameterDefinitionService) => {
        let obj = [{'source': 'Something', 'ruleType': 'vm-name-list'}];

        expect(service.populatePD(obj));
    }));

    it('processPDfile...', inject([ParameterDefinitionService], (service: ParameterDefinitionService)=> {
        let yaml = "---\nkind: Property Definition\nversion: V1\nvnf-parameter-list:\n- name: LICENSE_KEY\n  type: null\n  description: null\n  required: null\n  default: null\n  source: Manual\n  rule-type: null\n  request-keys: null\n  response-keys: null";
        let expectedPD = [{"name":"LICENSE_KEY","type":null,"description":null,"required":null,"default":null,"source":"Manual","rule-type":null,
        "request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null
        ,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}];
        
        expect(service.processPDfile("testfile.yaml", yaml)).toEqual(expectedPD);

    }));

    // it('processKeyFile...', inject([ParameterDefinitionService, ParamShareService], (service: ParameterDefinitionService, paramShareService: ParamShareService)=> {
    //     let keyFile = "PARAMVALUE|SOURCE|RULETYPE|KEY1|VALUE1|KEY2|VALUE2|KEY3|VALUE3\nvalue1|INSTAR|interface_ip_address|UniqueKeyName1|addressfqdn123|UniqueKeyValue|m001ssc001p1n001v001|FieldKeyName|ipaddress_v4\nvalue2|INSTAR|interface_ip_address|UniqueKeyName2|addressfqdnAsgar1|UniqueKeyValue|m001ssc001p1n001v002|FieldKeyName|ipaddress_v4";
    //     let expectedPD = [{"name":"name1","type":null,"description":null,"required":null,"default":null,"source":"Manual","rule-type":null,
    //     "request-keys":[{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"response-keys":[{"key-name":null
    //     ,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null},{"key-name":null,"key-value":null}],"ruleTypeValues":[null]}];
    //     localStorage['paramsContent'] = "{ \"name1\":\"value1\",\"name2\":\"value2\"}";
    //     paramShareService.setSessionParamData(expectedPD)
    //     expect(service.processKeyFile("testfile.txt", keyFile)).toEqual(expectedPD);

    // }));

});