org.nuiton.plugin
Class AbstractMojoTest<P extends org.nuiton.plugin.Plugin>

java.lang.Object
  extended by org.nuiton.plugin.AbstractMojoTest<P>
Type Parameters:
P - type of goal to test
Direct Known Subclasses:
SendEmailMojoTest

public abstract class AbstractMojoTest<P extends org.nuiton.plugin.Plugin>
extends Object

Base test class for a mojo.

Note: replace the previous class org.nuiton.util.BasePluginTestCase.

Inside each test method, we can use the following objects :

To change the behaviour of initialization of mojo, you can override the following methods :

Since:
1.0.3
Author:
tchemit

Nested Class Summary
protected  class AbstractMojoTest.MojoTestRule
          To offer inside each test method (annotated by a Test) the following properties :

AbstractMojoTest.MojoTestRule.testDir : location where to find resources for the test AbstractMojoTest.MojoTestRule.pomFile : location of the pom file to use to build the mojo AbstractMojoTest.MojoTestRule.mojo : the instanciated and initialized mojo

 
Field Summary
protected static File basedir
          the basedir of the project
protected static org.apache.commons.logging.Log log
          Test logger
 AbstractMojoTest.MojoTestRule name
          Your test rule which offers methodName, testDir, pomFile and mojo inside test methods.
protected static File testBasedir
          the basedir of all tests (by convention getBasedir()/target/test-classes).
 
Constructor Summary
AbstractMojoTest()
           
 
Method Summary
 void checkExistsPattern(File file, String pattern, String encoding, boolean required)
          Checks on the given file that : file exists the given pattern exists required = true (or not required = false) in the content of the file.
 void checkPattern(File file, String content, String pattern, boolean required)
           
protected  void clearMojo(P mojo)
           
protected  P createMojo(File pomFile, String goalName)
          Create the mojo base on the given pomFile for the given goalName.
 File getBasedir()
           
protected abstract  String getGoalName(String methodName)
          Obtain the name of the goal according to the methodName.
protected  String getMethodName()
           
protected  P getMojo()
           
protected  File getPomFile()
           
protected  File getPomFile(File testDir, String methodName, String goalName)
          Obtain the location of the pom file to use for next mojo test.
 String getRelativePathFromBasedir(File f)
           
 String getRelativePathFromTestBasedir(File f)
           
 File getTestBasedir()
           
protected  File getTestDir()
           
protected  File getTestDir(String methodName, String goalName)
          Obtain the location of the directory where to find resources for the next test.
protected  boolean isVerbose()
           
protected  void setUpMojo(P mojo, File pomFile)
          Initialize the given mojo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
Test logger


basedir

protected static File basedir
the basedir of the project


testBasedir

protected static File testBasedir
the basedir of all tests (by convention getBasedir()/target/test-classes).


name

public AbstractMojoTest.MojoTestRule name
Your test rule which offers methodName, testDir, pomFile and mojo inside test methods.

Constructor Detail

AbstractMojoTest

public AbstractMojoTest()
Method Detail

getBasedir

public File getBasedir()

getTestBasedir

public File getTestBasedir()

getRelativePathFromBasedir

public String getRelativePathFromBasedir(File f)

getRelativePathFromTestBasedir

public String getRelativePathFromTestBasedir(File f)

getGoalName

protected abstract String getGoalName(String methodName)
Obtain the name of the goal according to the methodName.

By convention, we should consider that a test class use always the same goal's name.

Parameters:
methodName - the name of the next test to execute.
Returns:
the name of the goal to test for the given method test name.

getTestDir

protected File getTestDir(String methodName,
                          String goalName)
Obtain the location of the directory where to find resources for the next test.

By convention, will be the package named by the test class name from the getTestBasedir().

Parameters:
methodName - the method of the next test to execute
goalName - the common goal name to use
Returns:
the directory where to find resources for the test

getPomFile

protected File getPomFile(File testDir,
                          String methodName,
                          String goalName)
Obtain the location of the pom file to use for next mojo test.

By default, the pom file is the file with name methodName+".xml" in the testDir.

Parameters:
testDir - the location of resources for the next test (is the result of the method getTestDir(String, String).
methodName - the name of the next test
goalName - the name of the common goal
Returns:
the location of the pom file for the next mojo test.

createMojo

protected P createMojo(File pomFile,
                       String goalName)
                                                 throws Exception
Create the mojo base on the given pomFile for the given goalName.

Parameters:
pomFile - the location of the pom file
goalName - the name of the goal to lookup
Returns:
the instanciated mojo
Throws:
Exception - if any problem while creating the mojo

setUpMojo

protected void setUpMojo(P mojo,
                         File pomFile)
                  throws Exception
Initialize the given mojo.

Parameters:
mojo - the instanciate mojo
pomFile - the pom file used to instanciate the mojo
Throws:
Exception - if any pb

getMojo

protected P getMojo()

getMethodName

protected String getMethodName()

getPomFile

protected File getPomFile()

getTestDir

protected File getTestDir()

isVerbose

protected boolean isVerbose()

clearMojo

protected void clearMojo(P mojo)

checkExistsPattern

public void checkExistsPattern(File file,
                               String pattern,
                               String encoding,
                               boolean required)
                        throws IOException
Checks on the given file that :

Parameters:
file - the file to test
pattern - the pattern to search
encoding - encoding of the file to read
required - flag to says if pattern should (or not) be found in file's content
Throws:
IOException - if could not read file

checkPattern

public void checkPattern(File file,
                         String content,
                         String pattern,
                         boolean required)
                  throws IOException
Throws:
IOException


Copyright © 2009-2010 CodeLutin. All Rights Reserved.