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.framework.Test;
22  import junit.framework.TestCase;
23  
24  /**
25   * Unit tests for {@link AbbotTestAll}.
26   */
27  public class AbbotTestAllTest extends TestCase
28  {
29      public void testGetScriptFileNamesNoPropertyDefined()
30      {
31          assertNull("The maven.abbot.src.files property must not be set for "
32              + "this test", System.getProperty("maven.abbot.src.files"));
33          String[] result = AbbotTestAll.getScriptFileNames();
34          assertNull(result);        
35      }
36  
37      public void testGetScriptFileNamesEmptyFileList()
38      {
39          System.setProperty("maven.abbot.src.files", "");
40          String[] result = AbbotTestAll.getScriptFileNames();
41          assertNull(result);        
42      }
43  
44      public void testGetScriptFileNamesSingleFile()
45      {
46          System.setProperty("maven.abbot.src.files", "c:/some/file");
47          String[] result = AbbotTestAll.getScriptFileNames();
48          assertEquals(1, result.length);        
49          assertEquals("c:/some/file", result[0]);        
50      }
51  
52      public void testGetScriptFileNamesTwoFiles()
53      {
54          System.setProperty("maven.abbot.src.files", 
55              "c:/some/file,c:/other/file");
56          String[] result = AbbotTestAll.getScriptFileNames();
57          assertEquals(2, result.length);        
58          assertEquals("c:/some/file", result[0]);        
59          assertEquals("c:/other/file", result[1]);        
60      }
61  
62      /**
63       * Verify we can construct a valid 
64       * {@link junit.extensions.abbot.ScriptTestSuite} object when
65       * executing a single script.
66       */
67      public void testConstructionOfScriptTestSuiteWithUniqueScript()
68      {
69          System.setProperty("maven.abbot.src.files", "c:/some/file.xml");
70  
71          Test suite = AbbotTestAll.suite();
72  
73          assertNotNull(suite);
74          assertEquals(AbbotTestAll.MavenScriptTestSuite.class.getName(), 
75              suite.getClass().getName());
76  
77          AbbotTestAll.MavenScriptTestSuite mavenSuite = 
78              (AbbotTestAll.MavenScriptTestSuite) suite;
79          assertEquals(1, mavenSuite.testCount());
80  
81          Test test = (Test) mavenSuite.tests().nextElement();
82          assertEquals(ScriptFixture.class.getName(), test.getClass().getName());
83      }
84  
85  }