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.EnforcerRuleHelper;
27  import org.apache.maven.plugin.testing.ArtifactStubFactory;
28  import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
29  
30  // TODO: Auto-generated Javadoc
31  /**
32   * The Class TestNoSnapshots.
33   *
34   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
35   */
36  public class TestRequireReleaseDeps
37      extends TestCase
38  {
39  
40      /**
41       * Test rule.
42       *
43       * @throws IOException Signals that an I/O exception has occurred.
44       */
45      public void testRule()
46          throws IOException
47      {
48  
49          ArtifactStubFactory factory = new ArtifactStubFactory();
50          MockProject project = new MockProject();
51          EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
52          project.setArtifacts( factory.getMixedArtifacts() );
53          project.setDependencyArtifacts( factory.getScopedArtifacts() );
54          RequireReleaseDeps rule = new RequireReleaseDeps();
55          rule.setSearchTransitive( false );
56  
57          TestEnforcerRuleUtils.execute( rule, helper, false );
58  
59          rule.setSearchTransitive( true );
60  
61          TestEnforcerRuleUtils.execute( rule, helper, true );
62  
63          // test onlyWhenRelease in each case
64  
65          project.setArtifact( factory.getSnapshotArtifact() );
66  
67          TestEnforcerRuleUtils.execute( rule, helper, true );
68  
69          rule.onlyWhenRelease = true;
70  
71          TestEnforcerRuleUtils.execute( rule, helper, false );
72  
73          project.setArtifact( factory.getReleaseArtifact() );
74  
75          TestEnforcerRuleUtils.execute( rule, helper, true );
76  
77          MockProject parent = new MockProject();
78          parent.setArtifact( factory.getSnapshotArtifact() );
79          project.setParent( parent );
80          project.setArtifacts( null );
81          project.setDependencyArtifacts( null );
82          helper = EnforcerTestUtils.getHelper(project);
83  
84          rule.setFailWhenParentIsSnapshot( true );
85          TestEnforcerRuleUtils.execute( rule, helper, true );
86  
87          rule.setFailWhenParentIsSnapshot( false );
88          TestEnforcerRuleUtils.execute( rule, helper, false );
89  
90  
91      }
92  
93      /**
94       * Test id.
95       */
96      public void testId()
97      {
98          RequireReleaseDeps rule = new RequireReleaseDeps();
99          rule.getCacheId();
100     }
101 }