commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bru...@apache.org
Subject cvs commit: jakarta-commons/net/src/test/org/apache/commons/net/telnet TelnetClientTest.java
Date Sun, 08 Feb 2004 11:26:59 GMT
brudav      2004/02/08 03:26:59

  Modified:    net/src/test/org/apache/commons/net/telnet
                        TelnetClientTest.java
  Log:
  Added setNoReaderThread() to start connections without the TelnetClient reader thread.
  New functionality requested by Scott Coleman to help add ftps support.
  
  Revision  Changes    Path
  1.7       +111 -3    jakarta-commons/net/src/test/org/apache/commons/net/telnet/TelnetClientTest.java
  
  Index: TelnetClientTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/test/org/apache/commons/net/telnet/TelnetClientTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TelnetClientTest.java	2 Jan 2004 03:39:07 -0000	1.6
  +++ TelnetClientTest.java	8 Feb 2004 11:26:59 -0000	1.7
  @@ -114,6 +114,23 @@
           tc3.connect("127.0.0.1", 3335);
           Thread.sleep(1000);
       }
  +    /***
  +     * open connections (ReaderThread test).
  +     ***/
  +    protected void openConnReaderThread() throws Exception
  +    {
  +        server1 = new TelnetTestSimpleServer(3333);
  +        server2 = new TelnetTestSimpleServer(3334);
  +
  +        tc1 = new TelnetClient();
  +        tc1.setReaderThread(false);
  +        tc2 = new TelnetClient();
  +        tc2.setReaderThread(true);
  +
  +        tc1.connect("127.0.0.1", 3333);
  +        tc2.connect("127.0.0.1", 3334);
  +        Thread.sleep(1000);
  +    }
   
       /***
        * tests the initial condition of the sessions
  @@ -448,7 +465,7 @@
           };
   
           byte buffread2b[] = new byte[11];
  -    
  +
           openConnections();
   
           numdo = 0;
  @@ -672,7 +689,80 @@
           assertTrue(test2spy_ok);
           assertTrue(stopspy_ok);
       }
  -
  +
  +    /***
  +     * test of setReaderThread
  +     ***/
  +    public void testSetReaderThread() throws Exception
  +    {
  +        boolean negotiation1_ok = false;
  +        boolean negotiation2_ok = false;
  +        boolean read_ok = false;
  +        byte buffread1[] = new byte[6];
  +        byte send1[] =
  +        {
  +            (byte)TelnetCommand.IAC, (byte)TelnetCommand.DO, (byte)15,
  +            (byte)TelnetCommand.IAC, (byte)TelnetCommand.WILL, (byte)15,
  +        };
  +        byte expected1[] =
  +        {
  +            (byte)TelnetCommand.IAC, (byte)TelnetCommand.WONT, (byte)15,
  +            (byte)TelnetCommand.IAC, (byte)TelnetCommand.DONT, (byte)15,
  +        };
  +
  +
  +        openConnReaderThread();
  +
  +        InputStream is1 = server1.getInputStream();
  +        OutputStream os1 = server1.getOutputStream();
  +        is1.skip(is1.available());
  +        os1.write(send1);
  +        os1.flush();
  +        os1.write("A".getBytes());
  +        os1.flush();
  +        Thread.sleep(1000);
  +        InputStream instr = tc1.getInputStream();
  +        byte[] buff = new byte[4];
  +        int ret_read = 0;
  +
  +        ret_read = instr.read(buff);
  +        if((ret_read == 1) && (buff[0] == 'A'))
  +        {
  +            read_ok = true;
  +        }
  +
  +        if(is1.available() == 6)
  +        {
  +            is1.read(buffread1);
  +
  +            if(equalBytes(buffread1, expected1))
  +                negotiation1_ok = true;
  +        }
  +
  +        InputStream is2 = server2.getInputStream();
  +        OutputStream os2 = server2.getOutputStream();
  +        Thread.sleep(1000);
  +        is2.skip(is2.available());
  +        os2.write(send1);
  +        os2.flush();
  +        Thread.sleep(1000);
  +        if(is2.available() == 6)
  +        {
  +            is2.read(buffread1);
  +
  +            if(equalBytes(buffread1, expected1))
  +                negotiation2_ok = true;
  +        }
  +
  +        closeConnReaderThread();
  +
  +        assertTrue(!tc1.getReaderThread());
  +        assertTrue(tc2.getReaderThread());
  +        assertTrue(read_ok);
  +        assertTrue(negotiation1_ok);
  +        assertTrue(negotiation2_ok);
  +    }
  +
       /***
        * closes all the connections
        ***/
  @@ -694,7 +784,25 @@
           catch (Exception e)
           {
           }
  -    }
  +    }
    /***
  +     * closes all the connections (ReaderThread test)
  +     ***/
  +    protected void closeConnReaderThread()
  +    {
  +        try
  +        {
  +            server1.disconnect();
  +            server1.stop();
  +            tc1.disconnect();
  +            server2.disconnect();
  +            server2.stop();
  +            tc2.disconnect();
  +            Thread.sleep(1000);
  +        }
  +        catch (Exception e)
  +        {
  +        }
  +    }
   
       /***
        * Helper method. compares two arrays of int
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message