2017-11-29 16:07:53 +01:00
|
|
|
import { TestBed, inject } from '@angular/core/testing';
|
|
|
|
|
2018-03-30 11:04:03 +02:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
|
|
|
|
import { HttpServer } from './http-server.service';
|
|
|
|
import { Server } from '../models/server';
|
2018-06-27 10:29:12 +02:00
|
|
|
import { Node } from '../cartography/models/node';
|
2018-03-30 11:04:03 +02:00
|
|
|
import { getTestServer } from './testing';
|
2017-11-29 16:07:53 +01:00
|
|
|
import { NodeService } from './node.service';
|
2018-03-30 11:04:03 +02:00
|
|
|
import { Appliance } from '../models/appliance';
|
|
|
|
import { Project } from '../models/project';
|
2018-07-03 11:34:37 +02:00
|
|
|
import { AppTestingModule } from "../testing/app-testing/app-testing.module";
|
2017-11-29 16:07:53 +01:00
|
|
|
|
|
|
|
describe('NodeService', () => {
|
2018-03-30 11:04:03 +02:00
|
|
|
let httpClient: HttpClient;
|
|
|
|
let httpTestingController: HttpTestingController;
|
|
|
|
let httpServer: HttpServer;
|
|
|
|
let service: NodeService;
|
|
|
|
let server: Server;
|
|
|
|
|
2017-11-29 16:07:53 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureTestingModule({
|
2018-03-30 11:04:03 +02:00
|
|
|
imports: [
|
2018-07-03 11:34:37 +02:00
|
|
|
HttpClientTestingModule,
|
|
|
|
AppTestingModule
|
2018-03-30 11:04:03 +02:00
|
|
|
],
|
|
|
|
providers: [
|
|
|
|
HttpServer,
|
|
|
|
NodeService
|
|
|
|
]
|
2017-11-29 16:07:53 +01:00
|
|
|
});
|
2018-03-30 11:04:03 +02:00
|
|
|
|
|
|
|
httpClient = TestBed.get(HttpClient);
|
|
|
|
httpTestingController = TestBed.get(HttpTestingController);
|
|
|
|
httpServer = TestBed.get(HttpServer);
|
|
|
|
service = TestBed.get(NodeService);
|
|
|
|
server = getTestServer();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
httpTestingController.verify();
|
2017-11-29 16:07:53 +01:00
|
|
|
});
|
|
|
|
|
2018-03-30 11:04:03 +02:00
|
|
|
it('should be created', inject([NodeService], (service: NodeService) => {
|
|
|
|
expect(service).toBeTruthy();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should start node', inject([NodeService], (service: NodeService) => {
|
|
|
|
const node = new Node();
|
|
|
|
node.project_id = "myproject";
|
|
|
|
node.node_id = "id";
|
|
|
|
|
|
|
|
service.start(server, node).subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id/start');
|
|
|
|
expect(req.request.method).toEqual("POST");
|
|
|
|
expect(req.request.body).toEqual({});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should stop node', inject([NodeService], (service: NodeService) => {
|
|
|
|
const node = new Node();
|
|
|
|
node.project_id = "myproject";
|
|
|
|
node.node_id = "id";
|
|
|
|
|
|
|
|
service.stop(server, node).subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id/stop');
|
|
|
|
expect(req.request.method).toEqual("POST");
|
|
|
|
expect(req.request.body).toEqual({});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should createFromAppliance node', inject([NodeService], (service: NodeService) => {
|
|
|
|
const project = new Project();
|
|
|
|
project.project_id = "myproject";
|
|
|
|
const appliance = new Appliance();
|
|
|
|
appliance.appliance_id = "myappliance";
|
|
|
|
|
|
|
|
service.createFromAppliance(server, project, appliance, 10, 20, "compute").subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/projects/myproject/appliances/myappliance');
|
|
|
|
expect(req.request.method).toEqual("POST");
|
|
|
|
expect(req.request.body).toEqual({
|
|
|
|
'x': 10, 'y': 20, 'compute_id': 'compute'});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should updatePosition of node', inject([NodeService], (service: NodeService) => {
|
|
|
|
const node = new Node();
|
|
|
|
node.project_id = "myproject";
|
|
|
|
node.node_id = "id";
|
|
|
|
|
|
|
|
service.updatePosition(server, node, 10, 20).subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id');
|
|
|
|
expect(req.request.method).toEqual("PUT");
|
|
|
|
expect(req.request.body).toEqual({
|
|
|
|
'x': 10,
|
|
|
|
'y': 20
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should update node', inject([NodeService], (service: NodeService) => {
|
|
|
|
const node = new Node();
|
|
|
|
node.project_id = "myproject";
|
|
|
|
node.node_id = "id";
|
|
|
|
node.x = 10;
|
|
|
|
node.y = 20;
|
|
|
|
node.z = 30;
|
|
|
|
|
|
|
|
service.update(server, node).subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id');
|
|
|
|
expect(req.request.method).toEqual("PUT");
|
|
|
|
expect(req.request.body).toEqual({
|
|
|
|
'x': 10,
|
|
|
|
'y': 20,
|
|
|
|
'z': 30
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should delete node', inject([NodeService], (service: NodeService) => {
|
|
|
|
const node = new Node();
|
|
|
|
node.project_id = "myproject";
|
|
|
|
node.node_id = "id";
|
|
|
|
|
|
|
|
service.delete(server, node).subscribe();
|
|
|
|
|
|
|
|
const req = httpTestingController.expectOne(
|
|
|
|
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id');
|
|
|
|
expect(req.request.method).toEqual("DELETE");
|
|
|
|
}));
|
|
|
|
|
2017-11-29 16:07:53 +01:00
|
|
|
});
|