test/command/OverTest.java
changeset 75 41d6c0cac8b3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/command/OverTest.java	Thu Oct 13 03:09:22 2011 +0200
     1.3 @@ -0,0 +1,135 @@
     1.4 +/*
     1.5 + *   StarOffice News Server
     1.6 + *   see AUTHORS for the list of contributors
     1.7 + *
     1.8 + *   This program is free software: you can redistribute it and/or modify
     1.9 + *   it under the terms of the GNU General Public License as published by
    1.10 + *   the Free Software Foundation, either version 3 of the License, or
    1.11 + *   (at your option) any later version.
    1.12 + *
    1.13 + *   This program is distributed in the hope that it will be useful,
    1.14 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 + *   GNU General Public License for more details.
    1.17 + *
    1.18 + *   You should have received a copy of the GNU General Public License
    1.19 + *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 + */
    1.21 +
    1.22 +package test.command;
    1.23 +
    1.24 +import java.text.SimpleDateFormat;
    1.25 +import java.util.ArrayList;
    1.26 +import java.util.List;
    1.27 +import test.AbstractTest;
    1.28 +
    1.29 +/**
    1.30 + * Tests the OVER/XOVER command.
    1.31 + * @author Christian Lins
    1.32 + * @since sonews/0.5.0
    1.33 + */
    1.34 +public class OverTest extends AbstractTest
    1.35 +{
    1.36 +
    1.37 +  @Override
    1.38 +  public int runTest()
    1.39 +    throws Exception
    1.40 +  {
    1.41 +    // Send HELLO to server
    1.42 +    String line = readln();
    1.43 +    if(!line.startsWith("200 "))
    1.44 +    {
    1.45 +      return 1;
    1.46 +    }
    1.47 +
    1.48 +    // Determine available groups
    1.49 +    println("LIST");
    1.50 +    line = readln();
    1.51 +    if(!line.startsWith("215 "))
    1.52 +    {
    1.53 +      return 2;
    1.54 +    }
    1.55 +
    1.56 +    List<String> groups = new ArrayList<String>();
    1.57 +    line = readln();
    1.58 +    for(;;)
    1.59 +    {
    1.60 +      if(line.equals("."))
    1.61 +      {
    1.62 +        break;
    1.63 +      }
    1.64 +      else
    1.65 +      {
    1.66 +        groups.add(line);
    1.67 +        line = readln();
    1.68 +      }
    1.69 +    }
    1.70 +
    1.71 +    if(groups.size() <= 0)
    1.72 +    {
    1.73 +      return 3;
    1.74 +    }
    1.75 +
    1.76 +    // Test OVER command on every group
    1.77 +    for(String group : groups)
    1.78 +    {
    1.79 +      String groupName = group.split(" ")[0];
    1.80 +      println("GROUP " + groupName);
    1.81 +      line = readln();
    1.82 +      if(!line.startsWith("211 "))
    1.83 +      {
    1.84 +        return 4;
    1.85 +      }
    1.86 +
    1.87 +      String[] lineToks = line.split(" ");
    1.88 +      println("XOVER " + lineToks[2] + "-" + lineToks[3]);
    1.89 +      line = readln();
    1.90 +      if(line.startsWith("423"))
    1.91 +      {
    1.92 +        continue;
    1.93 +      }
    1.94 +      else if(!line.startsWith("224 "))
    1.95 +      {
    1.96 +        return 5;
    1.97 +      }
    1.98 +      
    1.99 +      line = readln();
   1.100 +      for(;;)
   1.101 +      {
   1.102 +        if(line == null)
   1.103 +        {
   1.104 +          return 7;
   1.105 +        }
   1.106 +        else if(line.equals("."))
   1.107 +        {
   1.108 +          break;
   1.109 +        }
   1.110 +
   1.111 +        // Validate the line
   1.112 +        lineToks = line.split("\t");
   1.113 +        if(lineToks.length < 6)
   1.114 +        {
   1.115 +          return 6;
   1.116 +        }
   1.117 +        else
   1.118 +        {
   1.119 +          Integer.parseInt(lineToks[0]);
   1.120 +
   1.121 +          //SimpleDateFormat sdf = new SimpleDateFormat(group)
   1.122 +
   1.123 +          if(!lineToks[4].startsWith("<") && !lineToks[4].endsWith(">"))
   1.124 +          {
   1.125 +            log.println("Invalid Message-ID: " + lineToks[1]);
   1.126 +            log.flush();
   1.127 +            return 8;
   1.128 +          }
   1.129 +        }
   1.130 +
   1.131 +        line = readln();
   1.132 +      }
   1.133 +    }
   1.134 +    
   1.135 +    return 0;
   1.136 +  }
   1.137 +  
   1.138 +}