Class: Messaging::Fixtures::Handler
- Inherits:
-
Object
- Object
- Messaging::Fixtures::Handler
- Includes:
- Initializer, TestBench::Fixture
- Defined in:
- lib/messaging/fixtures/handler.rb,
lib/messaging/fixtures/defaults.rb
Defined Under Namespace
Modules: Defaults
Constant Summary collapse
- Error =
Class.new(RuntimeError)
Class Method Summary collapse
- .build(handler, input_message, entity = nil, entity_version = nil, entity_id: nil, clock_time: nil, identifier_uuid: nil, &test_block) ⇒ Object
- .set_clock_time(handler, clock_time) ⇒ Object
- .set_identifier_uuid(handler, identifier_uuid) ⇒ Object
- .set_store_entity(handler, entity, entity_version, entity_id) ⇒ Object
Instance Method Summary collapse
- #assert_input_message(&test_block) ⇒ Object
- #assert_write(message_class, &test_block) ⇒ Object
- #assert_written_message(written_message, &test_block) ⇒ Object
- #call ⇒ Object
- #entity_sequence ⇒ Object
- #refute_write(message_class = nil) ⇒ Object
Class Method Details
.build(handler, input_message, entity = nil, entity_version = nil, entity_id: nil, clock_time: nil, identifier_uuid: nil, &test_block) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/messaging/fixtures/handler.rb', line 16 def self.build(handler, , entity=nil, entity_version=nil, entity_id: nil, clock_time: nil, identifier_uuid: nil, &test_block) instance = new(handler, , entity, entity_version, entity_id, clock_time, identifier_uuid, test_block) set_store_entity(handler, entity, entity_version, entity_id) set_clock_time(handler, clock_time) set_identifier_uuid(handler, identifier_uuid) instance end |
.set_clock_time(handler, clock_time) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/messaging/fixtures/handler.rb', line 34 def self.set_clock_time(handler, clock_time) if clock_time.nil? if handler.respond_to?(:clock) handler.clock.now = Defaults.clock_time end else handler.clock.now = clock_time end end |
.set_identifier_uuid(handler, identifier_uuid) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/messaging/fixtures/handler.rb', line 44 def self.set_identifier_uuid(handler, identifier_uuid) if identifier_uuid.nil? if handler.respond_to?(:identifier) handler.identifier.set(Defaults.identifier_uuid) end else handler.identifier.set(identifier_uuid) end end |
.set_store_entity(handler, entity, entity_version, entity_id) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/messaging/fixtures/handler.rb', line 26 def self.set_store_entity(handler, entity, entity_version, entity_id) return if entity.nil? entity_id ||= entity.id handler.store.add(entity_id, entity, entity_version) end |
Instance Method Details
#assert_input_message(&test_block) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/messaging/fixtures/handler.rb', line 79 def (&test_block) context_name = "Input Message" if not .nil? context_name = "#{context_name}: #{.class.}" end fixture(Message, , title_context_name: context_name, &test_block) end |
#assert_write(message_class, &test_block) ⇒ Object
97 98 99 100 |
# File 'lib/messaging/fixtures/handler.rb', line 97 def assert_write(, &test_block) fixture = fixture(Writer, handler.write, , &test_block) fixture. end |
#assert_written_message(written_message, &test_block) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/messaging/fixtures/handler.rb', line 88 def (, &test_block) context_name = "Written Message" if not .nil? context_name = "#{context_name}: #{.class.}" end fixture(Message, , , title_context_name: context_name, &test_block) end |
#call ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/messaging/fixtures/handler.rb', line 54 def call context "Handler: #{handler.class.name.split('::').last}" do detail "Handler Class: #{handler.class.name}" if test_block.nil? raise Error, "Handler fixture must be executed with a block" end detail "Entity Class: #{entity.class.name}" detail "Entity Data: #{entity&.attributes.inspect}" if not clock_time.nil? detail "Clock Time: #{clock_time.inspect}" end if not identifier_uuid.nil? detail "Identifier UUID: #{identifier_uuid}" end handler.() test_block.call(self) end end |
#entity_sequence ⇒ Object
9 10 11 12 |
# File 'lib/messaging/fixtures/handler.rb', line 9 def entity_sequence return nil if entity.nil? entity.sequence end |
#refute_write(message_class = nil) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/messaging/fixtures/handler.rb', line 102 def refute_write(=nil) writer = handler.write context_name = "No Write" if not .nil? write_telemetry_data = Writer.get_data(writer, ) written = !write_telemetry_data.nil? context_name = "#{context_name}: #{.}" else written = writer.written? end context context_name do detail "Message Class: #{.inspect}" test "Not written" do refute(written) end end end |