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  import java.util.Set;
24  
25  import junit.framework.TestCase;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
29  import org.apache.maven.plugin.testing.ArtifactStubFactory;
30  import org.apache.maven.plugins.enforcer.utils.TestEnforcerRuleUtils;
31  import org.apache.maven.project.MavenProject;
32  
33  // TODO: Auto-generated Javadoc
34  /**
35   * The Class TestNoSnapshots.
36   *
37   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
38   */
39  public class TestRequireReleaseDeps
40      extends TestCase
41  {
42  
43      /**
44       * Test rule.
45       *
46       * @throws IOException Signals that an I/O exception has occurred.
47       */
48      public void testRule()
49          throws IOException
50      {
51  
52          ArtifactStubFactory factory = new ArtifactStubFactory();
53          MockProject project = new MockProject();
54          EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
55          project.setArtifacts( factory.getMixedArtifacts() );
56          project.setDependencyArtifacts( factory.getScopedArtifacts() );
57          RequireReleaseDeps rule = newRequireReleaseDeps();
58          rule.setSearchTransitive( false );
59  
60          TestEnforcerRuleUtils.execute( rule, helper, false );
61  
62          rule.setSearchTransitive( true );
63  
64          TestEnforcerRuleUtils.execute( rule, helper, true );
65  
66          // test onlyWhenRelease in each case
67  
68          project.setArtifact( factory.getSnapshotArtifact() );
69  
70          TestEnforcerRuleUtils.execute( rule, helper, true );
71  
72          rule.setOnlyWhenRelease( true );
73  
74          TestEnforcerRuleUtils.execute( rule, helper, false );
75  
76          project.setArtifact( factory.getReleaseArtifact() );
77  
78          TestEnforcerRuleUtils.execute( rule, helper, true );
79  
80          MockProject parent = new MockProject();
81          parent.setArtifact( factory.getSnapshotArtifact() );
82          project.setParent( parent );
83          project.setArtifacts( null );
84          project.setDependencyArtifacts( null );
85          helper = EnforcerTestUtils.getHelper(project);
86  
87          rule.setFailWhenParentIsSnapshot( true );
88          TestEnforcerRuleUtils.execute( rule, helper, true );
89  
90          rule.setFailWhenParentIsSnapshot( false );
91          TestEnforcerRuleUtils.execute( rule, helper, false );
92  
93  
94      }
95  
96      private RequireReleaseDeps newRequireReleaseDeps()
97      {
98          RequireReleaseDeps rule = new RequireReleaseDeps()
99          {
100             protected Set<Artifact> getDependenciesToCheck( MavenProject project )
101             {
102                 // the integration with dependencyGraphTree is verified with the integration tests
103                 // for unit-testing 
104                 return isSearchTransitive() ? project.getArtifacts() : project.getDependencyArtifacts();
105             }
106         };        
107         return rule;
108     }
109 
110     /**
111      * Test id.
112      */
113     public void testId()
114     {
115         RequireReleaseDeps rule = newRequireReleaseDeps();
116         rule.getCacheId();
117     }
118 }