aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/instantiationStatus/instantiationStatus.component.service.spec.ts
blob: 849f3de017516737cfe2ff01456ce400276e8a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.onap.ccsdk.parent</groupId>
		<artifactId>single-feature-parent</artifactId>
		<version>2.1.0</version>
		<relativePath/>
	</parent>

	<groupId>org.onap.sdnc.northbound</groupId>
	<artifactId>sdnc-northbound-all</artifactId>
	<version>2.1.0</version>
	<packaging>feature</packaging>

	<name>sdnc-northbound :: features :: ${project.artifactId}</name>

	<dependencyManagement>
	    <dependencies>
	    	<dependency>
  <groupId>org.onap.ccsdk.sli.core</groupId>
  <artifactId>sli-core-artifacts</artifactId>
  <version>${ccsdk.sli.core.version}</version>
  <type>pom</type>
  <scope>import</scope>
	    	</dependency>
	    </dependencies>
	</dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>sdnc-generic-resource-api</artifactId>
			<version>${project.version}</version>
			<type>xml</type>
			<classifier>features</classifier>
		</dependency>
                <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>sdnc-optical-service</artifactId>
                        <version>${project.version}</version>
                        <type>xml</type>
                        <classifier>features</classifier>
                </dependency>
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>sdnc-vnftools</artifactId>
			<version>${project.version}</version>
			<type>xml</type>
			<classifier>features</classifier>
		</dependency>

	
	</dependencies>
</project>
0'>380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
import {getTestBed, TestBed} from '@angular/core/testing';
import {
  COMPLETED_WITH_ERRORS,
  FAILED_AND_PAUSED,
  INPROGRESS,
  InstantiationStatusComponentService,
  PAUSE,
  PAUSE_UPON_COMPLETION,
  PENDING,
  ServiceStatus,
  STOPPED,
  SUCCESS_CIRCLE,
  UNKNOWN,
  X_O
} from './instantiationStatus.component.service';
import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
import {AaiService} from "../shared/services/aaiService/aai.service";
import {MsoService} from "../shared/services/msoService/mso.service";
import {NgRedux} from "@angular-redux/store";
import {HttpClientTestingModule} from "@angular/common/http/testing";
import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service";
import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
import {RouterTestingModule} from "@angular/router/testing";
import {of} from "rxjs";
import {UrlTree} from "@angular/router";
import each from "jest-each";
import {ServiceAction} from "../shared/models/serviceInstanceActions";
import {instance, mock, when} from "ts-mockito";

class MockAppStore<T> {
  dispatch() {}
}

