1 package org.apache.maven.scm.provider.accurev.command.checkin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
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
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 }