testinfo:
    summary: Test that ensures bridged channels in Stasis() can be stolen properly.
    description: |
        "This test originates one Local channel into Stasis() and Echo() and
        another Local channel into a pair of echo applications. It then puts
        the Stasis() Local channel half with uniqueid StasisChannel into a
        bridge and uses the AMI bridge action to pull StasisChannel and
        EchoChannel into a bridge and hangs them up. This test verifies that
        the appropriate events are generated."

test-modules:
    test-object:
        config-section: test-object-config
        typename: ari.AriOriginateTestObject
    modules:
        -
            config-section: pluggable-config
            typename: 'pluggable_modules.EventActionModule'

test-object-config:
    reactor-timeout: 15
    apps: testsuite
    test-iterations:
        - [ { channelId: 'dummy',
              endpoint: 'Local/dummy@default',
              context: 'default',
              extension: 'echo',
              priority: '1' },
            { channelId: 'alice',
              endpoint: 'Local/app_stasis@default',
              context: 'default',
              extension: 'echo',
              priority: '1' } ]

pluggable-config:
    -
#        ami-start:
        ari-events:
            match:
                type: StasisStart
                application: testsuite
                args: ['dummy']
                channel:
                    id: 'dummy;2'
            count: 1
    -
        ari-events:
            match:
                type: StasisStart
                application: testsuite
                args: ['test']
                channel:
                    id: 'alice;2'
            count: 1
        ari-requests:
            -
                method: 'post'
                uri: 'bridges/test_bridge'
            -
                method: 'post'
                uri: 'bridges/test_bridge/addChannel'
                params:
                    channel: '{channel.id}'
    -
        ari-events:
            match:
                type: ChannelEnteredBridge
                channel:
                    id: 'alice;2'
            count: 1
        ari-requests:
            method: 'post'
            uri: 'channels/bob'
            params:
                endpoint: 'Local/app_bridge@default'
                context: 'default'
                extension: 'echo'
                priority: '1'
    -
        ari-events:
            match:
                type: ChannelLeftBridge
                bridge:
                    id: 'test_bridge'
                channel:
                    id: 'alice;2'
            count: 1
    -
        ari-events:
            match:
                type: StasisEnd
                application: testsuite
                channel:
                    id: 'alice;2'
            count: 1
    -
        ami-events:
            conditions:
                match:
                    Event: BridgeCreate
                    bridgecreator: '<unknown>'
            count: 1
            conditions:
                match:
                    Event: BridgeEnter
                    uniqueid: 'alice;2'
                nomatch:
                    bridgecreator: 'Stasis'
            count: 1
    -
        ami-events:
            conditions:
                match:
                    Event: BridgeEnter
                    uniqueid: 'bob;2'
                nomatch:
                    bridgecreator: 'Stasis'
            count: 1
        ari-requests:
            method: 'delete'
            uri: 'channels/bob;2'
    -
        ami-events:
            conditions:
                match:
                    Event: BridgeLeave
                    uniqueid: 'bob;2'
                nomatch:
                    bridgename: 'test_bridge'
            count: 1
            conditions:
                match:
                    Event: BridgeLeave
                    uniqueid: 'alice;2'
                nomatch:
                    bridgename: 'test_bridge'
            count: 1
    -
        ami-events:
            conditions:
                match:
                    Event: BridgeDestroy
                    bridgecreator: '<unknown>'
            count: 1
        ari-requests:
            method: 'delete'
            uri: 'bridges/test_bridge'
    -
        ami-events:
            conditions:
                match:
                    Event: UserEvent
                    UserEvent: 'BridgeAppExit'
                    result: 'passed'
            count: 1
        ari-requests:
            method: 'delete'
            uri: 'channels/dummy;2'

properties:
    minversion: '12.8.0'
    dependencies:
        - python : autobahn.websocket
        - python : requests
        - python : twisted
        - python : starpy
        - asterisk : res_ari_channels
        - asterisk : res_ari_bridges
        - asterisk : app_echo
    tags:
        - ARI
