1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.util.ResourceExtractor;
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.util.List;
27 import java.util.regex.Pattern;
28
29 import junit.framework.TestCase;
30
31
32
33
34
35
36
37
38
39
40 public class MavenITmng2690MojoLoadingErrorsTest
41 extends AbstractMavenIntegrationTestCase
42 {
43
44 public MavenITmng2690MojoLoadingErrorsTest()
45 {
46 super( "(2.1.0-M1,)" );
47 }
48
49 public void testNoClassDefFromMojoLoad()
50 throws IOException, VerificationException
51 {
52 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2690/noclassdef-mojo" );
53
54 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
55 verifier.setAutoclean( false );
56
57 try
58 {
59 verifier.executeGoal( "validate" );
60
61 fail( "should throw an error during execution." );
62 }
63 catch ( VerificationException e )
64 {
65
66 }
67 finally
68 {
69 verifier.resetStreams();
70 }
71
72 List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
73
74 int msg = indexOf( lines, "(?i).*required class is missing.*" );
75 assertTrue( "User-friendly message was not found in output.", msg >= 0 );
76
77 int cls = lines.get( msg ).toString().replace( '/', '.' ).indexOf( TestCase.class.getName() );
78 assertTrue( "Missing class name was not found in output.", cls >= 0 );
79 }
80
81 public void testNoClassDefFromMojoConfiguration()
82 throws IOException, VerificationException
83 {
84 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2690/noclassdef-param" );
85
86 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
87 verifier.setAutoclean( false );
88
89 try
90 {
91 verifier.executeGoal( "validate" );
92
93 fail( "should throw an error during execution." );
94 }
95 catch ( VerificationException e )
96 {
97
98 }
99 finally
100 {
101 verifier.resetStreams();
102 }
103
104 List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
105
106 int msg = indexOf( lines, "(?i).*required class (i|wa)s missing( during (mojo )?configuration)?.*" );
107 assertTrue( "User-friendly message was not found in output.", msg >= 0 );
108
109 int cls = lines.get( msg ).toString().replace( '/', '.' ).indexOf( TestCase.class.getName() );
110 assertTrue( "Missing class name was not found in output.", cls >= 0 );
111 }
112
113 public void testMojoComponentLookupException()
114 throws IOException, VerificationException
115 {
116 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2690/mojo-complookup" );
117
118 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
119 verifier.setAutoclean( false );
120
121 try
122 {
123 verifier.executeGoal( "validate" );
124
125 fail( "should throw an error during execution." );
126 }
127 catch ( VerificationException e )
128 {
129
130 }
131 finally
132 {
133 verifier.resetStreams();
134 }
135
136 List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
137
138 String compLookupMsg =
139 "(?i).*unable to .* mojo 'mojo-component-lookup-exception' .* plugin "
140 + "'org\\.apache\\.maven\\.its\\.plugins:maven-it-plugin-error.*";
141
142 assertTrue( "User-friendly message was not found in output.", indexOf( lines, compLookupMsg ) > 0 );
143 }
144
145 public void testMojoRequirementComponentLookupException()
146 throws IOException, VerificationException
147 {
148 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2690/requirement-complookup" );
149
150 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
151 verifier.setAutoclean( false );
152
153 try
154 {
155 verifier.executeGoal( "validate" );
156
157 fail( "should throw an error during execution." );
158 }
159 catch ( VerificationException e )
160 {
161
162 }
163 finally
164 {
165 verifier.resetStreams();
166 }
167
168 List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
169
170 String compLookupMsg =
171 "(?i).*unable to .* mojo 'requirement-component-lookup-exception' .* plugin "
172 + "'org\\.apache\\.maven\\.its\\.plugins:maven-it-plugin-error.*";
173
174 assertTrue( "User-friendly message was not found in output.", indexOf( lines, compLookupMsg ) > 0 );
175 }
176
177 private int indexOf( List<String> logLines, String regex )
178 {
179 Pattern pattern = Pattern.compile( regex );
180
181 for ( int i = 0; i < logLines.size(); i++ )
182 {
183 String logLine = logLines.get( i );
184
185 if ( pattern.matcher( logLine ).matches() )
186 {
187 return i;
188 }
189 }
190
191 return -1;
192 }
193
194 }