client_for_poslynx 0.9.0 → 1.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,72 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'eventmachine'
4
-
5
- module ClientForPoslynx
6
- module Net
7
- class StructuredClient
8
-
9
- class EM_Connection < EM::Connection
10
- include EM::Protocols::POSLynx
11
-
12
- attr_reader :use_ssl, :directive_queue, :activity_queue
13
-
14
- def initialize(use_ssl, directive_queue, activity_queue)
15
- @use_ssl = use_ssl
16
- @directive_queue = directive_queue
17
- @activity_queue = activity_queue
18
- end
19
-
20
- def connection_completed
21
- if use_ssl
22
- start_tls verify_peer: false
23
- else
24
- handle_next_directive
25
- end
26
- end
27
-
28
- def ssl_handshake_completed
29
- handle_next_directive
30
- end
31
-
32
- def unbind
33
- EM.stop_event_loop
34
- end
35
-
36
- def receive_response(response)
37
- activity_queue << [ :received_response, response ]
38
- end
39
-
40
- def handle_next_directive
41
- EM.defer(
42
- ->{ directive_queue.shift },
43
- ->(directive){
44
- process_directive directive
45
- }
46
- )
47
- end
48
-
49
- def process_directive(directive)
50
- kind, *args = Array( directive )
51
- case kind
52
- when :end_session
53
- end_session
54
- when :send_request
55
- begin
56
- send_request *args
57
- ensure
58
- handle_next_directive
59
- end
60
- end
61
- end
62
-
63
- def end_session
64
- after_writing = true
65
- close_connection after_writing
66
- end
67
-
68
- end
69
-
70
- end
71
- end
72
- end
@@ -1,118 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'stringio'
5
-
6
- module ClientForPoslynx
7
-
8
- describe Net::StructuredClient do
9
-
10
- it "makes and closes a connection" do
11
- client_action = ->(port, log) do
12
- log << :client_connecting
13
- client = described_class.new( '127.0.0.1', port )
14
- begin
15
- sleep 0.1 # Let server report connection acceptance.
16
- ensure
17
- log << :client_disconnecting
18
- client.end_session
19
- end
20
- end
21
-
22
- server_action = ->(conn, log) do
23
- log << :server_received_connection
24
- conn.wait_writable
25
- c = conn.getc
26
- log << if c.nil? then :server_received_eof else :server_didnt_receive_eof end
27
- end
28
-
29
- log_array = TestTCP_Server.run_client_server_session(
30
- client_action, server_action
31
- )
32
-
33
- expect( log_array ).to eq( [
34
- :client_connecting,
35
- :server_received_connection,
36
- :client_disconnecting,
37
- :server_received_eof,
38
- ] )
39
- end
40
-
41
- it "sends a request" do
42
- request_to_send = Data::Requests::PinPadDisplayMessage.new.tap do |req|
43
- req.client_mac = 'abc'
44
- end
45
-
46
- client_action = ->(port, log) do
47
- client = described_class.new( '127.0.0.1', port )
48
- begin
49
- sleep 0.1 # Let server report connection acceptance.
50
- log << :sending_request
51
- client.send_request request_to_send
52
- ensure
53
- client.end_session
54
- end
55
- end
56
-
57
- server_action = ->(conn, log) do
58
- conn.wait_readable
59
- line = conn.gets
60
- log << [ :server_received_line, line ]
61
- end
62
-
63
- log_array = TestTCP_Server.run_client_server_session(
64
- client_action, server_action
65
- )
66
-
67
- expect( log_array.length ).to eq( 2 )
68
-
69
- expect( log_array.first ).to eq( :sending_request )
70
-
71
- msg, serial_data = log_array.last
72
- expect( msg ).to eq( :server_received_line )
73
-
74
- data = Data::AbstractData.xml_parse( serial_data )
75
- expect( data ).to be_kind_of( Data::Requests::PinPadDisplayMessage )
76
- expect( data.client_mac ).to eq( 'abc' )
77
- end
78
-
79
- it "receives a response" do
80
- response_data_to_send = Data::Responses::PinPadDisplayMessage.new.tap do |req|
81
- req.result = 'OkeyDokey'
82
- end
83
- serial_response_data_to_send = response_data_to_send.xml_serialize
84
-
85
- client_action = ->(port, log) do
86
- client = described_class.new( '127.0.0.1', port )
87
- begin
88
- sleep 0.1 # Let server send response.
89
- log << [ :got_response, client.get_response ]
90
- ensure
91
- client.end_session
92
- end
93
- end
94
-
95
- server_action = ->(conn, log) do
96
- conn.wait_writable
97
- log << :server_sending_response
98
- conn.puts serial_response_data_to_send
99
- end
100
-
101
- log_array = TestTCP_Server.run_client_server_session(
102
- client_action, server_action
103
- )
104
-
105
- expect( log_array.length ).to eq( 2 )
106
-
107
- expect( log_array.first ).to eq( :server_sending_response )
108
-
109
- msg, data = log_array.last
110
- expect( msg ).to eq( :got_response )
111
-
112
- expect( data ).to be_kind_of( Data::Responses::PinPadDisplayMessage )
113
- expect( data.result ).to eq( 'OkeyDokey' )
114
- end
115
-
116
- end
117
-
118
- end