View Javadoc

1   package org.apache.maven.plugins.release;
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 static org.mockito.Matchers.eq;
23  import static org.mockito.Matchers.isA;
24  import static org.mockito.Matchers.isNull;
25  import static org.mockito.Mockito.mock;
26  import static org.mockito.Mockito.verify;
27  import static org.mockito.Mockito.verifyNoMoreInteractions;
28  
29  import java.io.File;
30  import java.util.List;
31  
32  import org.apache.maven.model.DistributionManagement;
33  import org.apache.maven.model.Site;
34  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
35  import org.apache.maven.project.MavenProject;
36  import org.apache.maven.shared.release.ReleaseManager;
37  import org.apache.maven.shared.release.config.ReleaseDescriptor;
38  import org.apache.maven.shared.release.env.ReleaseEnvironment;
39  
40  /**
41   * Test release:perform.
42   *
43   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
44   */
45  public class StageReleaseMojoTest
46      extends AbstractMojoTestCase
47  {
48      private File workingDirectory;
49  
50      @SuppressWarnings( "unchecked" )
51      public void testStage()
52          throws Exception
53      {
54          StageReleaseMojo mojo = getMojoWithProjectSite( "stage.xml" );
55  
56          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
57          releaseDescriptor.setWorkingDirectory( workingDirectory.getAbsolutePath() );
58          File checkoutDirectory = getTestFile( "target/checkout" );
59          releaseDescriptor.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() );
60          releaseDescriptor.setPerformGoals( "deploy site:stage-deploy" );
61          releaseDescriptor.setAdditionalArguments( "-DaltDeploymentRepository=\"staging\"" );
62  
63          ReleaseManager mock = mock( ReleaseManager.class );
64          mojo.setReleaseManager( mock );
65  
66          mojo.execute();
67  
68          verify( mock ).perform( eq( releaseDescriptor ), isA( ReleaseEnvironment.class ), isNull( List.class ), eq( false ) );
69          verifyNoMoreInteractions( mock );
70      }
71  
72      private StageReleaseMojo getMojoWithProjectSite( String fileName )
73          throws Exception
74      {
75          StageReleaseMojo mojo = (StageReleaseMojo) lookupMojo( "stage", new File( workingDirectory, fileName ) );
76          mojo.setBasedir( workingDirectory );
77  
78          MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
79          DistributionManagement distributionManagement = new DistributionManagement();
80          distributionManagement.setSite( new Site() );
81          project.setDistributionManagement( distributionManagement );
82  
83          return mojo;
84      }
85  
86      protected void setUp()
87          throws Exception
88      {
89          super.setUp();
90          workingDirectory = getTestFile( "target/test-classes/mojos/stage" );
91      }
92  }