Coverage details for umich.cac.data.test.NodesFieldTest

LineHitsSource
1 package umich.cac.data.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.data.FieldName;
10 import umich.cac.data.NodesField;
11  
12 /**
13  * Tests for NodesField class.
14  *
15  * @author rmach@umich.edu
16  * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/data/test/NodesFieldTest.java,v 1.3 2003/10/21 19:08:00 rodmach Exp $
17  */
18  
19 public class NodesFieldTest extends TestCase {
20  
21     /** The new line seperator for this system */
2224    private String nl = System.getProperty("line.separator");
23  
24     /** Logger */
2527    private Logger logger = Logger.getLogger(NodesFieldTest.class.getName());
26  
27     /**
28      * Constructor
29      *
30      * @param testName
31      * name of test suite
32      */
33  
34     public NodesFieldTest(java.lang.String testName) {
3524        super(testName);
3624    }
37  
38     /**
39      * Main - for running stand-alone test
40      *
41      * @param args
42      * command line arguments
43      */
44  
45     public static void main(java.lang.String[] args) {
460        junit.textui.TestRunner.run(suite());
47  
480    }
49  
50     /**
51      * Return a new test suite
52      *
53      * @return a new test suite
54      */
55  
56     public static Test suite() {
573        TestSuite suite = new TestSuite(NodesFieldTest.class);
583        return suite;
59     }
60  
61     /**
62      * Test with the nodes=comma separated list of nodes
63      */
64  
65     public void testSingleNode() {
66  
673        String inputLine = "tg-c091";
68  
693        String expectedOutput =
70             "<nodes>"
71                 + nl
72                 + "<nodegroup numnodes=\"1\">"
73                 + nl
74                 + "<nodename>tg-c091</nodename>"
75                 + nl
76                 + "</nodegroup>"
77                 + nl
78                 + "</nodes>"
79                 + nl;
80  
813        testExample(inputLine, expectedOutput);
82  
833    }
84  
85     /**
86      * Test with the PPN property, which is converted to attribute
87      */
88  
89     public void testNodesFieldWithPPN() {
90  
913        String inputLine = "2:ppn=2";
92  
933        String expectedOutput =
94             "<nodes>"
95                 + nl
96                 + "<nodegroup numnodes=\"2\" ppn=\"2\"></nodegroup>"
97                 + nl
98                 + "</nodes>"
99                 + nl;
100  
1013        testExample(inputLine, expectedOutput);
102  
1033    }
104  
105     /**
106      * Test with a shared global property
107      */
108  
109     public void testNodesWithShared() {
110  
1113        String inputLine = "9#shared";
112  
1133        String expectedOutput =
114             "<nodes>"
115                 + nl
116                 + "<globalproperty>shared</globalproperty>"
117                 + nl
118                 + "<nodegroup numnodes=\"9\"></nodegroup>"
119                 + nl
120                 + "</nodes>"
121                 + nl;
122  
1233        testExample(inputLine, expectedOutput);
124  
1253    }
126  
127     /**
128      * Test just plain node number
129      */
130  
131     public void testNodes() {
132  
1333        String inputLine = "9";
134  
1353        String expectedOutput =
136             "<nodes>"
137                 + nl
138                 + "<nodegroup numnodes=\"9\"></nodegroup>"
139                 + nl
140                 + "</nodes>"
141                 + nl;
142  
1433        testExample(inputLine, expectedOutput);
144  
1453    }
146  
147     /**
148      * hosts are separated by +'s in the accounting file
149      */
150     public void testPlusSeparatedListOfHosts() {
1513        String inputLine = "tg-c065+tg-c066";
152  
1533        String expectedOutput =
154             "<nodes>"
155                 + nl
156                 + "<nodegroup numnodes=\"1\">"
157                 + nl
158                 + "<nodename>tg-c065</nodename>"
159                 + nl
160                 + "</nodegroup>"
161                 + nl
162                 + "<nodegroup numnodes=\"1\">"
163                 + nl
164                 + "<nodename>tg-c066</nodename>"
165                 + nl
166                 + "</nodegroup>"
167                 + nl
168                 + "</nodes>"
169                 + nl;
170  
1713        testExample(inputLine, expectedOutput);
172  
1733    }
174  
175     /**
176      * Test a complicated example that has hosts with various properties
177      */
178  
179     public void testExampleInput() {
180  
1813        String inputLine = "4:large+5:fast:large+2:compute:large";
182  
1833        String expectedOutput =
184             "<nodes>"
185                 + nl
186                 + "<nodegroup numnodes=\"4\">"
187                 + nl
188                 + "<property>large</property>"
189                 + nl
190                 + "</nodegroup>"
191                 + nl
192                 + "<nodegroup numnodes=\"5\">"
193                 + nl
194                 + "<property>fast</property>"
195                 + nl
196                 + "<property>large</property>"
197                 + nl
198                 + "</nodegroup>"
199                 + nl
200                 + "<nodegroup numnodes=\"2\">"
201                 + nl
202                 + "<property>compute</property>"
203                 + nl
204                 + "<property>large</property>"
205                 + nl
206                 + "</nodegroup>"
207                 + nl
208                 + "</nodes>"
209                 + nl;
210  
2113        testExample(inputLine, expectedOutput);
212  
2133    }
214  
215     /**
216      * I have found this case in an accounting example sent to me that has the
217      * host:ppn=number of nodes instead of 2:ppn=2
218      */
219     public void testHostnameWithPPN() {
2203        String inputLine = "tg-c128:ppn=2";
221  
2223        String expectedOutput =
223             "<nodes>"
224                 + nl
225                 + "<nodegroup numnodes=\"1\" ppn=\"2\">"
226                 + nl
227                 + "<nodename>tg-c128</nodename>"
228                 + nl
229                 + "</nodegroup>"
230                 + nl
231                 + "</nodes>"
232                 + nl;
233  
2343        testExample(inputLine, expectedOutput);
235  
2363    }
237  
238     /*
239      * Test the example input
240      *
241      * @param inputLine input line to test @param expectedOutput the expected
242      * output
243      */
244     private void testExample(String inputLine, String expectedOutput) {
245  
246         try {
247  
24824            NodesField userField = new NodesField(FieldName.NODES, inputLine);
24924            String output = userField.toXML();
250  
25124            if (logger.isLoggable(Level.INFO)) {
25224                StringBuffer outputBuffer = new StringBuffer();
25324                outputBuffer.append(nl);
25424                outputBuffer.append("CALCULATED");
25524                outputBuffer.append(nl);
25624                outputBuffer.append(output);
25724                outputBuffer.append(nl);
25824                outputBuffer.append("EXPECTED");
25924                outputBuffer.append(nl);
26024                outputBuffer.append(expectedOutput);
26124                outputBuffer.append(nl);
262  
263                 //Use system.out because logger buffers, and mixes with junit
264                 // out on error
26524                System.out.println(outputBuffer.toString());
266  
267             }
268  
26924            assertTrue(output.equals(expectedOutput));
270  
2710        } catch (Exception e) {
2720            fail();
27324        }
274  
27524    }
276  
277     /**
278      * Test that the User field properly renders XML
279      */
280  
281     public void testNodesFieldWithGlobalPropertiesAndProperties() {
282  
2833        String inputLine = "4+2:ppn=2:fatdisk:bigscratch#shared";
284  
2853        String expectedOutput =
286             "<nodes>"
287                 + nl
288                 + "<globalproperty>shared</globalproperty>"
289                 + nl
290                 + "<nodegroup numnodes=\"4\"></nodegroup>"
291                 + nl
292                 + "<nodegroup numnodes=\"2\" ppn=\"2\">"
293                 + nl
294                 + "<property>fatdisk</property>"
295                 + nl
296                 + "<property>bigscratch</property>"
297                 + nl
298                 + "</nodegroup>"
299                 + nl
300                 + "</nodes>"
301                 + nl;
302  
3033        testExample(inputLine, expectedOutput);
3043    }
305 }

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.