Author: tchemit Date: 2008-01-12 12:35:39 +0000 (Sat, 12 Jan 2008) New Revision: 139 Added: trunk/maven-jaxx-plugin/src/test/java/jaxx/ trunk/maven-jaxx-plugin/src/test/java/jaxx/CompileConfig.java trunk/maven-jaxx-plugin/src/test/java/jaxx/CompilerTest.java Log: ajout du test pour compiler des templates (reprise des tests de l'ancien projet). Added: trunk/maven-jaxx-plugin/src/test/java/jaxx/CompileConfig.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/jaxx/CompileConfig.java (rev 0) +++ trunk/maven-jaxx-plugin/src/test/java/jaxx/CompileConfig.java 2008-01-12 12:35:39 UTC (rev 139) @@ -0,0 +1,42 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package jaxx; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Une annotation pour configurer les tests de compilation. + * + * @author chemit + */ +@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) +@Target(value = {java.lang.annotation.ElementType.TYPE, java.lang.annotation.ElementType.METHOD}) +public @interface CompileConfig { + + public String packageName(); + + public boolean optimize() default true; + + public boolean runJavac() default false; + + public boolean verbose() default true; + + public String javaOpts() default ""; +} Added: trunk/maven-jaxx-plugin/src/test/java/jaxx/CompilerTest.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/jaxx/CompilerTest.java (rev 0) +++ trunk/maven-jaxx-plugin/src/test/java/jaxx/CompilerTest.java 2008-01-12 12:35:39 UTC (rev 139) @@ -0,0 +1,94 @@ +package jaxx; + +import junit.framework.TestCase; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +public class CompilerTest extends TestCase { + + protected JaxxGeneratorGoal goal; + + protected static File srcDir; + protected static final String PREFIX_PACKAGE = "testcases"; + + protected static File getSrcDir() { + if (srcDir == null) { + srcDir = new File("src" + File.separator + "test" + File.separator + "java"); + } + return srcDir; + } + + @Override + public void setUp() throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, MojoExecutionException, MojoFailureException { + CompileConfig anno = getClass().getMethod(getName()).getAnnotation(CompileConfig.class); + assertNotNull("could not found " + CompileConfig.class.getSimpleName() + " annotation on test " + getClass(), anno); + final File srcDir = getSrcDir(); + assertTrue("could not found srcDir (or not existing) : " + srcDir + " on test " + getClass(), srcDir != null && srcDir.exists()); + String packageName = anno.packageName(); + goal = new JaxxGeneratorGoal(); + goal.setSrc(srcDir); + goal.setOut(srcDir); + goal.setIncludes(new String[]{"**\\/" + PREFIX_PACKAGE + "\\/" + packageName + "\\/*.jaxx"}); + goal.setOptimize(anno.optimize()); + goal.setVerbose(anno.verbose()); + goal.setRunJavac(anno.runJavac()); + goal.setJavaOpts(anno.javaOpts()); + + } + + @Override + protected void tearDown() throws Exception { + String[] files = goal.getFiles(); + if (files != null) { + for (String s : files) { + + File file = new File(getSrcDir(), s.substring(0, s.length() - 4) + "java"); + System.out.println("delete file " + file); + boolean b = file.delete(); + assertTrue("could not delete file " + file, b); + } + super.tearDown(); + } + } + + + + @CompileConfig(packageName = "CssTests") + public void testCssTests() throws MojoExecutionException, MojoFailureException { + goal.execute(); + } + + @CompileConfig(packageName = "errors") + public void testErrors() throws MojoExecutionException, MojoFailureException { + } + + @CompileConfig(packageName = "Initializers") + public void testInitializers() throws MojoExecutionException, MojoFailureException { + goal.execute(); + } + + @CompileConfig(packageName = "InnerClasses") + public void testInnerClasses() throws MojoExecutionException, MojoFailureException { + System.out.println("hum"); + goal.execute(); + } + + @CompileConfig(packageName = "OverridingDataBindings") + public void testOverridingDataBindings() throws MojoExecutionException, MojoFailureException { + goal.execute(); + } + + @CompileConfig(packageName = "SpecialSubclassing") + public void testSpecialSubclassing() throws MojoExecutionException, MojoFailureException { + goal.execute(); + } + + @CompileConfig(packageName = "ClassReferences") + public void testClassReferences() throws MojoExecutionException, MojoFailureException { + goal.execute(); + } +} \ No newline at end of file