1 import { Injectable, Injector } from '@angular/core';
2 import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';
3 import { Observable, of } from 'rxjs';
4 import * as policytypes from './mock/policytypes.json';
5 import * as policyinstances from './mock/policy-instance.json';
6 import * as policyinstanceedit from './mock/policy-instance-edit.json';
7 import * as eijobs from './mock/ei-jobs.json';
8 import * as eiproducers from './mock/ei-producers.json';
12 url: 'api/policy/policytypes',
16 url: 'api/policy/policies?type=1',
20 url: 'api/policy/policies/2000?type=1',
21 json: policyinstanceedit
24 url: 'api/policy/policies/2000?ric=ric1&type=1',
28 url: 'api/enrichment/eijobs',
32 url: 'api/enrichment/eiproducers',
38 export class HttpMockRequestInterceptor implements HttpInterceptor {
39 constructor(private injector: Injector) {}
41 intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
42 for (const element of urls) {
43 if (request.url === element.url) {
44 console.log('Loaded from stub json : ' + request.url);
45 return of(new HttpResponse({ status: 200, body: ((element.json) as any).default }));
48 console.log('Loaded from mock http call :' + request.url);
49 return next.handle(request);