Package org.apache.maven.plugin.testing
Class AbstractMojoTestCase
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- org.codehaus.plexus.PlexusTestCase
-
- org.apache.maven.plugin.testing.AbstractMojoTestCase
-
- All Implemented Interfaces:
junit.framework.Test
public abstract class AbstractMojoTestCase extends org.codehaus.plexus.PlexusTestCase
TODO: add a way to use the plugin POM for the lookup so that the user doesn't have to provide the a:g:v:goal as the role hint for the mojo lookup. TODO: standardize the execution of the mojo and looking at the results, but could simply have a template method for verifying the state of the mojo post execution TODO: need a way to look at the state of the mojo without adding getters, this could be where we finally specify the expressions which extract values from the mojo. TODO: create a standard directory structure for picking up POMs to make this even easier, we really just need a testing descriptor and make this entirely declarative!- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description private org.codehaus.plexus.component.configurator.ComponentConfigurator
configurator
private org.codehaus.plexus.PlexusContainer
container
private static org.apache.maven.artifact.versioning.DefaultArtifactVersion
MAVEN_VERSION
private java.util.Map<java.lang.String,org.apache.maven.plugin.descriptor.MojoDescriptor>
mojoDescriptors
-
Constructor Summary
Constructors Constructor Description AbstractMojoTestCase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addGuiceModules(java.util.List<com.google.inject.Module> modules)
protected org.apache.maven.plugin.Mojo
configureMojo(org.apache.maven.plugin.Mojo mojo, java.lang.String artifactId, java.io.File pom)
Configure the mojoprotected org.apache.maven.plugin.Mojo
configureMojo(org.apache.maven.plugin.Mojo mojo, org.codehaus.plexus.configuration.PlexusConfiguration pluginConfiguration)
Configure the mojo with the given plexus configurationprotected org.codehaus.plexus.configuration.PlexusConfiguration
extractPluginConfiguration(java.lang.String artifactId, java.io.File pom)
protected org.codehaus.plexus.configuration.PlexusConfiguration
extractPluginConfiguration(java.lang.String artifactId, org.codehaus.plexus.util.xml.Xpp3Dom pomDom)
private void
finalizeMojoConfiguration(org.apache.maven.plugin.MojoExecution mojoExecution)
protected org.codehaus.plexus.PlexusContainer
getContainer()
private java.io.File
getPluginArtifactFile()
Returns best-effort plugin artifact file.protected java.lang.String
getPluginDescriptorLocation()
protected java.lang.String
getPluginDescriptorPath()
protected java.io.InputStream
getPublicDescriptorStream()
protected java.util.Map<java.lang.String,java.lang.Object>
getVariablesAndValuesFromObject(java.lang.Class<?> clazz, java.lang.Object object)
Convenience method to obtain all variables and values from the mojo (including its superclasses) Note: the values in the map are of type Object so the caller is responsible for casting to desired types.protected java.util.Map<java.lang.String,java.lang.Object>
getVariablesAndValuesFromObject(java.lang.Object object)
Convenience method to obtain all variables and values from the mojo (including its superclasses) Note: the values in the map are of type Object so the caller is responsible for casting to desired types.protected java.lang.Object
getVariableValueFromObject(java.lang.Object object, java.lang.String variable)
Convenience method to obtain the value of a variable on a mojo that might not have a getter.protected org.apache.maven.plugin.Mojo
lookupConfiguredMojo(org.apache.maven.execution.MavenSession session, org.apache.maven.plugin.MojoExecution execution)
protected org.apache.maven.plugin.Mojo
lookupConfiguredMojo(org.apache.maven.project.MavenProject project, java.lang.String goal)
protected org.apache.maven.plugin.Mojo
lookupEmptyMojo(java.lang.String goal, java.io.File pom)
Lookup the mojo leveraging the actual subprojects pomprotected org.apache.maven.plugin.Mojo
lookupEmptyMojo(java.lang.String goal, java.lang.String pluginPom)
Lookup an empty mojoprotected org.apache.maven.plugin.Mojo
lookupMojo(java.lang.String goal, java.io.File pom)
Lookup the mojo leveraging the actual subprojects pomprotected org.apache.maven.plugin.Mojo
lookupMojo(java.lang.String goal, java.lang.String pluginPom)
Lookup the mojo leveraging the subproject pomprotected org.apache.maven.plugin.Mojo
lookupMojo(java.lang.String groupId, java.lang.String artifactId, java.lang.String version, java.lang.String goal, org.codehaus.plexus.configuration.PlexusConfiguration pluginConfiguration)
lookup the mojo while we have all of the relavent informationprotected org.apache.maven.execution.MavenSession
newMavenSession(org.apache.maven.project.MavenProject project)
protected org.apache.maven.plugin.MojoExecution
newMojoExecution(java.lang.String goal)
private java.lang.String
resolveFromRootThenParent(org.codehaus.plexus.util.xml.Xpp3Dom pluginPomDom, java.lang.String element)
sometimes the parent element might contain the correct value so generalize that access TODO find out where this is probably done elsewhereprotected void
setUp()
protected void
setupContainer()
protected org.codehaus.plexus.ContainerConfiguration
setupContainerConfiguration()
protected void
setVariableValueToObject(java.lang.Object object, java.lang.String variable, java.lang.Object value)
Convenience method to set values to variables in objects that don't have settersprivate void
validateContainerStatus()
We should make sure this is called in each method that makes use of the container, otherwise we throw ugly NPE's crops up when the subclassing code defines the setUp method but doesn't call super.setUp()-
Methods inherited from class org.codehaus.plexus.PlexusTestCase
customizeContainerConfiguration, customizeContext, getBasedir, getClassLoader, getConfigurationName, getCustomConfigurationName, getResourceAsStream, getTestConfiguration, getTestConfiguration, getTestFile, getTestFile, getTestPath, getTestPath, lookup, lookup, lookup, lookup, release, tearDown, teardownContainer
-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
-
-
-
-
Field Detail
-
MAVEN_VERSION
private static final org.apache.maven.artifact.versioning.DefaultArtifactVersion MAVEN_VERSION
-
configurator
private org.codehaus.plexus.component.configurator.ComponentConfigurator configurator
-
container
private org.codehaus.plexus.PlexusContainer container
-
mojoDescriptors
private java.util.Map<java.lang.String,org.apache.maven.plugin.descriptor.MojoDescriptor> mojoDescriptors
-
-
Method Detail
-
setUp
protected void setUp() throws java.lang.Exception
- Overrides:
setUp
in classorg.codehaus.plexus.PlexusTestCase
- Throws:
java.lang.Exception
-
getPluginArtifactFile
private java.io.File getPluginArtifactFile() throws java.io.IOException
Returns best-effort plugin artifact file.First, attempts to determine parent directory of META-INF directory holding the plugin descriptor. If META-INF parent directory cannot be determined, falls back to test basedir.
- Throws:
java.io.IOException
-
getPublicDescriptorStream
protected java.io.InputStream getPublicDescriptorStream() throws java.lang.Exception
- Throws:
java.lang.Exception
-
getPluginDescriptorPath
protected java.lang.String getPluginDescriptorPath()
-
getPluginDescriptorLocation
protected java.lang.String getPluginDescriptorLocation()
-
setupContainer
protected void setupContainer()
- Overrides:
setupContainer
in classorg.codehaus.plexus.PlexusTestCase
-
addGuiceModules
protected void addGuiceModules(java.util.List<com.google.inject.Module> modules)
- Since:
- 3.0.0
-
setupContainerConfiguration
protected org.codehaus.plexus.ContainerConfiguration setupContainerConfiguration()
-
getContainer
protected org.codehaus.plexus.PlexusContainer getContainer()
- Overrides:
getContainer
in classorg.codehaus.plexus.PlexusTestCase
-
lookupMojo
protected org.apache.maven.plugin.Mojo lookupMojo(java.lang.String goal, java.lang.String pluginPom) throws java.lang.Exception
Lookup the mojo leveraging the subproject pom- Parameters:
goal
-pluginPom
-- Returns:
- a Mojo instance
- Throws:
java.lang.Exception
-
lookupEmptyMojo
protected org.apache.maven.plugin.Mojo lookupEmptyMojo(java.lang.String goal, java.lang.String pluginPom) throws java.lang.Exception
Lookup an empty mojo- Parameters:
goal
-pluginPom
-- Returns:
- a Mojo instance
- Throws:
java.lang.Exception
-
lookupMojo
protected org.apache.maven.plugin.Mojo lookupMojo(java.lang.String goal, java.io.File pom) throws java.lang.Exception
Lookup the mojo leveraging the actual subprojects pom- Parameters:
goal
-pom
-- Returns:
- a Mojo instance
- Throws:
java.lang.Exception
-
lookupEmptyMojo
protected org.apache.maven.plugin.Mojo lookupEmptyMojo(java.lang.String goal, java.io.File pom) throws java.lang.Exception
Lookup the mojo leveraging the actual subprojects pom- Parameters:
goal
-pom
-- Returns:
- a Mojo instance
- Throws:
java.lang.Exception
-
lookupMojo
protected org.apache.maven.plugin.Mojo lookupMojo(java.lang.String groupId, java.lang.String artifactId, java.lang.String version, java.lang.String goal, org.codehaus.plexus.configuration.PlexusConfiguration pluginConfiguration) throws java.lang.Exception
lookup the mojo while we have all of the relavent information- Parameters:
groupId
-artifactId
-version
-goal
-pluginConfiguration
-- Returns:
- a Mojo instance
- Throws:
java.lang.Exception
-
lookupConfiguredMojo
protected org.apache.maven.plugin.Mojo lookupConfiguredMojo(org.apache.maven.project.MavenProject project, java.lang.String goal) throws java.lang.Exception
- Parameters:
project
-goal
-- Returns:
- Throws:
java.lang.Exception
- Since:
- 2.0
-
lookupConfiguredMojo
protected org.apache.maven.plugin.Mojo lookupConfiguredMojo(org.apache.maven.execution.MavenSession session, org.apache.maven.plugin.MojoExecution execution) throws java.lang.Exception, org.codehaus.plexus.component.configurator.ComponentConfigurationException
- Parameters:
session
-execution
-- Returns:
- Throws:
java.lang.Exception
org.codehaus.plexus.component.configurator.ComponentConfigurationException
- Since:
- 2.0
-
newMavenSession
protected org.apache.maven.execution.MavenSession newMavenSession(org.apache.maven.project.MavenProject project)
- Parameters:
project
-- Returns:
- Since:
- 2.0
-
newMojoExecution
protected org.apache.maven.plugin.MojoExecution newMojoExecution(java.lang.String goal)
- Parameters:
goal
-- Returns:
- Since:
- 2.0
-
finalizeMojoConfiguration
private void finalizeMojoConfiguration(org.apache.maven.plugin.MojoExecution mojoExecution)
-
extractPluginConfiguration
protected org.codehaus.plexus.configuration.PlexusConfiguration extractPluginConfiguration(java.lang.String artifactId, java.io.File pom) throws java.lang.Exception
- Parameters:
artifactId
-pom
-- Returns:
- the plexus configuration
- Throws:
java.lang.Exception
-
extractPluginConfiguration
protected org.codehaus.plexus.configuration.PlexusConfiguration extractPluginConfiguration(java.lang.String artifactId, org.codehaus.plexus.util.xml.Xpp3Dom pomDom) throws java.lang.Exception
- Parameters:
artifactId
-pomDom
-- Returns:
- the plexus configuration
- Throws:
java.lang.Exception
-
configureMojo
protected org.apache.maven.plugin.Mojo configureMojo(org.apache.maven.plugin.Mojo mojo, java.lang.String artifactId, java.io.File pom) throws java.lang.Exception
Configure the mojo- Parameters:
mojo
-artifactId
-pom
-- Returns:
- a Mojo instance
- Throws:
java.lang.Exception
-
configureMojo
protected org.apache.maven.plugin.Mojo configureMojo(org.apache.maven.plugin.Mojo mojo, org.codehaus.plexus.configuration.PlexusConfiguration pluginConfiguration) throws java.lang.Exception
Configure the mojo with the given plexus configuration- Parameters:
mojo
-pluginConfiguration
-- Returns:
- a Mojo instance
- Throws:
java.lang.Exception
-
getVariableValueFromObject
protected java.lang.Object getVariableValueFromObject(java.lang.Object object, java.lang.String variable) throws java.lang.IllegalAccessException
Convenience method to obtain the value of a variable on a mojo that might not have a getter. NOTE: the caller is responsible for casting to to what the desired type is.- Parameters:
object
-variable
-- Returns:
- object value of variable
- Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
-
getVariablesAndValuesFromObject
protected java.util.Map<java.lang.String,java.lang.Object> getVariablesAndValuesFromObject(java.lang.Object object) throws java.lang.IllegalAccessException
Convenience method to obtain all variables and values from the mojo (including its superclasses) Note: the values in the map are of type Object so the caller is responsible for casting to desired types.- Parameters:
object
-- Returns:
- map of variable names and values
- Throws:
java.lang.IllegalAccessException
-
getVariablesAndValuesFromObject
protected java.util.Map<java.lang.String,java.lang.Object> getVariablesAndValuesFromObject(java.lang.Class<?> clazz, java.lang.Object object) throws java.lang.IllegalAccessException
Convenience method to obtain all variables and values from the mojo (including its superclasses) Note: the values in the map are of type Object so the caller is responsible for casting to desired types.- Parameters:
clazz
-object
-- Returns:
- map of variable names and values
- Throws:
java.lang.IllegalAccessException
-
setVariableValueToObject
protected void setVariableValueToObject(java.lang.Object object, java.lang.String variable, java.lang.Object value) throws java.lang.IllegalAccessException
Convenience method to set values to variables in objects that don't have setters- Parameters:
object
-variable
-value
-- Throws:
java.lang.IllegalAccessException
-
resolveFromRootThenParent
private java.lang.String resolveFromRootThenParent(org.codehaus.plexus.util.xml.Xpp3Dom pluginPomDom, java.lang.String element) throws java.lang.Exception
sometimes the parent element might contain the correct value so generalize that access TODO find out where this is probably done elsewhere- Parameters:
pluginPomDom
-element
-- Returns:
- Throws:
java.lang.Exception
-
validateContainerStatus
private void validateContainerStatus() throws java.lang.Exception
We should make sure this is called in each method that makes use of the container, otherwise we throw ugly NPE's crops up when the subclassing code defines the setUp method but doesn't call super.setUp()- Throws:
java.lang.Exception
-
-