1 19 20 package org.netbeans.modules.j2ee.dd.api.webservices; 21 22 import java.io.BufferedInputStream ; 23 import java.io.BufferedOutputStream ; 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileOutputStream ; 27 import junit.framework.Test; 28 import junit.framework.TestSuite; 29 import org.netbeans.junit.NbTestCase; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.FileUtil; 32 import org.xml.sax.InputSource ; 33 34 40 41 45 public class DDProviderTest extends NbTestCase { 46 47 private DDProvider dd; 48 49 public DDProviderTest(String testName) { 50 super(testName); 51 } 52 53 protected void setUp() throws Exception { 54 super.setUp(); 55 dd = DDProvider.getDefault(); 56 assertNotNull("DDProvider cannot be null.", dd); 57 } 58 59 protected void tearDown() throws Exception { 60 super.tearDown(); 61 dd = null; 62 } 63 64 public static Test suite() { 65 TestSuite suite = new TestSuite(DDProviderTest.class); 66 return suite; 67 } 68 69 72 public void testGetDDRootFromFOWHandler() throws Exception { 73 File f = new File (getDataDir(), "wHandler/webservices.xml").getAbsoluteFile(); 74 readWriteDD(f, true); 75 } 76 77 80 public void testGetDDRootFromInputSourceWHandler() throws Exception { 81 File f = new File (getDataDir(), "wHandler/webservices.xml").getAbsoluteFile(); 82 readWriteDD(f, false); 83 } 84 85 88 public void testGetDDRootFromFOWoHandler() throws Exception { 89 File f = new File (getDataDir(), "woHandler/webservices.xml").getAbsoluteFile(); 90 readWriteDD(f, true); 91 } 92 93 96 public void testGetDDRootFromInputSourceWoHandler() throws Exception { 97 File f = new File (getDataDir(), "woHandler/webservices.xml").getAbsoluteFile(); 98 readWriteDD(f, false); 99 } 100 101 private void readWriteDD(File ddFile, boolean useFO) throws Exception { 102 Webservices result = null; 103 if (!useFO) { 104 InputSource is = new InputSource (new BufferedInputStream (new FileInputStream (ddFile))); 105 result = dd.getDDRoot(is); 106 } else { 107 FileObject fo = FileUtil.toFileObject(ddFile); 108 result = dd.getDDRoot(fo); 109 } 110 assertNotNull("Result cannot be null.", result); 111 assertEquals(Webservices.STATE_VALID, result.getStatus()); 112 File dest = new File (getWorkDir(), "webservices.xml"); 113 File diff = new File (getWorkDir(), "webservices.xml.diff"); 114 assertTrue(dest.createNewFile()); 115 assertTrue(diff.createNewFile()); 116 result.write(new BufferedOutputStream (new FileOutputStream (dest))); 117 assertFile(dest, ddFile, diff); 118 } 119 } 120 | Popular Tags |