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  
26  public class MavenITmng7051OptionalProfileActivationTest
27          extends AbstractMavenIntegrationTestCase
28  {
29      private static final String PROJECT_PATH = "/mng-7051-optional-profile-activation";
30  
31      public MavenITmng7051OptionalProfileActivationTest()
32      {
33          super( "[4.0.0-alpha-1,)" );
34      }
35  
36      /**
37       * This test verifies that activating a non-existing profile breaks the build.
38       *
39       * @throws Exception in case of failure
40       */
41      public void testActivatingNonExistingProfileBreaks() throws Exception
42      {
43          final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
44          final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
45  
46          verifier.addCliOption( "-P" );
47          verifier.addCliOption( "non-existing-profile" );
48          verifier.setLogFileName( "test-breaking.txt" );
49  
50          try
51          {
52              verifier.executeGoal( "validate" );
53              fail( "Activated a non-existing profile without ? prefix should break the build, but it didn't." );
54          }
55          catch ( VerificationException ve )
56          {
57              // Inspect the reason why the build broke.
58              verifier.verifyTextInLog( "[ERROR] The requested profiles [non-existing-profile] could not be activated or deactivated because they do not exist." );
59          }
60      }
61  
62      /**
63       * This test verifies that activating a non-existing profile does not break the build when it is prefixed with <strong>?</strong>.
64       *
65       * @throws Exception in case of failure
66       */
67      public void testActivatingNonExistingProfileWithQuestionMarkDoesNotBreak() throws Exception
68      {
69          final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
70          final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
71  
72          verifier.addCliOption( "-P" );
73          verifier.addCliOption( "?non-existing-profile" );
74          verifier.setLogFileName( "test-non-breaking.txt" );
75  
76          verifier.executeGoal( "validate" );
77          verifier.verifyErrorFreeLog();
78          verifier.verifyTextInLog( "[INFO] The requested optional profiles [non-existing-profile] could not be activated or deactivated because they do not exist." );
79      }
80  
81      /**
82       * This test verifies that activating both an existing and a non-existing profile does not break the build when it the latter is prefixed with <strong>?</strong>.
83       *
84       * @throws Exception in case of failure
85       */
86      public void testActivatingExistingAndNonExistingProfiles() throws Exception
87      {
88          final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
89          final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
90  
91          verifier.addCliOption( "-P" );
92          verifier.addCliOption( "?non-existing-profile,existing" );
93          verifier.setLogFileName( "test-non-breaking-mixed.txt" );
94  
95          verifier.executeGoal( "validate" );
96          verifier.verifyErrorFreeLog();
97          verifier.verifyTextInLog( "[INFO] The requested optional profiles [non-existing-profile] could not be activated or deactivated because they do not exist." );
98      }
99  
100     /**
101      * This test verifies that deactivating a non-existing profile does not break the build when it is prefixed with <strong>?</strong>.
102      *
103      * @throws Exception in case of failure
104      */
105     public void testDeactivatingNonExistingProfileWithQuestionMarkDoesNotBreak() throws Exception
106     {
107         final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
108         final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
109 
110         verifier.addCliOption( "-P" );
111         verifier.addCliOption( "!?non-existing-profile" );
112         verifier.setLogFileName( "test-deactivating-non-breaking.txt" );
113 
114         verifier.executeGoal( "validate" );
115         verifier.verifyErrorFreeLog();
116         verifier.verifyTextInLog( "[INFO] The requested optional profiles [non-existing-profile] could not be activated or deactivated because they do not exist." );
117     }
118 
119     /**
120      * This test verifies that deactivating both an existing and a non-existing profile does not break the build when it the latter is prefixed with <strong>?</strong>.
121      *
122      * @throws Exception in case of failure
123      */
124     public void testDeactivatingExistingAndNonExistingProfiles() throws Exception
125     {
126         final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
127         final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
128 
129         verifier.addCliOption( "-P" );
130         verifier.addCliOption( "!?non-existing-profile,!existing" );
131         verifier.setLogFileName( "test-deactivating-non-breaking-mixed.txt" );
132 
133         verifier.executeGoal( "validate" );
134         verifier.verifyErrorFreeLog();
135         verifier.verifyTextInLog( "[INFO] The requested optional profiles [non-existing-profile] could not be activated or deactivated because they do not exist." );
136     }
137 }