View Javadoc
1   package org.apache.maven.plugins.enforcer;
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 java.io.IOException;
23  
24  import junit.framework.TestCase;
25  
26  import org.apache.maven.enforcer.rule.api.EnforcerRule;
27  import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
28  import org.apache.maven.plugin.testing.ArtifactStubFactory;
29  import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
30  
31  /**
32   * The Class TestRequireReleaseVersion.
33   *
34   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
35   */
36  public class TestRequireReleaseVersion
37      extends TestCase
38  {
39  
40      /**
41       * Test mojo.
42       *
43       * @throws IOException Signals that an I/O exception has occurred.
44       */
45      public void testMojo()
46          throws IOException
47      {
48          ArtifactStubFactory factory = new ArtifactStubFactory();
49          MockProject project = new MockProject();
50          EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
51  
52          project.setArtifact( factory.getReleaseArtifact() );
53  
54          EnforcerRule rule = new RequireReleaseVersion();
55  
56          TestEnforcerRuleUtils.execute( rule, helper, false );
57  
58          project.setArtifact( factory.getSnapshotArtifact() );
59  
60          TestEnforcerRuleUtils.execute( rule, helper, true );
61  
62          project.setArtifact( factory.getReleaseArtifact() );
63  
64          MockProject parent = new MockProject();
65          parent.setArtifact( factory.getSnapshotArtifact() );
66          project.setParent( parent );
67          helper = EnforcerTestUtils.getHelper(project);
68  
69          ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( true );
70          TestEnforcerRuleUtils.execute( rule, helper, true );
71  
72          ( (RequireReleaseVersion) rule ).setFailWhenParentIsSnapshot( false );
73          TestEnforcerRuleUtils.execute( rule, helper, false );
74  
75      }
76  
77      /**
78       * Test cache.
79       */
80      public void testCache()
81      {
82          EnforcerRule rule = new RequireReleaseVersion();
83          assertFalse( rule.isCacheable() );
84          assertFalse( rule.isResultValid( null ) );
85          assertEquals( "0", rule.getCacheId() );
86      }
87  
88  }