adapter_poll.feature 3.73 KB
Newer Older
1 2 3 4 5 6 7
# When the queue contains x messages 
# only mocks the API response 
# Testing how the API behaves with a full queue are defined in the API 

Feature: Can the adapter receive messages?
  The adapter poll method works as expected

8
  Scenario: No messages are received successfully if the queue is empty
9 10 11 12 13 14 15
    Given valid config
    When the adapter instance is created
    When the auth method is called
    When a mock receive API response is configured to return 0 messages
    When the poll method is called
    Then a successful response is returned with 0 messages  

16
  Scenario: 2 messages are received successfully if the queue contains 2 messages
17 18 19 20 21 22 23 24 25
    Given valid config
    When the adapter instance is created
    When the auth method is called
    When a mock receive API response is configured to return 2 messages 
    When the poll method is called
    Then a successful response is returned with 2 messages
    Then the protocol "validate" method is called 2 times
    Then the protocol "decode" method is called 2 times

26
  Scenario: 10 messages are received successfully if the queue contains 10 messages
27 28 29 30 31 32 33 34 35 36 37 38 39
    Given valid config
    When the adapter instance is created
    When the auth method is called
    When a mock receive API response is configured to return 10 messages 
    When the poll method is called
    Then a successful response is returned with 10 messages
    Then the protocol "validate" method is called 10 times
    Then the protocol "decode" method is called 10 times

  Scenario: An invalid token returns a forbidden response 
    Given valid config 
    When the adapter instance is created 
    When the auth method is called 
Dan Jones's avatar
Dan Jones committed
40
    When a mock receive API response is configured to return a 403 error
41 42
    When the poll method is called 
    Then an error response is returned with status 403
43 44 45 46 47

  Scenario: On 403 the message is retried once with new credentials 
    Given valid config 
    When the adapter instance is created 
    When the auth method is called 
Dan Jones's avatar
Dan Jones committed
48
    When a mock receive API response is configured to return a 403 error 
49
    When the poll method is called 
50 51
    Then an error response is returned with status 403 
    Then the credentials are deleted
52
    Then the poll method was called with is_retry on
53 54
    Then the total number of calls to "poll" was 2
    Then the total number of calls to "getAuthorizationHeader" was 1
55 56 57 58 59
    
  Scenario: On a retried 403 the message is not retried again
    Given valid config 
    When the adapter instance is created 
    When the auth method is called 
Dan Jones's avatar
Dan Jones committed
60
    When a mock receive API response is configured to return a 403 error 
61
    When the poll method is called with is_retry on
62 63
    Then an error response is returned with status 403
    Then the credentials are deleted 
64 65
    Then the total number of calls to "poll" was 1
  
Dan Jones's avatar
Dan Jones committed
66 67 68 69 70 71 72 73 74
  Scenario: On 503 the message is retried once with the same credentials 
    Given valid config 
    When the adapter instance is created 
    When the auth method is called 
    When a mock receive API response is configured to return a 503 error 
    When the poll method is called 
    Then an error response is returned with status 503 
    Then the credentials are not deleted
    Then the poll method was called with is_retry on
75 76
    Then the total number of calls to "poll" was 2
    Then the total number of calls to "getAuthorizationHeader" was 1
Dan Jones's avatar
Dan Jones committed
77 78 79 80 81 82 83 84 85
    
  Scenario: On a retried 503 the message is not retried again
    Given valid config 
    When the adapter instance is created 
    When the auth method is called 
    When a mock receive API response is configured to return a 503 error 
    When the poll method is called with is_retry on
    Then an error response is returned with status 503
    Then the credentials are not deleted 
86
    Then the total number of calls to "poll" was 1
Dan Jones's avatar
Dan Jones committed
87