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; chris@1: chris@1: import java.io.BufferedReader; chris@1: import java.io.File; chris@1: import java.io.IOException; chris@1: import java.io.InputStreamReader; chris@1: import java.io.PrintWriter; chris@1: import java.net.Socket; chris@1: import java.net.UnknownHostException; chris@1: chris@1: /** chris@1: * Base class for every test performed by the TestBench. chris@1: * Connects to a NNTP Server and provides basic methods for sending and chris@1: * receiving data. chris@1: * @author Christian Lins chris@1: * @since sonews/0.5.0 chris@1: */ chris@1: public abstract class AbstractTest chris@1: { chris@1: chris@1: protected static PrintWriter log; chris@1: chris@1: static chris@1: { chris@1: try chris@1: { chris@1: log = new PrintWriter(new File("test.log")); chris@1: } chris@1: catch(Exception ex) chris@1: { chris@1: ex.printStackTrace(); chris@1: } chris@1: } chris@1: chris@1: protected BufferedReader in; chris@1: protected PrintWriter out; chris@1: protected Socket socket; chris@1: chris@1: /** chris@1: * Connects to NNTP Server using for chris@1: * @param host chris@1: * @param port chris@1: * @throws java.io.IOException chris@1: * @throws java.net.UnknownHostException chris@1: */ chris@1: public void connect(String host, int port) chris@1: throws IOException, UnknownHostException chris@1: { chris@1: socket = new Socket(host, port); chris@1: socket.setSoTimeout(10000); chris@1: this.in = new BufferedReader(new InputStreamReader(socket.getInputStream())); chris@1: this.out = new PrintWriter(socket.getOutputStream()); chris@1: } chris@1: chris@1: protected void println(String line) chris@1: { chris@1: this.out.println(line); chris@1: this.out.flush(); chris@1: chris@1: log.println(">> " + line); chris@1: log.flush(); chris@1: } chris@1: chris@1: protected String readln() chris@1: throws IOException chris@1: { chris@1: String line = this.in.readLine(); chris@1: log.println("<< " + line); chris@1: log.flush(); chris@1: return line; chris@1: } chris@1: chris@1: public abstract int runTest() throws Exception; chris@1: chris@1: }