KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > url > resource > ResourceProtocolTest


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.system.url.resource;
19
20 import java.io.InputStream JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.apache.geronimo.system.url.GeronimoURLFactory;
26
27 import junit.framework.TestCase;
28
29 /**
30  * Unit test for the 'resource' protocol.
31  *
32  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
33  */

34 public class ResourceProtocolTest extends TestCase {
35     static {
36         //
37
// Have to install factory to make sure that our file handler is used
38
// and not Sun's
39
//
40
GeronimoURLFactory.install();
41     }
42
43     public void testCreateURL() throws MalformedURLException JavaDoc {
44         new URL JavaDoc("resource:resource.properties");
45     }
46
47     public void testRead() throws Exception JavaDoc {
48         URL JavaDoc url = new URL JavaDoc("resource:resource.properties");
49         Properties JavaDoc props = new Properties JavaDoc();
50         InputStream JavaDoc 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 JavaDoc {
60         URL JavaDoc url = new URL JavaDoc("resource:resource.properties#" + getClass().getName());
61         Properties JavaDoc props = new Properties JavaDoc();
62         InputStream JavaDoc 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