diff options
Diffstat (limited to 'catalog-ui/src/app/ng2/services')
2 files changed, 105 insertions, 11 deletions
diff --git a/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.spec.ts b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.spec.ts new file mode 100644 index 0000000000..4de556cdd5 --- /dev/null +++ b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.spec.ts @@ -0,0 +1,80 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import {TestBed} from '@angular/core/testing'; +import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config"; +import {ComponentInstanceServiceNg2} from "./component-instance.service"; +import {Capability} from "../../../models/capability"; +import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing"; + +describe('ComponentInstanceServiceNg2', () => { + let httpTestingController: HttpTestingController; + let componentInstanceService: ComponentInstanceServiceNg2; + let rootApi: string = 'http://localhost/' + let componentApiRoot: string = 'catalog/' + beforeEach(() => { + const sdcConfigToken: Partial<ISdcConfig> = { + 'api': { + 'root': rootApi, + 'component_api_root': componentApiRoot, + } + }; + TestBed.configureTestingModule({ + providers: [ComponentInstanceServiceNg2, + {provide: SdcConfigToken, useValue: sdcConfigToken} + ], + imports: [HttpClientTestingModule] + }); + httpTestingController = TestBed.get(HttpTestingController); + componentInstanceService = TestBed.get(ComponentInstanceServiceNg2); + }); + + it('should be created', () => { + expect(componentInstanceService).toBeTruthy(); + }); + + it('updateInstanceCapability call should return the expected data', () => { + const capabilityToUpdate = new Capability(); + capabilityToUpdate.type = "tosca.capabilities.Scalable"; + capabilityToUpdate.name = "capScalable"; + capabilityToUpdate.ownerId = "191f8a83-d362-4db4-af30-75d71a55c959.a822dd1c-3560-47ea-b8a2-f557fed5e186.vfcapreq10"; + capabilityToUpdate.uniqueId = "2047eb3c-de31-4413-a358-8710a3dd2670"; + capabilityToUpdate.external = true; + + const componentTypeUrl = "services/"; + let actualCapability: Capability; + componentInstanceService.updateInstanceCapability(componentTypeUrl, "componentId", "componentInstanceId", capabilityToUpdate) + .subscribe(capability => { + actualCapability = capability; + }); + + const request = + httpTestingController.expectOne(`${rootApi}${componentApiRoot}${componentTypeUrl}componentId/componentInstances/componentInstanceId/capability/`); + + expect(request.request.method).toEqual('PUT'); + + request.flush(capabilityToUpdate); + expect(actualCapability.name).toEqual(capabilityToUpdate.name); + expect(actualCapability.type).toEqual(capabilityToUpdate.type); + expect(actualCapability.ownerId).toEqual(capabilityToUpdate.ownerId); + expect(actualCapability.uniqueId).toEqual(capabilityToUpdate.uniqueId); + expect(actualCapability.external).toEqual(capabilityToUpdate.external); + }); + +}); diff --git a/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts index 5ae2918805..1e4ddda9c0 100644 --- a/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts +++ b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts @@ -18,15 +18,25 @@ * ============LICENSE_END========================================================= */ -import {Injectable, Inject} from '@angular/core'; -import { Observable } from 'rxjs/Observable'; -import {PropertyFEModel, PropertyBEModel, Requirement} from "app/models"; -import {CommonUtils, ComponentType, ServerTypeUrl, ComponentInstanceFactory} from "app/utils"; -import {Component, ComponentInstance, Capability, PropertyModel, ArtifactGroupModel, ArtifactModel, AttributeModel, IFileDownload} from "app/models"; -import {SdcConfigToken, ISdcConfig} from "../../config/sdc-config.config"; -import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { InputBEModel } from '../../../models/properties-inputs/input-be-model'; -import { HttpHelperService } from '../http-hepler.service'; +import {Inject, Injectable} from '@angular/core'; +import {Observable} from 'rxjs/Observable'; +import { + ArtifactGroupModel, + ArtifactModel, + AttributeModel, + Capability, + Component, + ComponentInstance, + IFileDownload, + PropertyBEModel, + PropertyModel, + Requirement +} from "app/models"; +import {CommonUtils, ComponentInstanceFactory, ComponentType, ServerTypeUrl} from "app/utils"; +import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config"; +import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {InputBEModel} from '../../../models/properties-inputs/input-be-model'; +import {HttpHelperService} from '../http-hepler.service'; import {AttributeBEModel} from "../../../models/attributes-outputs/attribute-be-model"; import {OutputBEModel} from "../../../models/attributes-outputs/output-be-model"; @@ -158,6 +168,11 @@ export class ComponentInstanceServiceNg2 { '/requirementName/' + requirement.name, requirement); } + updateInstanceCapability(componentTypeUrl: string, componentId: string, componentInstanceId: string, capability: Capability): Observable<Capability> { + const url = `${this.baseUrl}${componentTypeUrl}${componentId}/componentInstances/${componentInstanceId}/capability/`; + return this.http.put<Capability>(url, capability); + } + updateInstanceInputs(component: Component, componentInstanceId: string, inputs: PropertyBEModel[]): Observable<PropertyBEModel[]> { return this.http.post<Array<PropertyModel>>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/inputs', inputs) @@ -203,7 +218,6 @@ export class ComponentInstanceServiceNg2 { } addInstanceArtifact = (componentType:string, componentId:string, instanceId:string, artifact:ArtifactModel):Observable<ArtifactModel> => { - // let deferred = this.$q.defer<ArtifactModel>(); let headerObj = new HttpHeaders(); if (artifact.payloadData) { headerObj = headerObj.set('Content-MD5', HttpHelperService.getHeaderMd5(artifact)); @@ -217,7 +231,7 @@ export class ComponentInstanceServiceNg2 { updateInstanceArtifact = (componentType:string, componentId:string, instanceId:string, artifact:ArtifactModel):Observable<ArtifactModel> => { return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + instanceId + '/artifacts/' + artifact.uniqueId, artifact).map((res) => { return new ArtifactModel(res); - });; + }); }; deleteInstanceArtifact = (componentId:string, componentType:string, instanceId:string, artifactId:string, artifactLabel:string):Observable<ArtifactModel> => { |