From e409ac955e6f0654f1721c69e1885bda23e1cf99 Mon Sep 17 00:00:00 2001 From: Lathish Date: Fri, 22 Jan 2021 10:43:14 +0000 Subject: [PATCH] Add A1 Policy Type/Policy Types logic from backend This commit do not test the Policy instances functionality. Issue-ID: NONRTRIC-407 Change-Id: Id537ae199737d4892b1f344c68cf397cda5f5853 Signed-off-by: Lathish --- webapp-frontend/nginx.conf | 2 +- webapp-frontend/src/app/interceptor.mock.ts | 35 +++++++++---- webapp-frontend/src/app/interfaces/policy.types.ts | 11 +++- ...instance-2.json => policy-instance-notype.json} | 0 webapp-frontend/src/app/mock/policy-type1.json | 43 ++++++++++++++++ webapp-frontend/src/app/mock/policy-types.json | 6 +++ .../policy-control/policy-control.component.html | 26 +++++----- .../policy-control.component.spec.ts | 15 +++--- .../app/policy-control/policy-control.component.ts | 48 +++++++++--------- .../policy-instance-dialog.component.ts | 8 +-- .../policy-control/policy-instance.component.ts | 19 +++---- .../policy-control/policy-instance.datasource.ts | 7 ++- .../app/policy-control/policy-type.datasource.ts | 58 ++++++++++------------ .../src/app/services/policy/policy.service.spec.ts | 42 +++++++++------- .../src/app/services/policy/policy.service.ts | 28 ++++------- 15 files changed, 204 insertions(+), 144 deletions(-) rename webapp-frontend/src/app/mock/{policy-instance-2.json => policy-instance-notype.json} (100%) create mode 100644 webapp-frontend/src/app/mock/policy-type1.json create mode 100644 webapp-frontend/src/app/mock/policy-types.json diff --git a/webapp-frontend/nginx.conf b/webapp-frontend/nginx.conf index 47d7b26..4700d85 100644 --- a/webapp-frontend/nginx.conf +++ b/webapp-frontend/nginx.conf @@ -5,7 +5,7 @@ http { upstream backend { # to be replaced with hostname:port of nonrtric-gateway once it gets ready - server controlpanel-backend-container:8080; + server nonrtricgateway:8080; } server { diff --git a/webapp-frontend/src/app/interceptor.mock.ts b/webapp-frontend/src/app/interceptor.mock.ts index 89034a8..e444d91 100644 --- a/webapp-frontend/src/app/interceptor.mock.ts +++ b/webapp-frontend/src/app/interceptor.mock.ts @@ -22,41 +22,54 @@ import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } fr import { Injectable, Injector } from '@angular/core'; import { Observable, of } from 'rxjs'; import * as policyinstances1 from './mock/policy-instance-1.json'; -import * as policyinstances2 from './mock/policy-instance-2.json'; +import * as policyinstancesNoType from './mock/policy-instance-notype.json'; import * as eijobs from './mock/ei-jobs.json'; import * as eiproducers from './mock/ei-producers.json'; import * as nopolicyinstances from './mock/nopolicyinstances.json'; -import * as policytypes from './mock/policytypes.json'; +import * as policytypesList from './mock/policy-types.json'; +import * as policytypes1 from './mock/policy-type1.json'; import * as policyinstanceedit from './mock/policy-instance-edit.json'; import * as rics from './mock/rics.json'; const urls = [ { - url: 'api/policy/policytypes', - json: policytypes + url: 'v2/policy-types', + json: policytypesList }, { - url: 'api/policy/policies?type=1', + url: 'v2/policy-types/', + json: policytypes1 + }, + { + url: 'v2/policy-types/1', + json: policytypes1 + }, + { + url: 'v2/policies?type=1', json: policyinstances1 }, { - url: 'api/policy/policies?type=2', - json: policyinstances2 + url: 'v2/policies?type=', + json: policyinstancesNoType }, { - url: 'api/policy/policies?type=2', + url: 'v2/policies?type=2', json: nopolicyinstances }, { - url: 'api/policy/policies/2000?type=1', + url: 'v2/policies/2000?type=1', + json: policyinstanceedit + }, + { + url: 'v2/policies/3000?type=1', json: policyinstanceedit }, { - url: 'api/policy/policies/2001?type=2', + url: 'v2/policies/2001?type=', json: policyinstanceedit }, { - url: 'api/policy/policies/2000?ric=ric1&type=1', + url: 'v2/policies/2000?ric=ric1&type=1', json: '' }, { diff --git a/webapp-frontend/src/app/interfaces/policy.types.ts b/webapp-frontend/src/app/interfaces/policy.types.ts index b6ecce6..8bc5eb1 100644 --- a/webapp-frontend/src/app/interfaces/policy.types.ts +++ b/webapp-frontend/src/app/interfaces/policy.types.ts @@ -20,12 +20,19 @@ // Models of data used by the Policy Control -export interface PolicyType { +export interface PolicyTypeSchema { name: string; - schema: string; schemaObject: any; } +export interface PolicyType { + policy_schema: any; +} + +export interface PolicyTypes { + policytype_ids: any[]; +} + export interface PolicyInstance { id: string; json: string; diff --git a/webapp-frontend/src/app/mock/policy-instance-2.json b/webapp-frontend/src/app/mock/policy-instance-notype.json similarity index 100% rename from webapp-frontend/src/app/mock/policy-instance-2.json rename to webapp-frontend/src/app/mock/policy-instance-notype.json diff --git a/webapp-frontend/src/app/mock/policy-type1.json b/webapp-frontend/src/app/mock/policy-type1.json new file mode 100644 index 0000000..2777ca1 --- /dev/null +++ b/webapp-frontend/src/app/mock/policy-type1.json @@ -0,0 +1,43 @@ +{ + "policy_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "description": "Type 1 policy type", + "additionalProperties": false, + "title": "1", + "type": "object", + "properties": { + "qosObjectives": { + "additionalProperties": false, + "type": "object", + "properties": { + "priorityLevel": { + "type": "number" + } + }, + "required": [ + "priorityLevel" + ] + }, + "scope": { + "additionalProperties": false, + "type": "object", + "properties": { + "qosId": { + "type": "string" + }, + "ueId": { + "type": "string" + } + }, + "required": [ + "ueId", + "qosId" + ] + } + }, + "required": [ + "scope", + "qosObjectives" + ] + } +} \ No newline at end of file diff --git a/webapp-frontend/src/app/mock/policy-types.json b/webapp-frontend/src/app/mock/policy-types.json new file mode 100644 index 0000000..9bad9ad --- /dev/null +++ b/webapp-frontend/src/app/mock/policy-types.json @@ -0,0 +1,6 @@ +{ + "policytype_ids": [ + "", + "1" + ] +} \ No newline at end of file diff --git a/webapp-frontend/src/app/policy-control/policy-control.component.html b/webapp-frontend/src/app/policy-control/policy-control.component.html index 27e56e3..a8f5021 100644 --- a/webapp-frontend/src/app/policy-control/policy-control.component.html +++ b/webapp-frontend/src/app/policy-control/policy-control.component.html @@ -18,7 +18,7 @@ ========================LICENSE_END=================================== --> -
+
Policy Control
@@ -56,8 +56,8 @@ - - + + @@ -68,12 +68,12 @@ - + - + { let component: PolicyControlComponent; let fixture: ComponentFixture; beforeEach(async(() => { - const policyTypeDataSourceSpy = jasmine.createSpyObj('PolicyTypeDataSource', [ 'connect', 'loadTable', 'disconnect' ]); - const policyType = { - name: "type1", - schema: "{}", - schemaObject: "{}" - } - policyTypeDataSourceSpy.connect.and.returnValue(of([ policyType])); + const policyTypeDataSourceSpy = jasmine.createSpyObj('PolicyTypeDataSource', [ 'connect', 'getPolicyTypes', 'disconnect' ]); + var policyTypeSchema = {} as PolicyTypeSchema; + policyTypeSchema.name = ''; + policyTypeSchema.schemaObject = ''; + policyTypeDataSourceSpy.connect.and.returnValue(of([ policyTypeSchema])); policyTypeDataSourceSpy.disconnect(); let matDialogStub: Partial; diff --git a/webapp-frontend/src/app/policy-control/policy-control.component.ts b/webapp-frontend/src/app/policy-control/policy-control.component.ts index d74dc78..3a15226 100644 --- a/webapp-frontend/src/app/policy-control/policy-control.component.ts +++ b/webapp-frontend/src/app/policy-control/policy-control.component.ts @@ -24,14 +24,14 @@ import { MatDialog } from '@angular/material/dialog'; import { BehaviorSubject, Observable } from 'rxjs'; import { NoTypePolicyInstanceDialogComponent } from './no-type-policy-instance-dialog.component'; -import { PolicyType } from '../interfaces/policy.types'; +import { PolicyTypeSchema } from '../interfaces/policy.types'; import { PolicyTypeDataSource } from './policy-type.datasource'; import { getPolicyDialogProperties } from './policy-instance-dialog.component'; import { PolicyInstanceDialogComponent } from './policy-instance-dialog.component'; import { UiService } from '../services/ui/ui.service'; class PolicyTypeInfo { - constructor(public type: PolicyType) { } + constructor(public type: PolicyTypeSchema) { } isExpanded: BehaviorSubject = new BehaviorSubject(false); } @@ -60,22 +60,22 @@ export class PolicyControlComponent implements OnInit { private ui: UiService) { } ngOnInit() { - this.policyTypesDataSource.loadTable(); + this.policyTypesDataSource.getPolicyTypes(); this.ui.darkModeState.subscribe((isDark) => { this.darkMode = isDark; }); } - createPolicyInstance(policyType: PolicyType): void { + createPolicyInstance(policyTypeSchema: PolicyTypeSchema): void { let dialogRef; - if (this.isSchemaEmpty(policyType)) { + if (this.isSchemaEmpty(policyTypeSchema)) { dialogRef = this.dialog.open(NoTypePolicyInstanceDialogComponent, - getPolicyDialogProperties(policyType, null, this.darkMode)); + getPolicyDialogProperties(policyTypeSchema, null, this.darkMode)); } else { dialogRef = this.dialog.open(PolicyInstanceDialogComponent, - getPolicyDialogProperties(policyType, null, this.darkMode)); + getPolicyDialogProperties(policyTypeSchema, null, this.darkMode)); } - const info: PolicyTypeInfo = this.getPolicyTypeInfo(policyType); + const info: PolicyTypeInfo = this.getPolicyTypeInfo(policyTypeSchema); dialogRef.afterClosed().subscribe( (_) => { info.isExpanded.next(info.isExpanded.getValue()); @@ -83,40 +83,40 @@ export class PolicyControlComponent implements OnInit { ); } - toggleListInstances(policyType: PolicyType): void { - const info = this.getPolicyTypeInfo(policyType); + toggleListInstances(policyTypeSchema: PolicyTypeSchema): void { + const info = this.getPolicyTypeInfo(policyTypeSchema); info.isExpanded.next(!info.isExpanded.getValue()); } - private isSchemaEmpty(policyType: PolicyType): boolean { - return Object.keys(policyType.schemaObject).length === 0; + private isSchemaEmpty(policyTypeSchema: PolicyTypeSchema): boolean { + return Object.keys(policyTypeSchema.schemaObject).length === 0; } - getPolicyTypeInfo(policyType: PolicyType): PolicyTypeInfo { - let info: PolicyTypeInfo = this.policyTypeInfo.get(policyType.name); + getPolicyTypeInfo(policyTypeSchema: PolicyTypeSchema): PolicyTypeInfo { + let info: PolicyTypeInfo = this.policyTypeInfo.get(policyTypeSchema.name); if (!info) { - info = new PolicyTypeInfo(policyType); - this.policyTypeInfo.set(policyType.name, info); + info = new PolicyTypeInfo(policyTypeSchema); + this.policyTypeInfo.set(policyTypeSchema.name, info); } return info; } - getDisplayName(policyType: PolicyType): string { - if (policyType.schemaObject.title) { - return policyType.schemaObject.title; + getDisplayName(policyTypeSchema: PolicyTypeSchema): string { + if (policyTypeSchema.schemaObject.title) { + return policyTypeSchema.schemaObject.title; } return '< No type >'; } - isInstancesShown(policyType: PolicyType): boolean { - return this.getPolicyTypeInfo(policyType).isExpanded.getValue(); + isInstancesShown(policyTypeSchema: PolicyTypeSchema): boolean { + return this.getPolicyTypeInfo(policyTypeSchema).isExpanded.getValue(); } - getExpandedObserver(policyType: PolicyType): Observable { - return this.getPolicyTypeInfo(policyType).isExpanded.asObservable(); + getExpandedObserver(policyTypeSchema: PolicyTypeSchema): Observable { + return this.getPolicyTypeInfo(policyTypeSchema).isExpanded.asObservable(); } refreshTables() { - this.policyTypesDataSource.loadTable(); + this.policyTypesDataSource.getPolicyTypes(); } } diff --git a/webapp-frontend/src/app/policy-control/policy-instance-dialog.component.ts b/webapp-frontend/src/app/policy-control/policy-instance-dialog.component.ts index 3dcd79a..781efca 100644 --- a/webapp-frontend/src/app/policy-control/policy-instance-dialog.component.ts +++ b/webapp-frontend/src/app/policy-control/policy-instance-dialog.component.ts @@ -23,7 +23,7 @@ import { MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/materia import { MatMenuTrigger } from '@angular/material/menu'; import { JsonPointer } from 'angular6-json-schema-form'; import * as uuid from 'uuid'; -import { PolicyInstance, PolicyType } from '../interfaces/policy.types'; +import { PolicyInstance, PolicyTypeSchema } from '../interfaces/policy.types'; import { PolicyService } from '../services/policy/policy.service'; import { ErrorDialogService } from '../services/ui/error-dialog.service'; import { NotificationService } from './../services/ui/notification.service'; @@ -223,11 +223,11 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit { } } -export function getPolicyDialogProperties(policyType: PolicyType, instance: PolicyInstance, darkMode: boolean): MatDialogConfig { - const createSchema = policyType.schemaObject; +export function getPolicyDialogProperties(policyTypeSchema: PolicyTypeSchema, instance: PolicyInstance, darkMode: boolean): MatDialogConfig { + const createSchema = policyTypeSchema.schemaObject; const instanceId = instance ? instance.id : null; const instanceJson = instance ? instance.json : null; - const name = policyType.name; + const name = policyTypeSchema.name; const ric = instance ? instance.ric : null; return { maxWidth: '1200px', diff --git a/webapp-frontend/src/app/policy-control/policy-instance.component.ts b/webapp-frontend/src/app/policy-control/policy-instance.component.ts index ab9bfd9..f77bd83 100644 --- a/webapp-frontend/src/app/policy-control/policy-instance.component.ts +++ b/webapp-frontend/src/app/policy-control/policy-instance.component.ts @@ -21,7 +21,7 @@ import { MatSort } from '@angular/material'; import { Component, OnInit, ViewChild, Input, AfterViewInit } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { PolicyType } from '../interfaces/policy.types'; +import { PolicyTypeSchema } from '../interfaces/policy.types'; import { PolicyInstanceDataSource } from './policy-instance.datasource'; import { ErrorDialogService } from '../services/ui/error-dialog.service'; import { NotificationService } from '../services/ui/notification.service'; @@ -44,7 +44,7 @@ import { UiService } from '../services/ui/ui.service'; export class PolicyInstanceComponent implements OnInit, AfterViewInit { instanceDataSource: PolicyInstanceDataSource; - @Input() policyType: PolicyType; + @Input() policyTypeSchema: PolicyTypeSchema; @Input() expanded: Observable; @ViewChild(MatSort, { static: true }) sort: MatSort; darkMode: boolean; @@ -59,7 +59,7 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit { } ngOnInit() { - this.instanceDataSource = new PolicyInstanceDataSource(this.policySvc, this.sort, this.notificationService, this.policyType); + this.instanceDataSource = new PolicyInstanceDataSource(this.policySvc, this.sort, this.notificationService, this.policyTypeSchema); this.expanded.subscribe((isExpanded: boolean) => this.onExpand(isExpanded)); this.ui.darkModeState.subscribe((isDark) => { this.darkMode = isDark; @@ -77,17 +77,17 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit { } private isSchemaEmpty(): boolean { - return Object.keys(this.policyType.schemaObject).length === 0; + return Object.keys(this.policyTypeSchema.schemaObject).length === 0; } modifyInstance(instance: PolicyInstance): void { - this.policySvc.getPolicy(this.policyType.name, instance.id).subscribe( + this.policySvc.getPolicy(this.policyTypeSchema.name, instance.id).subscribe( (refreshedJson: any) => { instance.json = JSON.stringify(refreshedJson); if (this.isSchemaEmpty()) { this.dialog.open( NoTypePolicyInstanceDialogComponent, - getPolicyDialogProperties(this.policyType, instance, this.darkMode)).afterClosed().subscribe( + getPolicyDialogProperties(this.policyTypeSchema, instance, this.darkMode)).afterClosed().subscribe( (_: any) => { this.instanceDataSource.loadTable(); } @@ -95,7 +95,7 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit { } else { this.dialog.open( PolicyInstanceDialogComponent, - getPolicyDialogProperties(this.policyType, instance, this.darkMode)).afterClosed().subscribe( + getPolicyDialogProperties(this.policyTypeSchema, instance, this.darkMode)).afterClosed().subscribe( (_: any) => { this.instanceDataSource.loadTable(); } @@ -126,7 +126,7 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit { .afterClosed().subscribe( (res: any) => { if (res) { - this.policySvc.deletePolicy(this.policyType.name, instance.id) + this.policySvc.deletePolicy(this.policyTypeSchema.name, instance.id) .subscribe( (response: HttpResponse) => { switch (response.status) { @@ -144,7 +144,4 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit { } }); } - - - } diff --git a/webapp-frontend/src/app/policy-control/policy-instance.datasource.ts b/webapp-frontend/src/app/policy-control/policy-instance.datasource.ts index 9cf1d72..4bf2aad 100644 --- a/webapp-frontend/src/app/policy-control/policy-instance.datasource.ts +++ b/webapp-frontend/src/app/policy-control/policy-instance.datasource.ts @@ -26,10 +26,9 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { merge } from 'rxjs'; import { of } from 'rxjs/observable/of'; import { catchError, finalize, map } from 'rxjs/operators'; -import { PolicyInstance } from '../interfaces/policy.types'; +import { PolicyInstance, PolicyTypeSchema } from '../interfaces/policy.types'; import { PolicyService } from '../services/policy/policy.service'; import { NotificationService } from '../services/ui/notification.service'; -import { PolicyType } from '../interfaces/policy.types'; export class PolicyInstanceDataSource extends DataSource { @@ -45,13 +44,13 @@ export class PolicyInstanceDataSource extends DataSource { private policySvc: PolicyService, public sort: MatSort, private notificationService: NotificationService, - private policyType: PolicyType) { + private policyTypeSchema: PolicyTypeSchema) { super(); } loadTable() { this.loadingSubject.next(true); - this.policySvc.getPolicyInstances(this.policyType.name) + this.policySvc.getPolicyInstances(this.policyTypeSchema.name) .pipe( catchError((her: HttpErrorResponse) => { this.notificationService.error('Failed to get policy instances: ' + her.error); diff --git a/webapp-frontend/src/app/policy-control/policy-type.datasource.ts b/webapp-frontend/src/app/policy-control/policy-type.datasource.ts index 61ecc4a..db8f01f 100644 --- a/webapp-frontend/src/app/policy-control/policy-type.datasource.ts +++ b/webapp-frontend/src/app/policy-control/policy-type.datasource.ts @@ -19,14 +19,12 @@ */ import { CollectionViewer, DataSource } from '@angular/cdk/collections'; -import { HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { of } from 'rxjs/observable/of'; -import { catchError, finalize, map } from 'rxjs/operators'; import { Observable } from 'rxjs/Observable'; -import { PolicyType } from '../interfaces/policy.types'; +import { PolicyTypeSchema } from '../interfaces/policy.types'; import { PolicyService } from '../services/policy/policy.service'; import { NotificationService } from '../services/ui/notification.service'; @@ -34,13 +32,11 @@ import { NotificationService } from '../services/ui/notification.service'; providedIn: 'root' }) -export class PolicyTypeDataSource extends DataSource { +export class PolicyTypeDataSource extends DataSource { - private policyTypeSubject = new BehaviorSubject([]); + policyTypes: PolicyTypeSchema[] = []; - private loadingSubject = new BehaviorSubject(false); - - public loading$ = this.loadingSubject.asObservable(); + private policyTypeSubject = new BehaviorSubject([]); public rowCount = 1; // hide footer during intial load @@ -49,37 +45,35 @@ export class PolicyTypeDataSource extends DataSource { super(); } - loadTable() { - this.loadingSubject.next(true); - this.policySvc.getPolicyTypes() - .pipe( - catchError((her: HttpErrorResponse) => { - this.notificationService.error('Failed to get policy types: ' + her.statusText + ', ' + her.error); - return of([]); - }), - finalize(() => this.loadingSubject.next(false)) - ) - .subscribe((types: PolicyType[]) => { - this.rowCount = types.length; - for (let i = 0; i < types.length; i++) { - const policyType = types[i]; - try { - policyType.schemaObject = JSON.parse(policyType.schema); - } catch (jsonError) { - console.error('Could not parse schema: ' + policyType.schema); - policyType.schemaObject = { description: 'Incorrect schema: ' + jsonError }; + public getPolicyTypes() { + this.policyTypes = [] as PolicyTypeSchema[]; + this.policySvc.getPolicyTypes().subscribe(data => { + if (data.policytype_ids.length != 0) { + data.policytype_ids.forEach(policyId => { + var policyTypeSchema = {} as PolicyTypeSchema + if (policyId === "") { + policyTypeSchema.name = ''; + policyTypeSchema.schemaObject = '{}'; + this.policyTypes.push(policyTypeSchema); + } + else { + this.policySvc.getPolicyType(policyId).subscribe(policyType => { + policyTypeSchema.schemaObject = policyType.policy_schema; + policyTypeSchema.name = policyType.policy_schema.title; + this.policyTypes.push(policyTypeSchema); + }) } - } - this.policyTypeSubject.next(types); - }); + this.policyTypeSubject.next(this.policyTypes); + }) + } + }) } - connect(collectionViewer: CollectionViewer): Observable { + connect(collectionViewer: CollectionViewer): Observable { return of(this.policyTypeSubject.getValue()); } disconnect(collectionViewer: CollectionViewer): void { this.policyTypeSubject.complete(); - this.loadingSubject.complete(); } } diff --git a/webapp-frontend/src/app/services/policy/policy.service.spec.ts b/webapp-frontend/src/app/services/policy/policy.service.spec.ts index 15f849c..ee20509 100644 --- a/webapp-frontend/src/app/services/policy/policy.service.spec.ts +++ b/webapp-frontend/src/app/services/policy/policy.service.spec.ts @@ -21,10 +21,11 @@ import { TestBed } from '@angular/core/testing'; import { PolicyService } from './policy.service'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing' -import { PolicyInstance, PolicyType } from '../../interfaces/policy.types'; +import { PolicyInstance, PolicyTypes } from '../../interfaces/policy.types'; describe('PolicyService', () => { - let basePath = 'api/policy'; + let apiVersion2 = 'v2' + let basePath = ''; let policyService: PolicyService; let httpTestingController: HttpTestingController; beforeEach(() => TestBed.configureTestingModule({ @@ -39,15 +40,18 @@ describe('PolicyService', () => { }); describe('#getPolicyTypes', () => { - let expectedPolicytypes: PolicyType[]; + let expectedPolicytypes: PolicyTypes; + let emptyPolicyType: PolicyTypes; beforeEach(() => { policyService = TestBed.get(PolicyService); httpTestingController = TestBed.get(HttpTestingController); - expectedPolicytypes = [ - { name: '1', schema: '{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"description\":\"Type 2 policy type\",\"additionalProperties\":false,\"title\":\"2\",\"type\":\"object\",\"properties\":{\"qosObjectives\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"priorityLevel\":{\"type\":\"number\"}},\"required\":[\"priorityLevel\"]},\"scope\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"qosId\":{\"type\":\"string\"},\"ueId\":{\"type\":\"string\"}},\"required\":[\"ueId\",\"qosId\"]}},\"required\":[\"scope\",\"qosObjectives\"]}' }, - { name: '2', schema: '{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"description\":\"Type 1 policy type\",\"additionalProperties\":false,\"title\":\"1\",\"type\":\"object\",\"properties\":{\"qosObjectives\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"priorityLevel\":{\"type\":\"number\"}},\"required\":[\"priorityLevel\"]},\"scope\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"qosId\":{\"type\":\"string\"},\"ueId\":{\"type\":\"string\"}},\"required\":[\"ueId\",\"qosId\"]}},\"required\":[\"scope\",\"qosObjectives\"]}' }, - ] as PolicyType[]; + expectedPolicytypes = { + "policytype_ids": [ + "", + "1" + ] + } as PolicyTypes; }); //Policy Type Test Case 1: it('should return all policy types', () => { @@ -55,22 +59,26 @@ describe('PolicyService', () => { policytypes => expect(policytypes).toEqual(expectedPolicytypes, 'should return expected PolicyTypes'), fail ); - - const req = httpTestingController.expectOne(basePath + '/' + policyService.policyTypePath); + + const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyTypesPath); expect(req.request.method).toEqual('GET'); - req.flush(expectedPolicytypes); //Return expectedEmps + req.flush(expectedPolicytypes); }); //Policy Type Test Case 2: + emptyPolicyType = { + "policytype_ids": [ + ] + } as PolicyTypes; it('should return no policy types', () => { policyService.getPolicyTypes().subscribe( - policytypes => expect(policytypes.length).toEqual(0, 'should return empty array of Policy Types'), + policytypes => expect(policytypes).toEqual(emptyPolicyType, 'should return empty array of Policy Types'), fail ); - const req = httpTestingController.expectOne(basePath + '/' + policyService.policyTypePath); - req.flush([]); //Return empty data + const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyTypesPath); + req.flush(emptyPolicyType); //Return empty data }); }); describe('#getPolicyInstance', () => { @@ -90,18 +98,18 @@ describe('PolicyService', () => { policyinstances => expect(policyinstances).toEqual(expectedPolicyInstances, 'should return expected Policy Instances'), fail ); - const req = httpTestingController.expectOne(basePath + '/' + policyService.policyPath + '?type=' + policyTypeId); + const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyPath + '?type=' + policyTypeId); expect(req.request.method).toEqual('GET'); - req.flush(expectedPolicyInstances); //Return expectedEmps + req.flush(expectedPolicyInstances); }); //Policy Instances Test Case 2: it('should return no policy instances', () => { policyService.getPolicyInstances(policyTypeId).subscribe( - policyinstances => expect(policyinstances.length).toEqual(0, 'should return empty array of Policy Isntances'), + policyinstances => expect(policyinstances.length).toEqual(0, 'should return empty array of Policy Instances'), fail ); - const req = httpTestingController.expectOne(basePath + '/' + policyService.policyPath + '?type=' + policyTypeId); + const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyPath + '?type=' + policyTypeId); req.flush([]); //Return empty data }); }); diff --git a/webapp-frontend/src/app/services/policy/policy.service.ts b/webapp-frontend/src/app/services/policy/policy.service.ts index f24747b..c903b2c 100644 --- a/webapp-frontend/src/app/services/policy/policy.service.ts +++ b/webapp-frontend/src/app/services/policy/policy.service.ts @@ -22,7 +22,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { PolicyType, PolicyInstance, PolicyInstanceAck } from '../../interfaces/policy.types'; +import { PolicyInstance, PolicyInstanceAck, PolicyType, PolicyTypes } from '../../interfaces/policy.types'; import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.types'; /** @@ -33,12 +33,13 @@ import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.type }) export class PolicyService { - private basePath = 'api/policy'; - policyTypePath = 'policytypes'; + private apiVersion2 = 'v2' + private basePath = ''; + policyTypesPath = 'policy-types'; policyPath = 'policies'; private buildPath(...args: any[]) { - let result = this.basePath; + let result = this.basePath + this.apiVersion2; args.forEach(part => { result = result + '/' + part; }); @@ -49,21 +50,14 @@ export class PolicyService { // injects to variable httpClient } - /** - * Gets version details - * @returns Observable that should yield a String - */ - getVersion(): Observable { - const url = this.buildPath('version'); - return this.httpClient.get(url).pipe( - // Extract the string here - map(res => res['data']) - ); + getPolicyTypes(): Observable { + const url = this.buildPath(this.policyTypesPath); + return this.httpClient.get(url); } - getPolicyTypes(): Observable { - const url = this.buildPath(this.policyTypePath); - return this.httpClient.get(url); + getPolicyType(policyTypeId: string): Observable { + const url = this.buildPath(this.policyTypesPath + '/' + policyTypeId); + return this.httpClient.get(url); } getPolicyInstances(policyTypeId: string): Observable { -- 2.16.6