01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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.beans;
21:
22: import java.net.InetSocketAddress;
23:
24: import junit.framework.TestCase;
25:
26: /**
27: * Tests {@link InetSocketAddressEditor}.
28: *
29: * @author The Apache MINA Project (dev@mina.apache.org)
30: * @version $Rev: 598167 $, $Date: 2007-11-26 01:45:36 -0700 (Mon, 26 Nov 2007) $
31: */
32: public class InetSocketAddressEditorTest extends TestCase {
33: InetSocketAddressEditor editor;
34:
35: @Override
36: protected void setUp() throws Exception {
37: editor = new InetSocketAddressEditor();
38: }
39:
40: public void testSetAsTextWithWildcardAddress() throws Exception {
41: editor.setAsText("1");
42: assertEquals(new InetSocketAddress(1), editor.getValue());
43: editor.setAsText(":10");
44: assertEquals(new InetSocketAddress(10), editor.getValue());
45: }
46:
47: public void testSetAsTextWithHostName() throws Exception {
48: editor.setAsText("www.google.com:80");
49: assertEquals(new InetSocketAddress("www.google.com", 80),
50: editor.getValue());
51: }
52:
53: public void testSetAsTextWithIpAddress() throws Exception {
54: editor.setAsText("192.168.0.1:1000");
55: assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor
56: .getValue());
57: }
58:
59: public void testSetAsTextWithIllegalValues() throws Exception {
60: try {
61: editor.setAsText("bar");
62: fail("Illegal port number. IllegalArgumentException expected.");
63: } catch (IllegalArgumentException iae) {
64: }
65: try {
66: editor.setAsText(":foo");
67: fail("Illegal port number. IllegalArgumentException expected.");
68: } catch (IllegalArgumentException iae) {
69: }
70: try {
71: editor.setAsText("www.foo.com:yada");
72: fail("Illegal port number. IllegalArgumentException expected.");
73: } catch (IllegalArgumentException iae) {
74: }
75: }
76:
77: }
|