1 import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';
2 import { Injectable, Injector } from '@angular/core';
3 import { Observable, of } from 'rxjs';
5 import * as eijobs from './mock/ei-jobs.json';
6 import * as eiproducers from './mock/ei-producers.json';
7 import * as nopolicyinstances from './mock/nopolicyinstances.json';
8 import * as policytypes from './mock/policytypes.json';
9 import * as policyinstanceedit from './mock/policy-instance-edit.json';
10 import * as policyinstances from './mock/policy-instance.json';
11 import * as rics from './mock/rics.json';
15 url: 'api/policy/policytypes',
19 url: 'api/policy/policies?type=1',
23 url: 'api/policy/policies?type=2',
24 json: nopolicyinstances
27 url: 'api/policy/policies/2000?type=1',
28 json: policyinstanceedit
31 url: 'api/policy/policies/2000?ric=ric1&type=1',
35 url: 'api/enrichment/eijobs',
39 url: 'api/enrichment/eiproducers',
43 url: 'api/policy/rics?policyType=1',
47 url: 'api/policy/rics?policyType=2',
53 export class HttpMockRequestInterceptor implements HttpInterceptor {
54 constructor(private injector: Injector) {}
56 intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
57 if (request.method === "PUT" && request.url.includes("policies")) {
58 console.log('Answered PUT policy ' + request.url);
59 return of(new HttpResponse({ status: 200 }));
61 for (const element of urls) {
62 if (request.url === element.url) {
63 console.log('Loaded from stub json : ' + request.url);
64 return of(new HttpResponse({ status: 200, body: ((element.json) as any).default }));
67 console.log('Loaded from mock http call :' + request.url);
68 return next.handle(request);