View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  import java.util.Properties;
26  
27  import static org.junit.Assert.assertNotEquals;
28  
29  /**
30   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-469">MNG-469</a>.
31   *
32   * @author Benjamin Bentmann
33   *
34   */
35  public class MavenITmng0469ReportConfigTest
36      extends AbstractMavenIntegrationTestCase
37  {
38  
39      public MavenITmng0469ReportConfigTest()
40      {
41          super( "[2.0.0,)" );
42      }
43  
44      /**
45       * Test that {@code <reporting>} configuration also affects build plugins unless {@code <build>} configuration is also given.
46       *
47       * @throws Exception in case of failure
48       */
49      public void testitReportConfigOverridesBuildDefaults()
50          throws Exception
51      {
52          requiresMavenVersion( "[2.0.0,3.0-alpha-1)" );
53  
54          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0469/test0" );
55  
56          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
57          verifier.deleteDirectory( "target" );
58          verifier.setAutoclean( false );
59          verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT:config" );
60          verifier.verifyErrorFreeLog();
61          verifier.resetStreams();
62  
63          Properties props = verifier.loadProperties( "target/config.properties" );
64          assertEquals( "not-the-default-value", props.getProperty( "defaultParam" ) );
65      }
66  
67      /**
68       * Test that {@code <build>} configuration dominates {@code <reporting>} configuration for build goals.
69       *
70       * @throws Exception in case of failure
71       */
72      public void testitBuildConfigDominantDuringBuild()
73          throws Exception
74      {
75          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0469/test1" );
76  
77          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
78          verifier.deleteDirectory( "target" );
79          verifier.setAutoclean( false );
80          verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-configuration:2.1-SNAPSHOT:config" );
81          verifier.assertFilePresent( "target/build.txt" );
82          verifier.assertFileNotPresent( "target/reporting.txt" );
83          verifier.verifyErrorFreeLog();
84          verifier.resetStreams();
85      }
86  
87      /**
88       * Test that {@code <build>} configuration does not affect report goals.
89       *
90       * @throws Exception in case of failure
91       */
92      public void testitBuildConfigIrrelevantForReports()
93          throws Exception
94      {
95          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0469/test2" );
96  
97          Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
98          verifier.deleteDirectory( "target" );
99          verifier.setAutoclean( false );
100         if ( matchesVersionRange( "(,3.0-alpha-1)" ) )
101         {
102             verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-site:2.1-SNAPSHOT:generate" );
103             verifier.assertFilePresent( "target/site/info.properties" );
104         }
105         else
106         {
107             verifier.executeGoal( "validate" );
108             Properties props = verifier.loadProperties( "target/config.properties" );
109             assertEquals( "maven-it-plugin-site", props.getProperty( "project.reporting.plugins.0.artifactId" ) );
110             assertNotEquals( "fail.properties", props.getProperty( "project.reporting.plugins.0.configuration.children.infoFile.0.value" ) );
111         }
112         verifier.verifyErrorFreeLog();
113         verifier.resetStreams();
114     }
115 
116 }