PageRenderTime 19ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java

https://github.com/apache/maven
Java | 105 lines | 59 code | 15 blank | 31 comment | 0 complexity | d0742b73af2169c56a5d9afc04fb9db6 MD5 | raw file
Possible License(s): Apache-2.0
  1. package org.apache.maven.exception;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.io.IOException;
  21. import java.net.ConnectException;
  22. import org.apache.maven.model.Plugin;
  23. import org.apache.maven.plugin.MojoExecution;
  24. import org.apache.maven.plugin.MojoExecutionException;
  25. import org.apache.maven.plugin.PluginContainerException;
  26. import org.apache.maven.plugin.PluginExecutionException;
  27. import org.apache.maven.plugin.descriptor.MojoDescriptor;
  28. import org.apache.maven.plugin.descriptor.PluginDescriptor;
  29. import org.junit.jupiter.api.Test;
  30. import static org.junit.jupiter.api.Assertions.assertEquals;
  31. /**
  32. * @author <a href="mailto:baerrach@apache.org">Barrie Treloar</a>
  33. */
  34. public class DefaultExceptionHandlerTest
  35. {
  36. /**
  37. * Running Maven under JDK7 may cause connection issues because IPv6 is used by default.
  38. * <p>
  39. * e.g running mvn site:run will cause Jetty to fail.
  40. * </p>
  41. * <p>
  42. * The resolution is to add -Djava.net.preferIPv4Stack=true to the command line as documented in
  43. * http://cwiki.apache.org/confluence/display/MAVEN/ConnectException
  44. * </p>
  45. */
  46. @Test
  47. public void testJdk7ipv6()
  48. {
  49. ConnectException connEx = new ConnectException( "Connection refused: connect" );
  50. IOException ioEx = new IOException( "Unable to establish loopback connection", connEx );
  51. MojoExecutionException mojoEx =
  52. new MojoExecutionException( "Error executing Jetty: Unable to establish loopback connection", ioEx );
  53. ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
  54. ExceptionSummary exceptionSummary = exceptionHandler.handleException( mojoEx );
  55. String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/ConnectException";
  56. assertEquals( expectedReference, exceptionSummary.getReference() );
  57. }
  58. @Test
  59. public void testHandleExceptionAetherClassNotFound()
  60. {
  61. Throwable cause2 = new NoClassDefFoundError( "org/sonatype/aether/RepositorySystem" );
  62. Plugin plugin = new Plugin();
  63. Exception cause = new PluginContainerException( plugin, null, null, cause2 );
  64. PluginDescriptor pluginDescriptor = new PluginDescriptor();
  65. MojoDescriptor mojoDescriptor = new MojoDescriptor();
  66. mojoDescriptor.setPluginDescriptor( pluginDescriptor );
  67. MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
  68. Throwable exception = new PluginExecutionException( mojoExecution, null, cause );
  69. DefaultExceptionHandler handler = new DefaultExceptionHandler();
  70. ExceptionSummary summary = handler.handleException( exception );
  71. String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound";
  72. assertEquals( expectedReference, summary.getReference() );
  73. }
  74. @Test
  75. public void testHandleExceptionNoClassDefFoundErrorNull()
  76. {
  77. Throwable cause2 = new NoClassDefFoundError();
  78. Plugin plugin = new Plugin();
  79. Exception cause = new PluginContainerException( plugin, null, null, cause2 );
  80. PluginDescriptor pluginDescriptor = new PluginDescriptor();
  81. MojoDescriptor mojoDescriptor = new MojoDescriptor();
  82. mojoDescriptor.setPluginDescriptor( pluginDescriptor );
  83. MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
  84. Throwable exception = new PluginExecutionException( mojoExecution, null, cause );
  85. DefaultExceptionHandler handler = new DefaultExceptionHandler();
  86. ExceptionSummary summary = handler.handleException( exception );
  87. String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException";
  88. assertEquals( expectedReference, summary.getReference() );
  89. }
  90. }