KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > integration > spring > InetSocketAddressEditorTest


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

20 package org.apache.mina.integration.spring;
21
22 import java.net.InetSocketAddress JavaDoc;
23
24 import junit.framework.TestCase;
25
26 /**
27  * Tests {@link InetSocketAddressEditor}.
28  *
29  * @author The Apache Directory Project (mina-dev@directory.apache.org)
30  * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (금, 13 7월 2007) $
31  */

32 public class InetSocketAddressEditorTest extends TestCase {
33     InetSocketAddressEditor editor;
34
35     protected void setUp() throws Exception JavaDoc {
36         editor = new InetSocketAddressEditor();
37     }
38
39     public void testSetAsTextWithWildcardAddress() throws Exception JavaDoc {
40         editor.setAsText("1");
41         assertEquals(new InetSocketAddress JavaDoc(1), editor.getValue());
42         editor.setAsText(":10");
43         assertEquals(new InetSocketAddress JavaDoc(10), editor.getValue());
44     }
45
46     public void testSetAsTextWithHostName() throws Exception JavaDoc {
47         editor.setAsText("www.google.com:80");
48         assertEquals(new InetSocketAddress JavaDoc("www.google.com", 80), editor
49                 .getValue());
50     }
51
52     public void testSetAsTextWithIpAddress() throws Exception JavaDoc {
53         editor.setAsText("192.168.0.1:1000");
54         assertEquals(new InetSocketAddress JavaDoc("192.168.0.1", 1000), editor
55                 .getValue());
56     }
57
58     public void testSetAsTextWithIllegalValues() throws Exception JavaDoc {
59         try {
60             editor.setAsText(null);
61             fail("null string. IllegalArgumentException expected.");
62         } catch (IllegalArgumentException JavaDoc iae) {
63         }
64         try {
65             editor.setAsText("bar");
66             fail("Illegal port number. IllegalArgumentException expected.");
67         } catch (IllegalArgumentException JavaDoc iae) {
68         }
69         try {
70             editor.setAsText(":foo");
71             fail("Illegal port number. IllegalArgumentException expected.");
72         } catch (IllegalArgumentException JavaDoc iae) {
73         }
74         try {
75             editor.setAsText("www.foo.com:yada");
76             fail("Illegal port number. IllegalArgumentException expected.");
77         } catch (IllegalArgumentException JavaDoc iae) {
78         }
79     }
80
81 }
82
Popular Tags