Line | Hits | Source |
---|---|---|
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 */ | |
21 | 9 | private PbsToXml parse = new PbsToXml(); |
22 | ||
23 | /** The new line seperator for this system */ | |
24 | 9 | private String nl = System.getProperty("line.separator"); |
25 | ||
26 | /** Logger */ | |
27 | 12 | 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) { | |
36 | 9 | super(testName); |
37 | 9 | } |
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) { | |
46 | 0 | junit.textui.TestRunner.run(suite()); |
47 | 0 | } |
48 | ||
49 | /** | |
50 | * Return a new test suite | |
51 | * | |
52 | * @return a new test suite | |
53 | */ | |
54 | public static Test suite() { | |
55 | 3 | TestSuite suite = new TestSuite(PbsToXmlTest.class); |
56 | ||
57 | 3 | return suite; |
58 | } | |
59 | ||
60 | /** Test process record when invalid line is passed */ | |
61 | public void testProcessRecordInvalidLine() { | |
62 | 3 | String invalidLine = |
63 | "11/21/2002 10:22:10;Q;14877.head;queue=npaci;NOT VALID"; | |
64 | ||
65 | try { | |
66 | 3 | parse.processRecord(invalidLine); |
67 | 3 | } catch (InvalidRecordException e) { |
68 | 3 | assertTrue(true); |
69 | 3 | return; |
70 | 0 | } |
71 | ||
72 | //We should have had exception | |
73 | 0 | fail(); |
74 | 0 | } |
75 | ||
76 | /** Test process record when invalid record is passed */ | |
77 | public void testProcessRecordInvalidRecord() { | |
78 | 3 | String invalidLine = |
79 | "11/21/2002 10:22:10;INVALIDRECORD;14877.head;queue=npaci"; | |
80 | ||
81 | try { | |
82 | 3 | parse.processRecord(invalidLine); |
83 | 3 | } catch (InvalidRecordException e) { |
84 | 3 | assertTrue(true); |
85 | 3 | return; |
86 | 0 | } |
87 | ||
88 | //We should have had exception | |
89 | 0 | fail(); |
90 | 0 | } |
91 | ||
92 | /** | |
93 | * Test that process record works correctly (individual records tested in | |
94 | * there corresponding unit tests) | |
95 | */ | |
96 | public void testProcessQueueRecord() { | |
97 | 3 | String inputLine = "11/21/2002 10:22:10;Q;14876.head;queue=npaci"; |
98 | ||
99 | 3 | 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 { | |
118 | 3 | String output = parse.processRecord(inputLine); |
119 | 3 | if (logger.isLoggable(Level.INFO)) { |
120 | 3 | StringBuffer outputBuffer = new StringBuffer(); |
121 | 3 | outputBuffer.append(nl); |
122 | 3 | outputBuffer.append("CALCULATED"); |
123 | 3 | outputBuffer.append(nl); |
124 | 3 | outputBuffer.append(output); |
125 | 3 | outputBuffer.append(nl); |
126 | 3 | outputBuffer.append("EXPECTED"); |
127 | 3 | outputBuffer.append(nl); |
128 | 3 | outputBuffer.append(expectedOutput); |
129 | 3 | outputBuffer.append(nl); |
130 | //Use system.out because logger buffers, and mixes with junit | |
131 | // out on error | |
132 | 3 | System.out.println(outputBuffer.toString()); |
133 | } | |
134 | 3 | assertTrue(output.equals(expectedOutput)); |
135 | 0 | } catch (Exception e) { |
136 | 0 | fail(); |
137 | 3 | } |
138 | ||
139 | 3 | } |
140 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |