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 static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertTrue;
24  
25  import java.io.File;
26  import java.util.List;
27  
28  import org.apache.maven.model.Model;
29  import org.apache.maven.project.MavenProject;
30  import org.apache.maven.shared.release.config.ReleaseDescriptor;
31  import org.junit.Test;
32  
33  public class AbstractScmCommitPhaseTest
34  {
35      @Test
36      public void testDefaultCreatePomFiles()
37          throws Exception
38      {
39          List<File> files =
40              AbstractScmCommitPhase.createPomFiles(  new ReleaseDescriptor(),
41                                                     createProject( "artifactId", "1.0-SNAPSHOT", new File( "pom.xml" ) ) );
42          assertEquals( "Number of created files", files.size(), 1 );
43          assertTrue( files.contains( new File( "pom.xml" ) ) );
44      }
45  
46  
47      @Test
48      public void testCreatePomFilesSuppressCommitBeforeTag()
49          throws Exception
50      {
51          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
52          releaseDescriptor.setSuppressCommitBeforeTagOrBranch( true );
53          List<File> files =
54              AbstractScmCommitPhase.createPomFiles(  releaseDescriptor,
55                                                     createProject( "artifactId", "1.0-SNAPSHOT", new File( "pom.xml" ) ) );
56          assertEquals( "Number of created files", files.size(), 1 );
57          assertTrue( files.contains( new File( "pom.xml" ) ) );
58      }
59  
60      @Test
61      public void testCreatePomFilesWithReleasePom()
62          throws Exception
63      {
64          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
65          releaseDescriptor.setGenerateReleasePoms( true );
66          List<File> files =
67              AbstractScmCommitPhase.createPomFiles( releaseDescriptor,
68                                                     createProject( "artifactId", "1.0-SNAPSHOT", new File( "pom.xml" ) ) );
69          assertEquals( "Number of created files", files.size(), 2 );
70          assertTrue( files.contains( new File( "pom.xml" ) ) );
71          assertTrue( files.contains( new File( "release-pom.xml" ) ) );
72      }
73  
74      @Test
75      public void testCreatePomFilesWithReleasePomAndSuppressCommitBeforeTag()
76          throws Exception
77      {
78          ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
79          releaseDescriptor.setGenerateReleasePoms( true );
80          releaseDescriptor.setSuppressCommitBeforeTagOrBranch( true );
81          List<File> files =
82              AbstractScmCommitPhase.createPomFiles( releaseDescriptor,
83                                                     createProject( "artifactId", "1.0-SNAPSHOT", new File( "pom.xml" ) ) );
84          assertEquals( "Number of created files", files.size(), 1 );
85          assertTrue( files.contains( new File( "pom.xml" ) ) );
86      }
87  
88      private static MavenProject createProject( String artifactId, String version, File file )
89      {
90          Model model = new Model();
91          model.setGroupId( "groupId" );
92          model.setArtifactId( artifactId );
93          model.setVersion( version );
94          MavenProject project = new MavenProject( model );
95          project.setFile( file );
96          return project;
97      }
98  }