chris@1: /*
chris@1: * StarOffice News Server
chris@1: * see AUTHORS for the list of contributors
chris@1: *
chris@1: * This program is free software: you can redistribute it and/or modify
chris@1: * it under the terms of the GNU General Public License as published by
chris@1: * the Free Software Foundation, either version 3 of the License, or
chris@1: * (at your option) any later version.
chris@1: *
chris@1: * This program is distributed in the hope that it will be useful,
chris@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
chris@1: * GNU General Public License for more details.
chris@1: *
chris@1: * You should have received a copy of the GNU General Public License
chris@1: * along with this program. If not, see .
chris@1: */
chris@1:
chris@1: package test.command;
chris@1:
chris@1: import java.text.SimpleDateFormat;
chris@1: import java.util.ArrayList;
chris@1: import java.util.List;
chris@1: import test.AbstractTest;
chris@1:
chris@1: /**
chris@1: * Tests the OVER/XOVER command.
chris@1: * @author Christian Lins
chris@1: * @since sonews/0.5.0
chris@1: */
chris@1: public class OverTest extends AbstractTest
chris@1: {
chris@1:
chris@1: @Override
chris@1: public int runTest()
chris@1: throws Exception
chris@1: {
chris@1: // Send HELLO to server
chris@1: String line = readln();
chris@1: if(!line.startsWith("200 "))
chris@1: {
chris@1: return 1;
chris@1: }
chris@1:
chris@1: // Determine available groups
chris@1: println("LIST");
chris@1: line = readln();
chris@1: if(!line.startsWith("215 "))
chris@1: {
chris@1: return 2;
chris@1: }
chris@1:
chris@1: List groups = new ArrayList();
chris@1: line = readln();
chris@1: for(;;)
chris@1: {
chris@1: if(line.equals("."))
chris@1: {
chris@1: break;
chris@1: }
chris@1: else
chris@1: {
chris@1: groups.add(line);
chris@1: line = readln();
chris@1: }
chris@1: }
chris@1:
chris@1: if(groups.size() <= 0)
chris@1: {
chris@1: return 3;
chris@1: }
chris@1:
chris@1: // Test OVER command on every group
chris@1: for(String group : groups)
chris@1: {
chris@1: String groupName = group.split(" ")[0];
chris@1: println("GROUP " + groupName);
chris@1: line = readln();
chris@1: if(!line.startsWith("211 "))
chris@1: {
chris@1: return 4;
chris@1: }
chris@1:
chris@1: String[] lineToks = line.split(" ");
chris@1: println("XOVER " + lineToks[2] + "-" + lineToks[3]);
chris@1: line = readln();
chris@1: if(line.startsWith("423"))
chris@1: {
chris@1: continue;
chris@1: }
chris@1: else if(!line.startsWith("224 "))
chris@1: {
chris@1: return 5;
chris@1: }
chris@1:
chris@1: line = readln();
chris@1: for(;;)
chris@1: {
chris@1: if(line == null)
chris@1: {
chris@1: return 7;
chris@1: }
chris@1: else if(line.equals("."))
chris@1: {
chris@1: break;
chris@1: }
chris@1:
chris@1: // Validate the line
chris@1: lineToks = line.split("\t");
chris@1: if(lineToks.length < 6)
chris@1: {
chris@1: return 6;
chris@1: }
chris@1: else
chris@1: {
chris@1: Integer.parseInt(lineToks[0]);
chris@1:
chris@1: //SimpleDateFormat sdf = new SimpleDateFormat(group)
chris@1:
chris@1: if(!lineToks[4].startsWith("<") && !lineToks[4].endsWith(">"))
chris@1: {
chris@1: log.println("Invalid Message-ID: " + lineToks[1]);
chris@1: log.flush();
chris@1: return 8;
chris@1: }
chris@1: }
chris@1:
chris@1: line = readln();
chris@1: }
chris@1: }
chris@1:
chris@1: return 0;
chris@1: }
chris@1:
chris@1: }