test/TestBench.java
changeset 82 21f413541357
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/TestBench.java	Sun Oct 16 22:36:46 2011 +0200
     1.3 @@ -0,0 +1,98 @@
     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;
    1.23 +
    1.24 +import test.command.HelloQuitTest;
    1.25 +import test.command.ArticleTest;
    1.26 +import java.util.LinkedList;
    1.27 +import java.util.List;
    1.28 +import test.command.CapabilitiesTest;
    1.29 +import test.command.GroupTest;
    1.30 +import test.command.ListGroupTests;
    1.31 +import test.command.ListTest;
    1.32 +import test.command.NewGroupsTest;
    1.33 +import test.command.NextTest;
    1.34 +import test.command.OverTest;
    1.35 +import test.command.PostTest;
    1.36 +
    1.37 +/**
    1.38 + * Run this class to perform a full test.
    1.39 + * @author Christian Lins
    1.40 + * @since sonews/0.5.0
    1.41 + */
    1.42 +public final class TestBench 
    1.43 +{
    1.44 +  
    1.45 +  public static void main(String[] args)
    1.46 +  {
    1.47 +    System.out.println("TestBench for NNTP (RFC3799) based servers ");
    1.48 +    if(args.length < 1)
    1.49 +    {
    1.50 +      System.out.println("Usage: TestBench <host>[:port]");
    1.51 +      return;
    1.52 +    }
    1.53 +    
    1.54 +    String[] hostport = args[0].split(":");
    1.55 +    String host = hostport[0];
    1.56 +    int    port = 119;
    1.57 +    if(hostport.length == 2)
    1.58 +    {
    1.59 +      port = Integer.parseInt(hostport[1]);
    1.60 +    }
    1.61 +
    1.62 +    List<AbstractTest> tests = new LinkedList<AbstractTest>();
    1.63 +    
    1.64 +    // Add tests to perform
    1.65 +    tests.add(new HelloQuitTest());
    1.66 +    tests.add(new PostTest());    // Post before Article
    1.67 +    tests.add(new ArticleTest());
    1.68 +    tests.add(new CapabilitiesTest());
    1.69 +    tests.add(new GroupTest());
    1.70 +    tests.add(new ListGroupTests());
    1.71 +    tests.add(new ListTest());
    1.72 +    tests.add(new NewGroupsTest());
    1.73 +    tests.add(new NextTest());
    1.74 +    tests.add(new OverTest());
    1.75 +    
    1.76 +    // Perform all tests
    1.77 +    for(AbstractTest test : tests)
    1.78 +    {
    1.79 +      try
    1.80 +      {
    1.81 +        test.connect(host, port);
    1.82 +        int result = test.runTest();
    1.83 +        System.out.print(test.getClass().getName() + " finished with exit code " + result + "\t => ");
    1.84 +        if(result == 0)
    1.85 +        {
    1.86 +          System.out.println("SUCCESS");
    1.87 +        }
    1.88 +        else
    1.89 +        {
    1.90 +          System.out.println("FAILURE");
    1.91 +        }
    1.92 +      }
    1.93 +      catch(Exception ex)
    1.94 +      {
    1.95 +        System.out.println("Test " + test.getClass().getName() + " failed: " + ex.getLocalizedMessage());
    1.96 +        ex.printStackTrace();
    1.97 +      }
    1.98 +    }
    1.99 +  }
   1.100 +  
   1.101 +}