[Buix-commits] r895 - lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx
Author: tchemit Date: 2008-10-11 14:09:14 +0000 (Sat, 11 Oct 2008) New Revision: 895 Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java Log: refactor tests of the plugin using maven-plugin-testing-harness plugin Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-11 14:08:31 UTC (rev 894) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-11 14:09:14 UTC (rev 895) @@ -1,111 +1,132 @@ package org.codelutin.jaxx; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import java.io.File; -public class CompilerTest extends AbstractCompilerTest { +public class CompilerTest extends AbstractMojoTestCase { - @CompileConfig(packageName = "InnerClasses", runJavac = true) - public void testInnerClasses() throws MojoExecutionException, MojoFailureException { - goal.execute(); + /** log */ + protected static final Log log = LogFactory.getLog(CompilerTest.class); + + @Override + protected void setUp() throws Exception { + super.setUp(); + log.info(getName()); } - - @CompileConfig(packageName = "SpecialSubclassing", runJavac = true) - public void testSpecialSubclassing() throws MojoExecutionException, MojoFailureException { - try { - goal.execute(); - } catch (Exception e) { - // there is some inter-dependances between generated java file - // we runJavaC on each file, but we should compile a sourcePath instead... - assertTrue(true); - } - goal.execute(); + protected JaxxGeneratorMojo getMojo(String s) throws Exception { + File testPom = new File(getBasedir(), "src/test/resources/" + s + ".xml"); + JaxxGeneratorMojo mojo = (JaxxGeneratorMojo) lookupMojo("generate", testPom); + assertNotNull(mojo); + return mojo; } - @CompileConfig(packageName = "CSSTests", verbose = false, i18nable = false) - public void testCssTests() throws MojoExecutionException, MojoFailureException { - goal.execute(); + public void testInnerClasses() throws Exception { + JaxxGeneratorMojo mojo = getMojo("InnerClasses"); + mojo.execute(); + assertEquals(1, mojo.getFiles().length); } - @CompileConfig(packageName = "errors", verbose = false) - public void testErrors() throws MojoExecutionException, MojoFailureException { - //fixme : launch a goal for each files found : since we should failed for some files... - //goal.execute(); + public void testSpecialSubclassing() throws Exception { + JaxxGeneratorMojo mojo = getMojo("SpecialSubclassing"); + mojo.execute(); + assertEquals(7, mojo.getFiles().length); } - @CompileConfig(packageName = "Initializers", runJavac = false) - public void testInitializers() throws MojoExecutionException, MojoFailureException { - goal.execute(); + public void testCssTests() throws Exception { + JaxxGeneratorMojo mojo = getMojo("CSSTests"); + mojo.execute(); + assertEquals(7, mojo.getFiles().length); } - @CompileConfig(packageName = "Script", runJavac = false) - public void testScript() throws MojoExecutionException, MojoFailureException { - try { - goal.execute(); - } catch (Exception e) { - // there is some inter-dependances between generated java file - // we runJavaC on each file, but we should compile a sourcePath instead... - assertTrue(true); + public void testErrors() throws Exception { + JaxxGeneratorMojo mojo = getMojo("errors"); + // init mojo to get alls files to treate + mojo.init(); + String[] files = mojo.getFiles(); + // execute mjo on each jaxx file to produce the error + for (String file : files) { + mojo.setFiles(new String[]{file}); + try { + mojo.execute(); + // should never pass + fail(); + } catch (MojoExecutionException e) { + // ok jaxx compiler failed + assertTrue(true); + } catch (MojoFailureException e) { + // this exception should not appear + fail(); + } } } - @CompileConfig(packageName = "OverridingDataBindings", runJavac = false) - public void testOverridingDataBindings() throws MojoExecutionException, MojoFailureException { - goal.execute(); + public void testInitializers() throws Exception { + JaxxGeneratorMojo mojo = getMojo("Initializers"); + mojo.execute(); + assertEquals(1, mojo.getFiles().length); } - @CompileConfig(packageName = "ClassReferences", runJavac = true) - public void testClassReferences() throws MojoExecutionException, MojoFailureException { - try { - goal.execute(); - } catch (Exception e) { - // there is some inter-dependances between generated java file - // we runJavaC on each file, but we should compile a sourcePath instead... - assertTrue(true); - } - goal.execute(); + public void testScript() throws Exception { + JaxxGeneratorMojo mojo = getMojo("Script"); + mojo.execute(); + assertEquals(1, mojo.getFiles().length); } - @CompileConfig(packageName = "force", verbose = false) - public void testForce() throws MojoExecutionException, MojoFailureException, InterruptedException { + public void testOverridingDataBindings() throws Exception { + JaxxGeneratorMojo mojo = getMojo("OverridingDataBindings"); + mojo.execute(); + assertEquals(3, mojo.getFiles().length); + } + + public void testClassReferences() throws Exception { + JaxxGeneratorMojo mojo = getMojo("ClassReferences"); + mojo.execute(); + assertEquals(6, mojo.getFiles().length); + } + + public void testForce() throws Exception { + + JaxxGeneratorMojo mojo = getMojo("force"); // first round, with force option so will generate theonly JButton.jaxx file - goal.execute(); - String[] files = goal.getFiles(); + mojo.execute(); + String[] files = mojo.getFiles(); assertEquals(1, files.length); - File srcFile = new File(goal.getSrc(), files[0]); + File srcFile = new File(mojo.getSrc(), files[0]); - File dstFile = goal.getUpdater().getMirrorFile(srcFile); + File dstFile = mojo.getUpdater().getMirrorFile(srcFile); long oldTime = dstFile.lastModified(); // second round, no force so will not the file - goal.setForce(false); - goal.execute(); - files = goal.getFiles(); + mojo.setForce(false); + mojo.execute(); + files = mojo.getFiles(); assertEquals(0, files.length); Thread.sleep(1000); - assertEquals(oldTime, goal.getUpdater().getMirrorFile(srcFile).lastModified()); + assertEquals(oldTime, mojo.getUpdater().getMirrorFile(srcFile).lastModified()); // three round : modify a source with no force option srcFile.setLastModified(System.currentTimeMillis()); - goal.execute(); - files = goal.getFiles(); + mojo.execute(); + files = mojo.getFiles(); assertEquals(1, files.length); - assertTrue(goal.getUpdater().getMirrorFile(srcFile).lastModified() > oldTime); + assertTrue(mojo.getUpdater().getMirrorFile(srcFile).lastModified() > oldTime); // last round, reforce file generation for an no modify source - goal.setForce(true); - goal.execute(); - files = goal.getFiles(); + mojo.setForce(true); + mojo.execute(); + files = mojo.getFiles(); assertEquals(1, files.length); - assertTrue(goal.getUpdater().getMirrorFile(srcFile).lastModified() > oldTime); + assertTrue(mojo.getUpdater().getMirrorFile(srcFile).lastModified() > oldTime); } - } \ No newline at end of file Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java 2008-10-11 14:08:31 UTC (rev 894) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java 2008-10-11 14:09:14 UTC (rev 895) @@ -1,59 +1,76 @@ package org.codelutin.jaxx; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.codelutin.util.FileUtil; import java.io.File; import java.io.IOException; -public class I18nTest extends AbstractCompilerTest { +public class I18nTest extends AbstractMojoTestCase { - @CompileConfig(packageName = "i18n.text", verbose = false, i18nable = false) - public void testI18nTextNoI1_nabel() throws MojoExecutionException, MojoFailureException, IOException { - goal.execute(); - checkPattern("testId.setText(_(\"test.text\"));", false); - } + /** log */ + protected static final Log log = LogFactory.getLog(I18nTest.class); - @CompileConfig(packageName = "i18n.title", verbose = false, i18nable = false) - public void testI18nTitleNoI18nable() throws MojoExecutionException, MojoFailureException, IOException { - goal.execute(); - checkPattern("testId.setTitle(_(\"test.title\"));", false); + + @Override + protected void setUp() throws Exception { + super.setUp(); + log.info(getName()); } - @CompileConfig(packageName = "i18n.tooltiptext", verbose = false, i18nable = false) - public void testI18nToolTipTextNoI18nable() throws MojoExecutionException, MojoFailureException, IOException { - goal.execute(); - checkPattern("testId.setToolTipText(_(\"test.toolTipText\"));", false); + protected JaxxGeneratorMojo getMojo(String s) throws Exception { + File testPom = new File(getBasedir(), "src/test/resources/" + s + ".xml"); + JaxxGeneratorMojo mojo = (JaxxGeneratorMojo) lookupMojo("generate", testPom); + assertNotNull(mojo); + return mojo; } - @CompileConfig(packageName = "i18n.text", verbose = false, i18nable = true) - public void testI18nText() throws MojoExecutionException, MojoFailureException, IOException { - goal.execute(); - checkPattern("testId.setText(_(\"test.text\"));", true); - checkPattern("\"_(\\\"test.text\\\")\"", false); + public void testI18nText() throws Exception { + JaxxGeneratorMojo mojo = getMojo("i18n_text"); + mojo.setI18nable(false); + mojo.execute(); + checkPattern(mojo, "testId.setText(_(\"test.text\"));", false); + + mojo.setI18nable(true); + mojo.execute(); + checkPattern(mojo, "testId.setText(_(\"test.text\"));", true); + checkPattern(mojo, "\"_(\\\"test.text\\\")\"", false); } - @CompileConfig(packageName = "i18n.title", verbose = false, i18nable = true) - public void testI18nTitle() throws MojoExecutionException, MojoFailureException, IOException { - goal.execute(); - checkPattern("testId.setTitle(_(\"test.title\"));", true); - checkPattern("\"_(\\\"test.title\\\")\"", false); + public void testI18nTitle() throws Exception { + JaxxGeneratorMojo mojo = getMojo("i18n_title"); + mojo.setI18nable(false); + mojo.execute(); + checkPattern(mojo, "testId.setTitle(_(\"test.title\"));", false); + + mojo.setI18nable(true); + mojo.execute(); + checkPattern(mojo, "testId.setTitle(_(\"test.title\"));", true); + checkPattern(mojo, "\"_(\\\"test.title\\\")\"", false); } - @CompileConfig(packageName = "i18n.tooltiptext", verbose = false, i18nable = true) - public void testI18nToolTipText() throws MojoExecutionException, MojoFailureException, IOException { - goal.execute(); - checkPattern("testId.setToolTipText(_(\"test.toolTipText\"));", true); - checkPattern("\"_(\\\"test.toolTipText\\\")\"", false); + public void testI18nToolTipText() throws Exception { + JaxxGeneratorMojo mojo = getMojo("i18n_tooltiptext"); + mojo.setI18nable(false); + mojo.execute(); + checkPattern(mojo, "testId.setToolTipText(_(\"test.toolTipText\"));", false); + + mojo.setI18nable(true); + mojo.execute(); + checkPattern(mojo, "testId.setToolTipText(_(\"test.toolTipText\"));", true); + checkPattern(mojo, "\"_(\\\"test.toolTipText\\\")\"", false); } - protected void checkPattern(String pattern, boolean required) throws IOException { - String[] files = goal.getFiles(); + protected void checkPattern(JaxxGeneratorMojo mojo, String pattern, boolean required) throws IOException { + String[] files = mojo.getFiles(); for (String file : files) { // check we have a the required testId.setTitle(_("test.title")); - File f = new File(getOutDir(), file.substring(0, file.length() - 4) + "java"); - log.info("check generated file " + f); + File f = new File(mojo.getOutJava(), file.substring(0, file.length() - 4) + "java"); + if (mojo.isVerbose()) { + log.info("check generated file " + f); + } assertTrue("generated file " + f + " was not found...", f.exists()); String content = FileUtil.readAsString(f);
participants (1)
-
tchemit@users.labs.libre-entreprise.org