package org.apache.maven.javacc;

import junit.framework.TestCase;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import org.codehaus.plexus.util.FileUtils;

/**
 * 
 * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 
 * @version $Id: JJTreeBeanTest.java,v 1.2 2004/02/20 13:23:19 evenisse Exp $
 */
public class JJTreeBeanTest extends TestCase
{
    public void testGenerate()
    {
        final File grammarFile = new File( System.getProperty( "basedir" ), "src/test-data/JJTreeSample.jjt" );
        final File headerFile = new File( System.getProperty( "basedir" ), "src/test-data/JJTreeSample.jjt.header" );
        final JJTreeBean bean = new JJTreeBean();
        bean.setGeneratedSourceDirectory( "target" + File.separator + "generated-java" );
        bean.setGrammar( grammarFile.getAbsolutePath() );    
        bean.setHeader( headerFile.getAbsolutePath() );
        final String packageName = "org.apache.maven.javacc.jtree";       
        bean.setJjtreePackageName( packageName );
        bean.setJavaccPackageName( packageName );
        try
        {
            FileUtils.deleteDirectory( bean.getJJTreeOutputDir() );
            bean.generate();
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail( "Generation failed" );
         
        }
        final String[] fileNames = bean.getJJTreeOutputDir().list(); 
        final List list = Arrays.asList( fileNames );
        assertTrue( list.contains( "JJTreeSample.jj" ) );
    }

}
