View Javadoc

1   package org.apache.maven.abbot;
2   
3   /* ====================================================================
4    *   Copyright 2004 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import junit.extensions.abbot.ScriptFixture;
21  import junit.extensions.abbot.ScriptTestSuite;
22  import junit.framework.Test;
23  import java.io.File;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.StringTokenizer;
27  
28  /**
29   * TestAll is the entry point for all Abbot functional tests.
30   * It executes all xml files located in the passed src/abbot/ dir.
31   */
32  public class AbbotTestAll extends ScriptFixture
33  {
34      /**
35       * Location of Abbot scripts
36       */
37      private static final String TESTPATH = 
38          System.getProperty("maven.abbot.src.dir");
39  
40      /**
41       * Should we recurse in the directory where Abbot scripts are located?
42       */
43      private static final boolean RECURSE =
44          Boolean.getBoolean("maven.abbot.recurse");
45  
46      /**
47       * Custom ScriptTestSuite to only accept xml files.
48       */
49      public static class MavenScriptTestSuite extends ScriptTestSuite
50      {
51          public MavenScriptTestSuite(Class fixtureClass, String dirName, 
52              boolean recurse)
53          {
54              super(fixtureClass, dirName, recurse);
55          }
56  
57          public MavenScriptTestSuite(Class fixtureClass, String[] filenames)
58          {
59              super(fixtureClass, filenames);
60          }
61  
62          public boolean accept(File file)
63  		{
64  		    return file.getName().endsWith(".xml");
65  		}        
66      }
67      
68      /**
69       * Return test suite containing all scripts.
70       */
71      public static Test suite()
72      {
73          MavenScriptTestSuite suite;
74          String[] files = getScriptFileNames();
75          
76          if (files == null)
77          {        
78              suite = new MavenScriptTestSuite(ScriptFixture.class, TESTPATH, 
79                  RECURSE);
80          }
81          else
82          {
83              suite = new MavenScriptTestSuite(ScriptFixture.class, files);
84          }
85          
86          return suite;
87      }
88  
89      /**
90       * @see ScriptFixture#ScriptFixture(java.lang.String)
91       */
92      public AbbotTestAll(String name)
93      {
94          super(name);
95      }
96  
97      /**
98       * @return the file list (as a String array) specified by the optional 
99       *         <code>maven.abbot.src.files</code> Maven property or null
100      *         if the property is not defined. Also returns null if there
101      *         are no files defined in the <code>maven.abbot.src.files</code>
102      *         property. 
103      */
104     protected static String[] getScriptFileNames()
105     {
106         String files = System.getProperty("maven.abbot.src.files");
107         String[] result = null;
108 
109         if (files != null)
110         {
111             List fileList = new ArrayList();
112             StringTokenizer st = new StringTokenizer(files, ",");
113             while (st.hasMoreTokens())
114             {
115                 fileList.add(st.nextToken());
116             }
117 
118             if (!fileList.isEmpty())
119             {
120                 result = (String[]) fileList.toArray(new String[0]);
121             }
122         }
123 
124         return result;
125     }
126         
127 }