View Javadoc
1   package org.apache.maven.scm.provider.accurev.command.tag;
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.tag.TagScmResult;
37  import org.apache.maven.scm.provider.accurev.AccuRevInfo;
38  import org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository;
39  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
40  import org.junit.Test;
41  
42  public class AccuRevTagCommandTest
43      extends AbstractAccuRevCommandTest
44  {
45  
46      @Test
47      public void testTag()
48          throws Exception
49      {
50          final ScmFileSet testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) );
51          final File basedir = testFileSet.getBasedir();
52  
53          final String basisStream = "basisStream";
54          final AccuRevInfo info = new AccuRevInfo( basedir );
55          info.setBasis( basisStream );
56  
57          AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository();
58          repo.setStreamName( "myStream" );
59          repo.setAccuRev( accurev );
60          repo.setProjectPath( "/project/dir" );
61  
62          when( accurev.info( basedir )).thenReturn(info);
63          
64          when( accurev.mksnap( "theTagName", basisStream ) ).thenReturn( Boolean.TRUE );
65  
66          List<File> taggedFiles = Collections.singletonList( new File( "tagged/file" ) );
67          when( accurev.statTag( "theTagName" ) ).thenReturn( taggedFiles );
68  
69          AccuRevTagCommand command = new AccuRevTagCommand( getLogger() );
70  
71          CommandParameters commandParameters = new CommandParameters();
72          commandParameters.setString( CommandParameter.TAG_NAME, "theTagName" );
73          TagScmResult result = command.tag( repo, testFileSet, commandParameters );
74  
75          assertThat( result.isSuccess(), is( true ) );
76          assertThat( result.getTaggedFiles().size(), is( 1 ) );
77          assertHasScmFile( result.getTaggedFiles(), "tagged/file", ScmFileStatus.TAGGED );
78  
79      }
80  
81      @Test
82      public void testAccuRevError()
83          throws Exception
84      {
85          final ScmFileSet testFileSet = new ScmFileSet( new File( "/my/workspace/project/dir" ) );
86          final File basedir = testFileSet.getBasedir();
87  
88          final String basisStream = "basisStream";
89          final AccuRevInfo info = new AccuRevInfo( basedir );
90          info.setBasis( basisStream );
91  
92          AccuRevScmProviderRepository repo = new AccuRevScmProviderRepository();
93          repo.setStreamName( "myStream" );
94          repo.setAccuRev( accurev );
95          repo.setProjectPath( "/project/dir" );
96          when( accurev.info( basedir )).thenReturn(info);
97  
98          when( accurev.mksnap( "theTagName", basisStream ) ).thenReturn( Boolean.FALSE );
99          AccuRevTagCommand command = new AccuRevTagCommand( getLogger() );
100 
101         CommandParameters commandParameters = new CommandParameters();
102         commandParameters.setString( CommandParameter.TAG_NAME, "theTagName" );
103         TagScmResult result = command.tag( repo, testFileSet, commandParameters );
104 
105         assertThat( result.isSuccess(), is( false ) );
106         assertThat( result.getProviderMessage(), notNullValue() );
107 
108     }
109 
110 }