001package org.apache.maven.scm.provider.accurev.command.checkin; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile; 023import static org.hamcrest.Matchers.is; 024import static org.hamcrest.Matchers.notNullValue; 025import static org.junit.Assert.assertThat; 026import static org.mockito.Mockito.when; 027 028import java.io.File; 029import java.util.ArrayList; 030import java.util.Arrays; 031import java.util.List; 032 033import org.apache.maven.scm.CommandParameter; 034import org.apache.maven.scm.CommandParameters; 035import org.apache.maven.scm.ScmException; 036import org.apache.maven.scm.ScmFileSet; 037import org.apache.maven.scm.ScmFileStatus; 038import org.apache.maven.scm.command.checkin.CheckInScmResult; 039import org.apache.maven.scm.provider.accurev.AccuRevException; 040import org.apache.maven.scm.provider.accurev.AccuRevInfo; 041import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; 042import org.junit.Test; 043 044public class AccuRevCheckInCommandTest 045 extends AbstractAccuRevCommandTest 046{ 047 048 @Test 049 public void testCheckInRecursive() 050 throws Exception 051 { 052 // Setup test data so that the checkin area is the repo's project path. 053 final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) ); 054 final File basedir = testFileSet.getBasedir(); 055 056 final AccuRevInfo info = new AccuRevInfo( basedir ); 057 info.setTop( basedir.getAbsolutePath() ); 058 059 when( accurev.info( basedir ) ).thenReturn( info ); 060 061 List<File> promotedFiles = Arrays.asList( new File( "kept/file" ), new File( "promoted/file" ) ); 062 when( accurev.promoteAll( basedir, "A commit message" ) ).thenReturn( promotedFiles ); 063 064 AccuRevCheckInCommand command = new AccuRevCheckInCommand( getLogger() ); 065 066 CommandParameters commandParameters = new CommandParameters(); 067 commandParameters.setString( CommandParameter.MESSAGE, "A commit message" ); 068 CheckInScmResult result = command.checkIn( repo, testFileSet, commandParameters ); 069 070 assertThat( result.isSuccess(), is( true ) ); 071 assertThat( result.getCheckedInFiles().size(), is( 2 ) ); 072 assertHasScmFile( result.getCheckedInFiles(), "kept/file", ScmFileStatus.CHECKED_IN ); 073 assertHasScmFile( result.getCheckedInFiles(), "promoted/file", ScmFileStatus.CHECKED_IN ); 074 } 075 076 @Test 077 public void testCheckInFailure() 078 throws Exception 079 { 080 // Setup test data so that the checkin area is the repo's project path. 081 final ScmFileSet testFileSet = new ScmFileSet( new File( basedir, "project/dir" ) ); 082 final File basedir = testFileSet.getBasedir(); 083 084 final AccuRevInfo info = new AccuRevInfo( basedir ); 085 info.setTop( basedir.getAbsolutePath() ); 086 087 when( accurev.info( basedir ) ).thenReturn( info ); 088 089 when( accurev.promoteAll( basedir, "A commit message" ) ).thenReturn( null ); 090 091 AccuRevCheckInCommand command = new AccuRevCheckInCommand( getLogger() ); 092 093 CommandParameters commandParameters = new CommandParameters(); 094 commandParameters.setString( CommandParameter.MESSAGE, "A commit message" ); 095 CheckInScmResult result = command.checkIn( repo, testFileSet, commandParameters ); 096 097 assertThat( result.isSuccess(), is( false ) ); 098 assertThat( result.getProviderMessage(), notNullValue() ); 099 } 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 // TODO test basedir is top + project path. is OK. 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}