View Javadoc
1   package org.apache.maven.scm.provider.accurev.command.checkin;
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.apache.maven.scm.ScmFileMatcher.assertHasScmFile;
23  import static org.hamcrest.Matchers.is;
24  import static org.hamcrest.Matchers.notNullValue;
25  import static org.junit.Assert.assertThat;
26  import static org.mockito.Mockito.when;
27  
28  import java.io.File;
29  import java.util.ArrayList;
30  import java.util.Arrays;
31  import java.util.List;
32  
33  import org.apache.maven.scm.CommandParameter;
34  import org.apache.maven.scm.CommandParameters;
35  import org.apache.maven.scm.ScmException;
36  import org.apache.maven.scm.ScmFileSet;
37  import org.apache.maven.scm.ScmFileStatus;
38  import org.apache.maven.scm.command.checkin.CheckInScmResult;
39  import org.apache.maven.scm.provider.accurev.AccuRevException;
40  import org.apache.maven.scm.provider.accurev.AccuRevInfo;
41  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
42  import org.junit.Test;
43  
44  public class AccuRevCheckInCommandTest
45      extends AbstractAccuRevCommandTest
46  {
47  
48      @Test
49      public void testCheckInRecursive()
50          throws Exception
51      {
52          // Setup test data so that the checkin area is the repo's project path.
53          final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) );
54          final File basedir = testFileSet.getBasedir();
55  
56          final AccuRevInfo info = new AccuRevInfo( basedir );
57          info.setTop( basedir.getAbsolutePath() );
58  
59          when( accurev.info( basedir ) ).thenReturn( info );
60  
61          List<File> promotedFiles = Arrays.asList( new File( "kept/file" ), new File( "promoted/file" ) );
62          when( accurev.promoteAll( basedir, "A commit message" ) ).thenReturn( promotedFiles );
63  
64          AccuRevCheckInCommand command = new AccuRevCheckInCommand( getLogger() );
65  
66          CommandParameters commandParameters = new CommandParameters();
67          commandParameters.setString( CommandParameter.MESSAGE, "A commit message" );
68          CheckInScmResult result = command.checkIn( repo, testFileSet, commandParameters );
69  
70          assertThat( result.isSuccess(), is( true ) );
71          assertThat( result.getCheckedInFiles().size(), is( 2 ) );
72          assertHasScmFile( result.getCheckedInFiles(), "kept/file", ScmFileStatus.CHECKED_IN );
73          assertHasScmFile( result.getCheckedInFiles(), "promoted/file", ScmFileStatus.CHECKED_IN );
74      }
75  
76      @Test
77      public void testCheckInFailure()
78          throws Exception
79      {
80          // Setup test data so that the checkin area is the repo's project path.
81          final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) );
82          final File basedir = testFileSet.getBasedir();
83  
84          final AccuRevInfo info = new AccuRevInfo( basedir );
85          info.setTop( basedir.getAbsolutePath() );
86  
87          when( accurev.info( basedir ) ).thenReturn( info );
88  
89          when( accurev.promoteAll( basedir, "A commit message" ) ).thenReturn( null );
90  
91          AccuRevCheckInCommand command = new AccuRevCheckInCommand( getLogger() );
92  
93          CommandParameters commandParameters = new CommandParameters();
94          commandParameters.setString( CommandParameter.MESSAGE, "A commit message" );
95          CheckInScmResult result = command.checkIn( repo, testFileSet, commandParameters );
96  
97          assertThat( result.isSuccess(), is( false ) );
98          assertThat( result.getProviderMessage(), notNullValue() );
99      }
100 
101     @Test( expected = ScmException.class )
102     public void testCheckinRecursiveSubDirectoryNotSupported()
103         throws AccuRevException, ScmException
104     {
105         final ScmFileSet testFileSet = new ScmFileSet( basedir );
106         final AccuRevInfo info = new AccuRevInfo( basedir );
107         info.setTop( basedir.getParent() );
108 
109         // TODO test basedir is top + project path. is OK.
110         when( accurev.info( basedir ) ).thenReturn( info );
111 
112         AccuRevCheckInCommand command = new AccuRevCheckInCommand( getLogger() );
113 
114         CommandParameters commandParameters = new CommandParameters();
115         commandParameters.setString( CommandParameter.MESSAGE, "Commit message" );
116         command.checkIn( repo, testFileSet, commandParameters );
117         fail( "Expected ScmException" );
118     }
119 
120     @Test
121     public void testCheckinExplicitFiles()
122         throws Exception
123     {
124         final List<File> files = new ArrayList<File>();
125 
126         files.add( new File( "project/dir/pom.xml" ) );
127         files.add( new File( "project/dir/src/main/java/Bar.java" ) );
128 
129         final ScmFileSet testFileSet = new ScmFileSet( basedir, files );
130 
131         when( accurev.info( basedir ) ).thenReturn( info );
132 
133         when( accurev.promote( basedir, files, "A commit message" ) ).thenReturn( files );
134 
135         AccuRevCheckInCommand command = new AccuRevCheckInCommand( getLogger() );
136 
137         CommandParameters commandParameters = new CommandParameters();
138         commandParameters.setString( CommandParameter.MESSAGE, "A commit message" );
139         CheckInScmResult result = command.checkIn( repo, testFileSet, commandParameters );
140 
141         assertThat( result.isSuccess(), is( true ) );
142         assertThat( result.getCheckedInFiles().size(), is( 2 ) );
143         assertHasScmFile( result.getCheckedInFiles(), "project/dir/pom.xml", ScmFileStatus.CHECKED_IN );
144         assertHasScmFile( result.getCheckedInFiles(), "project/dir/src/main/java/Bar.java", ScmFileStatus.CHECKED_IN );
145 
146     }
147 }