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