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;
023
024import java.net.InetAddress;
025import java.net.UnknownHostException;
026
027import org.junit.Before;
028import org.junit.Test;
029
030/**
031 * Tests {@link InetAddressEditor}.
032 *
033 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
034 */
035public class InetAddressEditorTest {
036    InetAddressEditor editor;
037
038    @Before
039    public void setUp() throws Exception {
040        editor = new InetAddressEditor();
041    }
042
043    @Test
044    public void testSetAsTextWithHostName() throws Exception {
045        try {
046            InetAddress expected = InetAddress.getByName("www.google.com");
047            editor.setAsText("www.google.com");
048            assertEquals(expected, editor.getValue());
049        } catch (UnknownHostException uhe) {
050            // No DNS. Skip the test.
051        }
052
053        editor.setAsText("localhost");
054        assertEquals(InetAddress.getByName("localhost"), editor.getValue());
055    }
056
057    @Test
058    public void testSetAsTextWithIpAddress() throws Exception {
059        editor.setAsText("127.0.0.1");
060        assertEquals(InetAddress.getByName("127.0.0.1"), editor.getValue());
061    }
062}