1 package org.apache.maven.exception;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.net.ConnectException;
24
25 import org.apache.maven.model.Plugin;
26 import org.apache.maven.plugin.MojoExecution;
27 import org.apache.maven.plugin.MojoExecutionException;
28
29 import org.apache.maven.plugin.PluginContainerException;
30 import org.apache.maven.plugin.PluginExecutionException;
31 import org.apache.maven.plugin.descriptor.MojoDescriptor;
32 import org.apache.maven.plugin.descriptor.PluginDescriptor;
33 import org.junit.Test;
34
35 import static org.junit.Assert.assertEquals;
36
37
38
39
40 public class DefaultExceptionHandlerTest
41 {
42
43
44
45
46
47
48
49
50
51
52 @Test
53 public void testJdk7ipv6()
54 {
55 ConnectException connEx = new ConnectException( "Connection refused: connect" );
56 IOException ioEx = new IOException( "Unable to establish loopback connection", connEx );
57 MojoExecutionException mojoEx =
58 new MojoExecutionException( "Error executing Jetty: Unable to establish loopback connection", ioEx );
59
60 ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
61 ExceptionSummary exceptionSummary = exceptionHandler.handleException( mojoEx );
62
63 String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/ConnectException";
64 assertEquals( expectedReference, exceptionSummary.getReference() );
65
66 }
67
68 @Test
69 public void testHandleExceptionAetherClassNotFound()
70 {
71 Throwable cause2 = new NoClassDefFoundError( "org/sonatype/aether/RepositorySystem" );
72 Plugin plugin = new Plugin();
73 Exception cause = new PluginContainerException( plugin, null, null, cause2 );
74 PluginDescriptor pluginDescriptor = new PluginDescriptor();
75 MojoDescriptor mojoDescriptor = new MojoDescriptor();
76 mojoDescriptor.setPluginDescriptor( pluginDescriptor );
77 MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
78 Throwable exception = new PluginExecutionException( mojoExecution, null, cause );
79
80 DefaultExceptionHandler handler = new DefaultExceptionHandler();
81 ExceptionSummary summary = handler.handleException( exception );
82
83 String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound";
84 assertEquals( expectedReference, summary.getReference() );
85 }
86
87 @Test
88 public void testHandleExceptionNoClassDefFoundErrorNull()
89 {
90 Throwable cause2 = new NoClassDefFoundError();
91 Plugin plugin = new Plugin();
92 Exception cause = new PluginContainerException( plugin, null, null, cause2 );
93 PluginDescriptor pluginDescriptor = new PluginDescriptor();
94 MojoDescriptor mojoDescriptor = new MojoDescriptor();
95 mojoDescriptor.setPluginDescriptor( pluginDescriptor );
96 MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
97 Throwable exception = new PluginExecutionException( mojoExecution, null, cause );
98
99 DefaultExceptionHandler handler = new DefaultExceptionHandler();
100 ExceptionSummary summary = handler.handleException( exception );
101
102 String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException";
103 assertEquals( expectedReference, summary.getReference() );
104 }
105 }