001    package org.apache.maven.exception;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.io.IOException;
023    import java.net.ConnectException;
024    
025    import org.apache.maven.plugin.MojoExecutionException;
026    
027    import junit.framework.TestCase;
028    
029    /**
030     * @author <a href="mailto:baerrach@apache.org">Barrie Treloar</a>
031     */
032    public class DefaultExceptionHandlerTest
033        extends TestCase
034    {
035        /**
036         * Running Maven under JDK7 may cause connection issues because IPv6 is used by default.
037         * <p>
038         * e.g running mvn site:run will cause Jetty to fail.
039         * </p>
040         * <p>
041         * The resolution is to add -Djava.net.preferIPv4Stack=true to the command line as documented in
042         * http://cwiki.apache.org/confluence/display/MAVEN/ConnectException
043         * </p>
044         */
045        public void testJdk7ipv6()
046        {
047            ConnectException connEx = new ConnectException( "Connection refused: connect" );
048            IOException ioEx = new IOException( "Unable to establish loopback connection" );
049            ioEx.initCause( connEx );
050            MojoExecutionException mojoEx =
051                new MojoExecutionException( "Error executing Jetty: Unable to establish loopback connection", ioEx );
052    
053            ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
054            ExceptionSummary exceptionSummary = exceptionHandler.handleException( mojoEx );
055    
056            String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/ConnectException";
057            assertEquals( expectedReference, exceptionSummary.getReference() );
058    
059        }
060    }