mirror of https://github.com/apache/maven.git
[MNG-6819] Refactor unit tests for ModelInterpolator
This commit is contained in:
parent
14c9e156bc
commit
be3c4eb406
|
@ -29,9 +29,9 @@ import org.apache.maven.model.Scm;
|
||||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.SimpleProblemCollector;
|
import org.apache.maven.model.building.SimpleProblemCollector;
|
||||||
import org.apache.maven.model.path.PathTranslator;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -42,19 +42,19 @@ import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jdcasey
|
* @author jdcasey
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractModelInterpolatorTest
|
public abstract class AbstractModelInterpolatorTest
|
||||||
extends TestCase
|
|
||||||
{
|
{
|
||||||
|
protected ModelInterpolator interpolator;
|
||||||
private Properties context;
|
private Properties context;
|
||||||
|
|
||||||
protected void setUp()
|
@Before
|
||||||
throws Exception
|
public void setUp()
|
||||||
{
|
{
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
context = new Properties();
|
context = new Properties();
|
||||||
context.put( "basedir", "myBasedir" );
|
context.put( "basedir", "myBasedir" );
|
||||||
context.put( "project.baseUri", "myBaseUri" );
|
context.put( "project.baseUri", "myBaseUri" );
|
||||||
|
@ -68,24 +68,13 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
assertEquals( "Expected no fatals", 0, collector.getFatals().size() );
|
assertEquals( "Expected no fatals", 0, collector.getFatals().size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void assertCollectorState( int numFatals, int numErrors, int numWarnings, SimpleProblemCollector collector )
|
||||||
* @deprecated instead use {@link #assertCollectorState(int, int, int, SimpleProblemCollector)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected void assertColllectorState( int numFatals, int numErrors, int numWarnings,
|
|
||||||
SimpleProblemCollector collector )
|
|
||||||
{
|
{
|
||||||
assertEquals( "Errors", numErrors, collector.getErrors().size() );
|
assertEquals( "Errors", numErrors, collector.getErrors().size() );
|
||||||
assertEquals( "Warnings", numWarnings, collector.getWarnings().size() );
|
assertEquals( "Warnings", numWarnings, collector.getWarnings().size() );
|
||||||
assertEquals( "Fatals", numFatals, collector.getFatals().size() );
|
assertEquals( "Fatals", numFatals, collector.getFatals().size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertCollectorState( int numFatals, int numErrors, int numWarnings,
|
|
||||||
SimpleProblemCollector collector )
|
|
||||||
{
|
|
||||||
assertColllectorState(numFatals, numErrors, numWarnings, collector);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ModelBuildingRequest createModelBuildingRequest( Properties p )
|
private ModelBuildingRequest createModelBuildingRequest( Properties p )
|
||||||
{
|
{
|
||||||
ModelBuildingRequest config = new DefaultModelBuildingRequest();
|
ModelBuildingRequest config = new DefaultModelBuildingRequest();
|
||||||
|
@ -96,6 +85,7 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat()
|
public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat()
|
||||||
{
|
{
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
|
@ -121,13 +111,13 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
|
|
||||||
Date secondTestDate = cal.getTime();
|
Date secondTestDate = cal.getTime();
|
||||||
|
|
||||||
SimpleDateFormat format =
|
SimpleDateFormat format = new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
|
||||||
new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
|
|
||||||
format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
|
format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
|
||||||
assertEquals( "1976-11-11T00:16:00Z", format.format( firstTestDate ) );
|
assertEquals( "1976-11-11T00:16:00Z", format.format( firstTestDate ) );
|
||||||
assertEquals( "1976-11-11T23:16:00Z", format.format( secondTestDate ) );
|
assertEquals( "1976-11-11T23:16:00Z", format.format( secondTestDate ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover()
|
public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover()
|
||||||
{
|
{
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
|
@ -146,15 +136,14 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
|
|
||||||
Date secondTestDate = cal.getTime();
|
Date secondTestDate = cal.getTime();
|
||||||
|
|
||||||
SimpleDateFormat format =
|
SimpleDateFormat format = new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
|
||||||
new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
|
|
||||||
format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
|
format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
|
||||||
assertEquals( "2014-06-15T23:16:00Z", format.format( firstTestDate ) );
|
assertEquals( "2014-06-15T23:16:00Z", format.format( firstTestDate ) );
|
||||||
assertEquals( "2014-11-16T00:16:00Z", format.format( secondTestDate ) );
|
assertEquals( "2014-11-16T00:16:00Z", format.format( secondTestDate ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldNotThrowExceptionOnReferenceToNonExistentValue()
|
@Test
|
||||||
throws Exception
|
public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
|
||||||
|
@ -166,15 +155,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
|
|
||||||
assertProblemFree( collector );
|
assertProblemFree( collector );
|
||||||
assertEquals( "${test}/somepath", out.getScm().getConnection() );
|
assertEquals( "${test}/somepath", out.getScm().getConnection() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldThrowExceptionOnRecursiveScmConnectionReference()
|
@Test
|
||||||
throws Exception
|
public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
|
||||||
|
@ -183,22 +172,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
|
|
||||||
model.setScm( scm );
|
model.setScm( scm );
|
||||||
|
|
||||||
try
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
{
|
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector );
|
interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector );
|
||||||
assertCollectorState( 0, 1, 0, collector );
|
assertCollectorState( 0, 1, 0, collector );
|
||||||
}
|
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression()
|
@Test
|
||||||
throws Exception
|
public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
|
||||||
|
@ -212,16 +194,16 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
|
|
||||||
assertProblemFree( collector );
|
assertProblemFree( collector );
|
||||||
|
|
||||||
assertEquals( "test/somepath", out.getScm().getConnection() );
|
assertEquals( "test/somepath", out.getScm().getConnection() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldInterpolateOrganizationNameCorrectly()
|
@Test
|
||||||
throws Exception
|
public void shouldInterpolateOrganizationNameCorrectly() throws Exception
|
||||||
{
|
{
|
||||||
String orgName = "MyCo";
|
String orgName = "MyCo";
|
||||||
|
|
||||||
|
@ -235,15 +217,14 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
|
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
new SimpleProblemCollector() );
|
||||||
new SimpleProblemCollector() );
|
|
||||||
|
|
||||||
assertEquals( orgName + " Tools", out.getName() );
|
assertEquals( orgName + " Tools", out.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion()
|
@Test
|
||||||
throws Exception
|
public void shouldInterpolateDependencyVersionToSetSameAsProjectVersion() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
model.setVersion( "3.8.1" );
|
model.setVersion( "3.8.1" );
|
||||||
|
@ -256,15 +237,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
assertCollectorState(0, 0, 1, collector );
|
assertCollectorState( 0, 0, 1, collector );
|
||||||
|
|
||||||
assertEquals( "3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
|
assertEquals( "3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldNotInterpolateDependencyVersionWithInvalidReference()
|
@Test
|
||||||
throws Exception
|
public void testShouldNotInterpolateDependencyVersionWithInvalidReference() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
model.setVersion( "3.8.1" );
|
model.setVersion( "3.8.1" );
|
||||||
|
@ -292,15 +273,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
assertProblemFree( collector );
|
assertProblemFree( collector );
|
||||||
|
|
||||||
assertEquals( "${something}", ( out.getDependencies().get( 0 ) ).getVersion() );
|
assertEquals( "${something}", ( out.getDependencies().get( 0 ) ).getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTwoReferences()
|
@Test
|
||||||
throws Exception
|
public void testTwoReferences() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
model.setVersion( "3.8.1" );
|
model.setVersion( "3.8.1" );
|
||||||
|
@ -314,15 +295,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
assertCollectorState( 0, 0, 2, collector );
|
assertCollectorState( 0, 0, 2, collector );
|
||||||
|
|
||||||
assertEquals( "foo-3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
|
assertEquals( "foo-3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBasedir()
|
@Test
|
||||||
throws Exception
|
public void testBasedir() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
model.setVersion( "3.8.1" );
|
model.setVersion( "3.8.1" );
|
||||||
|
@ -343,8 +324,8 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
assertEquals( "file://localhost/myBasedir/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() );
|
assertEquals( "file://localhost/myBasedir/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBaseUri()
|
@Test
|
||||||
throws Exception
|
public void testBaseUri() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
model.setVersion( "3.8.1" );
|
model.setVersion( "3.8.1" );
|
||||||
|
@ -365,10 +346,10 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
assertEquals( "myBaseUri/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() );
|
assertEquals( "myBaseUri/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnvars()
|
@Test
|
||||||
throws Exception
|
public void testEnvars() throws Exception
|
||||||
{
|
{
|
||||||
Properties context = new Properties();
|
Properties context = new Properties();
|
||||||
|
|
||||||
context.put( "env.HOME", "/path/to/home" );
|
context.put( "env.HOME", "/path/to/home" );
|
||||||
|
|
||||||
|
@ -383,15 +364,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
assertProblemFree( collector );
|
assertProblemFree( collector );
|
||||||
|
|
||||||
assertEquals( "/path/to/home", out.getProperties().getProperty( "outputDirectory" ) );
|
assertEquals( "/path/to/home", out.getProperties().getProperty( "outputDirectory" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnvarExpressionThatEvaluatesToNullReturnsTheLiteralString()
|
@Test
|
||||||
throws Exception
|
public void envarExpressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
|
||||||
|
@ -404,15 +385,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
assertProblemFree( collector );
|
assertProblemFree( collector );
|
||||||
|
|
||||||
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" );
|
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExpressionThatEvaluatesToNullReturnsTheLiteralString()
|
@Test
|
||||||
throws Exception
|
public void expressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
|
||||||
|
@ -425,15 +406,15 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model out =
|
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
|
||||||
interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
|
collector );
|
||||||
assertProblemFree( collector );
|
assertProblemFree( collector );
|
||||||
|
|
||||||
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" );
|
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly()
|
@Test
|
||||||
throws Exception
|
public void shouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly() throws Exception
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
|
||||||
|
@ -472,8 +453,8 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() );
|
assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldInterpolateUnprefixedBasedirExpression()
|
@Test
|
||||||
throws Exception
|
public void shouldInterpolateUnprefixedBasedirExpression() throws Exception
|
||||||
{
|
{
|
||||||
File basedir = new File( "/test/path" );
|
File basedir = new File( "/test/path" );
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -485,21 +466,57 @@ public abstract class AbstractModelInterpolatorTest
|
||||||
ModelInterpolator interpolator = createInterpolator();
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
|
||||||
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
final SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
Model result = interpolator.interpolateModel( model, basedir, createModelBuildingRequest( context ), collector );
|
Model result = interpolator.interpolateModel( model, basedir, createModelBuildingRequest( context ),
|
||||||
assertProblemFree( collector );
|
collector );
|
||||||
|
assertProblemFree( collector );
|
||||||
|
|
||||||
|
|
||||||
List<Dependency> rDeps = result.getDependencies();
|
List<Dependency> rDeps = result.getDependencies();
|
||||||
assertNotNull( rDeps );
|
assertNotNull( rDeps );
|
||||||
assertEquals( 1, rDeps.size() );
|
assertEquals( 1, rDeps.size() );
|
||||||
assertEquals( new File( basedir, "artifact.jar" ).getAbsolutePath(),
|
assertEquals( new File( basedir, "artifact.jar" ).getAbsolutePath(),
|
||||||
new File( rDeps.get( 0 ).getSystemPath() ).getAbsolutePath() );
|
new File( rDeps.get( 0 ).getSystemPath() ).getAbsolutePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ModelInterpolator createInterpolator( PathTranslator translator )
|
@Test
|
||||||
throws Exception;
|
public void testRecursiveExpressionCycleNPE() throws Exception
|
||||||
|
{
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty( "aa", "${bb}" );
|
||||||
|
props.setProperty( "bb", "${aa}" );
|
||||||
|
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
|
||||||
|
|
||||||
protected abstract ModelInterpolator createInterpolator()
|
Model model = new Model();
|
||||||
throws Exception;
|
model.setProperties( props );
|
||||||
|
|
||||||
|
SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
interpolator.interpolateModel( model, null, request, collector );
|
||||||
|
|
||||||
|
assertCollectorState( 0, 2, 0, collector );
|
||||||
|
assertTrue( collector.getErrors().get( 0 ).contains( "Detected the following recursive expression cycle" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRecursiveExpressionCycleBaseDir() throws Exception
|
||||||
|
{
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty( "basedir", "${basedir}" );
|
||||||
|
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
|
||||||
|
|
||||||
|
Model model = new Model();
|
||||||
|
model.setProperties( props );
|
||||||
|
|
||||||
|
SimpleProblemCollector collector = new SimpleProblemCollector();
|
||||||
|
ModelInterpolator interpolator = createInterpolator();
|
||||||
|
interpolator.interpolateModel( model, null, request, collector );
|
||||||
|
|
||||||
|
assertCollectorState( 0, 1, 0, collector );
|
||||||
|
assertEquals(
|
||||||
|
"Resolving expression: '${basedir}': Detected the following recursive expression cycle in 'basedir': [basedir]",
|
||||||
|
collector.getErrors().get( 0 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract ModelInterpolator createInterpolator() throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.SimpleProblemCollector;
|
import org.apache.maven.model.building.SimpleProblemCollector;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -37,6 +38,8 @@ import java.util.concurrent.FutureTask;
|
||||||
import static org.hamcrest.CoreMatchers.anyOf;
|
import static org.hamcrest.CoreMatchers.anyOf;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StringSearchModelInterpolatorTest - not in use
|
* StringSearchModelInterpolatorTest - not in use
|
||||||
|
@ -48,28 +51,19 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
public class StringSearchModelInterpolatorTest
|
public class StringSearchModelInterpolatorTest
|
||||||
extends AbstractModelInterpolatorTest
|
extends AbstractModelInterpolatorTest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected ModelInterpolator interpolator;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp()
|
public void setUp()
|
||||||
throws Exception
|
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
interpolator = new StringSearchModelInterpolator();
|
interpolator = new StringSearchModelInterpolator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ModelInterpolator createInterpolator( org.apache.maven.model.path.PathTranslator translator )
|
|
||||||
{
|
|
||||||
return this.interpolator;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ModelInterpolator createInterpolator()
|
protected ModelInterpolator createInterpolator()
|
||||||
{
|
{
|
||||||
return this.interpolator;
|
return this.interpolator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateStringArray()
|
public void testInterpolateStringArray()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -99,6 +93,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithStringArrayField()
|
public void testInterpolateObjectWithStringArrayField()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -123,6 +118,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "value2", obj.values[1] );
|
assertEquals( "value2", obj.values[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithStringListField()
|
public void testInterpolateObjectWithStringListField()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -149,6 +145,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "value2", obj.values.get( 1 ) );
|
assertEquals( "value2", obj.values.get( 1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithStringListFieldAndOneLiteralValue()
|
public void testInterpolateObjectWithStringListFieldAndOneLiteralValue()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -175,6 +172,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "value2", obj.values.get( 1 ) );
|
assertEquals( "value2", obj.values.get( 1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithUnmodifiableStringListField()
|
public void testInterpolateObjectWithUnmodifiableStringListField()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -198,6 +196,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "${key}", obj.values.get( 0 ) );
|
assertEquals( "${key}", obj.values.get( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithStringArrayListField()
|
public void testInterpolateObjectWithStringArrayListField()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -228,6 +227,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "value4", ( (String[]) obj.values.get( 1 ) )[1] );
|
assertEquals( "value4", ( (String[]) obj.values.get( 1 ) )[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithStringToStringMapField()
|
public void testInterpolateObjectWithStringToStringMapField()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -254,6 +254,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "value2", obj.values.get( "key2" ) );
|
assertEquals( "value2", obj.values.get( "key2" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue()
|
public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -280,6 +281,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "value2", obj.values.get( "key2" ) );
|
assertEquals( "value2", obj.values.get( "key2" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithUnmodifiableStringToStringMapField()
|
public void testInterpolateObjectWithUnmodifiableStringToStringMapField()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -303,6 +305,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "${key}", obj.values.get( "key" ) );
|
assertEquals( "${key}", obj.values.get( "key" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithStringToStringArrayMapField()
|
public void testInterpolateObjectWithStringToStringArrayMapField()
|
||||||
{
|
{
|
||||||
Model model = new Model();
|
Model model = new Model();
|
||||||
|
@ -333,6 +336,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
assertEquals( "value4", ( (String[]) obj.values.get( "key2" ) )[1] );
|
assertEquals( "value4", ( (String[]) obj.values.get( "key2" ) )[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInterpolateObjectWithPomFile()
|
public void testInterpolateObjectWithPomFile()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -364,6 +368,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
) ) );
|
) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNotInterpolateObjectWithFile()
|
public void testNotInterpolateObjectWithFile()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -411,6 +416,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
return (Map<Class<?>, ?>) field.get( null );
|
return (Map<Class<?>, ?>) field.get( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNotInterpolateFile()
|
public void testNotInterpolateFile()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -438,6 +444,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConcurrentInterpolation()
|
public void testConcurrentInterpolation()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -452,7 +459,6 @@ public class StringSearchModelInterpolatorTest
|
||||||
|
|
||||||
final StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator();
|
final StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator();
|
||||||
|
|
||||||
|
|
||||||
int numItems = 100;
|
int numItems = 100;
|
||||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
@ -497,7 +503,6 @@ public class StringSearchModelInterpolatorTest
|
||||||
return new ObjectWithMixedProtection( values, values2, values3, "${key5}" );
|
return new ObjectWithMixedProtection( values, values2, values3, "${key5}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class ObjectWithStringArrayField
|
private static final class ObjectWithStringArrayField
|
||||||
{
|
{
|
||||||
private final String[] values;
|
private final String[] values;
|
||||||
|
@ -567,6 +572,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFinalFieldsExcludedFromInterpolation()
|
public void testFinalFieldsExcludedFromInterpolation()
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
|
@ -578,7 +584,7 @@ public class StringSearchModelInterpolatorTest
|
||||||
StringSearchModelInterpolator interpolator = new StringSearchModelInterpolator();
|
StringSearchModelInterpolator interpolator = new StringSearchModelInterpolator();
|
||||||
interpolator.interpolateObject( new ClassWithFinalField(), new Model(), null, request, problems );
|
interpolator.interpolateObject( new ClassWithFinalField(), new Model(), null, request, problems );
|
||||||
|
|
||||||
assertProblemFree( problems );
|
assertProblemFree( problems );
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ClassWithFinalField
|
static class ClassWithFinalField
|
||||||
|
@ -586,7 +592,8 @@ public class StringSearchModelInterpolatorTest
|
||||||
public static final String CONSTANT = "${expression}";
|
public static final String CONSTANT = "${expression}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocationTrackerShouldBeExcludedFromInterpolation()
|
@Test
|
||||||
|
public void locationTrackerShouldBeExcludedFromInterpolation()
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.setProperty( "expression", "value" );
|
props.setProperty( "expression", "value" );
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package org.apache.maven.model.interpolation;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class StringVisitorModelInterpolatorTest extends AbstractModelInterpolatorTest
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
interpolator = new StringVisitorModelInterpolator();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelInterpolator createInterpolator()
|
||||||
|
{
|
||||||
|
return this.interpolator;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue