let fixture: ComponentFixture<EICoordinatorComponent>;
beforeEach(async(() => {
- const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'connect', 'loadTable', 'disconnect' ]);
+ const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'connect', 'getJobs', 'disconnect' ]);
const producerDataSourceSpy = jasmine.createSpyObj('EIProducerDataSource', [ 'connect', 'loadTable', 'getProducers', 'disconnect' ]);
jobDataSourceSpy.connect.and.returnValue(of([]));
}
ngOnInit() {
- this.eiJobsDataSource.loadTable();
+ this.eiJobsDataSource.getJobs();
this.producers$= this.eiProducersDataSource.getProducers();
this.filteredProducers$ = defer(() => this.formGroup.get("filter")
}
refreshTables() {
- this.eiJobsDataSource.loadTable();
+ this.eiJobsDataSource.getJobs();
this.eiProducersDataSource.loadTable();
}
}
--- /dev/null
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * 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.
+ * ========================LICENSE_END===================================
+ */
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { BehaviorSubject, of } from 'rxjs';
+
+import { EIJobDataSource } from './ei-job.datasource';
+import { EIService } from '../services/ei/ei.service';
+import { NotificationService } from '../services/ui/notification.service';
+import { ToastrModule } from 'ngx-toastr';
+import { EIJob } from '../interfaces/ei.types';
+
+describe('EIJobDataSource', () => {
+ let dataSource: EIJobDataSource;
+ let eiServiceSpy: any;
+
+ let job = { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1', target_uri: 'hhtp://url', owner: 'owner'};
+
+ beforeEach(() => {
+ eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getJobsForProducer']);
+
+ eiServiceSpy.getProducerIds.and.returnValue(of([ 'producer1', 'producer2']));
+ eiServiceSpy.getJobsForProducer.and.returnValue(of([job]));
+ TestBed.configureTestingModule({
+ imports: [ToastrModule.forRoot()],
+ providers: [
+ { provide: EIService, useValue: eiServiceSpy },
+ NotificationService
+ ]
+ });
+ });
+
+ it('should create', () => {
+ dataSource = TestBed.get(EIJobDataSource);
+ expect(dataSource).toBeTruthy();
+ });
+
+ it('#getJobs and connect', () => {
+ dataSource.getJobs();
+ const jobsSubject: BehaviorSubject<EIJob[]> = dataSource.eiJobsSubject;
+ const value = jobsSubject.getValue();
+ expect(value).toEqual([ job, job ]);
+ expect(dataSource.rowCount).toEqual(2);
+ });
+});
export class EIJobDataSource extends MatTableDataSource<EIJob> {
- private eiJobSubject = new BehaviorSubject<EIJob[]>([]);
+ eiJobsSubject = new BehaviorSubject<EIJob[]>([]);
private loadingSubject = new BehaviorSubject<boolean>(false);
super();
}
- loadTable() {
+ getJobs() {
this.loadingSubject.next(true);
- this.eiSvc.getEIJobs()
+ this.eiSvc.getProducerIds()
.pipe(
catchError((her: HttpErrorResponse) => {
this.notificationService.error('Failed to get EI jobs: ' + her.error);
}),
finalize(() => this.loadingSubject.next(false))
)
- .subscribe((instances: EIJob[]) => {
- this.rowCount = instances.length;
- this.eiJobSubject.next(instances);
+ .subscribe((producerIds: String[]) => {
+ producerIds.forEach(id => {
+ this.getJobsForProducer(id);
+ });
});
}
+ private getJobsForProducer(id: String) {
+ console.log('Getting jobs for producer ID: ', id);
+ this.eiSvc.getJobsForProducer(id).subscribe(jobs => {
+ this.addJobsToSubject(jobs);
+ this.rowCount = this.eiJobsSubject.getValue().length;
+ });
+ }
+
+ private addJobsToSubject(jobs: EIJob[]) {
+ const currentValue = this.eiJobsSubject.value;
+ const updatedValue = [...currentValue, ...jobs];
+ this.eiJobsSubject.next(updatedValue);
+ }
+
connect(): BehaviorSubject<EIJob[]> {
- return this.eiJobSubject;
+ return this.eiJobsSubject;
}
disconnect(): void {
- this.eiJobSubject.complete();
+ this.eiJobsSubject.complete();
this.loadingSubject.complete();
}
}
import * as policyinstances2 from './mock/policy-instance-2.json';
import * as policyinstances1Status from './mock/policy-instance-1-status.json';
import * as policyinstances2Status from './mock/policy-instance-2-status.json';
-import * as eijobs from './mock/ei-jobs.json';
+import * as eijobsProd1 from './mock/ei-jobs-producer1.json';
+import * as eijobsProd2 from './mock/ei-jobs-producer2.json';
+import * as eiProducerIds from './mock/ei-producerids.json';
import * as eiproducers from './mock/ei-producers.json';
-import * as policyinstanceNoType from './mock/policy-instance-notype.json';
import * as policytypesList from './mock/policy-types.json';
import * as policytypes1 from './mock/policy-type1.json';
import * as policyinstanceedit from './mock/policy-instance-edit.json';
url: '/a1-policy/v2/rics?policytype_id=',
json: ric2
},
- {
- url: 'api/enrichment/eijobs',
- json: eijobs
- },
{
url: 'api/enrichment/eiproducers',
json: eiproducers
{
url: 'api/policy/rics?policyType=2',
json: rics
+ },
+ {
+ url: '/ei-producer/v1/eiproducers',
+ json: eiProducerIds
+ },
+ {
+ url: '/ei-producer/v1/eiproducers/producer1/eijobs',
+ json: eijobsProd1
+ },
+ {
+ url: '/ei-producer/v1/eiproducers/producer2/eijobs',
+ json: eijobsProd2
}
];
},
{
"ei_job_identity": "job2",
- "ei_type_identity": "type2",
+ "ei_type_identity": "type1",
+ "owner": "owner1",
"ei_job_data": {
"jobparam2": "value2_job2",
"jobparam3": "value3_job2",
--- /dev/null
+[
+ {
+ "ei_job_identity": "job3",
+ "ei_type_identity": "type2",
+ "owner": "owner1",
+ "ei_job_data": {
+ "jobparam2": "value2_job3",
+ "jobparam3": "value3_job3",
+ "jobparam1": "value1_job3"
+ },
+ "target_uri": "https://ricsim_g3_1:8185/datadelivery"
+ }
+ ]
\ No newline at end of file
--- /dev/null
+[
+ "producer1",
+ "producer2"
+]
\ No newline at end of file
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
import { TestBed } from '@angular/core/testing';
-import { EIJob, EIProducer } from '../../interfaces/ei.types';
+import { EIJob } from '../../interfaces/ei.types';
import { EIService } from './ei.service';
describe('EIService', () => {
- let basePath = 'api/enrichment';
+ let basePath = '/ei-producer/v1';
let service: EIService;
let httpTestingController: HttpTestingController;
});
describe('#getEIProducers', () => {
- let expectedEIProducers: EIProducer[];
+ let expectedEIProducerIds: String[];
beforeEach(() => {
service = TestBed.get(EIService);
httpTestingController = TestBed.get(HttpTestingController);
- expectedEIProducers = [
- { ei_producer_id: '1', ei_producer_types: ['EI Type 1'], status: 'ENABLED' },
- { ei_producer_id: '1', ei_producer_types: ['EI Type 1'], status: 'ENABLED' }
- ] as EIProducer[];
+ expectedEIProducerIds = [ 'producer1', 'producer2' ] as String[];
});
- it('should return all producers', () => {
- service.getEIProducers().subscribe(
- producers => expect(producers).toEqual(expectedEIProducers, 'should return expected EIProducers'),
+ it('should return all producer IDs', () => {
+ service.getProducerIds().subscribe(
+ producers => expect(producers).toEqual(expectedEIProducerIds, 'should return expected EIProducer IDs'),
fail
);
- const req = httpTestingController.expectOne(basePath + '/' + service.eiProducerPath);
+ const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath);
expect(req.request.method).toEqual('GET');
- req.flush(expectedEIProducers); //Return expectedEITypes
+ req.flush(expectedEIProducerIds); //Return expected producer IDs
httpTestingController.verify();
});
});
it('should return all jobs', () => {
- service.getEIJobs().subscribe(
+ service.getJobsForProducer('producer1').subscribe(
jobs => expect(jobs).toEqual(expectedEIJobs, 'should return expected Jobs'),
fail
);
- const req = httpTestingController.expectOne(basePath + '/' + service.eiJobPath);
+ const req = httpTestingController.expectOne(basePath + '/' + service.eiProducersPath + '/producer1/' + service.eiJobsPath);
expect(req.request.method).toEqual('GET');
req.flush(expectedEIJobs); //Return expectedEIJobs
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
-import { Observable } from 'rxjs';
-import { map } from 'rxjs/operators';
+import { Observable, of } from 'rxjs';
import { EIJob, EIProducer } from '../../interfaces/ei.types';
-import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.types';
/**
* Services for calling the EI endpoints.
})
export class EIService {
- private basePath = 'api/enrichment';
- eiJobPath = 'eijobs';
- eiProducerPath = 'eiproducers';
+ private basePath = '/ei-producer/v1';
+ eiJobsPath = 'eijobs';
+ eiProducersPath = 'eiproducers';
private buildPath(...args: any[]) {
let result = this.basePath;
// injects to variable httpClient
}
- getEIJobs(): Observable<EIJob[]> {
- const url = this.buildPath(this.eiJobPath);
+ getProducerIds(): Observable<String[]> {
+ const url = this.buildPath(this.eiProducersPath);
+ return this.httpClient.get<String[]>(url);
+ }
+
+ getJobsForProducer(producerId: String): Observable<EIJob[]> {
+ const url = this.buildPath(this.eiProducersPath, producerId, this.eiJobsPath);
return this.httpClient.get<EIJob[]>(url);
}
getEIProducers(): Observable<EIProducer[]> {
- const url = this.buildPath(this.eiProducerPath);
+ const url = this.buildPath(this.eiProducersPath);
return this.httpClient.get<EIProducer[]>(url);
}
}