View Javadoc
1   package org.apache.maven.it;
2   
3   import java.io.File;
4   import java.util.Properties;
5   
6   import org.apache.maven.it.util.ResourceExtractor;
7   
8   public class MavenITmng5774ConfigurationProcessorsTest
9       extends AbstractMavenIntegrationTestCase
10  {
11      public MavenITmng5774ConfigurationProcessorsTest()
12      {
13          super( "(3.2.5,)" );
14      }
15  
16      public void testBehaviourWhereThereIsOneUserSuppliedConfigurationProcessor()
17          throws Exception
18      {
19          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5774-configuration-processors" );
20  
21          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
22          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
23  
24          verifier = newVerifier( new File( testDir, "build-with-one-processor-valid" ).getAbsolutePath() );
25          verifier.deleteDirectory( "target" );
26          verifier.deleteArtifacts( "org.apache.maven.its.it-configuration-processors" );
27          verifier.getCliOptions().add( "-s" );
28          verifier.getCliOptions().add( new File( testDir, "settings.xml" ).getAbsolutePath() );
29          verifier.executeGoal( "process-resources" );
30          verifier.verifyErrorFreeLog();
31          // Making sure our configuration processor executes
32          verifier.verifyTextInLog( "[INFO] ConfigurationProcessorOne.process()" );
33          // We have a property value injected by our configuration processor. Make sure it's correct
34          verifier.assertFilePresent( "target/classes/result.properties" );
35          Properties result = verifier.loadProperties( "target/classes/result.properties" );
36          assertEquals( "yes", result.getProperty( "configurationProcessorContributedValue" ) );
37          verifier.resetStreams();
38      }
39  
40      public void testBehaviourWhereThereAreTwoUserSuppliedConfigurationProcessor()
41          throws Exception
42      {
43          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5774-configuration-processors" );
44  
45          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
46          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
47  
48          verifier = newVerifier( new File( testDir, "build-with-two-processors-invalid" ).getAbsolutePath() );
49          verifier.deleteDirectory( "target" );
50          verifier.deleteArtifacts( "org.apache.maven.its.it-configuration-processors" );
51          verifier.getCliOptions().add( "-s" );
52          verifier.getCliOptions().add( new File( testDir, "settings.xml" ).getAbsolutePath() );
53          try
54          {
55              verifier.executeGoal( "process-resources" );
56              fail( "We expected this invocation to fail because of too many user supplied configuration processors being present" );
57          }
58          catch ( VerificationException e )
59          {
60              verifier.verifyTextInLog( "There can only be one user supplied ConfigurationProcessor" );
61          }
62          verifier.resetStreams();
63      }
64  }