1   package org.apache.maven.plugin.ear.it;
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 org.codehaus.plexus.util.FileUtils;
23  import org.codehaus.plexus.util.IOUtil;
24  import org.codehaus.plexus.util.ReaderFactory;
25  
26  import java.io.File;
27  import java.util.Properties;
28  
29  /**
30   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
31   * @version $Id: EarMojoIT.java 749046 2009-03-01 15:37:29Z snicoll $
32   * @noinspection JavaDoc
33   */
34  public class EarMojoIT
35      extends AbstractEarPluginIT
36  {
37  
38      /**
39       * Builds an EAR with a single EJB and no configuration.
40       */
41      public void testProject001()
42          throws Exception
43      {
44          doTestProject( "project-001", new String[]{"ejb-sample-one-1.0.jar"} );
45      }
46  
47      /**
48       * Builds an EAR with a customized artifact location and a customized artifact name.
49       */
50      public void testProject002()
51          throws Exception
52      {
53          doTestProject( "project-002", new String[]{"APP-INF/lib/ejb-sample-one-1.0.jar", "ejb-sample-two.jar"} );
54      }
55  
56      /**
57       * Builds an EAR with a defalt bundle directory for <tt>java</tt> modules.
58       */
59      public void testProject003()
60          throws Exception
61      {
62          doTestProject( "project-003", new String[]{"ejb-sample-one-1.0.jar", "APP-INF/lib/jar-sample-one-1.0.jar",
63              "APP-INF/lib/jar-sample-two-1.0.jar"} );
64      }
65  
66      /**
67       * Builds an EAR with a defalt bundle directory for _java_ modules and a custom
68       * location overriding the default.
69       */
70      public void testProject004()
71          throws Exception
72      {
73          doTestProject( "project-004", new String[]{"ejb-sample-one-1.0.jar", "jar-sample-one-1.0.jar",
74              "APP-INF/lib/jar-sample-two-1.0.jar"} );
75      }
76  
77      /**
78       * Builds an EAR with a custom URI.
79       */
80      public void testProject005()
81          throws Exception
82      {
83          doTestProject( "project-005", new String[]{"ejb-sample-one-1.0.jar", "libs/another-name.jar"} );
84      }
85  
86      /**
87       * Builds an EAR with an excluded module.
88       */
89      public void testProject006()
90          throws Exception
91      {
92          doTestProject( "project-006", new String[]{"ejb-sample-one-1.0.jar", "jar-sample-two-1.0.jar"} );
93      }
94  
95      /**
96       * Builds an EAR with a classified artifact and no extra configuration.
97       */
98      public void testProject007()
99          throws Exception
100     {
101         doTestProject( "project-007", new String[]{"ejb-sample-one-1.0-classified.jar"} );
102     }
103 
104     /**
105      * Builds an EAR with deployment descriptor configuration for J2EE 1.3.
106      */
107     public void testProject008()
108         throws Exception
109     {
110         doTestProject( "project-008", new String[]{"ejb-sample-one-1.0.jar"} );
111     }
112 
113     /**
114      * Builds an EAR with deployment descriptor configuration for J2EE 1.4.
115      */
116     public void testProject009()
117         throws Exception
118     {
119         doTestProject( "project-009", new String[]{"ejb-sample-one-1.0.jar"} );
120     }
121 
122     /**
123      * Builds an EAR with deployment descriptor configuration for Java EE 5.
124      */
125     public void testProject010()
126         throws Exception
127     {
128         doTestProject( "project-010", new String[]{"ejb-sample-one-1.0.jar"} );
129     }
130 
131     /**
132      * Builds an EAR and make sure that deployment descriptor default settings are applied.
133      */
134     public void testProject011()
135         throws Exception
136     {
137         doTestProject( "project-011", new String[]{"ejb-sample-one-1.0.jar"} );
138     }
139 
140     /**
141      * Builds an EAR and make sure that EAR resources are bundled within the EAR.
142      */
143     public void testProject012()
144         throws Exception
145     {
146         doTestProject( "project-012", new String[]{"README.txt", "LICENSE.txt", "ejb-sample-one-1.0.jar"} );
147     }
148 
149     /**
150      * Builds an EAR and make sure that EAR resources in a customized resources directory are bundled within the EAR.
151      */
152     public void testProject013()
153         throws Exception
154     {
155         doTestProject( "project-013", new String[]{"README.txt", "LICENSE.txt", "ejb-sample-one-1.0.jar"} );
156     }
157 
158     /**
159      * Builds an EAR and make sure that EAR resources are bundled within the EAR using includes and excludes.
160      */
161     public void testProject014()
162         throws Exception
163     {
164         doTestProject( "project-014", new String[]{"LICENSE.txt", "ejb-sample-one-1.0.jar"} );
165     }
166 
167     /**
168      * Builds an EAR and make sure that default manifest is taken into account.
169      */
170     public void testProject015()
171         throws Exception
172     {
173         final File baseDir = doTestProject( "project-015", new String[]{"ejb-sample-one-1.0.jar"} );
174         final File expectedManifest = new File( baseDir, "src/main/application/META-INF/MANIFEST.MF" );
175         final File actualManifest = new File( getEarDirectory( baseDir, "project-015" ), "META-INF/MANIFEST.MF" );
176         assertTrue( "Manifest was not copied", actualManifest.exists() );
177         assertTrue( FileUtils.contentEquals( expectedManifest, actualManifest ) );
178     }
179 
180     /**
181      * Builds an EAR and make sure that custom manifest is taken into account.
182      */
183     public void testProject016()
184         throws Exception
185     {
186         System.out.println( "Skipped project-016: need a way to extract the EAR archive" );
187         /*
188         final File baseDir = doTestProject( "project-016", new String[]{"ejb-sample-one-1.0.jar"} );
189         final File expectedManifest = new File(baseDir, "src/main/ear/META-INF/MANIFEST.MF");
190         // TODO: needs a way to extract the EAR archive
191         */
192     }
193 
194     /**
195      * Builds an EAR and make sure that custom application.xml is taken into account.
196      */
197     public void testProject017()
198         throws Exception
199     {
200         doTestProject( "project-017", new String[]{"ejb-sample-one-1.0.jar"} );
201     }
202 
203     /**
204      * Builds an EAR with a custom final name.
205      */
206     public void testProject018()
207         throws Exception
208     {
209         final File baseDir = executeMojo( "project-018", new Properties() );
210         final File expectedFile = new File( baseDir, "target/my-custom-file.ear" );
211         assertTrue( "EAR archive not found", expectedFile.exists() );
212     }
213 
214     /**
215      * Builds an EAR with unpacked archives using the unpackTypes.
216      */
217     public void testProject019()
218         throws Exception
219     {
220         doTestProject( "project-019",
221                        new String[]{"ejb-sample-one-1.0.jar", "sar-sample-one-1.0.sar", "jar-sample-one-1.0.jar"},
222                        new boolean[]{false, true, true} );
223     }
224 
225     /**
226      * Builds an EAR with unpacked archives using the unpack module attribute.
227      */
228     public void testProject020()
229         throws Exception
230     {
231         doTestProject( "project-020",
232                        new String[]{"ejb-sample-one-1.0.jar", "sar-sample-one-1.0.sar", "jar-sample-one-1.0.jar"},
233                        new boolean[]{true, false, false} );
234     }
235 
236     /**
237      * Builds an EAR with unpacked archives using both unpackTypes and the unpack module attribute.
238      */
239     public void testProject021()
240         throws Exception
241     {
242         doTestProject( "project-021",
243                        new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar", "sar-sample-one-1.0.sar",
244                            "jar-sample-one-1.0.jar", "jar-sample-two-1.0.jar"},
245                        new boolean[]{false, true, false, false, true} );
246     }
247 
248     /**
249      * Builds an EAR with a classifier.
250      */
251     public void testProject022()
252         throws Exception
253     {
254         final File baseDir = executeMojo( "project-022", new Properties() );
255         final File expectedFile = new File( baseDir, "target/maven-ear-plugin-test-project-022-99.0-myclassifier.ear" );
256         assertTrue( "EAR archive not found", expectedFile.exists() );
257     }
258 
259     /**
260      * Builds an EAR and make sure that a single classified dependency is detected without specifying the classifier.
261      */
262     public void testProject023()
263         throws Exception
264     {
265         doTestProject( "project-023", new String[]{"ejb-sample-one-1.0-classified.jar", "ejb-sample-two-1.0.jar"},
266                        new boolean[]{true, false} );
267     }
268 
269     /**
270      * Builds an EAR and make sure that a single classified dependency is detected when specifying the classifier.
271      */
272     public void testProject024()
273         throws Exception
274     {
275         doTestProject( "project-024", new String[]{"ejb-sample-one-1.0-classified.jar", "ejb-sample-two-1.0.jar"},
276                        new boolean[]{true, false} );
277     }
278 
279     /**
280      * Builds an EAR and make sure that a classified dependency with mutiple candidates is detected when specifying the classifier.
281      */
282     public void testProject025()
283         throws Exception
284     {
285         doTestProject( "project-025", new String[]{"ejb-sample-one-1.0-classified.jar", "ejb-sample-one-1.0.jar"},
286                        new boolean[]{true, false} );
287     }
288 
289     /**
290      * Builds an EAR and make sure that the build fails if a unclassifed module configuration with mutiple candidates is specified.
291      */
292     public void testProject026()
293         throws Exception
294     {
295         final File baseDir = executeMojo( "project-026", new Properties(), false );
296         // Stupido, checks that the ear archive is not there
297         assertFalse( "Execution should have failed", getEarArchive( baseDir, "project-026" ).exists() );
298     }
299 
300     /**
301      * Builds an EAR and make sure that provided dependencies are not included in the EAR.
302      */
303     public void testProject027()
304         throws Exception
305     {
306         doTestProject( "project-027", new String[]{"ejb-sample-one-1.0.jar"} );
307     }
308 
309     /**
310      * Builds an EAR and make sure that test dependencies are not included in the EAR.
311      */
312     public void testProject028()
313         throws Exception
314     {
315         doTestProject( "project-028", new String[]{"ejb-sample-one-1.0.jar"} );
316     }
317 
318     /**
319      * Builds an EAR and make sure that system dependencies are not included in the EAR.
320      */
321     public void testProject029()
322         throws Exception
323     {
324         doTestProject( "project-029", new String[]{"ejb-sample-one-1.0.jar"} );
325     }
326 
327     /**
328      * Builds an EAR and make sure that ejb-client dependencies are detected and not added by default in the
329      * generated application.xml.
330      */
331     public void testProject030()
332         throws Exception
333     {
334         doTestProject( "project-030", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0-client.jar"} );
335     }
336 
337     /**
338      * Builds an EAR with a Jboss 4 configuration specifying the security domain and the
339      * unauthenticated-principal to use.
340      */
341     public void testProject031()
342         throws Exception
343     {
344         doTestProject( "project-031", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
345     }
346 
347     /**
348      * Builds an EAR with a Jboss 3.2 configuration specifying the jmx-name to use.
349      */
350     public void testProject032()
351         throws Exception
352     {
353         doTestProject( "project-032", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
354     }
355 
356     /**
357      * Builds an EAR with a Jboss 4 configuration and Jboss specific modules.
358      */
359     public void testProject033()
360         throws Exception
361     {
362         doTestProject( "project-033",
363                        new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar", "sar-sample-one-1.0.sar",
364                            "har-sample-one-1.0.har"} );
365     }
366 
367     /**
368      * Builds an EAR with custom security settings.
369      */
370     public void testProject034()
371         throws Exception
372     {
373         doTestProject( "project-034", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
374     }
375 
376     /**
377      * Builds an EAR with a full filename mapping and make sure that custom locations are not overriden.
378      */
379     public void testProject035()
380         throws Exception
381     {
382         doTestProject( "project-035",
383                        new String[]{"foo/eartest-ejb-sample-one-1.0.jar", "eartest-ejb-sample-two-1.0.jar",
384                            "libs/eartest-jar-sample-one-1.0.jar", "libs/eartest-jar-sample-two-1.0.jar",
385                            "sar-sample-one.sar"} );
386     }
387 
388     /**
389      * Builds an EAR with a full filename mapping and make sure that groupIds with dots are replaced by dashes in filenames.
390      */
391     public void testProject036()
392         throws Exception
393     {
394         doTestProject( "project-036",
395                        new String[]{"foo/eartest-ejb-sample-one-1.0.jar", "eartest-ejb-sample-two-1.0.jar",
396                            "com-foo-bar-ejb-sample-one-1.0.jar", "com-foo-bar-ejb-sample-two-1.0.jar",
397                            "libs/eartest-jar-sample-one-1.0.jar", "libs/eartest-jar-sample-two-1.0.jar",
398                            "sar-sample-one.sar"} );
399     }
400 
401     /**
402      * Builds an EAR and make sure that ejb-client dependencies are detected and added in the generated application.xml if
403      * includeInApplicationXml is set.
404      */
405     public void testProject037()
406         throws Exception
407     {
408         doTestProject( "project-037", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0-client.jar"} );
409     }
410 
411     /**
412      * Builds an EAR and make sure that a non-classified dependency with mutiple candidates is
413      * detected when specifying the mainArtifactId as classifier.
414      */
415     public void testProject038()
416         throws Exception
417     {
418         doTestProject( "project-038", new String[]{"ejb-sample-one-1.0-classified.jar", "ejb-sample-one-1.0.jar"},
419                        new boolean[]{false, true} );
420     }
421 
422     /**
423      * Builds an EAR with a Jboss 4 configuration specifying specifying the loader repository to use.
424      */
425     public void testProject039()
426         throws Exception
427     {
428         doTestProject( "project-039", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
429     }
430 
431     /**
432      * Builds an EAR with deployment descriptor configuration for Java EE 5 and
433      * an alternative deployment descriptor.
434      */
435     public void testProject040()
436         throws Exception
437     {
438         doTestProject( "project-040", new String[]{"ejb-sample-one-1.0.jar"} );
439     }
440 
441     /**
442      * Builds an EAR with a Jboss 4.2 configuration specifying the module order to use.
443      */
444     public void testProject041()
445         throws Exception
446     {
447         doTestProject( "project-041", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
448     }
449 
450     /**
451      * Builds an EAR with a Jboss 4.2 configuration specifying a datasource to add.
452      */
453     public void testProject042()
454         throws Exception
455     {
456         doTestProject( "project-042", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
457     }
458 
459 
460     /**
461      * Builds an EAR with a custom descriptor location (generatedDescriptorLocation setting).
462      */
463     public void testProject043()
464         throws Exception
465     {
466         final File baseDir = doTestProject( "project-043", new String[]{"ejb-sample-one-1.0.jar"} );
467         final File expectedApplicationXml = new File( baseDir, "target/custom-descriptor-dir/application.xml" );
468         assertTrue( "Application.xml file not found", expectedApplicationXml.exists() );
469         assertFalse( "Application.xml file should not be empty", expectedApplicationXml.length() == 0 );
470     }
471 
472     /**
473      * Builds an EAR with a custom library-directory.
474      */
475     public void testProject044()
476         throws Exception
477     {
478         doTestProject( "project-044", new String[]{"ejb-sample-one-1.0.jar", "myLibs/jar-sample-one-1.0.jar"} );
479     }
480 
481     /**
482      * Builds an EAR and filter the content of the sources directory.
483      */
484     public void testProject045()
485         throws Exception
486     {
487         final File baseDir = doTestProject( "project-045", new String[]{"README.txt", "ejb-sample-one-1.0.jar"} );
488         final File actualReadme = new File( getEarDirectory( baseDir, "project-045" ), "README.txt" );
489         final String content = IOUtil.toString( ReaderFactory.newReader( actualReadme, "UTF-8" ) );
490         assertTrue( "application name and version was not filtered properly", content.indexOf( "my-app 99.0" ) != -1 );
491         assertTrue( "Escaping did not work properly",
492                     content.indexOf( "will not be filtered ${application.name}." ) != -1 );
493     }
494 
495     /**
496      * Builds an EAR and filter the content of the sources directory using
497      * a custom filter file.
498      */
499     public void testProject046()
500         throws Exception
501     {
502         final File baseDir = doTestProject( "project-046", new String[]{"README.txt", "ejb-sample-one-1.0.jar"} );
503         final File actualReadme = new File( getEarDirectory( baseDir, "project-046" ), "README.txt" );
504         final String content = IOUtil.toString( ReaderFactory.newReader( actualReadme, "UTF-8" ) );
505         assertTrue( "application name and version was not filtered properly", content.indexOf( "my-app 99.0" ) != -1 );
506         assertTrue( "application build was not filtered properly", content.indexOf( "(Build 2)" ) != -1 );
507         assertTrue( "Unknown property should not have been filtered",
508                     content.indexOf( "will not be filtered ${application.unknown}." ) != -1 );
509     }
510 
511     /**
512      * Builds an EAR and filter the content with a list of extensions.
513      */
514     public void testProject047()
515         throws Exception
516     {
517         final File baseDir = doTestProject( "project-047", new String[]{"README.txt", "ejb-sample-one-1.0.jar"} );
518         final File actualReadme = new File( getEarDirectory( baseDir, "project-047" ), "README.txt" );
519         final String content = IOUtil.toString( ReaderFactory.newReader( actualReadme, "UTF-8" ) );
520         assertTrue( "application name and version should not have been filtered",
521                     content.indexOf( "my-app 99.0" ) == -1 );
522         assertTrue( "orignial properties not found",
523                     content.indexOf( "${application.name} ${project.version}" ) != -1 );
524     }
525 
526     /**
527      * Builds an EAR with a Jboss 5 configuration containing library directory.
528      */
529     public void testProject048()
530         throws Exception
531     {
532         doTestProject( "project-048", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
533     }
534 
535     /**
536      * Builds an EAR with a Jboss 4.2 configuration containing a library directory.
537      */
538     public void testProject049()
539         throws Exception
540     {
541         doTestProject( "project-049", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
542     }
543 
544     /**
545      * Builds an EAR with a Jboss 5 configuration containing a loader repository configuration definition.
546      */
547     public void testProject050()
548         throws Exception
549     {
550         doTestProject( "project-050", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
551     }
552 
553     /**
554      * Builds an EAR with a Jboss 5 configuration containing a loader repository class definition.
555      */
556     public void testProject051()
557         throws Exception
558     {
559         doTestProject( "project-051", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
560     }
561 
562     /**
563      * Builds an EAR with a Jboss 5 configuration containing a configuration parser class definition.
564      */
565     public void testProject052()
566         throws Exception
567     {
568         doTestProject( "project-052", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
569     }
570 
571     /**
572      * Builds an EAR with a Jboss 5 configuration containing only the loader repo configuration
573      */
574     public void testProject053()
575         throws Exception
576     {
577         doTestProject( "project-053", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
578     }
579 
580     /**
581      * Builds an EAR with deployment descriptor configuration for Java EE 5 and no application.xml
582      */
583     public void testProject054()
584         throws Exception
585     {
586         doTestProject( "project-054", new String[]{"ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar"} );
587     }
588 
589     /**
590      * Builds an EAR with jar dependencies added in application.xml.
591      */
592     public void testProject055()
593         throws Exception
594     {
595         doTestProject( "project-055", new String[]{"jar-sample-one-1.0.jar", "jar-sample-two-1.0.jar",
596             "jar-sample-three-with-deps-1.0.jar"} );
597     }
598 
599     /**
600      * Builds an EAR with deployment descriptor configuration for J2EE 1.4 and
601      * an alternative deployment descriptor.
602      */
603     public void testProject056()
604         throws Exception
605     {
606         doTestProject( "project-056", new String[]{"ejb-sample-one-1.0.jar"} );
607     }
608 }