Package org.asteriskjava.manager

Source Code of org.asteriskjava.manager.TestAsyncAgi

/*
* (c) 2004 Stefan Reuter
*
* Created on Sep 24, 2004
*/
package org.asteriskjava.manager;

import org.asteriskjava.manager.action.CommandAction;
import org.asteriskjava.manager.action.StatusAction;
import org.asteriskjava.manager.action.VoicemailUsersListAction;
import org.asteriskjava.manager.action.AgiAction;
import org.asteriskjava.manager.event.ManagerEvent;
import org.asteriskjava.manager.event.AsyncAgiEvent;
import org.asteriskjava.manager.response.CommandResponse;
import org.asteriskjava.manager.response.ManagerResponse;

import junit.framework.TestCase;

import java.util.Iterator;

/**
* @author srt
* @version $Id$
*/
public class TestAsyncAgi extends AbstractManagerTestCase
{
    public void testDialplanShow() throws Exception
    {
        DefaultManagerConnection managerConnection;

        managerConnection = getDefaultManagerConnection();
        managerConnection.login();

        CommandAction commandAction = new CommandAction("sip show peers");
        ManagerResponse response = managerConnection.sendAction(commandAction);
        if (response instanceof CommandResponse)
        {
            for (String item : ((CommandResponse) response).getResult())
            {
                System.out.println(item);
            }
        }
    }

    public void testAgiAction() throws Exception
    {
        DefaultManagerConnection dmc;

        dmc = getDefaultManagerConnection();
        dmc.addEventListener(new ManagerEventListener()
        {
            public void onManagerEvent(ManagerEvent event)
            {
                System.out.println("Got event: " + event);
                if (event instanceof AsyncAgiEvent)
                {
                    System.out.println("Decoded env: " + ((AsyncAgiEvent) event).decodeEnv());
                }
            }
        });
        dmc.login();
        System.out.println("Dial 1296");
        Thread.sleep(5000);
        ManagerResponse response = dmc.sendAction(new AgiAction(
                "IAX2/iax0-cgn_reucon_net-2",
                "EXEC Playback tt-monkeysintro",
                "myCommandId"));
        System.out.println(response);

        // wait to receive events
        Thread.sleep(20000);
        dmc.logoff();
        Thread.sleep(3000);
    }
}
TOP

Related Classes of org.asteriskjava.manager.TestAsyncAgi

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.