summaryrefslogtreecommitdiffstats
path: root/public/src/app/api
diff options
context:
space:
mode:
authorStone, Avi (as206k) <as206k@att.com>2018-06-03 13:12:12 +0300
committerAvi Stone <as206k@att.com>2018-06-03 11:56:49 +0000
commit548c5a220333c7cd666b861e737bff0b45461f18 (patch)
tree13c60b67291bd8bada498ad73c02a9e35afb5c9e /public/src/app/api
parent193095b01daf094c78f7fafacdf1c1cc31f290fe (diff)
Update FE project
Update FE to latest version so that fe can run on docker Change-Id: I9c5dee756b567dbe64fac6d3d6fd89362813bdcc Issue-ID: SDC-1359 Signed-off-by: Stone, Avi (as206k) <as206k@att.com>
Diffstat (limited to 'public/src/app/api')
-rw-r--r--public/src/app/api/rest-api.service.spec.ts476
-rw-r--r--public/src/app/api/rest-api.service.ts45
2 files changed, 496 insertions, 25 deletions
diff --git a/public/src/app/api/rest-api.service.spec.ts b/public/src/app/api/rest-api.service.spec.ts
index ce921cb..c0fea4b 100644
--- a/public/src/app/api/rest-api.service.spec.ts
+++ b/public/src/app/api/rest-api.service.spec.ts
@@ -1,23 +1,479 @@
-import { TestBed, inject } from '@angular/core/testing';
-import { HttpModule } from '@angular/http';
-import { RestApiService } from './rest-api.service';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { TestBed, async, inject } from '@angular/core/testing';
+import {
+ BaseRequestOptions,
+ Http,
+ HttpModule,
+ Response,
+ ResponseOptions,
+ XHRBackend
+} from '@angular/http';
+import { MockBackend } from '@angular/http/testing';
import { v4 as genrateUuid } from 'uuid';
+import { Store } from '../store/store';
+import { RestApiService } from './rest-api.service';
describe('RestApiService', () => {
- beforeEach(() => {
- TestBed.configureTestingModule({
- imports: [HttpModule],
- providers: [RestApiService]
- });
- });
+ let service: RestApiService;
+ let backend: MockBackend;
+
+ beforeEach(
+ async(() => {
+ TestBed.configureTestingModule({
+ imports: [HttpModule, HttpClientTestingModule],
+ providers: [
+ RestApiService,
+ Store,
+ MockBackend,
+ BaseRequestOptions,
+ {
+ provide: Http,
+ deps: [MockBackend, BaseRequestOptions],
+ useFactory: (
+ backend: XHRBackend,
+ defaultOptions: BaseRequestOptions
+ ) => {
+ return new Http(backend, defaultOptions);
+ }
+ }
+ ]
+ });
+ // Get the MockBackend
+ backend = TestBed.get(MockBackend);
+ service = TestBed.get(RestApiService);
+ })
+ );
it(
'should be created',
- inject([RestApiService], (service: RestApiService) => {
+ inject([RestApiService], () => {
expect(service).toBeTruthy();
})
);
+ it('should baseUrl match localhost', () => {
+ expect(service.baseUrl).toBe('http://localhost:8446');
+ });
+
+ it('should headers user id get default', () => {
+ service.addHeaders();
+ expect(service.headers.get('USER_ID')).toBe('ym903w');
+ });
+
+ it('should headers Content-Type json', () => {
+ service.addHeaders();
+ expect(service.headers.get('Content-Type')).toBe('application/json');
+ });
+
+ it(
+ 'should get service instance from API',
+ async(() => {
+ const serviceInstances = [
+ {
+ name: 'ciService669277f472b0',
+ category: 'Mobility'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(serviceInstances)
+ })
+ )
+ );
+ });
+
+ service.getServiceInstances('123456').subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(serviceInstances);
+ });
+ })
+ );
+
+ it(
+ 'should get template resources from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service.getTemplateResources().subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(template);
+ });
+ })
+ );
+
+ it(
+ 'should getCompositionMonitoringComponent from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service.getCompositionMonitoringComponent('123456').subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(template);
+ });
+ })
+ );
+
+ it(
+ 'importVFCMT from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service.importVFCMT({}).subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(template);
+ });
+ })
+ );
+
+ it(
+ 'deleteMonitoringComponent from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service
+ .deleteMonitoringComponent(
+ {
+ contextType: 'service',
+ uuid: '123456'
+ },
+ '45678',
+ 'liav'
+ )
+ .subscribe(_res => {
+ console.log('delete', _res);
+ });
+ })
+ );
+
+ it(
+ 'deleteMonitoringComponentWithBlueprint from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service
+ .deleteMonitoringComponentWithBlueprint(
+ {
+ contextType: 'service',
+ uuid: '123456'
+ },
+ 'voskComp',
+ '45678',
+ 'liav'
+ )
+ .subscribe(_res => {
+ console.log('delete', _res);
+ });
+ })
+ );
+
+ it(
+ 'createNewVFCMT from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service.createNewVFCMT({}).subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(template);
+ });
+ })
+ );
+
+ it(
+ 'saveMonitoringComponent from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service
+ .saveMonitoringComponent({
+ contextType: 'service',
+ serviceUuid: '123456',
+ vfiName: 'liavVfi',
+ vfcmtUuid: '987456',
+ cdump: {}
+ })
+ .subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(template);
+ });
+ })
+ );
+
+ it(
+ 'submitMonitoringComponent from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service
+ .submitMonitoringComponent({
+ contextType: 'service',
+ serviceUuid: '123456',
+ vfiName: 'liavVfi',
+ vfcmtUuid: '987456',
+ cdump: {},
+ flowType: 'SNMP'
+ })
+ .subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(template);
+ });
+ })
+ );
+
+ it(
+ 'should get Vfcmt Reference Data from API',
+ async(() => {
+ const template = [
+ {
+ name: 'AviStone1234',
+ version: '0.1'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(template)
+ })
+ )
+ );
+ });
+
+ service.getVfcmtReferenceData('123456').subscribe(_res => {
+ expect(_res.length).toBe(1);
+ expect(_res).toEqual(template);
+ });
+ })
+ );
+
+ it(
+ 'should get vfcmt list from API',
+ async(() => {
+ const dummyVfcmts = [
+ {
+ uuid: 'cba37ed8-94e1-406f-b4f5-b5edbc31ac85',
+ name: 'CIe4d5a9b271d6'
+ },
+ {
+ uuid: '64471437-8feb-40d9-a8b0-9407a81dd5c0',
+ name: 'teSt.__.monitoring---TempLATE.6hnc'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ expect(connection.request.url).toMatch(
+ 'http://localhost:8446/service/123456/0.1/monitoringComponents'
+ );
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(dummyVfcmts)
+ })
+ )
+ );
+ });
+
+ service
+ .getMonitoringComponents({
+ contextType: 'service',
+ uuid: '123456',
+ version: '0.1'
+ })
+ .subscribe(_res => {
+ expect(_res.length).toBe(2);
+ expect(_res).toEqual(dummyVfcmts);
+ });
+ })
+ );
+
+ it(
+ 'should get migration vfcmt list from API',
+ async(() => {
+ const dummyVfcmts = [
+ {
+ uuid: 'cba37ed8-94e1-406f-b4f5-b5edbc31ac85',
+ name: 'CIe4d5a9b271d6'
+ },
+ {
+ uuid: '64471437-8feb-40d9-a8b0-9407a81dd5c0',
+ name: 'teSt.__.monitoring---TempLATE.6hnc'
+ }
+ ];
+
+ backend.connections.subscribe(connection => {
+ expect(connection.request.url).toMatch(
+ 'http://localhost:8446/service/123456/0.1/getVfcmtsForMigration'
+ );
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(dummyVfcmts)
+ })
+ )
+ );
+ });
+
+ service
+ .getVfcmtsForMigration({
+ contextType: 'service',
+ uuid: '123456',
+ version: '0.1'
+ })
+ .subscribe(_res => {
+ expect(_res.length).toBe(2);
+ expect(_res).toEqual(dummyVfcmts);
+ });
+ })
+ );
+
+ it(
+ 'should get flow type from API',
+ async(() => {
+ const flowType = ['syslog', 'SNMP'];
+
+ backend.connections.subscribe(connection => {
+ expect(connection.request.url).toMatch(
+ 'http://localhost:8446/conf/composition'
+ );
+ connection.mockRespond(
+ new Response(
+ new ResponseOptions({
+ body: JSON.stringify(flowType)
+ })
+ )
+ );
+ });
+
+ service.getFlowType().subscribe(_res => {
+ expect(_res.length).toBe(2);
+ expect(_res).toEqual(flowType);
+ });
+ })
+ );
+
it('should genrate deffrent uuid each time for request id', () => {
const firstUuid = genrateUuid();
const secondUuid = genrateUuid();
diff --git a/public/src/app/api/rest-api.service.ts b/public/src/app/api/rest-api.service.ts
index ba5cc54..cd55a6d 100644
--- a/public/src/app/api/rest-api.service.ts
+++ b/public/src/app/api/rest-api.service.ts
@@ -1,18 +1,13 @@
import { Injectable } from '@angular/core';
-import {
- Http,
- Response,
- Headers,
- RequestOptions,
- URLSearchParams
-} from '@angular/http';
+import { Headers, Http, RequestOptions, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
+import 'rxjs/add/observable/throw';
+import 'rxjs/add/operator/catch';
// Import RxJs required methods
import 'rxjs/add/operator/map';
-import 'rxjs/add/operator/catch';
-import 'rxjs/add/observable/throw';
-import { environment } from '../../environments/environment';
import { v4 as uuidGenarator } from 'uuid';
+import { environment } from '../../environments/environment';
+import { Store } from '../store/store';
@Injectable()
export class RestApiService {
@@ -20,16 +15,24 @@ export class RestApiService {
headers: Headers;
baseUrl: string;
- constructor(private http: Http) {
+ constructor(private http: Http, public store: Store) {
this.baseUrl = `${environment.apiBaseUrl}`;
+ }
+
+ addHeaders() {
+ const userID =
+ this.store.sdcParmas === undefined
+ ? 'ym903w'
+ : this.store.sdcParmas.userId;
this.headers = new Headers({
'Content-Type': 'application/json',
- USER_ID: 'ym903w'
+ USER_ID: userID
});
this.options = new RequestOptions({ headers: this.headers });
}
getVfcmtsForMigration(params) {
+ this.addHeaders();
const { contextType, uuid, version } = params;
const url = `${
this.baseUrl
@@ -44,6 +47,7 @@ export class RestApiService {
}
getVfcmtReferenceData(vfcmtUUID) {
+ this.addHeaders();
const url = `${this.baseUrl}/getVfcmtReferenceData/${vfcmtUUID}`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
@@ -53,6 +57,7 @@ export class RestApiService {
}
getFlowType() {
+ this.addHeaders();
const url = `${this.baseUrl}/conf/composition`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
@@ -62,6 +67,7 @@ export class RestApiService {
}
createNewVFCMT(params) {
+ this.addHeaders();
const url = `${this.baseUrl}/createMC`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
@@ -73,6 +79,7 @@ export class RestApiService {
}
importVFCMT(params) {
+ this.addHeaders();
const url = `${this.baseUrl}/importMC`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
@@ -84,6 +91,7 @@ export class RestApiService {
}
getServiceInstances(serviceID) {
+ this.addHeaders();
const url = `${this.baseUrl}/service/${serviceID}`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
@@ -95,6 +103,7 @@ export class RestApiService {
}
getTemplateResources() {
+ this.addHeaders();
const url = `${this.baseUrl}/getResourcesByMonitoringTemplateCategory`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
@@ -104,6 +113,7 @@ export class RestApiService {
}
getMonitoringComponents(params) {
+ this.addHeaders();
const { contextType, uuid, version } = params;
const url = `${
this.baseUrl
@@ -116,6 +126,7 @@ export class RestApiService {
}
deleteMonitoringComponent(params, vfcmtUuid, vfiName) {
+ this.addHeaders();
const { contextType, uuid } = params;
const url = `${
this.baseUrl
@@ -123,7 +134,7 @@ export class RestApiService {
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
.delete(url, this.options)
- .map((res: Response) => res.json())
+ .map((res: Response) => res)
.catch((error: any) => Observable.throw(error.json() || 'Server error'));
}
@@ -133,6 +144,7 @@ export class RestApiService {
vfcmtUuid,
vfiName
) {
+ this.addHeaders();
const { contextType, uuid } = params;
const url = `${
this.baseUrl
@@ -140,11 +152,12 @@ export class RestApiService {
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
.delete(url, this.options)
- .map((res: Response) => res.json())
+ .map((res: Response) => res)
.catch((error: any) => Observable.throw(error.json() || 'Server error'));
}
getCompositionMonitoringComponent(vfcmtUuid) {
+ this.addHeaders();
const url = `${this.baseUrl}/getMC/${vfcmtUuid}`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
@@ -154,18 +167,20 @@ export class RestApiService {
}
saveMonitoringComponent(params) {
+ this.addHeaders();
const { contextType, serviceUuid, vfiName, vfcmtUuid, cdump } = params;
const url = `${
this.baseUrl
}/${contextType}/${serviceUuid}/${vfiName}/saveComposition/${vfcmtUuid}`;
this.options.headers.set('X-ECOMP-RequestID', uuidGenarator());
return this.http
- .post(url, cdump, this.options)
+ .post(url, JSON.stringify(cdump), this.options)
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json() || 'Server error'));
}
submitMonitoringComponent(params) {
+ this.addHeaders();
const { contextType, serviceUuid, vfiName, vfcmtUuid, flowType } = params;
const url = `${
this.baseUrl