1 17 package org.apache.excalibur.source.test; 18 19 import junit.framework.TestCase; 20 21 import org.apache.excalibur.source.SourceNotFoundException; 22 import org.apache.excalibur.source.SourceValidity; 23 import org.apache.excalibur.source.impl.ResourceSource; 24 25 31 public class ResourceSourceTestCase extends TestCase 32 { 33 34 public ResourceSourceTestCase() 35 { 36 this("ResourceSource"); 37 } 38 39 public ResourceSourceTestCase(String name) 40 { 41 super(name); 42 } 43 44 protected void setUp() throws Exception 45 { 46 super.setUp(); 47 } 48 49 public void testExistingSource() throws Exception 50 { 51 ResourceSource src = new ResourceSource("resource://org/apache/excalibur/source/test/ResourceSourceTestCase.class"); 52 assertTrue("Resource doesn't exist", src.exists()); 53 assertTrue("Lentgh should be positive", src.getContentLength() > 0); 54 assertNotNull("InputStream shouldn't be null", src.getInputStream()); 55 } 56 57 public void testNonExistingSource() throws Exception 58 { 59 ResourceSource src = new ResourceSource("resource://org/apache/excalibur/source/test/DoesNotExist"); 60 assertFalse("Resource shouldn't exist", src.exists()); 61 assertEquals("Should have no length", -1, src.getContentLength()); 62 assertEquals("Should have no lastModified", 0, src.getLastModified()); 63 64 try 65 { 66 src.getInputStream(); 67 fail("getInputStream should fail"); 68 } catch(SourceNotFoundException e) { 69 } 71 } 72 73 public void testValidity() throws Exception 74 { 75 ResourceSource src1 = new ResourceSource("resource://org/apache/excalibur/source/test/ResourceSourceTestCase.class"); 76 ResourceSource src2 = new ResourceSource("resource://org/apache/excalibur/source/test/ResourceSourceTestCase.class"); 77 78 SourceValidity val1 = src1.getValidity(); 79 SourceValidity val2 = src2.getValidity(); 80 81 assertEquals("Validities should match", SourceValidity.VALID, val1.isValid(val2)); 82 } 83 84 protected void tearDown() throws Exception 85 { 86 super.tearDown(); 87 } 88 89 } 90 | Popular Tags |