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