KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > pmti > v1 > autodoc > v1 > server > LogFileServer


1 /*
2  * @(#)LogFileServer.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Part of the GroboUtils package at:
9  * http://groboutils.sourceforge.net
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */

29 package net.sourceforge.groboutils.pmti.v1.autodoc.v1.server;
30
31
32 import java.io.File JavaDoc;
33 import java.io.Writer JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 import net.sourceforge.groboutils.autodoc.v1.testserver.TestData;
37 import net.sourceforge.groboutils.autodoc.v1.testserver.TestInfo;
38
39 import net.sourceforge.groboutils.pmti.v1.autodoc.v1.ITFTestData;
40
41
42 /**
43  * An interface which corresponds to a part of the framework that knows how
44  * to deal with the framework's <tt>TestData</tt>. It may directly deal with
45  * the data, or pass it off to a remote server.
46  *
47  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
48  * @since March 17, 2002
49  * @version $Date: 2003/02/10 22:51:56 $
50  */

51 public class LogFileServer extends AbstractAppendFileServer
52 {
53     public LogFileServer( File JavaDoc f )
54     {
55         super( f );
56     }
57     
58     
59     
60     
61     /**
62      * Write the TestData with all the result's encountered BugTestLog
63      * events.
64      */

65     protected void writeTestData( TestData td, Writer JavaDoc w )
66             throws IOException JavaDoc
67     {
68         if (td == null || !(td instanceof ITFTestData))
69         {
70             return;
71         }
72         String JavaDoc newline = System.getProperty( "line.separator" );
73         ITFTestData itd = (ITFTestData)td;
74         TestInfo ti = td.getTestInfo();
75         
76         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( ti.getSuite() );
77         sb.append( '#' ).
78             append( ti.getMethod() ).
79             append( " test count=" ).
80             append( itd.getTestCount() ).
81             append( " runtime in ms=" ).
82             append( itd.getRunTime() ).
83             append( newline ).
84             append( " Failures:" );
85         appendArray( sb, itd.getFailures(), newline );
86         sb.append( newline ).
87             append( " Errors:" );
88         appendArray( sb, itd.getErrors(), newline );
89         sb.append( newline ).
90             append( " Bugs: " );
91         String JavaDoc logs[] = itd.getIssues();
92         if (logs.length <= 0)
93         {
94             sb.append("none" );
95         }
96         else
97         {
98             sb.append( logs[0] );
99             for (int i = 1; i < logs.length; ++i)
100             {
101                 sb.append( ", " ).
102                     append( logs[i] );
103             }
104         }
105         sb.append( newline );
106         
107         w.write( sb.toString() );
108         w.flush();
109     }
110     
111     
112     void appendArray( StringBuffer JavaDoc sb, Object JavaDoc[] list, String JavaDoc newline )
113     {
114         if (list == null || list.length <= 0)
115         {
116             sb.append( " none" );
117         }
118         else
119         {
120             for (int i = 0; i < list.length; ++i)
121             {
122                 sb.append( newline ).
123                     append( " " ).
124                     append( list[i] );
125             }
126         }
127     }
128 }
129
130
Popular Tags