1 package org.apache.maven.scm.provider.accurev.command.update;
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.Matchers.any;
27 import static org.mockito.Matchers.eq;
28 import static org.mockito.Mockito.when;
29
30 import java.io.File;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.Date;
34 import java.util.List;
35 import java.util.Map;
36
37 import org.apache.maven.scm.CommandParameter;
38 import org.apache.maven.scm.CommandParameters;
39 import org.apache.maven.scm.ScmFileSet;
40 import org.apache.maven.scm.ScmFileStatus;
41 import org.apache.maven.scm.command.update.UpdateScmResult;
42 import org.apache.maven.scm.provider.accurev.Transaction;
43 import org.apache.maven.scm.provider.accurev.WorkSpace;
44 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
45 import org.hamcrest.core.IsInstanceOf;
46 import org.junit.Test;
47
48 public class AccurevUpdateCommandTest
49 extends AbstractAccuRevCommandTest
50 {
51
52 private ScmFileSet testFileSet;
53
54 private File basedir;
55
56 @Override
57 public void setUp()
58 throws Exception
59 {
60 super.setUp();
61 testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) );
62 basedir = testFileSet.getBasedir();
63
64 info.setWorkSpace( "theWorkSpace" );
65 when( accurev.info( basedir ) ).thenReturn( info );
66
67 }
68
69 @Test
70 public void testUpdate()
71 throws Exception
72 {
73
74 final File keptFile = new File( "updated/file" );
75 final File keptAdded = new File( "new/file" );
76
77 List<File> files = Arrays.asList( keptFile, keptAdded );
78
79 when( accurev.update( eq( basedir ), any( String.class ) ) ).thenReturn( files );
80
81 AccuRevUpdateCommand command = new AccuRevUpdateCommand( getLogger() );
82
83 CommandParameters commandParameters = new CommandParameters();
84 commandParameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString( false ) );
85 UpdateScmResult result = command.update( repo, testFileSet, commandParameters );
86
87 assertThat( result.isSuccess(), is( true ) );
88 assertThat( result.getUpdatedFiles().size(), is( 2 ) );
89 assertHasScmFile( result.getUpdatedFiles(), "updated/file", ScmFileStatus.UPDATED );
90 assertHasScmFile( result.getUpdatedFiles(), "new/file", ScmFileStatus.UPDATED );
91
92 }
93
94 @Test
95 public void testUpdateWithChangeLog()
96 throws Exception
97 {
98
99 final WorkSpace wsBefore = new WorkSpace( "theWorkSpace", 123 );
100
101 Map<String, WorkSpace> workspaces = Collections.singletonMap( "theWorkSpace", wsBefore );
102
103 when( accurev.showWorkSpaces() ).thenReturn( workspaces );
104
105 List<File> emptyList = Collections.emptyList();
106 when( accurev.update( eq( basedir ), any( String.class ) ) ).thenReturn( emptyList );
107
108 final Date currentDate = new Date();
109 List<Transaction> transactions =
110 Collections.singletonList( new Transaction( 197L, currentDate, "type", "user" ) );
111
112 when(
113 accurev.history( any( String.class ), any( String.class ), any( String.class ), eq( 1 ), eq( true ),
114 eq( true ) ) ).thenReturn( transactions );
115
116 AccuRevUpdateCommand command = new AccuRevUpdateCommand( getLogger() );
117
118 CommandParameters commandParameters = new CommandParameters();
119 commandParameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString( true ) );
120 UpdateScmResult result = command.update( repo, testFileSet, commandParameters );
121
122 assertThat( result.isSuccess(), is( true ) );
123 assertThat( result, IsInstanceOf.instanceOf( AccuRevUpdateScmResult.class ) );
124 AccuRevUpdateScmResult accuRevResult = (AccuRevUpdateScmResult) result;
125 assertThat( accuRevResult.getFromRevision(), is( "theWorkSpace/123" ) );
126 assertThat( accuRevResult.getToRevision(), is( "theWorkSpace/197" ) );
127
128 }
129
130 @Test
131 public void testAccuRevFailure()
132 throws Exception
133 {
134 final ScmFileSet testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) );
135 final File basedir = testFileSet.getBasedir();
136
137 info.setWorkSpace( "theWorkSpace" );
138
139 when( accurev.update( eq( basedir ), any( String.class ) ) ).thenReturn( null );
140
141 AccuRevUpdateCommand command = new AccuRevUpdateCommand( getLogger() );
142
143 CommandParameters commandParameters = new CommandParameters();
144 commandParameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, Boolean.toString( false ) );
145 UpdateScmResult result = command.update( repo, testFileSet, commandParameters );
146
147 assertThat( result.isSuccess(), is( false ) );
148 assertThat( result.getProviderMessage(), notNullValue() );
149
150 }
151 }