1 41 42 package com.sun.jmx.examples.scandir.config; 43 44 import junit.framework.*; 45 import java.io.File ; 46 47 52 public class XmlConfigUtilsTest extends TestCase { 53 54 public XmlConfigUtilsTest(String testName) { 55 super(testName); 56 } 57 58 protected void setUp() throws Exception { 59 } 60 61 protected void tearDown() throws Exception { 62 } 63 64 public static Test suite() { 65 TestSuite suite = new TestSuite(XmlConfigUtilsTest.class); 66 67 return suite; 68 } 69 70 71 74 public void testWriteToFile() throws Exception { 75 System.out.println("writeToFile"); 76 77 final File file = File.createTempFile("test",".xml"); 78 file.deleteOnExit(); 79 80 final String 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 95 public void testReadFromFile() throws Exception { 96 System.out.println("readFromFile"); 97 98 final String tmp = System.getProperty("java.io.tmpdir"); 99 final File 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 |