| /* |
| ******************************************************************************* |
| * Copyright (c) 2018 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ******************************************************************************* |
| */ |
| |
| import { Subscription } from 'rxjs/Subscription'; |
| |
| export abstract class AbstractMockObservableService { |
| protected _subscription: Subscription; |
| protected _fakeContent: any; |
| protected _fakeError: any; |
| |
| set error(err) { |
| this._fakeError = err; |
| } |
| |
| set content(data) { |
| this._fakeContent = data; |
| } |
| |
| get subscription(): Subscription { |
| return this._subscription; |
| } |
| |
| subscribe(next: Function, error?: Function, complete?: Function): Subscription { |
| this._subscription = new Subscription(); |
| |
| if (next && this._fakeContent && !this._fakeError) { |
| next(this._fakeContent); |
| } |
| if (error && this._fakeError) { |
| error(this._fakeError); |
| } |
| if (complete) { |
| complete(); |
| } |
| return this._subscription; |
| } |
| |
| do( doFunc: Function, error?: Function, complete?: Function ): Subscription { |
| this._subscription = new Subscription(); |
| |
| if (this._fakeContent && !this._fakeError ) { |
| doFunc( this._fakeContent ); |
| } |
| |
| if (error && this._fakeError) { |
| error(this._fakeError); |
| } |
| |
| if (complete) { |
| complete(); |
| } |
| |
| return this._subscription; |
| } |
| } |