View Javadoc

1   package org.apache.maven.shared.release.phase;
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.model.Model;
23  import org.apache.maven.model.Scm;
24  import org.apache.maven.project.MavenProject;
25  import org.apache.maven.shared.release.ReleaseFailureException;
26  import org.apache.maven.shared.release.config.ReleaseDescriptor;
27  import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
28  import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
29  import org.codehaus.plexus.PlexusTestCase;
30  
31  import java.util.Collections;
32  
33  /**
34   * Test the POM verification check phase.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   */
38  public class CheckPomPhaseTest
39      extends PlexusTestCase
40  {
41      private ReleasePhase phase;
42  
43      protected void setUp()
44          throws Exception
45      {
46          super.setUp();
47  
48          phase = (ReleasePhase) lookup( ReleasePhase.ROLE, "check-poms" );
49      }
50  
51      public void testCorrectlyConfigured()
52          throws Exception
53      {
54          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
55          releaseDescriptor.setScmSourceUrl( "scm-url" );
56  
57          phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) );
58  
59          phase.simulate( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) );
60  
61          // successful execution is verification enough
62          assertTrue( true );
63      }
64  
65      public void testGetUrlFromProjectConnection()
66          throws Exception
67      {
68          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
69          MavenProject project = createProject( "1.0-SNAPSHOT" );
70          Scm scm = new Scm();
71          scm.setConnection( "scm:svn:file://localhost/tmp/repo" );
72          project.setScm( scm );
73  
74          phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( project ) );
75  
76          assertEquals( "Check URL", "scm:svn:file://localhost/tmp/repo", releaseDescriptor.getScmSourceUrl() );
77      }
78  
79      public void testGetUrlFromProjectConnectionSimulate()
80          throws Exception
81      {
82          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
83          MavenProject project = createProject( "1.0-SNAPSHOT" );
84          Scm scm = new Scm();
85          scm.setConnection( "scm:svn:file://localhost/tmp/repo" );
86          project.setScm( scm );
87  
88          phase.simulate( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( project ) );
89  
90          assertEquals( "Check URL", "scm:svn:file://localhost/tmp/repo", releaseDescriptor.getScmSourceUrl() );
91      }
92  
93      public void testGetUrlFromProjectDevConnection()
94          throws Exception
95      {
96          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
97          MavenProject project = createProject( "1.0-SNAPSHOT" );
98          Scm scm = new Scm();
99          scm.setConnection( "scm:svn:file://localhost/tmp/repo" );
100         scm.setDeveloperConnection( "scm:svn:https://localhost/tmp/repo" );
101         project.setScm( scm );
102 
103         phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( project ) );
104 
105         assertEquals( "Check URL", "scm:svn:https://localhost/tmp/repo", releaseDescriptor.getScmSourceUrl() );
106     }
107 
108     public void testGetUrlFromProjectDevConnectionSimulate()
109         throws Exception
110     {
111         ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
112         MavenProject project = createProject( "1.0-SNAPSHOT" );
113         Scm scm = new Scm();
114         scm.setConnection( "scm:svn:file://localhost/tmp/repo" );
115         scm.setDeveloperConnection( "scm:svn:https://localhost/tmp/repo" );
116         project.setScm( scm );
117 
118         phase.simulate( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( project ) );
119 
120         assertEquals( "Check URL", "scm:svn:https://localhost/tmp/repo", releaseDescriptor.getScmSourceUrl() );
121     }
122 
123     public void testGetInvalidUrl()
124         throws Exception
125     {
126         ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
127         MavenProject project = createProject( "1.0-SNAPSHOT" );
128         Scm scm = new Scm();
129         scm.setConnection( "scm:cvs:" );
130         project.setScm( scm );
131 
132         try
133         {
134             phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( project ) );
135 
136             fail( "Should have thrown an exception" );
137         }
138         catch ( ReleaseScmRepositoryException e )
139         {
140             assertTrue( true );
141         }
142     }
143 
144     public void testGetInvalidProvider()
145         throws Exception
146     {
147         ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
148         MavenProject project = createProject( "1.0-SNAPSHOT" );
149         Scm scm = new Scm();
150         scm.setConnection( "scm:foo:" );
151         project.setScm( scm );
152 
153         try
154         {
155             phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( project ) );
156 
157             fail( "Should have thrown an exception" );
158         }
159         catch ( ReleaseFailureException e )
160         {
161             assertTrue( true );
162         }
163     }
164 
165     public void testMissingUrl()
166         throws Exception
167     {
168         ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
169 
170         try
171         {
172             phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) );
173 
174             fail( "Should have failed to execute" );
175         }
176         catch ( ReleaseFailureException e )
177         {
178             assertTrue( true );
179         }
180 
181         try
182         {
183             phase.simulate( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) );
184 
185             fail( "Should have failed to simulate" );
186         }
187         catch ( ReleaseFailureException e )
188         {
189             assertTrue( true );
190         }
191     }
192 
193     public void testReleasingNonSnapshot()
194         throws Exception
195     {
196         ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
197         releaseDescriptor.setScmSourceUrl( "scm-url" );
198 
199         try
200         {
201             phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0" ) ) );
202 
203             fail( "Should have failed to execute" );
204         }
205         catch ( ReleaseFailureException e )
206         {
207             assertTrue( true );
208         }
209 
210         try
211         {
212             phase.simulate( releaseDescriptor, new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0" ) ) );
213 
214             fail( "Should have failed to simulate" );
215         }
216         catch ( ReleaseFailureException e )
217         {
218             assertTrue( true );
219         }
220     }
221 
222     private static MavenProject createProject( String version )
223     {
224         Model model = new Model();
225 
226         model.setArtifactId( "artifactId" );
227         model.setGroupId( "groupId" );
228         model.setVersion( version );
229 
230         return new MavenProject( model );
231     }
232 }