}
@Test
public void testReadRequest() throws Exception
{
AgiRequest request;
expect(socket.readLine()).andReturn("agi_network: yes");
expect(socket.readLine()).andReturn("agi_network_script: myscript.agi");
expect(socket.readLine()).andReturn("agi_request: agi://host/myscript.agi");
expect(socket.readLine()).andReturn("agi_channel: SIP/1234-d715");
expect(socket.readLine()).andReturn("");
byte[] ipLocal = new byte[4];
ipLocal[0] = Integer.valueOf(192).byteValue();
ipLocal[1] = Integer.valueOf(168).byteValue();
ipLocal[2] = Integer.valueOf(0).byteValue();
ipLocal[3] = Integer.valueOf(1).byteValue();
expect(socket.getLocalAddress()).andReturn(InetAddress.getByAddress(ipLocal));
expect(socket.getLocalPort()).andReturn(1234);
byte[] ipRemote = new byte[4];
ipRemote[0] = Integer.valueOf(192).byteValue();
ipRemote[1] = Integer.valueOf(168).byteValue();
ipRemote[2] = Integer.valueOf(0).byteValue();
ipRemote[3] = Integer.valueOf(2).byteValue();
expect(socket.getRemoteAddress()).andReturn(InetAddress.getByAddress(ipRemote));
expect(socket.getRemotePort()).andReturn(1235);
replay(socket);
request = agiReader.readRequest();
assertEquals("incorrect script", "myscript.agi", request.getScript());
assertEquals("incorrect requestURL", "agi://host/myscript.agi", request.getRequestURL());
assertEquals("incorrect channel", "SIP/1234-d715", request.getChannel());
assertEquals("incorrect local address", ipLocal[0], request.getLocalAddress().getAddress()[0]);
assertEquals("incorrect local address", ipLocal[1], request.getLocalAddress().getAddress()[1]);
assertEquals("incorrect local address", ipLocal[2], request.getLocalAddress().getAddress()[2]);
assertEquals("incorrect local address", ipLocal[3], request.getLocalAddress().getAddress()[3]);
assertEquals("incorrect local port", 1234, request.getLocalPort());
assertEquals("incorrect remote address", ipRemote[0], request.getRemoteAddress().getAddress()[0]);
assertEquals("incorrect remote address", ipRemote[1], request.getRemoteAddress().getAddress()[1]);
assertEquals("incorrect remote address", ipRemote[2], request.getRemoteAddress().getAddress()[2]);
assertEquals("incorrect remote address", ipRemote[3], request.getRemoteAddress().getAddress()[3]);
assertEquals("incorrect remote port", 1235, request.getRemotePort());
verify(socket);
}