Coverage details for umich.cac.pbs.test.PbsToXmlTest

LineHitsSource
1 package umich.cac.pbs.test;
2  
3 import java.util.logging.Level;
4 import java.util.logging.Logger;
5  
6 import junit.framework.Test;
7 import junit.framework.TestCase;
8 import junit.framework.TestSuite;
9 import umich.cac.pbs.InvalidRecordException;
10 import umich.cac.pbs.PbsToXml;
11  
12 /**
13  * Tests for PbsToXml class.
14  *
15  * @author rmach@umich.edu
16  * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/pbs/test/PbsToXmlTest.java,v 1.3 2003/10/21 19:08:00 rodmach Exp $
17  */
18 public class PbsToXmlTest extends TestCase {
19  
20     /** The object to perform testing on */
219    private PbsToXml parse = new PbsToXml();
22  
23     /** The new line seperator for this system */
249    private String nl = System.getProperty("line.separator");
25  
26     /** Logger */
2712    private Logger logger = Logger.getLogger(PbsToXmlTest.class.getName());
28  
29     /**
30      * Constructor
31      *
32      * @param testName
33      * name of test suite
34      */
35     public PbsToXmlTest(java.lang.String testName) {
369        super(testName);
379    }
38  
39     /**
40      * Main - for running stand-alone test
41      *
42      * @param args
43      * command line arguments
44      */
45     public static void main(java.lang.String[] args) {
460        junit.textui.TestRunner.run(suite());
470    }
48  
49     /**
50      * Return a new test suite
51      *
52      * @return a new test suite
53      */
54     public static Test suite() {
553        TestSuite suite = new TestSuite(PbsToXmlTest.class);
56  
573        return suite;
58     }
59  
60     /** Test process record when invalid line is passed */
61     public void testProcessRecordInvalidLine() {
623        String invalidLine =
63             "11/21/2002 10:22:10;Q;14877.head;queue=npaci;NOT VALID";
64  
65         try {
663            parse.processRecord(invalidLine);
673        } catch (InvalidRecordException e) {
683            assertTrue(true);
693            return;
700        }
71  
72         //We should have had exception
730        fail();
740    }
75  
76     /** Test process record when invalid record is passed */
77     public void testProcessRecordInvalidRecord() {
783        String invalidLine =
79             "11/21/2002 10:22:10;INVALIDRECORD;14877.head;queue=npaci";
80  
81         try {
823            parse.processRecord(invalidLine);
833        } catch (InvalidRecordException e) {
843            assertTrue(true);
853            return;
860        }
87  
88         //We should have had exception
890        fail();
900    }
91  
92     /**
93      * Test that process record works correctly (individual records tested in
94      * there corresponding unit tests)
95      */
96     public void testProcessQueueRecord() {
973        String inputLine = "11/21/2002 10:22:10;Q;14876.head;queue=npaci";
98  
993        String expectedOutput =
100             "<queue_record>"
101                 + nl
102                 + "<jobid>14876.head</jobid>"
103                 + nl
104                 + "<date>"
105                 + nl
106                 + "<day>11/21/2002</day>"
107                 + nl
108                 + "<time>10:22:10</time>"
109                 + nl
110                 + "</date>"
111                 + nl
112                 + "<queue>npaci</queue>"
113                 + nl
114                 + "</queue_record>"
115                 + nl;
116  
117         try {
1183            String output = parse.processRecord(inputLine);
1193            if (logger.isLoggable(Level.INFO)) {
1203                StringBuffer outputBuffer = new StringBuffer();
1213                outputBuffer.append(nl);
1223                outputBuffer.append("CALCULATED");
1233                outputBuffer.append(nl);
1243                outputBuffer.append(output);
1253                outputBuffer.append(nl);
1263                outputBuffer.append("EXPECTED");
1273                outputBuffer.append(nl);
1283                outputBuffer.append(expectedOutput);
1293                outputBuffer.append(nl);
130                 //Use system.out because logger buffers, and mixes with junit
131                 // out on error
1323                System.out.println(outputBuffer.toString());
133             }
1343            assertTrue(output.equals(expectedOutput));
1350        } catch (Exception e) {
1360            fail();
1373        }
138  
1393    }
140 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.