test/command/OverTest.java
author cli
Wed, 14 Sep 2011 12:54:40 +0200
changeset 60 39f1fadf50a0
parent 1 6fceb66e1ad7
permissions -rwxr-xr-x
Add libcommons-codec-java to Debian dependencies.
     1 /*
     2  *   StarOffice News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     5  *   This program is free software: you can redistribute it and/or modify
     6  *   it under the terms of the GNU General Public License as published by
     7  *   the Free Software Foundation, either version 3 of the License, or
     8  *   (at your option) any later version.
     9  *
    10  *   This program is distributed in the hope that it will be useful,
    11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *   GNU General Public License for more details.
    14  *
    15  *   You should have received a copy of the GNU General Public License
    16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    19 package test.command;
    20 
    21 import java.text.SimpleDateFormat;
    22 import java.util.ArrayList;
    23 import java.util.List;
    24 import test.AbstractTest;
    25 
    26 /**
    27  * Tests the OVER/XOVER command.
    28  * @author Christian Lins
    29  * @since sonews/0.5.0
    30  */
    31 public class OverTest extends AbstractTest
    32 {
    33 
    34   @Override
    35   public int runTest()
    36     throws Exception
    37   {
    38     // Send HELLO to server
    39     String line = readln();
    40     if(!line.startsWith("200 "))
    41     {
    42       return 1;
    43     }
    44 
    45     // Determine available groups
    46     println("LIST");
    47     line = readln();
    48     if(!line.startsWith("215 "))
    49     {
    50       return 2;
    51     }
    52 
    53     List<String> groups = new ArrayList<String>();
    54     line = readln();
    55     for(;;)
    56     {
    57       if(line.equals("."))
    58       {
    59         break;
    60       }
    61       else
    62       {
    63         groups.add(line);
    64         line = readln();
    65       }
    66     }
    67 
    68     if(groups.size() <= 0)
    69     {
    70       return 3;
    71     }
    72 
    73     // Test OVER command on every group
    74     for(String group : groups)
    75     {
    76       String groupName = group.split(" ")[0];
    77       println("GROUP " + groupName);
    78       line = readln();
    79       if(!line.startsWith("211 "))
    80       {
    81         return 4;
    82       }
    83 
    84       String[] lineToks = line.split(" ");
    85       println("XOVER " + lineToks[2] + "-" + lineToks[3]);
    86       line = readln();
    87       if(line.startsWith("423"))
    88       {
    89         continue;
    90       }
    91       else if(!line.startsWith("224 "))
    92       {
    93         return 5;
    94       }
    95       
    96       line = readln();
    97       for(;;)
    98       {
    99         if(line == null)
   100         {
   101           return 7;
   102         }
   103         else if(line.equals("."))
   104         {
   105           break;
   106         }
   107 
   108         // Validate the line
   109         lineToks = line.split("\t");
   110         if(lineToks.length < 6)
   111         {
   112           return 6;
   113         }
   114         else
   115         {
   116           Integer.parseInt(lineToks[0]);
   117 
   118           //SimpleDateFormat sdf = new SimpleDateFormat(group)
   119 
   120           if(!lineToks[4].startsWith("<") && !lineToks[4].endsWith(">"))
   121           {
   122             log.println("Invalid Message-ID: " + lineToks[1]);
   123             log.flush();
   124             return 8;
   125           }
   126         }
   127 
   128         line = readln();
   129       }
   130     }
   131     
   132     return 0;
   133   }
   134   
   135 }