package org.apache.maven.abbot;

/* ====================================================================
 *   Copyright 2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */

import junit.extensions.abbot.ScriptFixture;
import junit.framework.Test;
import junit.framework.TestCase;

/**
 * Unit tests for {@link AbbotTestAll}.
 */
public class AbbotTestAllTest extends TestCase
{
    public void testGetScriptFileNamesNoPropertyDefined()
    {
        assertNull("The maven.abbot.src.files property must not be set for "
            + "this test", System.getProperty("maven.abbot.src.files"));
        String[] result = AbbotTestAll.getScriptFileNames();
        assertNull(result);        
    }

    public void testGetScriptFileNamesEmptyFileList()
    {
        System.setProperty("maven.abbot.src.files", "");
        String[] result = AbbotTestAll.getScriptFileNames();
        assertNull(result);        
    }

    public void testGetScriptFileNamesSingleFile()
    {
        System.setProperty("maven.abbot.src.files", "c:/some/file");
        String[] result = AbbotTestAll.getScriptFileNames();
        assertEquals(1, result.length);        
        assertEquals("c:/some/file", result[0]);        
    }

    public void testGetScriptFileNamesTwoFiles()
    {
        System.setProperty("maven.abbot.src.files", 
            "c:/some/file,c:/other/file");
        String[] result = AbbotTestAll.getScriptFileNames();
        assertEquals(2, result.length);        
        assertEquals("c:/some/file", result[0]);        
        assertEquals("c:/other/file", result[1]);        
    }

    /**
     * Verify we can construct a valid 
     * {@link junit.extensions.abbot.ScriptTestSuite} object when
     * executing a single script.
     */
    public void testConstructionOfScriptTestSuiteWithUniqueScript()
    {
        System.setProperty("maven.abbot.src.files", "c:/some/file.xml");

        Test suite = AbbotTestAll.suite();

        assertNotNull(suite);
        assertEquals(AbbotTestAll.MavenScriptTestSuite.class.getName(), 
            suite.getClass().getName());

        AbbotTestAll.MavenScriptTestSuite mavenSuite = 
            (AbbotTestAll.MavenScriptTestSuite) suite;
        assertEquals(1, mavenSuite.testCount());

        Test test = (Test) mavenSuite.tests().nextElement();
        assertEquals(ScriptFixture.class.getName(), test.getClass().getName());
    }

}
