KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > examples > scandir > config > XmlConfigUtilsTest


1 /*
2  * XmlConfigUtilsTest.java
3  * JUnit based test
4  *
5  * Created on July 13, 2006, 4:10 PM
6  *
7  * @(#)XmlConfigUtilsTest.java 1.2 06/08/02
8  *
9  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  *
14  * -Redistribution of source code must retain the above copyright notice, this
15  * list of conditions and the following disclaimer.
16  *
17  * -Redistribution in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
22  * be used to endorse or promote products derived from this software without
23  * specific prior written permission.
24  *
25  * This software is provided "AS IS," without a warranty of any kind. ALL
26  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
27  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
28  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
29  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
30  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
31  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
32  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
33  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
34  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
35  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36  *
37  * You acknowledge that this software is not designed, licensed or intended
38  * for use in the design, construction, operation or maintenance of any
39  * nuclear facility.
40  */

41
42 package com.sun.jmx.examples.scandir.config;
43
44 import junit.framework.*;
45 import java.io.File JavaDoc;
46
47 /**
48  * Unit tests for {@code XmlConfigUtils}
49  *
50  * @author Sun Microsystems, 2006 - All rights reserved.
51  */

52 public class XmlConfigUtilsTest extends TestCase {
53
54     public XmlConfigUtilsTest(String JavaDoc testName) {
55         super(testName);
56     }
57
58     protected void setUp() throws Exception JavaDoc {
59     }
60
61     protected void tearDown() throws Exception JavaDoc {
62     }
63
64     public static Test suite() {
65         TestSuite suite = new TestSuite(XmlConfigUtilsTest.class);
66
67         return suite;
68     }
69
70
71     /**
72      * Test of writeToFile method, of class XmlConfigUtils.
73      */

74     public void testWriteToFile() throws Exception JavaDoc {
75         System.out.println("writeToFile");
76
77         final File JavaDoc file = File.createTempFile("test",".xml");
78         file.deleteOnExit();
79
80         final String JavaDoc tmp = System.getProperty("java.io.tmpdir");
81
82         DirectoryScannerConfig dir1 =
83                 new DirectoryScannerConfig("scan2");
84         dir1.setRootDirectory(tmp);
85         ScanManagerConfig bean = new ScanManagerConfig("session2");
86         bean.putScan(dir1);
87         XmlConfigUtils instance = new XmlConfigUtils(file.getPath());
88
89         instance.writeToFile(bean);
90     }
91
92     /**
93      * Test of readFromFile method, of class com.sun.jmx.examples.scandir.config.XmlConfigUtils.
94      */

95     public void testReadFromFile() throws Exception JavaDoc {
96         System.out.println("readFromFile");
97
98         final String JavaDoc tmp = System.getProperty("java.io.tmpdir");
99         final File JavaDoc file = File.createTempFile("test",".xml");
100         file.deleteOnExit();
101
102         DirectoryScannerConfig dir1 =
103                 new DirectoryScannerConfig("scan1");
104         dir1.setRootDirectory(tmp);
105         ScanManagerConfig bean = new ScanManagerConfig("session1");
106         bean.putScan(dir1);
107         XmlConfigUtils instance = new XmlConfigUtils(file.getPath());
108
109         instance.writeToFile(bean);
110
111         ScanManagerConfig expResult = bean;
112         ScanManagerConfig result = instance.readFromFile();
113         System.out.println(result);
114         assertEquals(expResult, result);
115
116
117     }
118
119 }
120
Popular Tags