@@ -226,7 +226,7 @@ describe('NGSI-LD - IoT Agent Lazy Devices', function () {
226226 it ( 'should call the device handler for each of the contexts' ) ;
227227 } ) ;
228228
229- describe ( 'When a context query arrives to the IoT Agent' , function ( ) {
229+ describe ( 'When a context query arrives to the IoT Agent using retrieveEntity ' , function ( ) {
230230 const options = {
231231 url :
232232 'http://localhost:' +
@@ -294,6 +294,76 @@ describe('NGSI-LD - IoT Agent Lazy Devices', function () {
294294 } ) ;
295295 } ) ;
296296
297+ describe ( 'When a context query arrives to the IoT Agent using queryEntities' , function ( ) {
298+ const options = {
299+ url :
300+ 'http://localhost:' +
301+ iotAgentConfig . server . port +
302+ '/ngsi-ld/v1/entities/?id=urn:ngsi-ld:Light:light1&attrs=dimming' ,
303+ method : 'GET' ,
304+ headers : {
305+ 'fiware-service' : 'smartgondor' ,
306+ 'fiware-servicepath' : 'gardens'
307+ }
308+ } ;
309+ const sensorData = [
310+ {
311+ id : 'Light:light1' ,
312+ type : 'Light' ,
313+ dimming : {
314+ type : 'Percentage' ,
315+ value : 19
316+ }
317+ }
318+ ] ;
319+
320+ beforeEach ( function ( done ) {
321+ nock . cleanAll ( ) ;
322+
323+ contextBrokerMock = nock ( 'http://192.168.1.1:1026' )
324+ . matchHeader ( 'fiware-service' , 'smartgondor' )
325+ . post (
326+ '/ngsi-ld/v1/csourceRegistrations/' ,
327+ utils . readExampleFile (
328+ './test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent1.json'
329+ )
330+ )
331+ . reply ( 201 , null , { Location : '/ngsi-ld/v1/csourceRegistrations/6319a7f5254b05844116584d' } ) ;
332+
333+ contextBrokerMock
334+ . matchHeader ( 'fiware-service' , 'smartgondor' )
335+ . post ( '/ngsi-ld/v1/entityOperations/upsert/' )
336+ . reply ( 204 ) ;
337+
338+ async . series ( [ apply ( iotAgentLib . activate , iotAgentConfig ) , apply ( iotAgentLib . register , device1 ) ] , done ) ;
339+ } ) ;
340+
341+ it ( 'should return the information querying the underlying devices' , function ( done ) {
342+ const expectedResponse = [
343+ utils . readExampleFile (
344+ './test/unit/ngsi-ld/examples/contextProviderResponses/queryInformationResponse.json'
345+ )
346+ ] ;
347+
348+ iotAgentLib . setDataUpdateHandler ( function ( id , type , service , subservice , attributes , callback ) {
349+ callback ( null ) ;
350+ } ) ;
351+
352+ iotAgentLib . setDataQueryHandler ( function ( id , type , service , subservice , attributes , callback ) {
353+ id . should . equal ( 'urn:ngsi-ld:' + device1 . type + ':' + device1 . id ) ;
354+ type . should . equal ( device1 . type ) ;
355+ attributes [ 0 ] . should . equal ( 'dimming' ) ;
356+ callback ( null , sensorData [ 0 ] ) ;
357+ } ) ;
358+
359+ request ( options , function ( error , response , body ) {
360+ should . not . exist ( error ) ;
361+ body . should . eql ( expectedResponse ) ;
362+ done ( ) ;
363+ } ) ;
364+ } ) ;
365+ } ) ;
366+
297367 describe ( 'When a context query arrives to the IoT Agent and no handler is set' , function ( ) {
298368 const options = {
299369 url :
0 commit comments