1 | /*
|
2 | * File: NAMadapter_test.js
|
3 | *
|
4 | * Author: Luis Fernando Garcia
|
5 | * Polytechnic University of Madrid (UPM)
|
6 | *
|
7 | * Date: 07/10/2014
|
8 | *
|
9 | * Description:
|
10 | *
|
11 | * License:
|
12 | *
|
13 | * Redistribution and use in source and binary forms, with or without modification,
|
14 | * are permitted provided that the following conditions are met:
|
15 | *
|
16 | * * Redistributions of source code must retain the following copyright notice,
|
17 | * this list of conditions and the disclaimer below.
|
18 | *
|
19 | * Copyright (c) 2003-2008, Polytechnic University of Madrid (UPM)
|
20 | *
|
21 | * All rights reserved.
|
22 | *
|
23 | * * Redistribution in binary form must reproduce the above copyright notice,
|
24 | * this list of conditions and the following disclaimer in the documentation
|
25 | * and/or other materials provided with the distribution.
|
26 | *
|
27 | * * Neither the name of Polytechnic University of Madrid nor the names of its
|
28 | * contributors may be used to endorse or promote products derived from this
|
29 | * software without explicit prior written permission.
|
30 | *
|
31 | * You are under no obligation whatsoever to provide any enhancements to Polytechnic
|
32 | * University of Madrid,or its contributors. If you choose to provide your enhance-
|
33 | * ments, or if you choose to otherwise publish or distribute your enhancement, in
|
34 | * source code form without contemporaneously requiring end users to enter into a
|
35 | * separate written license agreement for such enhancements, then you thereby grant
|
36 | * Polytechnic University of Madrid, its contributors, and its members a non-exclusive,
|
37 | * royalty-free, perpetual license to copy, display, install, use, modify, prepare
|
38 | * derivative works, incorporate into the software or other computer software, dis-
|
39 | * tribute, and sublicense your enhancements or derivative works thereof, in binary
|
40 | * and source code form.
|
41 | *
|
42 | * DISCLAIMER - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
43 | * “AS IS” AND WITH ALL FAULTS. THE POLYTECHNIC UNIVERSITY OF MADRID, ITS CONTRI-
|
44 | * BUTORS, AND ITS MEMBERS DO NOT IN ANY WAY WARRANT, GUARANTEE, OR ASSUME ANY RES-
|
45 | * PONSIBILITY, LIABILITY OR OTHER UNDERTAKING WITH RESPECT TO THE SOFTWARE. ANY E-
|
46 | * XPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRAN-
|
47 | * TIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT
|
48 | * ARE HEREBY DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE,
|
49 | * ACCURACY, AND EFFORT IS WITH THE USER THEREOF. IN NO EVENT SHALL THE COPYRIGHT
|
50 | * OWNER, CONTRIBUTORS, OR THE UNIVERSITY CORPORATION FOR ADVANCED INTERNET DEVELO-
|
51 | * PMENT, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
52 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTIT-
|
53 | * UTE GOODS OR SERVICES; REMOVAL OR REINSTALLATION LOSS OF USE, DATA, SAVINGS OR
|
54 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILIT-
|
55 | * Y, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHE-
|
56 | * RWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRUBUTION OF THIS SOFTWARE, EVEN
|
57 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
58 | *
|
59 | */
|
60 |
|
61 |
|
62 | var superagent = require('superagent');
|
63 | var expect = require('expect.js');
|
64 | var regions = require('../models/regions.js');
|
65 | var config = require('../config/config.js');
|
66 |
|
67 |
|
68 | describe('NAMadapter rest api server', function(){
|
69 | this.timeout(36000);
|
70 |
|
71 |
|
72 | it('check run NAM component - web server', function(done){
|
73 | superagent.get('http://localhost:' + config.port_API)
|
74 | .end(function(e,res){
|
75 | //console.log(res.body);
|
76 | expect(e).to.eql(null);
|
77 | expect(res.statusCode).to.eql(200);
|
78 | done();
|
79 | });
|
80 | });
|
81 |
|
82 | it('check iperf probe', function(done){
|
83 | superagent.get('http://localhost:' + config.port_API + '/monitoring/iperf')
|
84 | .end(function(e,res){
|
85 | //console.log(res.body);
|
86 | expect(e).to.eql(null);
|
87 | expect(res.statusCode).to.eql(200);
|
88 | expect(res.body.port_iperf).to.eql(config.port_iperf_server);
|
89 | done();
|
90 | });
|
91 | });
|
92 | it('check ntp requirement', function(done){
|
93 | superagent.get('http://localhost:' + config.port_API + '/monitoring/owdserver/1')
|
94 | .end(function(e,res){
|
95 | //console.log(res.body);
|
96 | expect(e).to.eql(null);
|
97 | expect(res.statusCode).to.eql(200);
|
98 | expect(res.body.result).to.eql("NTP OK ");
|
99 | done();
|
100 | });
|
101 | });
|
102 |
|
103 | //Check new measure
|
104 |
|
105 | it('get new measure BDW', function(done){
|
106 | superagent.get('http://localhost:3000/monitoring/bdw/127.0.0.1')
|
107 | .end(function(e, res){
|
108 | //console.log(res.text);
|
109 | expect(e).to.eql(null)
|
110 | expect(res.body).to.not.be.empty();
|
111 | expect(res.body).to.be.an('object')
|
112 | //expect(res.body._id.length).to.eql(24)
|
113 | //expect(res.body._id).to.eql(id)
|
114 |
|
115 | done();
|
116 | });
|
117 |
|
118 | });
|
119 |
|
120 | it('get new measure OWD', function(done){
|
121 | superagent.get('http://localhost:3000/monitoring/owd/127.0.0.1')
|
122 | .end(function(e, res){
|
123 | //console.log(res.result);
|
124 | expect(e).to.eql(null)
|
125 | expect(res.body).to.not.be.empty();
|
126 | expect(res.body).to.be.an('object');
|
127 | //expect(res.body._id.length).to.eql(24)
|
128 | //expect(res.body._id).to.eql(id)
|
129 |
|
130 | done();
|
131 | });
|
132 |
|
133 | });
|
134 |
|
135 | it('checks test list', function(done){
|
136 | superagent.get('http://localhost:3000/testshows/')
|
137 | .end(function(e, res){
|
138 | //console.log(res);
|
139 | expect(e).to.eql(null)
|
140 | expect(res.body).to.not.be.empty();
|
141 | expect(res.body).to.be.an('object');
|
142 |
|
143 | done();
|
144 | });
|
145 |
|
146 | });
|
147 |
|
148 |
|
149 | it('check web service mongo DB, post region', function(done){
|
150 | superagent.post('http://localhost:' + config.port_API +'/monitoring/regions')
|
151 | .send({
|
152 | "_links": "{}",
|
153 | "id": "Spain_UPM"
|
154 |
|
155 | })
|
156 | .end(function(e,res){
|
157 | //console.log(res.body);
|
158 | expect(e).to.eql(null);
|
159 | expect(res.statusCode).to.eql(200);
|
160 | expect(res.body).to.be.an('object');
|
161 | done();
|
162 | });
|
163 | });
|
164 |
|
165 | it('check web service mongo DB, region list', function(done){
|
166 | superagent.get('http://localhost:3000/monitoring/regions')
|
167 | .end(function(e, res){
|
168 | //console.log(res.body);
|
169 | expect(e).to.eql(null)
|
170 | expect(res.body).to.not.be.empty();
|
171 | expect(res.body).to.be.an('object');
|
172 | done();
|
173 | });
|
174 |
|
175 | });
|
176 |
|
177 |
|
178 | // Add host
|
179 | it('check web service mongo DB, post host', function(done){
|
180 | superagent.post('http://localhost:3000/monitoring/regions/Madrid_UPM/hosts')
|
181 | .send({
|
182 | hostId: '0001',
|
183 | regionId: 'XIFI',
|
184 | type: undefined,
|
185 | ipAddress: {ipAddress_Local: '192.168.1.35', ipAddress_public : '138.4.47.33'},
|
186 | port_API_NAM: undefined,
|
187 | ping_status: true,
|
188 | bdw_status: true,
|
189 | owd_status: true,
|
190 | BDW_endpoint_dest_schedule:
|
191 | [ { regionId: 'trento',
|
192 | hostIdDestination: '1234',
|
193 | frecuency: 5,
|
194 | },
|
195 | { regionId: 'madrid',
|
196 | hostIdDestination: '123',
|
197 | frecuency: 5,
|
198 | } ],
|
199 | OWD_endpoint_dest_schedule:
|
200 | [ { regionId: 'trento',
|
201 | hostIdDestination: '1234',
|
202 | frecuency: 5,
|
203 | },
|
204 | { regionId: 'madrid',
|
205 | hostIdDestination: '123',
|
206 | frecuency: 5,
|
207 | } ]
|
208 |
|
209 | })
|
210 | .end(function(e,res){
|
211 | //console.log(res.body)
|
212 | expect(e).to.eql(null)
|
213 | //expect(res.body.length).to.eql(1)
|
214 | //expect(res.body[0]._id.length).to.eql(24)
|
215 | //id = res.body[0]._id
|
216 | done();
|
217 | });
|
218 | });
|
219 |
|
220 | it('check web service mongo DB, hosts list', function(done){
|
221 | superagent.get('http://localhost:3000/monitoring/regions/Madrid_UPM/hosts')
|
222 | .end(function(e, res){
|
223 | //console.log(res);
|
224 | expect(e).to.eql(null);
|
225 | expect(res.body).to.not.be.empty();
|
226 | expect(res.body).to.be.an('object');
|
227 | done();
|
228 | });
|
229 |
|
230 | });
|
231 |
|
232 |
|
233 | });
|