blob: 0e1d1ff0587db46e149e9184413b2665c0a21697 [file] [log] [blame]
Skip Wonnell2c977e22018-03-01 08:30:15 -06001/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
Arundathi Patilb1f449e2018-07-24 16:53:55 +05305
6Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
Skip Wonnell2c977e22018-03-01 08:30:15 -06007===================================================================
8
9Unless otherwise specified, all software contained herein is licensed
10under the Apache License, Version 2.0 (the License);
11you may not use this software except in compliance with the License.
12You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing, software
17distributed under the License is distributed on an "AS IS" BASIS,
18WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19See the License for the specific language governing permissions and
20limitations under the License.
21
22ECOMP is a trademark and service mark of AT&T Intellectual Property.
23============LICENSE_END============================================
24*/
25
26/* tslint:disable:no-unused-variable */
27import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
28import { NO_ERRORS_SCHEMA, Output } from '@angular/core';
29import { MyvnfsComponent } from './myvnfs.component';
30import { FormsModule } from '@angular/forms';
31import { NotificationService } from './../../shared/services/notification.service';
32import { ParamShareService } from './../../shared/services/paramShare.service';
33import { MappingEditorService } from './../../shared/services/mapping-editor.service';
34import { DialogService } from 'ng2-bootstrap-modal';
35import { RouterTestingModule } from '@angular/router/testing';
36import { HttpUtilService } from '.././../shared/services/httpUtil/http-util.service';
37import { UtilityService } from '.././../shared/services/utilityService/utility.service';
38// import{TableFilterPipe} from '.././../shared/modules/tidy-table/table-filter.pipe';
39import { TidyTableModule } from '../../shared/modules/tidy-table/tidy-table.module';
40import { NgModule } from '@angular/core';
41import { NgProgress } from 'ngx-progressbar';
Arundathi Patilb1f449e2018-07-24 16:53:55 +053042import { NotificationsService } from 'angular2-notifications';
Skip Wonnell2c977e22018-03-01 08:30:15 -060043
44import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
45import {
46 HttpModule,
47 Http,
48 Response,
49 ResponseOptions,
50 XHRBackend
51} from '@angular/http';
52
53import { MockBackend } from '@angular/http/testing';
54describe('MyvnfsComponent', () => {
55 let component: MyvnfsComponent;
56 let fixture: ComponentFixture<MyvnfsComponent>;
57
58 beforeEach(async(() => {
59 TestBed.configureTestingModule({
60 declarations: [MyvnfsComponent],
61 schemas: [NO_ERRORS_SCHEMA],
62 imports: [FormsModule, RouterTestingModule, TidyTableModule, HttpModule, NgbModule.forRoot()],
63 providers: [
64
65 { provide: XHRBackend, useClass: MockBackend },
Arundathi Patilb1f449e2018-07-24 16:53:55 +053066 NgProgress, UtilityService, ParamShareService, DialogService, NotificationService, HttpUtilService, MappingEditorService, NotificationsService]
Skip Wonnell2c977e22018-03-01 08:30:15 -060067
68 })
69 .compileComponents();
70 }));
71
72 beforeEach(() => {
73
74 fixture = TestBed.createComponent(MyvnfsComponent);
75 component = fixture.componentInstance;
76 fixture.detectChanges();
77 });
78
79 it('should create myvnfscomponent', () => {
80 expect(component).toBeTruthy();
81 });
82 it('Post call to get artifact', inject([HttpUtilService, XHRBackend], (httpUtilService, mockBackend) => {
83
84 const mockResponse = {
85 "output": {
86 "data": {
87 "block": "{\"userID\":\"ug0221\",\"designInfo\":[{\"vnf-type\":\"demo123\",\"vnfc-type\":\"null\",\"protocol\":\"\",\"incart\":\"N\",\"action\":\"AllAction\",\"artifact-name\":\"reference_AllAction_demo123_0.0.1V.json\",\"artifact-type\":\"APPC-CONFIG\"}],\"statusInfo\":null,\"artifactInfo\":null}",
88 "status":{
89 "code": "400",
90 "message": "success"
91 }
92 }
93 }
94 }
95
96 //"{'userID':'ug0221','designInfo':[{'vnf-type':'demo123','vnfc-type':'null','protocol':'','incart':'N','action':'AllAction','artifact-name':'reference_AllAction_demo123_0.0.1V.json','artifact-type':'APPC-CONFIG'}]}"
97 const data = {
98 'input': {
99 'design-request': {
100 'request-id': "apiToken",
101 'action': 'getDesigns',
102 'payload': '{"userID": "","filter":"reference"}'
103 }
104 }
105 };
106
107
108 mockBackend.connections.subscribe((connection) => {
109 connection.mockRespond(new Response(new ResponseOptions({
110 body: JSON.stringify(mockResponse)
111 })));
112 });
113 component.getArtifacts(data)
114 httpUtilService.post({
115 url: "test url",
116 data: data
117 }).subscribe((resp) => {
118 console.log("resp")
119 console.log(resp)
120 let block = JSON.parse(resp.output.data.block)
121 expect(block.userID).toBe("ug0221");
122
123
124
125
126 });
127
128
129 }))
130 it('Checking for the successfull post call', inject([HttpUtilService, XHRBackend], (httpUtilService, mockBackend) => {
131
132 const mockResponse = {
133 "output": {
134 "data": {
135 "block": "{\"userID\":\"ug0221\",\"designInfo\":[{\"vnf-type\":\"demo123\",\"vnfc-type\":\"null\",\"protocol\":\"\",\"incart\":\"N\",\"action\":\"AllAction\",\"artifact-name\":\"reference_AllAction_demo123_0.0.1V.json\",\"artifact-type\":\"APPC-CONFIG\"}],\"statusInfo\":null,\"artifactInfo\":null}",
136 "status":{
137 "code": "400",
138 "message": "success"
139 }
140 }
141 }
142 }
143 const data = {
144 'input': {
145 'design-request': {
146 'request-id': "apiToken",
147 'action': 'getDesigns',
148 'payload': '{"userID": "","filter":"reference"}'
149 }
150 }
151 };
152
153
154 mockBackend.connections.subscribe((connection) => {
155 connection.mockRespond(new Response(new ResponseOptions({
156 body: JSON.stringify(mockResponse)
157 })));
158 });
159 component.getArtifacts(data)
160 httpUtilService.post({
161 url: "test url",
162 data: data
163 }).subscribe((resp) => {
164 console.log("resp")
165 console.log(resp)
166 let block = JSON.parse(resp.output.data.status.code)
167 console.log("code",block)
168 expect(block).toBe(400);
169 });
Arundathi Patildfacced2018-07-31 14:34:39 +0530170 }));
171
172 it('should test navigateToReference', ()=>{
173 component.navigateToReference({paramData : 'data'});
174 expect(JSON.parse(sessionStorage.getItem('updateParams'))).toEqual({paramData : 'data'});
175 });
Arundathi Patil7296d552018-08-30 15:26:57 +0530176
177 it('should test validateVnfName function with empty name value', ()=>{
178 component.validateVnfName('');
179 expect(component.errorMessage).toBe('');
180 expect(component.invalid).toBe(true);
181 });
182
183 it('should test validateVnfName function with name value leading and trailing white spaces', ()=>{
184 component.validateVnfName(' name ');
185 expect(component.errorMessage).toBe('Leading and trailing spaces are not allowed');
186 expect(component.invalid).toBe(true);
187 });
188
189 it('should test validateVnfName function with name including more than one space', ()=>{
190 component.validateVnfName('na me');
191 expect(component.errorMessage).toBe('More than one space is not allowed in VNF Type');
192 expect(component.invalid).toBe(true);
193 });
194
195 it('should test validateVnfName function with name length greated than 150', ()=>{
196 component.validateVnfName('namenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenanamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenanamenamnamenamename');
197 expect(component.errorMessage).toBe('VNF Type should be of minimum one character and maximum 150 character');
198 expect(component.invalid).toBe(true);
199 });
200
201 it('should test validateVnfName function with valid name value', ()=>{
202 component.validateVnfName('name');
203 expect(component.errorMessage).toBe('');
204 expect(component.invalid).toBe(false);
205 });
Arundathi Patil4e132242018-08-31 21:29:10 +0530206
207 it('should test buildNewDesign method with respons yes', ()=> {
208 component.vnfType = 'ABC';
209 component.vnfcRequired = true;
210 component.buildNewDesign('yes');
211 let vnfparams = sessionStorage.getItem('vnfParams');
212 let vnfcSelectionFlag = sessionStorage.getItem('vnfcSelectionFlag');
213 expect(vnfparams).toBe('{"vnfType":"ABC"}');
214 expect(vnfcSelectionFlag).toBe("true");
215 });
216
217 it('should test buildNewDesign method with response other than yes', ()=> {
218 component.vnfType = 'ABC';
219 component.vnfcRequired = true;
220 component.buildNewDesign('No');
221 let vnfparams = sessionStorage.getItem('vnfParams');
222 expect(vnfparams).toBe("");
223 });
Arundathi Patilb1f449e2018-07-24 16:53:55 +0530224});