from unittest import TestCase

from amqp.adapter.amq_route_factory import AMQRouteFactory, NULL_ROUTE
from amqp.model.model import AMQRoute


class TestAMQRouteFactory(TestCase):
    def test_from_string(self):
        _f = AMQRouteFactory()
        _r: AMQRoute = _f.from_string(
            "amq-clever-pybook::amq-clever-pybook:clever.pybook.localhost.#:5:0"
        )
        self.assertEqual("", _r.exchange)
        self.assertEqual("amq-clever-pybook", _r.queue)
        self.assertEqual(5, _r.timeout)
        _r2: AMQRoute = _f.from_string(
            "amq-clever-pybook:amq-clever-pybook:clever.pybook.localhost.#:5"
        )
        self.assertEqual(NULL_ROUTE, _r2)

    def test_validate(self):
        _f = AMQRouteFactory()
        self.assertTrue(
            _f.validate(
                "amq-clever-pybook::amq-clever-pybook:clever.pybook.localhost.#:5:0"
            )
        )
        self.assertFalse(
            _f.validate("amq-clever-pybook:amq-clever-pybook:clever.pybook.localhost.#")
        )
