View Javadoc
1   package org.apache.maven.scm.provider.accurev.command.add;
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.Collections;
30  import java.util.List;
31  
32  import org.apache.maven.scm.CommandParameter;
33  import org.apache.maven.scm.CommandParameters;
34  import org.apache.maven.scm.ScmFileSet;
35  import org.apache.maven.scm.ScmFileStatus;
36  import org.apache.maven.scm.command.add.AddScmResult;
37  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
38  import org.junit.Test;
39  
40  public class AccuRevAddCommandTest
41      extends AbstractAccuRevCommandTest
42  {
43  
44      @Test
45      public void testAdd()
46          throws Exception
47      {
48          final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) );
49          final List<File> files = testFileSet.getFileList();
50  
51          when( accurev.add( basedir, files, "A new file" ) ).thenReturn(
52                                                                          Collections.singletonList( new File(
53                                                                                                               "added/file" ) ) );
54          
55          AccuRevAddCommand command = new AccuRevAddCommand( getLogger() );
56  
57          CommandParameters commandParameters = new CommandParameters();
58          commandParameters.setString( CommandParameter.MESSAGE, "A new file" );
59          AddScmResult result = command.add( repo, testFileSet, commandParameters );
60  
61          assertThat( result.isSuccess(), is( true ) );
62          assertThat( result.getAddedFiles().size(), is( 1 ) );
63          assertHasScmFile( result.getAddedFiles(), "added/file", ScmFileStatus.ADDED );
64      }
65  
66      @Test
67      public void testAddFailed()
68          throws Exception
69      {
70          final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) );
71          final List<File> files = testFileSet.getFileList();
72  
73          when( accurev.add( basedir, files, "A new file" ) ).thenReturn(null);
74                                                                         
75          AccuRevAddCommand command = new AccuRevAddCommand( getLogger() );
76  
77          CommandParameters commandParameters = new CommandParameters();
78          commandParameters.setString( CommandParameter.MESSAGE, "A new file" );
79          AddScmResult result = command.add( repo, testFileSet, commandParameters );
80  
81          assertThat( result.isSuccess(), is( false ) );
82          assertThat( result.getProviderMessage(), notNullValue() );
83      }
84  
85  }