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