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