1   package org.apache.maven.javacc;
2   
3   /* ====================================================================
4    *   Copyright 2001-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  
21  import junit.framework.TestCase;
22  
23  import org.codehaus.plexus.util.FileUtils;
24  
25  import java.io.File;
26  
27  import java.util.Arrays;
28  import java.util.List;
29  
30  /**
31   *
32   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
33   * @version $Id: JavaccBeanTest.java 373246 2006-01-28 21:11:33Z ltheussl $
34   */
35  public class JavaccBeanTest extends TestCase
36  {
37      public void testGenerate()
38      {
39          final String basedir = System.getProperty( "basedir" );
40  
41          final File grammarFile =
42              new File( basedir, "src/test-data/JavaCCSample.jj" );
43  
44          final File headerFile =
45              new File( basedir, "src/test-data/JavaCCSample.jj.header" );
46  
47          final JavaccBean bean = new JavaccBean();
48  
49          bean.setGrammar( grammarFile.getAbsolutePath() );
50  
51          bean.setHeader( headerFile.getAbsolutePath() );
52  
53          final String fs = File.separator;
54  
55          final String gsd =
56              basedir + fs + "target" + fs + "generated-src" + fs + "main" + fs
57              + "java";
58  
59          bean.setGeneratedSourceDirectory( gsd );
60  
61          final String packageName = "org.apache.maven.javacc.javacc";
62  
63          bean.setJavaccPackageName( packageName );
64  
65          try
66          {
67              FileUtils.deleteDirectory( bean.getJavaccOutputDir() );
68  
69              bean.generate();
70          }
71          catch ( Exception e )
72          {
73              e.printStackTrace();
74  
75              fail( "Generation failed" );
76          }
77  
78          final String[] fileNames = bean.getJavaccOutputDir().list();
79  
80          final List list = Arrays.asList( fileNames );
81  
82          assertTrue( list.contains( "Simple1.java" ) );
83  
84          assertTrue( list.contains( "Token.java" ) );
85      }
86  }