def setUp(self):
     self._messageMapperRegistry = MessageMapperRegistry()
     self._message_store = FakeMessageStore()
     self._producer = FakeProducer()
     self._commandProcessor = CommandProcessor(
         message_mapper_registry=self._messageMapperRegistry,
         message_store=self._message_store,
         producer=self._producer)
 def setUp(self):
     self._messageMapperRegistry = MessageMapperRegistry()
     self._message_store = FakeMessageStore()
     self._producer = FakeProducer()
     self._commandProcessor = CommandProcessor(
         message_mapper_registry=self._messageMapperRegistry,
         message_store=self._message_store,
         producer=self._producer,
     )
    def setUp(self):
        self._messageMapperRegistry = MessageMapperRegistry()
        self._messageMapperRegistry.register(MyCommand, lambda: map_to_message)

        self._messageMapperRegistry
        self._message_store = FakeMessageStore()
        self._producer = FakeProducer()
        self._commandProcessor = CommandProcessor(
            message_mapper_registry=self._messageMapperRegistry,
            message_store=self._message_store,
            producer=self._producer)
class PostTests(unittest.TestCase):
    def setUp(self):
        self._messageMapperRegistry = MessageMapperRegistry()
        self._messageMapperRegistry.register(MyCommand, map_to_message)

        self._messageMapperRegistry
        self._message_store = FakeMessageStore()
        self._producer = FakeProducer()
        self._commandProcessor = CommandProcessor(
            message_mapper_registry=self._messageMapperRegistry,
            message_store=self._message_store,
            producer=self._producer)

    def test_handle_command(self):
        """ given that we have a message mapper and producer registered for a commnd,
            when we post a command,
            it should send via the producer
        """
        self._request = MyCommand()
        self._commandProcessor.post(self._request)

        self.assertTrue(self._message_store.message_was_added, "Expected a message to be added")
        self.assertTrue(self._message_store.get_message(self._request.id), "Expected the command to be converted into a message")
        self.assertTrue(self._producer.was_sent_message, "Expected a message to be sent via the producer")
        self.assertTrue(str(self._message_store.get_message(self._request.id).body), "")

    def test_missing_message_mapper(self):
        """given that we have no message mapper registered for a command
            when we post a command
            it should raise an error
        """
        self._request = MyOtherCommand()

        was_exception_thrown = False
        try:
            self._commandProcessor.post(self._request)
        except ConfigurationException as ex:
            was_exception_thrown = True

        self.assertTrue(was_exception_thrown)
class PostTests(unittest.TestCase):
    def setUp(self):
        self._messageMapperRegistry = MessageMapperRegistry()
        self._message_store = FakeMessageStore()
        self._producer = FakeProducer()
        self._commandProcessor = CommandProcessor(
            message_mapper_registry=self._messageMapperRegistry,
            message_store=self._message_store,
            producer=self._producer)

    def test_handle_command(self):
        """ given that we have a message mapper and producer registered for a commnd, when we post a command, it should send via the producer"""
        self._request = MyCommand()
        self._commandProcessor.post(self._request)

        self.assertTrue(self._message_store.message_was_added, "Expected a message to be added")
        self.assertTrue(self._message_store.get_message(self._request.id), "Expected the command to be converted into a message")
        self.assertTrue(self._producer.was_sent_message, "Expected a message to be sent via the producer")
class PostTests(unittest.TestCase):
    def setUp(self):
        self._messageMapperRegistry = MessageMapperRegistry()
        self._messageMapperRegistry.register(MyCommand, map_to_message)

        self._messageMapperRegistry
        self._message_store = FakeMessageStore()
        self._producer = FakeProducer()
        self._commandProcessor = CommandProcessor(
            message_mapper_registry=self._messageMapperRegistry,
            message_store=self._message_store,
            producer=self._producer)

    def test_handle_command(self):
        """ given that we have a message mapper and producer registered for a commnd, when we post a command, it should send via the producer"""
        self._request = MyCommand()
        self._commandProcessor.post(self._request)

        self.assertTrue(self._message_store.message_was_added, "Expected a message to be added")
        self.assertTrue(self._message_store.get_message(self._request.id), "Expected the command to be converted into a message")
        self.assertTrue(self._producer.was_sent_message, "Expected a message to be sent via the producer")
class PostTests(unittest.TestCase):
    def setUp(self):
        self._messageMapperRegistry = MessageMapperRegistry()
        self._messageMapperRegistry.register(MyCommand, map_to_message)

        self._message_store = FakeMessageStore()
        self._producer = FakeProducer()
        self._commandProcessor = CommandProcessor(
            message_mapper_registry=self._messageMapperRegistry,
            message_store=self._message_store,
            producer=self._producer)

    def test_handle_command(self):
        """ given that we have a message mapper and producer registered for a commnd,
            when we post a command,
            it should send via the producer
        """
        self._request = MyCommand()
        self._commandProcessor.post(self._request)

        self.assertTrue(self._message_store.message_was_added,
                        "Expected a message to be added")
        self.assertTrue(self._message_store.get_message(self._request.id),
                        "Expected the command to be converted into a message")
        self.assertTrue(self._producer.was_sent_message,
                        "Expected a message to be sent via the producer")
        self.assertTrue(
            str(self._message_store.get_message(self._request.id).body), "")

    def test_missing_message_mapper(self):
        """given that we have no message mapper registered for a command
            when we post a command
            it should raise an error
        """
        self._request = MyOtherCommand()

        was_exception_thrown = False
        try:
            self._commandProcessor.post(self._request)
        except ConfigurationException:
            was_exception_thrown = True

        # it looks as though we should use self_assertRaises...
        self.assertTrue(was_exception_thrown, "")

    def test_missing_message_producer(self):
        """given that we have no me message producer configured for the commandprocessor
            when we post a command
            it should raise a confiugration error
        """
        self._commandProcessor = CommandProcessor(
            message_mapper_registry=self._messageMapperRegistry,
            message_store=self._message_store,
            producer=None)

        was_exception_thrown = False
        try:
            self._request = MyCommand()
            self._commandProcessor.post(self._request)
        except ConfigurationException:
            was_exception_thrown = True

        self.assertTrue(was_exception_thrown)

    def test_missing_message_mapper_registry(self):
        """ given that we have no message mapper registry for the commandprocessor
            when we post a command
            it should raise a configuration error
        """
        self._commandProcessor = CommandProcessor(
            message_mapper_registry=None,
            message_store=self._message_store,
            producer=self._producer)

        was_exception_thrown = False
        try:
            self._request = MyCommand()
            self._commandProcessor.post(self._request)
        except ConfigurationException:
            was_exception_thrown = True

        self.assertTrue(was_exception_thrown)