1 17 18 package org.apache.geronimo.system.url.resource; 19 20 import java.io.InputStream ; 21 import java.net.MalformedURLException ; 22 import java.net.URL ; 23 import java.util.Properties ; 24 25 import org.apache.geronimo.system.url.GeronimoURLFactory; 26 27 import junit.framework.TestCase; 28 29 34 public class ResourceProtocolTest extends TestCase { 35 static { 36 GeronimoURLFactory.install(); 41 } 42 43 public void testCreateURL() throws MalformedURLException { 44 new URL ("resource:resource.properties"); 45 } 46 47 public void testRead() throws Exception { 48 URL url = new URL ("resource:resource.properties"); 49 Properties props = new Properties (); 50 InputStream input = url.openConnection().getInputStream(); 51 try { 52 props.load(input); 53 assertEquals("whatever", props.getProperty("some.property")); 54 } finally { 55 input.close(); 56 } 57 } 58 59 public void testRead_FromClass() throws Exception { 60 URL url = new URL ("resource:resource.properties#" + getClass().getName()); 61 Properties props = new Properties (); 62 InputStream input = url.openConnection().getInputStream(); 63 try { 64 props.load(input); 65 assertEquals("fromclass", props.getProperty("some.property")); 66 } finally { 67 input.close(); 68 } 69 } 70 } 71 | Popular Tags |