KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > common > propertyeditor > URLEditorTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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.common.propertyeditor;
19
20 import java.beans.PropertyEditor JavaDoc;
21 import java.io.File JavaDoc;
22 import java.net.URL JavaDoc;
23
24 import junit.framework.TestCase;
25
26 /**
27  * Unit test for {@link URLEditor} class.
28  *
29  * @version $Rev: 476049 $
30  */

31 public class URLEditorTest extends TestCase {
32     PropertyEditor JavaDoc editor;
33
34     protected void setUp() {
35         editor = PropertyEditors.findEditor(URL JavaDoc.class);
36     }
37
38     public void testEditorClass() throws Exception JavaDoc {
39         assertEquals(URLEditor.class, editor.getClass());
40     }
41
42     public void testHTTP() throws Exception JavaDoc {
43         checkURL("http://www.apache.org", null);
44     }
45
46     public void testFTP() throws Exception JavaDoc {
47         checkURL("ftp://ftp.apache.org", null);
48     }
49
50     public void testFileURL() throws Exception JavaDoc {
51         URL JavaDoc base = new URL JavaDoc("file://test.resource");
52         base = new File JavaDoc(base.getFile()).toURI().toURL();
53         checkURL("file://test.resource", base);
54     }
55
56     public void testFile() throws Exception JavaDoc {
57         URL JavaDoc testValue = new File JavaDoc("test.resource").toURI().toURL();
58         checkURL("test.resource", testValue);
59     }
60
61     protected void checkURL(String JavaDoc text, URL JavaDoc test) throws Exception JavaDoc {
62         editor.setAsText(text);
63         if (test == null) {
64             test = new URL JavaDoc(text);
65         }
66         assertEquals(test, editor.getValue());
67     }
68 }
69
Popular Tags