@@ -265,4 +265,88 @@ describe('integration of module::vertxEventBus', function () {
265265
266266 } ) ;
267267
268+ describe ( 'vertxEventBus (w/o autoconnect)' , function ( ) {
269+
270+ var vertxEventBus , $timeout , $rootScope , $log ;
271+
272+ beforeEach ( module ( 'knalli.angular-vertxbus' , function ( vertxEventBusProvider ) {
273+ // Override (improve test running time)
274+ vertxEventBusProvider
275+ . useDebug ( true )
276+ . useSockJsReconnectInterval ( 2000 )
277+ . useReconnect ( false )
278+ . disableAutoConnect ( ) ;
279+ } ) ) ;
280+
281+ beforeEach ( inject ( function ( _vertxEventBus_ , _$timeout_ , _$rootScope_ , _$log_ ) {
282+ vertxEventBus = _vertxEventBus_ ;
283+ $timeout = _$timeout_ ;
284+ $rootScope = _$rootScope_ ;
285+ $log = _$log_ ;
286+ SockJS . currentMockInstance . $log = $log ;
287+ } ) ) ;
288+
289+ it ( 'should not fail calling close() on non existing connection' , function ( done ) {
290+ this . timeout ( 20000 ) ;
291+ setTimeout ( function ( ) {
292+ vertxEventBus . close ( ) ;
293+ setTimeout ( done , 1200 ) ;
294+ } , 200 ) ;
295+ } ) ;
296+
297+ it ( 'should not fail calling reconnect() on non existing connection' , function ( done ) {
298+ this . timeout ( 20000 ) ;
299+ setTimeout ( function ( ) {
300+ vertxEventBus . reconnect ( true ) ;
301+ setTimeout ( done , 1200 ) ;
302+ } , 200 ) ;
303+ } ) ;
304+
305+ it ( 'should not call the onopen function because no automatic connect' , function ( done ) {
306+ this . timeout ( 20000 ) ;
307+ var onopenCount = 0 ;
308+ vertxEventBus . onopen = function ( ) {
309+ $log . debug ( 'onopen' ) ;
310+ onopenCount ++ ;
311+ } ;
312+ var oncloseCount = 0 ;
313+ vertxEventBus . onclose = function ( ) {
314+ $log . debug ( 'onclose' ) ;
315+ oncloseCount ++ ;
316+ } ;
317+ setTimeout ( function ( ) {
318+ expect ( onopenCount ) . to . be ( 0 ) ; // should be not called!
319+ setTimeout ( done , 1200 ) ;
320+ } , 200 ) ;
321+ } ) ;
322+
323+ it ( 'should not call the onopen function because no automatic connect' , function ( done ) {
324+ this . timeout ( 20000 ) ;
325+ var onopenCount = 0 ;
326+ vertxEventBus . onopen = function ( ) {
327+ $log . debug ( 'onopen' ) ;
328+ onopenCount ++ ;
329+ } ;
330+ var oncloseCount = 0 ;
331+ vertxEventBus . onclose = function ( ) {
332+ $log . debug ( 'onclose' ) ;
333+ oncloseCount ++ ;
334+ } ;
335+ setTimeout ( function ( ) {
336+ expect ( onopenCount ) . to . be ( 0 ) ; // should be not called!
337+ $log . debug ( 'apply connection config..' ) ;
338+ vertxEventBus . configureConnection ( 'http://localhost:1234' , '/eventbus1' ) ;
339+ vertxEventBus . connect ( ) ;
340+ setTimeout ( function ( ) {
341+ $log . debug ( 'check..' ) ;
342+ expect ( SockJS . currentMockInstance . url ) . to . be ( 'http://localhost:1234/eventbus1' ) ;
343+ expect ( onopenCount ) . to . be ( 1 ) ;
344+ expect ( oncloseCount ) . to . be ( 0 ) ;
345+ done ( ) ;
346+ } , 1200 ) ;
347+ } , 200 ) ;
348+ } ) ;
349+
350+ } ) ;
351+
268352} ) ;
0 commit comments