from unittest import TestCase

from messagebus import SubscriptionInfo

from dimessageprocessor import EventProcessorDefinition, MessageProcessorDefinition
from testmodule.processor import SimpleProcessor


class TestEventProcessorDefinition(TestCase):

    def test_stores_processor_type(self):
        definition = EventProcessorDefinition(processor_type=SimpleProcessor, subscription_type=SubscriptionInfo.TYPE_REENTRANT)
        self.assertEqual(definition.processor_type, SimpleProcessor)

    def test_stores_subscription_type(self):
        definition = EventProcessorDefinition(processor_type=SimpleProcessor, subscription_type=SubscriptionInfo.TYPE_NON_REENTRANT)
        self.assertEqual(definition.subscription_type, SubscriptionInfo.TYPE_NON_REENTRANT)

    def test_str(self):
        definition = EventProcessorDefinition(processor_type=SimpleProcessor, subscription_type=SubscriptionInfo.TYPE_REENTRANT)
        self.assertIn("SimpleProcessor", str(definition))

    def test_invalid_subscription_type_raises(self):
        with self.assertRaises(ValueError):
            EventProcessorDefinition(processor_type=SimpleProcessor, subscription_type=99)


class TestMessageProcessorDefinition(TestCase):

    def test_stores_processor_type(self):
        definition = MessageProcessorDefinition(processor_type=SimpleProcessor)
        self.assertEqual(definition.processor_type, SimpleProcessor)

    def test_str(self):
        definition = MessageProcessorDefinition(processor_type=SimpleProcessor)
        self.assertIn("SimpleProcessor", str(definition))
