001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.mina.integration.beans; 021 022import static org.junit.Assert.assertEquals; 023import static org.junit.Assert.fail; 024 025import java.net.InetSocketAddress; 026 027import org.junit.Before; 028import org.junit.Test; 029 030/** 031 * Tests {@link InetSocketAddressEditor}. 032 * 033 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 034 */ 035public class InetSocketAddressEditorTest { 036 InetSocketAddressEditor editor; 037 038 @Before 039 public void setUp() throws Exception { 040 editor = new InetSocketAddressEditor(); 041 } 042 043 @Test 044 public void testSetAsTextWithWildcardAddress() throws Exception { 045 editor.setAsText("1"); 046 assertEquals(new InetSocketAddress(1), editor.getValue()); 047 editor.setAsText(":10"); 048 assertEquals(new InetSocketAddress(10), editor.getValue()); 049 } 050 051 @Test 052 public void testSetAsTextWithHostName() throws Exception { 053 editor.setAsText("www.google.com:80"); 054 assertEquals(new InetSocketAddress("www.google.com", 80), editor.getValue()); 055 } 056 057 public void testSetAsTextWithIpAddress() throws Exception { 058 editor.setAsText("192.168.0.1:1000"); 059 assertEquals(new InetSocketAddress("192.168.0.1", 1000), editor.getValue()); 060 } 061 062 @Test 063 public void testSetAsTextWithIllegalValues() throws Exception { 064 try { 065 editor.setAsText("bar"); 066 fail("Illegal port number. IllegalArgumentException expected."); 067 } catch (IllegalArgumentException iae) { 068 } 069 try { 070 editor.setAsText(":foo"); 071 fail("Illegal port number. IllegalArgumentException expected."); 072 } catch (IllegalArgumentException iae) { 073 } 074 try { 075 editor.setAsText("www.foo.com:yada"); 076 fail("Illegal port number. IllegalArgumentException expected."); 077 } catch (IllegalArgumentException iae) { 078 } 079 } 080}