001package org.apache.maven.scm.provider.accurev.command.remove;
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.Collections;
030import java.util.List;
031
032import org.apache.maven.scm.CommandParameter;
033import org.apache.maven.scm.CommandParameters;
034import org.apache.maven.scm.ScmFileSet;
035import org.apache.maven.scm.ScmFileStatus;
036import org.apache.maven.scm.command.remove.RemoveScmResult;
037import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
038import org.junit.Test;
039
040public class AccuRevRemoveCommandTest
041    extends AbstractAccuRevCommandTest
042{
043
044    @Test
045    public void testRemove()
046        throws Exception
047    {
048        final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) );
049
050        List<File> removedFiles = Collections.singletonList( new File( "removed/file" ) );
051
052        when( accurev.defunct( basedir, testFileSet.getFileList(), "A deleted file" ) ).thenReturn( removedFiles );
053
054        AccuRevRemoveCommand command = new AccuRevRemoveCommand( getLogger() );
055
056        CommandParameters commandParameters = new CommandParameters();
057        commandParameters.setString( CommandParameter.MESSAGE, "A deleted file" );
058        RemoveScmResult result = command.remove( repo, testFileSet, commandParameters );
059
060        assertThat( result.isSuccess(), is( true ) );
061        assertThat( result.getRemovedFiles().size(), is( 1 ) );
062        assertHasScmFile( result.getRemovedFiles(), "removed/file", ScmFileStatus.DELETED );
063    }
064
065    @Test
066    public void testAddFailed()
067        throws Exception
068    {
069        final ScmFileSet testFileSet = new ScmFileSet( basedir, new File( "src/main/java/Foo.java" ) );
070
071        when( accurev.defunct( basedir, testFileSet.getFileList(), "A deleted file" ) ).thenReturn( null );
072
073        AccuRevRemoveCommand command = new AccuRevRemoveCommand( getLogger() );
074
075        CommandParameters commandParameters = new CommandParameters();
076        commandParameters.setString( CommandParameter.MESSAGE, "A deleted file" );
077        RemoveScmResult result = command.remove( repo, testFileSet, commandParameters );
078
079        assertThat( result.isSuccess(), is( false ) );
080        assertThat( result.getProviderMessage(), notNullValue() );
081    }
082
083}