summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/services/templateService
diff options
context:
space:
mode:
authorAlexey Sandler <alexey.sandler@intl.att.com>2019-12-03 13:04:42 +0200
committerIttay Stern <ittay.stern@att.com>2019-12-03 17:40:32 +0200
commit9e65dc01257d59b78f89077b94cc6393efef1893 (patch)
treec08fc893af8efd88a1d3e691cde9e565e0314674 /vid-webpack-master/src/app/shared/services/templateService
parent2a8f0ba72f2c449d2048674a22820d4f8385f8ca (diff)
Drawing Board RECREATE will use a new route that retrieves a template
Use endpoint "templateTopology" instead of "bulkForRetry" Issue-ID: VID-724 Change-Id: Ic92971e29d1f78768aeb82158ce424ff31bfbbb0 Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/services/templateService')
-rw-r--r--vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts51
-rw-r--r--vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.ts26
2 files changed, 77 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts b/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts
new file mode 100644
index 000000000..80b113bde
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.spec.ts
@@ -0,0 +1,51 @@
+import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing";
+import {InstantiationTemplatesService} from "./instantiationTemplates.service";
+import {mock} from "ts-mockito";
+import {NgRedux} from "@angular-redux/store";
+import {getTestBed, TestBed} from "@angular/core/testing";
+import {ServiceInstance} from "../../models/serviceInstance";
+import {Constants} from "../../utils/constants";
+
+class MockAppStore<T> {
+ dispatch() {}
+ getState() {}
+}
+
+describe("TemplateService", ()=>{
+ let injector;
+ let httpMock: HttpTestingController;
+ let templateService: InstantiationTemplatesService;
+
+ beforeAll( done => (async () => {
+ TestBed.configureTestingModule({
+ imports: [HttpClientTestingModule],
+ providers: [
+ InstantiationTemplatesService,
+ {provide: NgRedux, useClass: MockAppStore},
+ ]
+ });
+ await TestBed.compileComponents();
+
+ injector = getTestBed();
+ httpMock = injector.get(HttpTestingController);
+ templateService = injector.get(InstantiationTemplatesService);
+ })().then(done).catch(done.fail));
+
+ describe ('#retrieveInstantiationTemplateTopology tests', () => {
+ test('when called -> retrieve template from backend', done => {
+ const mockedTemplate = mock(ServiceInstance);
+ const jobId: string = "some-random-job-id";
+
+ templateService.retrieveInstantiationTemplateTopology(jobId)
+ .subscribe((result: ServiceInstance) => {
+ expect(Object.is(result, mockedTemplate)).toBe(true);
+ done();
+ });
+
+ httpMock
+ .expectOne(`${Constants.Path.INSTANTIATION_TEMPLATE_TOPOLOGY}/${jobId}`)
+ .flush(mockedTemplate);
+ })
+ })
+});
+
diff --git a/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.ts b/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.ts
new file mode 100644
index 000000000..21cdc9296
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/services/templateService/instantiationTemplates.service.ts
@@ -0,0 +1,26 @@
+import {Injectable} from "@angular/core";
+import {HttpClient} from "@angular/common/http";
+import {NgRedux} from "@angular-redux/store";
+import {AppState} from "../../store/reducers";
+import {Observable} from "rxjs";
+import {ServiceInstance} from "../../models/serviceInstance";
+import {Constants} from "../../utils/constants";
+import {createServiceInstance} from "../../storeUtil/utils/service/service.actions";
+
+@Injectable()
+export class InstantiationTemplatesService {
+ constructor(private http: HttpClient, private store: NgRedux<AppState>) {
+ }
+
+ retrieveInstantiationTemplateTopology(jobId: string): Observable<ServiceInstance> {
+ let pathQuery: string = `${Constants.Path.INSTANTIATION_TEMPLATE_TOPOLOGY}/${jobId}`;
+ return this.http.get<ServiceInstance>(pathQuery)
+ }
+
+ public retrieveAndStoreInstantiationTemplateTopology(jobId: string, serviceModelId: string): Observable<ServiceInstance> {
+ return this.retrieveInstantiationTemplateTopology(jobId).do((instantiationTemplate: ServiceInstance) => {
+ this.store.dispatch(createServiceInstance(instantiationTemplate, serviceModelId));
+ });
+ };
+
+}