X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Finterceptor.mock.ts;h=826d6256258614e92e00cccfa182cca34f6ba8e0;hb=refs%2Fchanges%2F87%2F5587%2F1;hp=bfba913332e4df962d5bcb3b6463a8257437b7e5;hpb=b025b9b3ed3dbe3dc3ccf4edd1fdac05373a8b80;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/interceptor.mock.ts b/webapp-frontend/src/app/interceptor.mock.ts index bfba913..826d625 100644 --- a/webapp-frontend/src/app/interceptor.mock.ts +++ b/webapp-frontend/src/app/interceptor.mock.ts @@ -1,33 +1,106 @@ -import { Injectable, Injector } from '@angular/core'; +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2021 Nordix Foundation + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ========================LICENSE_END=================================== + */ + import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http'; +import { Injectable, Injector } from '@angular/core'; import { Observable, of } from 'rxjs'; -import * as policytypes from './mock/policytypes.json'; -import * as policyinstances from './mock/policy-instance.json'; -import * as policyinstanceedit from './mock/policy-instance-edit.json'; -import * as eijobs from './mock/ei-jobs.json'; +import * as policyinstances1 from './mock/policy-instance-1.json'; +import * as policies from './mock/policies.json'; +import * as policyinstances2 from './mock/policy-instance-2.json'; +import * as policyinstances1Status from './mock/policy-instance-1-status.json'; +import * as policyinstances2Status from './mock/policy-instance-2-status.json'; +import * as eijobsProd1 from './mock/ei-jobs-producer1.json'; +import * as eijobsProd2 from './mock/ei-jobs-producer2.json'; +import * as eiProducerIds from './mock/ei-producerids.json'; import * as eiproducers from './mock/ei-producers.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'; +import * as ric1 from './mock/ric1.json'; +import * as ric2 from './mock/ric2.json'; const urls = [ { - url: 'api/policy/policytypes', - json: policytypes + url: '/a1-policy/v2/policy-types', + json: policytypesList + }, + { + url: '/a1-policy/v2/policy-types/', + json: policytypes1 + }, + { + url: '/a1-policy/v2/policy-types/1', + json: policytypes1 + }, + { + url: '/a1-policy/v2/policies?policytype_id=', + json: policies + }, + { + url: '/a1-policy/v2/policies?policytype_id=1', + json: policies + }, + { + url: '/a1-policy/v2/policies/2000', + json: policyinstances1 }, { - url: 'api/policy/policies?type=1', - json: policyinstances + url: '/a1-policy/v2/policies/2100', + json: policyinstances2 }, { - url: 'api/policy/policies/2000?type=1', + url: '/a1-policy/v2/policies/2000/status', + json: policyinstances1Status + }, + { + url: '/a1-policy/v2/policies/2100/status', + json: policyinstances2Status + }, + { + url: '/a1-policy/v2/policies/2000?type=', json: policyinstanceedit }, { - url: 'api/policy/policies/2000?ric=ric1&type=1', + url: '/a1-policy/v2/policies/2100?type=', + json: policyinstanceedit + }, + { + url: '/a1-policy/v2/policies/2000?type=1', + json: policyinstanceedit + }, + { + url: '/a1-policy/v2/policies/2100?type=1', + json: policyinstanceedit + }, + { + url: '/a1-policy/v2/policies/2000?ric=ric1&type=1', json: '' }, { - url: 'api/enrichment/eijobs', - json: eijobs + url: '/a1-policy/v2/rics?policytype_id=1', + json: ric1 + }, + { + url: '/a1-policy/v2/rics?policytype_id=', + json: ric2 }, { url: 'api/enrichment/eiproducers', @@ -36,12 +109,28 @@ const urls = [ { url: 'api/policy/rics?policyType=1', json: rics + }, + { + url: 'api/policy/rics?policyType=2', + json: rics + }, + { + url: '/ei-producer/v1/eiproducers', + json: eiProducerIds + }, + { + url: '/ei-producer/v1/eiproducers/producer1/eijobs', + json: eijobsProd1 + }, + { + url: '/ei-producer/v1/eiproducers/producer2/eijobs', + json: eijobsProd2 } ]; @Injectable() export class HttpMockRequestInterceptor implements HttpInterceptor { - constructor(private injector: Injector) {} + constructor(private injector: Injector) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { if (request.method === "PUT" && request.url.includes("policies")) { @@ -51,6 +140,9 @@ export class HttpMockRequestInterceptor implements HttpInterceptor { for (const element of urls) { if (request.url === element.url) { console.log('Loaded from stub json : ' + request.url); + if (request.method === 'DELETE') { + return of(new HttpResponse({ status: 204 })); + } return of(new HttpResponse({ status: 200, body: ((element.json) as any).default })); } }