1 17 package org.apache.excalibur.source.test; 18 19 import junit.framework.TestCase; 20 21 import java.io.File ; 22 import java.io.FileOutputStream ; 23 import java.net.URL ; 24 import java.util.Collections ; 25 import org.apache.excalibur.source.impl.URLSource; 26 27 33 public class URLSourceTestCase extends TestCase 34 { 35 36 URLSource m_urlSource; 37 File tempFile; 38 39 protected void setUp() throws Exception 40 { 41 super.setUp(); 42 m_urlSource = new URLSource(); 43 44 tempFile = File.createTempFile( "filesource", "test-exists" ); 45 FileOutputStream out = new FileOutputStream (tempFile); 46 out.write(1); 47 out.close(); 48 } 49 50 protected void tearDown() throws Exception 51 { 52 super.tearDown(); 53 54 tempFile.delete(); 55 } 56 57 public void testFileExists() throws Exception 58 { 59 m_urlSource.init( tempFile.toURL(), Collections.EMPTY_MAP ); 60 assertTrue( m_urlSource.exists() ); 61 } 62 63 public void testFileDoesNotExist() throws Exception 64 { 65 File tempFile = new File ("phantom-file"); 66 67 m_urlSource.init( tempFile.toURL(), Collections.EMPTY_MAP ); 68 assertFalse( m_urlSource.exists() ); 69 } 70 71 public void testHttpHostDoesNotExist() throws Exception 72 { 73 m_urlSource.init( new URL ( "http://some.invalid.host/no_such_file" ), 74 Collections.EMPTY_MAP ); 75 assertFalse( m_urlSource.exists() ); 76 } 77 78 public void testHttpDoesExist() throws Exception 79 { 80 m_urlSource.init( new URL ( "http://excalibur.apache.org/" ), 81 Collections.EMPTY_MAP ); 82 assertTrue( m_urlSource.exists() ); 83 } 84 } 85 | Popular Tags |