View Javadoc
1   package org.apache.maven.plugins.war;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.Enumeration;
25  import java.util.HashMap;
26  import java.util.LinkedList;
27  import java.util.Map;
28  import java.util.jar.JarEntry;
29  import java.util.jar.JarFile;
30  import java.util.zip.ZipEntry;
31  
32  import org.apache.maven.artifact.Artifact;
33  import org.apache.maven.artifact.handler.ArtifactHandler;
34  import org.apache.maven.plugin.MojoExecutionException;
35  import org.apache.maven.plugins.war.WarMojo;
36  import org.apache.maven.plugins.war.stub.JarArtifactStub;
37  import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor;
38  import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub;
39  import org.apache.maven.plugins.war.stub.ProjectHelperStub;
40  import org.apache.maven.plugins.war.stub.WarArtifact4CCStub;
41  import org.codehaus.plexus.util.IOUtil;
42  
43  /**
44   * comprehensive test on buildExplodedWebApp is done on WarExplodedMojoTest
45   */
46  public class WarMojoTest
47      extends AbstractWarMojoTest
48  {
49      WarMojo mojo;
50  
51      private static File pomFile = new File( getBasedir(),
52                                              "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml" );
53  
54      protected File getTestDirectory()
55      {
56          return new File( getBasedir(), "target/test-classes/unit/warmojotest" );
57      }
58  
59      public void setUp()
60          throws Exception
61      {
62          super.setUp();
63          mojo = (WarMojo) lookupMojo( "war", pomFile );
64      }
65  
66      public void testEnvironment()
67          throws Exception
68      {
69          // see setup
70      }
71  
72      public void testSimpleWar()
73          throws Exception
74      {
75          String testId = "SimpleWar";
76          MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
77          String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
78          File webAppDirectory = new File( getTestDirectory(), testId );
79          WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
80          String warName = "simple";
81          File webAppSource = createWebAppSource( testId );
82          File classesDir = createClassesDir( testId, true );
83          File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
84  
85          project.setArtifact( warArtifact );
86          this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
87          setVariableValueToObject( mojo, "outputDirectory", outputDir );
88          setVariableValueToObject( mojo, "warName", warName );
89          mojo.setWebXml( new File( xmlSource, "web.xml" ) );
90  
91          mojo.execute();
92  
93          // validate jar file
94          File expectedJarFile = new File( outputDir, "simple.war" );
95          assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
96              "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
97              "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
98              mojo.getWebXml().toString(), null, null, null, null } );
99      }
100 
101     public void testSimpleWarPackagingExcludeWithIncludesRegEx()
102         throws Exception
103     {
104         String testId = "SimpleWarPackagingExcludeWithIncludesRegEx";
105         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
106         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
107         File webAppDirectory = new File( getTestDirectory(), testId );
108         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
109         String warName = "simple";
110         File webAppSource = createWebAppSource( testId );
111         File classesDir = createClassesDir( testId, true );
112         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
113 
114         project.setArtifact( warArtifact );
115         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
116         setVariableValueToObject( mojo, "outputDirectory", outputDir );
117         setVariableValueToObject( mojo, "warName", warName );
118         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
119         setVariableValueToObject( mojo, "packagingIncludes", "%regex[(.(?!exile))+]" );
120 
121         mojo.execute();
122 
123         // validate jar file
124         File expectedJarFile = new File( outputDir, "simple.war" );
125         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
126             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
127             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
128             mojo.getWebXml().toString(), null, null, null, }, new String[] { "org/web/app/last-exile.jsp" } );
129     }
130 
131     public void testClassifier()
132         throws Exception
133     {
134         String testId = "Classifier";
135         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
136         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
137         File webAppDirectory = new File( getTestDirectory(), testId );
138         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
139         ProjectHelperStub projectHelper = new ProjectHelperStub();
140         String warName = "simple";
141         File webAppSource = createWebAppSource( testId );
142         File classesDir = createClassesDir( testId, true );
143         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
144 
145         project.setArtifact( warArtifact );
146         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
147         setVariableValueToObject( mojo, "projectHelper", projectHelper );
148         setVariableValueToObject( mojo, "classifier", "test-classifier" );
149         setVariableValueToObject( mojo, "outputDirectory", outputDir );
150         setVariableValueToObject( mojo, "warName", warName );
151         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
152 
153         mojo.execute();
154 
155         // validate jar file
156         File expectedJarFile = new File( outputDir, "simple-test-classifier.war" );
157         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
158             "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
159             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
160             mojo.getWebXml().toString(), null, null, null, null } );
161     }
162 
163     public void testPrimaryArtifact()
164         throws Exception
165     {
166         String testId = "PrimaryArtifact";
167         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
168         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
169         File webAppDirectory = new File( getTestDirectory(), testId );
170         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
171         ProjectHelperStub projectHelper = new ProjectHelperStub();
172         String warName = "simple";
173         File webAppSource = createWebAppSource( testId );
174         File classesDir = createClassesDir( testId, true );
175         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
176 
177         warArtifact.setFile( new File( "error.war" ) );
178         project.setArtifact( warArtifact );
179         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
180         setVariableValueToObject( mojo, "projectHelper", projectHelper );
181         setVariableValueToObject( mojo, "outputDirectory", outputDir );
182         setVariableValueToObject( mojo, "warName", warName );
183         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
184 
185         mojo.execute();
186 
187         // validate jar file
188         File expectedJarFile = new File( outputDir, "simple.war" );
189         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
190             "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
191             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
192             mojo.getWebXml().toString(), null, null, null, null } );
193     }
194 
195     public void testNotPrimaryArtifact()
196         throws Exception
197     {
198         // use a different pom
199         File pom = new File( getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml" );
200         mojo = (WarMojo) lookupMojo( "war", pom );
201 
202         String testId = "NotPrimaryArtifact";
203         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
204         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
205         File webAppDirectory = new File( getTestDirectory(), testId );
206         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
207         ProjectHelperStub projectHelper = new ProjectHelperStub();
208         String warName = "simple";
209         File webAppSource = createWebAppSource( testId );
210         File classesDir = createClassesDir( testId, true );
211         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
212 
213         warArtifact.setFile( new File( "error.war" ) );
214         project.setArtifact( warArtifact );
215         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
216         setVariableValueToObject( mojo, "projectHelper", projectHelper );
217         setVariableValueToObject( mojo, "outputDirectory", outputDir );
218         setVariableValueToObject( mojo, "warName", warName );
219         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
220 
221         mojo.execute();
222 
223         // validate jar file
224         File expectedJarFile = new File( outputDir, "simple.war" );
225         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
226             "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
227             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
228             mojo.getWebXml().toString(), null, null, null, null } );
229     }
230 
231     public void testMetaInfContent()
232         throws Exception
233     {
234         String testId = "SimpleWarWithMetaInfContent";
235         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
236         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
237         File webAppDirectory = new File( getTestDirectory(), testId );
238         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
239         String warName = "simple";
240         File webAppSource = createWebAppSource( testId );
241         File classesDir = createClassesDir( testId, true );
242         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
243 
244         // Create the sample config.xml
245         final File configFile = new File( webAppSource, "META-INF/config.xml" );
246         createFile( configFile, "<config></config>" );
247 
248         project.setArtifact( warArtifact );
249         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
250         setVariableValueToObject( mojo, "outputDirectory", outputDir );
251         setVariableValueToObject( mojo, "warName", warName );
252         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
253 
254         mojo.execute();
255 
256         // validate jar file
257         File expectedJarFile = new File( outputDir, "simple.war" );
258         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "META-INF/config.xml",
259             "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp",
260             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
261             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null,
262             mojo.getWebXml().toString(), null, null, null, null } );
263     }
264 
265     public void testMetaInfContentWithContainerConfig()
266         throws Exception
267     {
268         String testId = "SimpleWarWithContainerConfig";
269         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
270         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
271         File webAppDirectory = new File( getTestDirectory(), testId );
272         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
273         String warName = "simple";
274         File webAppSource = createWebAppSource( testId );
275         File classesDir = createClassesDir( testId, true );
276         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
277 
278         // Create the sample config.xml
279         final File configFile = new File( webAppSource, "META-INF/config.xml" );
280         createFile( configFile, "<config></config>" );
281 
282         project.setArtifact( warArtifact );
283         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
284         setVariableValueToObject( mojo, "outputDirectory", outputDir );
285         setVariableValueToObject( mojo, "warName", warName );
286         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
287         mojo.setContainerConfigXML( configFile );
288 
289         mojo.execute();
290 
291         // validate jar file
292         File expectedJarFile = new File( outputDir, "simple.war" );
293         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "META-INF/config.xml",
294             "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp",
295             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
296             "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null,
297             mojo.getWebXml().toString(), null, null, null, null } );
298     }
299 
300     public void testFailOnMissingWebXmlFalse()
301         throws Exception
302     {
303 
304         String testId = "SimpleWarMissingWebXmlFalse";
305         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
306         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
307         File webAppDirectory = new File( getTestDirectory(), testId );
308         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
309         String warName = "simple";
310         File webAppSource = createWebAppSource( testId );
311         File classesDir = createClassesDir( testId, true );
312 
313         project.setArtifact( warArtifact );
314         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
315         setVariableValueToObject( mojo, "outputDirectory", outputDir );
316         setVariableValueToObject( mojo, "warName", warName );
317         mojo.setFailOnMissingWebXml( false );
318         mojo.execute();
319 
320         // validate jar file
321         File expectedJarFile = new File( outputDir, "simple.war" );
322         final Map<String, JarEntry> jarContent =
323             assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "pansit.jsp",
324                 "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
325                 "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null,
326                 null, null, null } );
327 
328         assertFalse( "web.xml should be missing", jarContent.containsKey( "WEB-INF/web.xml" ) );
329     }
330 
331     public void testFailOnMissingWebXmlTrue()
332         throws Exception
333     {
334 
335         String testId = "SimpleWarMissingWebXmlTrue";
336         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
337         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
338         File webAppDirectory = new File( getTestDirectory(), testId );
339         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
340         String warName = "simple";
341         File webAppSource = createWebAppSource( testId );
342         File classesDir = createClassesDir( testId, true );
343 
344         project.setArtifact( warArtifact );
345         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
346         setVariableValueToObject( mojo, "outputDirectory", outputDir );
347         setVariableValueToObject( mojo, "warName", warName );
348         mojo.setFailOnMissingWebXml( true );
349 
350         try
351         {
352             mojo.execute();
353             fail( "Building of the war isn't possible because web.xml is missing" );
354         }
355         catch ( MojoExecutionException e )
356         {
357             // expected behaviour
358         }
359     }
360     
361     public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used()
362         throws Exception
363     {
364         String testId = "SimpleWarUnderServlet30";
365         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
366         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
367         File webAppDirectory = new File( getTestDirectory(), testId );
368         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
369         String warName = "simple";
370         File webAppSource = createWebAppSource( testId );
371         File classesDir = createClassesDir( testId, true );
372 
373         final ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
374         JarArtifactStub jarArtifactStub = new JarArtifactStub( getBasedir(), artifactHandler );
375         jarArtifactStub.setFile( new File( getBasedir(),
376                                            "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar" ) );
377         jarArtifactStub.setScope( Artifact.SCOPE_PROVIDED );
378         project.addArtifact( jarArtifactStub );
379 
380         project.setArtifact( warArtifact );
381         project.setFile( warArtifact.getFile() );
382         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
383         setVariableValueToObject( mojo, "outputDirectory", outputDir );
384         setVariableValueToObject( mojo, "warName", warName );
385 
386         mojo.execute();
387 
388         // validate war file
389         File expectedWarFile = new File( outputDir, "simple.war" );
390         final Map<String, JarEntry> jarContent =
391             assertJarContent( expectedWarFile,
392                               new String[] { "META-INF/MANIFEST.MF", "pansit.jsp", "org/web/app/last-exile.jsp",
393                                   "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
394                                   "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" },
395                               new String[] { null, null, null, null, null } );
396 
397         assertFalse( "web.xml should be missing", jarContent.containsKey( "WEB-INF/web.xml" ) );
398     }
399 
400     public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed()
401         throws Exception
402     {
403         String testId = "SimpleWarNotUnderServlet30";
404         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
405         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
406         File webAppDirectory = new File( getTestDirectory(), testId );
407         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
408         String warName = "simple";
409         File webAppSource = createWebAppSource( testId );
410         File classesDir = createClassesDir( testId, true );
411 
412         project.setArtifact( warArtifact );
413         project.setFile( warArtifact.getFile() );
414         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
415         setVariableValueToObject( mojo, "outputDirectory", outputDir );
416         setVariableValueToObject( mojo, "warName", warName );
417 
418         try
419         {
420             mojo.execute();
421             fail( "Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the project "
422                 + "does not depend on Servlet 3.0" );
423         }
424         catch ( MojoExecutionException e )
425         {
426             // expected behaviour
427         }
428     }
429 
430     public void testAttachClasses()
431         throws Exception
432     {
433         String testId = "AttachClasses";
434         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
435         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
436         File webAppDirectory = new File( getTestDirectory(), testId );
437         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
438         String warName = "simple";
439         File webAppSource = createWebAppSource( testId );
440         File classesDir = createClassesDir( testId, false );
441         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
442 
443         project.setArtifact( warArtifact );
444         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
445         setVariableValueToObject( mojo, "outputDirectory", outputDir );
446         setVariableValueToObject( mojo, "warName", warName );
447         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
448         mojo.setAttachClasses( true );
449         mojo.setClassesClassifier( "classes" );
450 
451         mojo.execute();
452 
453         // validate jar file
454         File expectedJarFile = new File( outputDir, "simple-classes.jar" );
455         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" },
456                           new String[] { null, null } );
457     }
458 
459     public void testAttachClassesWithCustomClassifier()
460         throws Exception
461     {
462         String testId = "AttachClassesCustomClassifier";
463         MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
464         String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
465         File webAppDirectory = new File( getTestDirectory(), testId );
466         WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
467         String warName = "simple";
468         File webAppSource = createWebAppSource( testId );
469         File classesDir = createClassesDir( testId, false );
470         File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
471 
472         project.setArtifact( warArtifact );
473         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
474         setVariableValueToObject( mojo, "outputDirectory", outputDir );
475         setVariableValueToObject( mojo, "warName", warName );
476         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
477         mojo.setAttachClasses( true );
478         mojo.setClassesClassifier( "mystuff" );
479 
480         mojo.execute();
481 
482         // validate jar file
483         File expectedJarFile = new File( outputDir, "simple-mystuff.jar" );
484         assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" },
485                           new String[] { null, null } );
486     }
487 
488     protected Map<String, JarEntry> assertJarContent( final File expectedJarFile, final String[] files,
489                                                       final String[] filesContent )
490         throws IOException
491     {
492         return assertJarContent( expectedJarFile, files, filesContent, null );
493     }
494 
495     protected Map<String, JarEntry> assertJarContent( final File expectedJarFile, final String[] files,
496                                                       final String[] filesContent, final String[] mustNotBeInJar )
497         throws IOException
498     {
499         // Sanity check
500         assertEquals( "Could not test, files and filesContent lenght does not match", files.length, filesContent.length );
501 
502         assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() );
503         final Map<String, JarEntry> jarContent = new HashMap<String, JarEntry>();
504         final JarFile jarFile = new JarFile( expectedJarFile );
505 
506         JarEntry entry;
507         Enumeration<JarEntry> enumeration = jarFile.entries();
508         while ( enumeration.hasMoreElements() )
509         {
510             entry = (JarEntry) enumeration.nextElement();
511             Object previousValue = jarContent.put( entry.getName(), entry );
512             assertNull( "Duplicate Entry in Jar File: " + entry.getName(), previousValue );
513         }
514 
515         for ( int i = 0; i < files.length; i++ )
516         {
517             String file = files[i];
518 
519             assertTrue( "File[" + file + "] not found in archive", jarContent.containsKey( file ) );
520             if ( filesContent[i] != null )
521             {
522                 assertEquals( "Content of file[" + file + "] does not match", filesContent[i],
523                               IOUtil.toString( jarFile.getInputStream( (ZipEntry) jarContent.get( file ) ) ) );
524             }
525         }
526         if ( mustNotBeInJar != null )
527         {
528             for ( String file : mustNotBeInJar )
529             {
530                 assertFalse( "File[" + file + "]  found in archive", jarContent.containsKey( file ) );
531 
532             }
533         }
534         return jarContent;
535     }
536 
537 }