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';
9 import * as rics from './mock/rics.json';
13 url: 'api/policy/policytypes',
17 url: 'api/policy/policies?type=1',
21 url: 'api/policy/policies/2000?type=1',
22 json: policyinstanceedit
25 url: 'api/policy/policies/2000?ric=ric1&type=1',
29 url: 'api/enrichment/eijobs',
33 url: 'api/enrichment/eiproducers',
37 url: 'api/policy/rics?policyType=1',
43 export class HttpMockRequestInterceptor implements HttpInterceptor {
44 constructor(private injector: Injector) {}
46 intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
47 if (request.method === "PUT" && request.url.includes("policies")) {
48 console.log('Answered PUT policy ' + request.url);
49 return of(new HttpResponse({ status: 200 }));
51 for (const element of urls) {
52 if (request.url === element.url) {
53 console.log('Loaded from stub json : ' + request.url);
54 return of(new HttpResponse({ status: 200, body: ((element.json) as any).default }));
57 console.log('Loaded from mock http call :' + request.url);
58 return next.handle(request);