Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 260 lines (191 sloc) 10.749 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
Feature: Lexing AMI
As a RubyAMI user
I want to lex the AMI protocol
So that I can control Asterisk asynchronously

Scenario: Lexing only the initial AMI version header
Given a new lexer
And a version header for AMI 1.0

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And the version should be set to 1.0

Scenario: Lexing the initial AMI header and a login attempt
Given a new lexer
And a version header for AMI 1.0
And a normal login success with events

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 message should have been received

Scenario: Lexing the initial AMI header and then a Response:Follows section
Given a new lexer
And a version header for AMI 1.0
And a multi-line Response:Follows body of ragel_description

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And the 'follows' body of 1 message received should equal ragel_description

Scenario: Lexing a Response:Follows section with no body
Given a new lexer
And a version header for AMI 1.0
And a multi-line Response:Follows body of empty_String

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And the 'follows' body of 1 message received should equal empty_string

Scenario: Lexing a multi-line Response:Follows simulating the "core show channels" command
Given a new lexer
And a version header for AMI 1.0
Given a multi-line Response:Follows body of show_channels_from_wayne

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And the 'follows' body of 1 message received should equal show_channels_from_wayne

Scenario: Lexing a multi-line Response:Follows simulating the "core show uptime" command
Given a new lexer
And a version header for AMI 1.0
Given a multi-line Response:Follows response simulating uptime

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And the first message received should have a key "System uptime" with value "46 minutes, 30 seconds"

Scenario: Lexing a Response:Follows section which has a colon not on the first line
Given a new lexer
And a multi-line Response:Follows body of with_colon_after_first_line

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 message should have been received
And the 'follows' body of 1 message received should equal with_colon_after_first_line

@wip
Scenario: Lexing an immediate response with a colon in it.
Given a new lexer
And an immediate response with text "markq has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime), W:0, C:0, A:0, SL:0.0% within 0s\r\n No Members\r\n No Callers\r\n\r\n\r\n\r\n"

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 message should have been received
And 1 message should be an immediate response with text "markq has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime), W:0, C:0, A:0, SL:0.0% within 0s\r\n No Members\r\n No Callers"

Scenario: Lexing the initial AMI header and then an "Authentication Required" error.
Given a new lexer
And a version header for AMI 1.0
And an Authentication Required error

When the buffer is lexed

Then the protocol should have lexed without syntax errors

Scenario: Lexing the initial AMI header and then a Response:Follows section
Given a new lexer
And a version header for AMI 1.0
And a multi-line Response:Follows body of ragel_description
And a multi-line Response:Follows body of ragel_description

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And the 'follows' body of 2 messages received should equal ragel_description

Scenario: Lexing a stanza without receiving an AMI header
Given a new lexer
And a normal login success with events

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 message should have been received

Scenario: Receiving an immediate response as soon as the socket is opened
Given a new lexer
And an immediate response with text "Immediate responses are so ridiculous"

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 message should have been received
And 1 message should be an immediate response with text "Immediate responses are so ridiculous"

Scenario: Receiving an immediate message surrounded by real messages
Given a new lexer
And a normal login success with events
And an immediate response with text "No queues have been created."
And a normal login success with events

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 3 messages should have been received
And 1 message should be an immediate response with text "No queues have been created."

Scenario: Receiving a Pong after a simulated login
Given a new lexer
And a version header for AMI 1.0
And a normal login success with events
And a Pong response with an ActionID of randomness

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 2 messages should have been received

Scenario: Ten Pong responses in a row
Given a new lexer
And 5 Pong responses without an ActionID
And 5 Pong responses with an ActionID of randomness

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 10 messages should have been received

Scenario: A Pong with an ActionID
Given a new lexer
And a Pong response with an ActionID of 1224469850.61673

When the buffer is lexed

Then the first message received should have a key "ActionID" with value "1224469850.61673"

Scenario: A response containing a floating point value
Given a new lexer
And a custom stanza named "call"
And the custom stanza named "call" has key "ActionID" with value "1224469850.61673"
And the custom stanza named "call" has key "Uniqueid" with value "1173223225.10309"

When the custom stanza named "call" is added to the buffer
And the buffer is lexed

Then the 1st message received should have a key "Uniqueid" with value "1173223225.10309"

Scenario: Receiving a message with custom key/value pairs
Given a new lexer
And a custom stanza named "person"
And the custom stanza named "person" has key "ActionID" with value "1224469850.61673"
And the custom stanza named "person" has key "Name" with value "Jay Phillips"
And the custom stanza named "person" has key "Age" with value "21"
And the custom stanza named "person" has key "Location" with value "San Francisco, CA"
And the custom stanza named "person" has key "x-header" with value "<FooBAR>"
And the custom stanza named "person" has key "Channel" with value "IAX2/127.0.0.1/4569-9904"
And the custom stanza named "person" has key "I have spaces" with value "i have trailing padding "

When the custom stanza named "person" is added to the buffer
And the buffer is lexed

Then the protocol should have lexed without syntax errors
And the first message received should have a key "Name" with value "Jay Phillips"
And the first message received should have a key "ActionID" with value "1224469850.61673"
And the first message received should have a key "Name" with value "Jay Phillips"
And the first message received should have a key "Age" with value "21"
And the first message received should have a key "Location" with value "San Francisco, CA"
And the first message received should have a key "x-header" with value "<FooBAR>"
And the first message received should have a key "Channel" with value "IAX2/127.0.0.1/4569-9904"
And the first message received should have a key "I have spaces" with value "i have trailing padding "

Scenario: Executing a stanza that was partially received
Given a new lexer
And a normal login success with events split into two pieces

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 message should have been received

Scenario: Receiving an AMI error followed by a normal event
Given a new lexer
And an AMI error whose message is "Missing action in request"
And a normal login success with events

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 AMI error should have been received
And the 1st AMI error should have the message "Missing action in request"
And 1 message should have been received

Scenario: Lexing an immediate response
Given a new lexer
And a normal login success with events
And an immediate response with text "Yes, plain English is sent sometimes over AMI."
And a normal login success with events

When the buffer is lexed

Then the protocol should have lexed without syntax errors
And 3 messages should have been received
And 1 message should be an immediate response with text "Yes, plain English is sent sometimes over AMI."

Scenario: Lexing an AMI event
Given a new lexer
And a custom event with name "NewChannelEvent" identified by "this_event"
And a custom header for event identified by "this_event" whose key is "Foo" and value is "Bar"
And a custom header for event identified by "this_event" whose key is "Channel" and value is "IAX2/127.0.0.1:4569-9904"
And a custom header for event identified by "this_event" whose key is "AppData" and value is "agi://localhost"

When the custom event identified by "this_event" is added to the buffer
And the buffer is lexed

Then the protocol should have lexed without syntax errors
And 1 event should have been received
And the 1st event should have the name "NewChannelEvent"
And the 1st event should have key "Foo" with value "Bar"
And the 1st event should have key "Channel" with value "IAX2/127.0.0.1:4569-9904"
And the 1st event should have key "AppData" with value "agi://localhost"

Scenario: Lexing an immediate packet with a colon in it (syntax error)
Given a new lexer
And syntactically invalid immediate_packet_with_colon
And a stanza break

When the buffer is lexed

Then 0 messages should have been received
And the protocol should have lexed with 1 syntax error
And the syntax error fixture named immediate_packet_with_colon should have been encountered
Something went wrong with that request. Please try again.