Defining a BrokerConnection
===========================

We define a connection with id *bar*. Note that the utility name and the connection id is
the same concept::

    >>> from affinitic.zamqp.connection import BrokerConnection
    >>> import grokcore.component as grok
    >>> class DummyBrokerConnection(BrokerConnection):
    ...     id = 'bar'
    ...     grok.name(id)

As we don't have grok in here, we just use zope.component to define our utility (normally this
step is done magicaly by grok)::

    >>> from affinitic.zamqp.interfaces import IBrokerConnection
    >>> from zope.component import provideUtility
    >>> conn = DummyBrokerConnection()
    >>> provideUtility(conn, IBrokerConnection, name=conn.id)

Using BrokerConnectionFactory
=============================

It's now easy to create an AMQP connection (a `BrokerConnection <#affinitic.zamqp.connection.BrokerConnection>`_) using the ``createObject`` factory call from ``zope.component``::

    >>> from zope.component import createObject
    >>> connection = createObject('AMQPBrokerConnection', 'bar')
    >>> connection
    <DummyBrokerConnection object at ...>

And if we ask for another connection, we get a new connection::

    >>> connection2 = createObject('AMQPBrokerConnection', 'bar')
    >>> connection == connection2
    False

Interface conformance
=====================

Using ``zope.interface`` to check wheter our implementation does what it promise to implement.

    >>> from zope.interface.verify import verifyObject

For BrokerConnection::

    >>> from affinitic.zamqp.interfaces import IBrokerConnection
    >>> from affinitic.zamqp.connection import BrokerConnection
    >>> verifyObject(IBrokerConnection, BrokerConnection())
    True

For BrokerConnectionFactory::

    >>> from affinitic.zamqp.interfaces import IBrokerConnectionFactory
    >>> from affinitic.zamqp.connection import BrokerConnectionFactory
    >>> factory = BrokerConnectionFactory()
    >>> verifyObject(IBrokerConnectionFactory, factory)
    True

The provided interface by the objects created by the factory is IBrokerConnection

    >>> implemented = factory.getInterfaces()
    >>> implemented.isOrExtends(IBrokerConnection)
    True

