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 org.apache.maven.model.DistributionManagement;
23  import org.apache.maven.model.Site;
24  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
25  import org.apache.maven.project.MavenProject;
26  import org.apache.maven.shared.release.ReleaseManager;
27  import org.apache.maven.shared.release.config.ReleaseDescriptor;
28  import org.apache.maven.shared.release.env.ReleaseEnvironment;
29  import org.jmock.Mock;
30  import org.jmock.core.Constraint;
31  import org.jmock.core.constraint.IsEqual;
32  import org.jmock.core.constraint.IsInstanceOf;
33  import org.jmock.core.constraint.IsNull;
34  import org.jmock.core.matcher.InvokeOnceMatcher;
35  
36  import java.io.File;
37  
38  /**
39   * Test release:perform.
40   *
41   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
42   */
43  public class StageReleaseMojoTest
44      extends AbstractMojoTestCase
45  {
46      private File workingDirectory;
47  
48      public void testStage()
49          throws Exception
50      {
51          StageReleaseMojo mojo = getMojoWithProjectSite( "stage.xml" );
52  
53          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
54          releaseDescriptor.setWorkingDirectory( workingDirectory.getAbsolutePath() );
55          File checkoutDirectory = getTestFile( "target/checkout" );
56          releaseDescriptor.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() );
57          releaseDescriptor.setPerformGoals( "deploy site:stage-deploy" );
58          releaseDescriptor.setAdditionalArguments( "-DaltDeploymentRepository=\"staging\"" );
59  
60          Mock mock = new Mock( ReleaseManager.class );
61  
62          Constraint[] constraints = new Constraint[] {
63              new IsEqual( releaseDescriptor ),
64              new IsInstanceOf( ReleaseEnvironment.class ),
65              new IsNull(),
66              new IsEqual( Boolean.FALSE )
67          };
68  
69          mock.expects( new InvokeOnceMatcher() ).method( "perform" ).with( constraints );
70          mojo.setReleaseManager( (ReleaseManager) mock.proxy() );
71  
72          mojo.execute();
73  
74          assertTrue( true );
75      }
76  
77      private StageReleaseMojo getMojoWithProjectSite( String fileName )
78          throws Exception
79      {
80          StageReleaseMojo mojo = (StageReleaseMojo) lookupMojo( "stage", new File( workingDirectory, fileName ) );
81          mojo.setBasedir( workingDirectory );
82  
83          MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
84          DistributionManagement distributionManagement = new DistributionManagement();
85          distributionManagement.setSite( new Site() );
86          project.setDistributionManagement( distributionManagement );
87  
88          return mojo;
89      }
90  
91      protected void setUp()
92          throws Exception
93      {
94          super.setUp();
95          workingDirectory = getTestFile( "target/test-classes/mojos/stage" );
96      }
97  }