Re: FitNesse integration

[email protected] Wed, 20 Aug 2003 16:55:06 -0400
Newsgroups gmane.comp.programming.tools.fit.devel
Message-ID <[email protected]>
I'll look at it and get back to you shortly.

John Roth

----- Original Message ----- 
From: "Micah Martin" <[email protected]>
To: "'FIT Developers'" <[email protected]>
Sent: Wednesday, August 20, 2003 4:12 PM
Subject: [Fit-dev] FitNesse integration


> Code is worth a thousand words.
>
> This code should express my intent.
> Using the Listener idea Ward suggested I implemented the chunking ability
> (in Java).  This required only minor changes to the Fixture class;
although
> I did rip out the inner Counts class and put it in it's own file.  Two new
> classes for this are FixtureListener (Interface) and NullFixtureListener
> which is used by default in Fixture
>
> I also wrote a new implementation of FitFilter.  I call it FitServer
though
> becuase thats what it feels like.  It will handle multiple test executions
> and represents all the functionallity I've mentioned to integrate with
> FitNesse.
>
> Of course I'm interested in comments.
>
> Micah
>
> Here is the FitServer code... the rest of the source is available at
> http://fitnesse.org/files/fitSource.zip.  (The attachment was too big to
> post)
>
> public class FitServer
> {
> public static final DecimalFormat format = new
> DecimalFormat("0000000000");
>
> public String input;
> public Parse tables;
> public Fixture fixture = new Fixture();
> Counts counts = new Counts();
>
> public static void main(String argv[])
> {
> new FitServer().run(argv);
> }
>
> public void run(String argv[])
> {
> args(argv);
> process();
> exit();
> }
>
> public void process()
> {
> fixture.listner = new TablePrintingFixtureListener();
> try
> {
> int size = 1;
> while( (size = readSize()) != 0)
> {
> String document = readDocument(size);
> tables = new Parse(document);
> newFixture().doTables(tables);
> counts.tally(fixture.counts);
> }
> }
> catch(Exception e)
> {
> exception(e);
> }
> }
>
> private Fixture newFixture()
> {
> fixture = new Fixture();
> fixture.listner = new TablePrintingFixtureListener();
> return fixture;
> }
>
> public void args(String[] argv)
> {
> if(argv.length != 0)
> {
> System.err.println("usage: java fit.FitServer");
> System.exit(-1);
> }
> }
>
> private int readSize() throws Exception
> {
> byte[] bytes = new byte[10];
> System.in.read(bytes);
>     Number n = format.parse(new String(bytes));
> return n.intValue();
> }
>
> private String readDocument(int size) throws Exception
> {
> byte[] bytes = new byte[size];
> System.in.read(bytes);
> return new String(bytes);
> }
>
> protected void exception(Exception e)
> {
> tables = new Parse("body", "Unable to parse input. Input
> ignored.", null, null);
> fixture.exception(tables, e);
> }
>
> protected void exit()
> {
> System.exit(counts.wrong + counts.exceptions);
> }
>
> class TablePrintingFixtureListener implements FixtureListener
> {
> public void tableFinished(Parse table)
> {
> try
> {
> ByteArrayOutputStream byteBuffer = new
> ByteArrayOutputStream();
> PrintWriter writer = new
> PrintWriter(byteBuffer);
> Parse more = table.more;
> table.more = null;
> if(table.trailer == null)
> table.trailer = "";
> table.print(writer);
> table.more = more;
> writer.close();
>
> byte[] bytes = byteBuffer.toByteArray();
>
> System.out.write(format.format(bytes.length).getBytes());
> System.out.write(bytes);
> System.out.flush();
> }
> catch(IOException e)
> {
> e.printStackTrace();
> }
> }
>
> public void tablesFinished(Counts count)
> {
> try
> {
>
> System.out.write(format.format(0).getBytes());
>
> System.out.write(format.format(count.right).getBytes());
>
> System.out.write(format.format(count.wrong).getBytes());
>
> System.out.write(format.format(count.ignores).getBytes());
>
> System.out.write(format.format(count.exceptions).getBytes());
> System.out.flush();
> }
> catch(IOException e)
> {
> e.printStackTrace();
> }
> }
> }
> }
>
>
> -------------------------------------------------------------------
> Micah Martin  -  [email protected]
> Software Developer  -  Object Mentor, Inc.
> www.objectmentor.com
>
>
>
>
> -------------------------------------------------------------------
> Micah Martin  -  [email protected]
> Software Developer  -  Object Mentor, Inc.
> www.objectmentor.com
>
>
>
> _______________________________________________
> Fit-dev mailing list
> [email protected]
> http://lists.freepan.org/mailman/listinfo.cgi/fit-dev