View Javadoc

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.beans;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.fail;
24  
25  import java.net.InetSocketAddress;
26  
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  /**
31   * Tests {@link InetSocketAddressEditor}.
32   *
33   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
34   */
35  public class InetSocketAddressEditorTest {
36      InetSocketAddressEditor editor;
37  
38      @Before
39      public void setUp() throws Exception {
40          editor = new InetSocketAddressEditor();
41      }
42  
43      @Test
44      public void testSetAsTextWithWildcardAddress() throws Exception {
45          editor.setAsText("1");
46          assertEquals(new InetSocketAddress(1), editor.getValue());
47          editor.setAsText(":10");
48          assertEquals(new InetSocketAddress(10), editor.getValue());
49      }
50  
51      @Test
52      public void testSetAsTextWithHostName() throws Exception {
53          editor.setAsText("www.google.com:80");
54          assertEquals(new InetSocketAddress("www.google.com", 80), editor.getValue());
55      }
56  
57      public void testSetAsTextWithIpAddress() throws Exception {
58          editor.setAsText("192.168.0.1:1000");
59          assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor.getValue());
60      }
61  
62      @Test
63      public void testSetAsTextWithIllegalValues() throws Exception {
64          try {
65              editor.setAsText("bar");
66              fail("Illegal port number. IllegalArgumentException expected.");
67          } catch (IllegalArgumentException iae) {
68          }
69          try {
70              editor.setAsText(":foo");
71              fail("Illegal port number. IllegalArgumentException expected.");
72          } catch (IllegalArgumentException iae) {
73          }
74          try {
75              editor.setAsText("www.foo.com:yada");
76              fail("Illegal port number. IllegalArgumentException expected.");
77          } catch (IllegalArgumentException iae) {
78          }
79      }
80  }