describe('Instantiation Status Service', () => {
  let injector;
  let aaiService: AaiService;
  let msoService: MsoService;
  let service: InstantiationStatusComponentService;
  let mockFeatureFlagsService: FeatureFlagsService = mock(FeatureFlagsService);


  beforeAll(done => (async () => {
    TestBed.configureTestingModule({
      imports: [
        HttpClientTestingModule,
        RouterTestingModule,
      ],
      providers: [
        InstantiationStatusComponentService,
        AaiService,
        MsoService,
        FeatureFlagsService,
        {provide: NgRedux, useClass: MockAppStore},
        {provide: FeatureFlagsService, useValue: instance(mockFeatureFlagsService)}
      ]
    });
    await TestBed.compileComponents();

    injector = getTestBed();
    aaiService = injector.get(AaiService);
    msoService = injector.get(MsoService);
    service = injector.get(InstantiationStatusComponentService);

  })().then(done).catch(done.fail));

  test('generateServiceInfoDataMapping should return mapping of arrays', () => {
    let data : ServiceInfoModel[] = generateServiceInfoData();
    let result = service.generateServiceInfoDataMapping(data);

    expect(result['1']).toBeDefined();
    expect(result['2']).toBeDefined();
    expect(result['3']).toBeDefined();

    expect(result['1'].length).toEqual(2);
    expect(result['2'].length).toEqual(2);
    expect(result['3'].length).toEqual(1);
  });

  test('generateServiceInfoDataMapping if array is empty  should return empty object', () => {
    let result = service.generateServiceInfoDataMapping([]);

    expect(result['1']).not.toBeDefined();
    expect(result['2']).not.toBeDefined();
    expect(result['3']).not.toBeDefined();
  });

  test('convertObjectToArray', () => {

    jest.spyOn(service, 'convertObjectToArray').mockReturnValue(
      of([])
    );

    let data : ServiceInfoModel[] = generateServiceInfoData();
    service.convertObjectToArray(data).subscribe((result) => {
      expect(result).toBeDefined();
    });
  });

  describe('navigations tests:', () => {

    const item = {
      serviceModelId: '28aeb8f6-5620-4148-8bfb-a5fb406f0309',
      serviceInstanceId: 'myInstanceId',
      serviceType: 'myService',
      subscriberId: 'mySubscriber',
      jobId: 'aJobId'
    };

    test('click on "Open" button should open new view edit', () => {
      let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.VIEW);
      expect(params.toString().startsWith('/servicePlanning/VIEW')).toBeTruthy();
      expect(params.queryParams).toEqual(
        {
          serviceModelId: item.serviceModelId,
          serviceInstanceId: item.serviceInstanceId,
          serviceType: item.serviceType,
          subscriberId: item.subscriberId,
          jobId: item.jobId
        });
    });

    test('build the View Edit url', () => {

      let serviceModelUrl: string = '/servicePlanning/EDIT?serviceModelId=28aeb8f6-5620-4148-8bfb-a5fb406f0309' +
        '&serviceInstanceId=myInstanceId&serviceType=myService&subscriberId=mySubscriber&jobId=aJobId';
      let prefix: string = '../../serviceModels.htm#';
      let tree: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.EDIT);
      let result = service.getViewEditUrl(tree);
      expect(result).toEqual(prefix + serviceModelUrl);
    });

    test('recreate url shall contains mode RECREATE and only jobId and serviceModelId', () =>{
      let params: UrlTree = service.getNewViewEditUrlTree(<any>item, DrawingBoardModes.RECREATE);
      expect(params.toString().startsWith('/servicePlanning/RECREATE')).toBeTruthy();
      expect(params.queryParams).toEqual(
        {
          serviceModelId: item.serviceModelId,
          jobId: item.jobId
        });
    });
  });

  for (let [status, tooltip] of Object.entries({
    'pending': 'Pending: The action required will be sent as soon as possible.',
    'IN_PROGRESS': 'In-progress: the service is in process of the action required.',
    'PAUSED': 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.',
    'FAILED': 'Failed: All planned actions have failed.',
    'COMPLETED': 'Completed successfully: Service is successfully instantiated, updated or deleted.',
    'STOPPED': 'Stopped: Due to previous failure, will not be instantiated.',
    'StOpPeD': 'Stopped: Due to previous failure, will not be instantiated.',
    'COMPLETED_WITH_ERRORS': 'Completed with errors: some of the planned actions where successfully committed while other have not.\n Open the service to check it out.',
    'UNEXPECTED_RANDOM_STATUS': 'Unexpected status: "UNEXPECTED_RANDOM_STATUS"',
    'COMPLETED_AND_PAUSED': 'Pause upon completion. you may resume the instantiation.\n Open the service to check it out.',
    'FAILED_AND_PAUSED': 'Failed and Paused: you may re-deploy the instantiation.',
  })) {

    test(`getStatusTooltip should return status popover: status=${status}`, () => {
      expect(service.getStatus(status).tooltip).toEqual(tooltip);
    });

  }

  test(`service.getStatus should handle undefined status`, () => {
    const statusResult = service.getStatus(undefined);
    expect(statusResult.tooltip).toEqual('Unexpected status: "undefined"');
    expect(statusResult.iconClassName).toEqual(UNKNOWN);
  });


  each([
      [true, ServiceAction.INSTANTIATE],
      [false, ServiceAction.UPDATE],
      [false, ServiceAction.DELETE],
  ]).
  test('isRecreateEnabled: should be %s if action is %s', (expected:boolean, action:ServiceAction) => {
    let serviceInfoModel = new ServiceInfoModel();
    serviceInfoModel.action = action;
    expect(service.isRecreateEnabled(serviceInfoModel)).toBe(expected);
  });

  each([
    [true, true],
    [false, false],
  ]).
  test('isRecreateVisible: should be %s if flag is %s', (expected:boolean, flag:boolean) => {
    when(mockFeatureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(flag);
    expect(service.isRecreateVisible()).toEqual(expected);
  });

  test('getStatusTooltip should return correct icon per job status', () => {
    let result : ServiceStatus  = service.getStatus('pending');
    expect(result.iconClassName).toEqual(PENDING);

    result = service.getStatus('IN_PROGRESS');
    expect(result.iconClassName).toEqual(INPROGRESS);

    result = service.getStatus('PAUSED');
    expect(result.iconClassName).toEqual(PAUSE);

    result = service.getStatus('FAILED');
    expect(result.iconClassName).toEqual(X_O);

    result = service.getStatus('COMPLETED');
    expect(result.iconClassName).toEqual(SUCCESS_CIRCLE);

    result = service.getStatus('STOPPED');
    expect(result.iconClassName).toEqual(STOPPED);

    result = service.getStatus('COMPLETED_WITH_ERRORS');
    expect(result.iconClassName).toEqual(COMPLETED_WITH_ERRORS);

    result = service.getStatus('UNEXPECTED_RANDOM_STATUS');
    expect(result.iconClassName).toEqual(UNKNOWN);

    result = service.getStatus('COMPLETED_AND_PAUSED');
    expect(result.iconClassName).toEqual(PAUSE_UPON_COMPLETION);

    result = service.getStatus('FAILED_AND_PAUSED');
    expect(result.iconClassName).toEqual(FAILED_AND_PAUSED);

    result = service.getStatus(undefined);
    expect(result.iconClassName).toEqual(UNKNOWN);
  });

  function generateServiceInfoData(){
    return JSON.parse(JSON.stringify([
      {
        "created": 1519956533000,
        "modified": 1521727738000,
        "createdId": null,
        "modifiedId": null,
        "rowNum": null,
        "auditUserId": null,
        "auditTrail": null,
        "jobId": "6748648484",
        "userId": "2222",
        "jobStatus": "FAILED",
        "pause": false,
        "owningEntityId": "1234",
        "owningEntityName": null,
        "project": null,
        "aicZoneId": null,
        "aicZoneName": null,
        "tenantId": null,
        "tenantName": null,
        "regionId": null,
        "regionName": null,
        "serviceType": null,
        "subscriberName": null,
        "serviceInstanceId": "1",
        "serviceInstanceName": null,
        "serviceModelId": null,
        "serviceModelName": null,
        "serviceModelVersion": null,
        "createdBulkDate": 1519956533000,
        "statusModifiedDate": 1520042933000,
        "templateId": "1",
        "hidden": false
      },
      {
        "created": 1519956533000,
        "modified": 1521727738000,
        "createdId": null,
        "modifiedId": null,
        "rowNum": null,
        "auditUserId": null,
        "auditTrail": null,
        "jobId": "6748648484",
        "userId": "2222",
        "jobStatus": "FAILED",
        "pause": false,
        "owningEntityId": "1234",
        "owningEntityName": null,
        "project": null,
        "aicZoneId": null,
        "aicZoneName": null,
        "tenantId": null,
        "tenantName": null,
        "regionId": null,
        "regionName": null,
        "serviceType": null,
        "subscriberName": null,
        "serviceInstanceId": "1",
        "serviceInstanceName": null,
        "serviceModelId": null,
        "serviceModelName": null,
        "serviceModelVersion": null,
        "createdBulkDate": 1519956533000,
        "statusModifiedDate": 1520042933000,
        "templateId": "1",
        "hidden": false
      },
      {
        "created": 1519956533000,
        "modified": 1521727738000,
        "createdId": null,
        "modifiedId": null,
        "rowNum": null,
        "auditUserId": null,
        "auditTrail": null,
        "jobId": "6748648484",
        "userId": "2222",
        "jobStatus": "FAILED",
        "pause": false,
        "owningEntityId": "1234",
        "owningEntityName": null,
        "project": null,
        "aicZoneId": null,
        "aicZoneName": null,
        "tenantId": null,
        "tenantName": null,
        "regionId": null,
        "regionName": null,
        "serviceType": null,
        "subscriberName": null,
        "serviceInstanceId": "2",
        "serviceInstanceName": null,
        "serviceModelId": null,
        "serviceModelName": null,
        "serviceModelVersion": null,
        "createdBulkDate": 1519956533000,
        "statusModifiedDate": 1520042933000,
        "templateId": "2",
        "hidden": false
      },
      {
        "created": 1519956533000,
        "modified": 1521727738000,
        "createdId": null,
        "modifiedId": null,
        "rowNum": null,
        "auditUserId": null,
        "auditTrail": null,
        "jobId": "6748648484",
        "userId": "2222",
        "jobStatus": "FAILED",
        "pause": false,
        "owningEntityId": "1234",
        "owningEntityName": null,
        "project": null,
        "aicZoneId": null,
        "aicZoneName": null,
        "tenantId": null,
        "tenantName": null,
        "regionId": null,
        "regionName": null,
        "serviceType": null,
        "subscriberName": null,
        "serviceInstanceId": "2",
        "serviceInstanceName": null,
        "serviceModelId": null,
        "serviceModelName": null,
        "serviceModelVersion": null,
        "createdBulkDate": 1519956533000,
        "statusModifiedDate": 1520042933000,
        "templateId": "2",
        "hidden": false
      },
      {
        "created": 1519956533000,
        "modified": 1521727738000,
        "createdId": null,
        "modifiedId": null,
        "rowNum": null,
        "auditUserId": null,
        "auditTrail": null,
        "jobId": "6748648484",
        "userId": "2222",
        "jobStatus": "FAILED",
        "pause": false,
        "owningEntityId": "1234",
        "owningEntityName": null,
        "project": null,
        "aicZoneId": null,
        "aicZoneName": null,
        "tenantId": null,
        "tenantName": null,
        "regionId": null,
        "regionName": null,
        "serviceType": null,
        "subscriberName": null,
        "serviceInstanceId": "3",
        "serviceInstanceName": null,
        "serviceModelId": null,
        "serviceModelName": null,
        "serviceModelVersion": null,
        "createdBulkDate": 1519956533000,
        "statusModifiedDate": 1520042933000,
        "templateId": "3",
        "hidden": false
      }
    ]));
  }

});