Example #1
0
    def testReEnteringAScope(self):

        event = Event();

        service1 = Service();

        scope = Scope('scope');
        container = Container();
        container.addScope(scope);
        container.enterScope('scope');

        container.set('service.listener', service1, 'scope');

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);
        dispatcher.dispatch('onEvent', event);

        service2 = Service();

        container.enterScope('scope');
        container.set('service.listener', service2, 'scope');

        dispatcher.dispatch('onEvent', event);

        container.leaveScope('scope');

        dispatcher.dispatch('onEvent');
Example #2
0
    def testPreventDuplicateListenerService(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent'], 5);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent'], 10);

        dispatcher.dispatch('onEvent', event);
Example #3
0
    def testRemoveBeforeDispatch(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        dispatcher.removeListener('onEvent', [container.get('service.listener'), 'onEvent']);
        self.assertFalse(dispatcher.hasListeners('onEvent'));
Example #4
0
    def testAddAListenerService(self):
        if self.__skip:
            return;

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        dispatcher.dispatch('onEvent', event);
Example #5
0
    def testGetListenersOnLazyLoad(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        listeners = dispatcher.getListeners();

        self.assertTrue('onEvent' in listeners);

        self.assertEqual(1, len(dispatcher.getListeners('onEvent')));
Example #6
0
    def testHasListenersOnLazyLoad(self):

        event = Event();

        service = Service();

        container = Container();
        container.set('service.listener', service);

        dispatcher = ContainerAwareEventDispatcher(container);
        dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

        event.setDispatcher(dispatcher);
        event.setName('onEvent');

        self.assertTrue(dispatcher.hasListeners());

        if (dispatcher.hasListeners('onEvent')) :
            dispatcher.dispatch('onEvent');
Example #7
0
    def testTriggerAListenerServiceOutOfScope(self):
        """@expectedException InvalidArgumentException

        """

        try:
            service = Service();

            scope = Scope('scope');
            container = Container();
            container.addScope(scope);
            container.enterScope('scope');

            container.set('service.listener', service, 'scope');

            dispatcher = ContainerAwareEventDispatcher(container);
            dispatcher.addListenerService('onEvent', ['service.listener', 'onEvent']);

            container.leaveScope('scope');
            dispatcher.dispatch('onEvent');

            self.fail()
        except Exception as e:
            self.assertTrue(isinstance(e, InvalidArgumentException));