2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 import {TestBed} from '@angular/core/testing';
21 import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config";
22 import {ComponentInstanceServiceNg2} from "./component-instance.service";
23 import {Capability} from "../../../models/capability";
24 import {HttpClientTestingModule, HttpTestingController} from "@angular/common/http/testing";
26 describe('ComponentInstanceServiceNg2', () => {
27 let httpTestingController: HttpTestingController;
28 let componentInstanceService: ComponentInstanceServiceNg2;
29 let rootApi: string = 'http://localhost/'
30 let componentApiRoot: string = 'catalog/'
32 const sdcConfigToken: Partial<ISdcConfig> = {
35 'component_api_root': componentApiRoot,
38 TestBed.configureTestingModule({
39 providers: [ComponentInstanceServiceNg2,
40 {provide: SdcConfigToken, useValue: sdcConfigToken}
42 imports: [HttpClientTestingModule]
44 httpTestingController = TestBed.get(HttpTestingController);
45 componentInstanceService = TestBed.get(ComponentInstanceServiceNg2);
48 it('should be created', () => {
49 expect(componentInstanceService).toBeTruthy();
52 it('updateInstanceCapability call should return the expected data', () => {
53 const capabilityToUpdate = new Capability();
54 capabilityToUpdate.type = "tosca.capabilities.Scalable";
55 capabilityToUpdate.name = "capScalable";
56 capabilityToUpdate.ownerId = "191f8a83-d362-4db4-af30-75d71a55c959.a822dd1c-3560-47ea-b8a2-f557fed5e186.vfcapreq10";
57 capabilityToUpdate.uniqueId = "2047eb3c-de31-4413-a358-8710a3dd2670";
58 capabilityToUpdate.external = true;
60 const componentTypeUrl = "services/";
61 let actualCapability: Capability;
62 componentInstanceService.updateInstanceCapability(componentTypeUrl, "componentId", "componentInstanceId", capabilityToUpdate)
63 .subscribe(capability => {
64 actualCapability = capability;
68 httpTestingController.expectOne(`${rootApi}${componentApiRoot}${componentTypeUrl}componentId/componentInstances/componentInstanceId/capability/`);
70 expect(request.request.method).toEqual('PUT');
72 request.flush(capabilityToUpdate);
73 expect(actualCapability.name).toEqual(capabilityToUpdate.name);
74 expect(actualCapability.type).toEqual(capabilityToUpdate.type);
75 expect(actualCapability.ownerId).toEqual(capabilityToUpdate.ownerId);
76 expect(actualCapability.uniqueId).toEqual(capabilityToUpdate.uniqueId);
77 expect(actualCapability.external).toEqual(capabilityToUpdate.external);