001package org.apache.maven.scm.provider.cvslib.command.changelog;
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 org.apache.maven.scm.ScmTestCase;
023import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
024import org.apache.maven.scm.command.changelog.ChangeLogSet;
025import org.apache.maven.scm.manager.ScmManager;
026import org.apache.maven.scm.provider.cvslib.AbstractCvsScmTest;
027import org.apache.maven.scm.provider.cvslib.CvsScmTestUtils;
028
029import java.util.Date;
030
031/**
032 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse </a>
033 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
034 *
035 */
036public class CvsChangeLogCommandTest
037    extends AbstractCvsScmTest
038{
039    /** {@inheritDoc} */
040    protected String getModule()
041    {
042        return "test-repo/changelog";
043    }
044
045    public void testGetCommandWithStartAndEndDate()
046        throws Exception
047    {
048        Date startDate = getDate( 2003, 1, 1 );
049
050        Date endDate = getDate( 2004, 1, 1 );
051
052        testChangeLog( startDate, endDate, 32, null );
053    }
054
055    public void testGetCommandWithoutEndDate()
056        throws Exception
057    {
058        Date startDate = getDate( 2003, 1, 1 );
059
060        Date endDate = null;
061
062        testChangeLog( startDate, endDate, 51, null );
063    }
064
065    public void testGetCommandWithBranchOrTag()
066        throws Exception
067    {
068        Date startDate = null;
069
070        Date endDate = null;
071
072        testChangeLog( startDate, endDate, 22, "1.107.4" );
073    }
074
075    @SuppressWarnings( "deprecation" )
076    private void testChangeLog( Date startDate, Date endDate, int changeLogSize, String branch )
077        throws Exception
078    {
079        if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) )
080        {
081            ScmTestCase.printSystemCmdUnavail( CvsScmTestUtils.CVS_COMMAND_LINE, getName() );
082            return;
083        }
084
085        ScmManager scmManager = getScmManager();
086
087        CvsScmTestUtils.executeCVS( getWorkingDirectory(),
088                                    "-f -d " + getTestFile( "src/test/repository/" ) + " co " + getModule() );
089
090        ChangeLogScmResult changeLogResult = scmManager.getProviderByRepository( getScmRepository() ).changeLog(
091            getScmRepository(), getScmFileSet(), startDate, endDate, 0, branch );
092
093        if ( !changeLogResult.isSuccess() )
094        {
095            fail( changeLogResult.getProviderMessage() + "\n" + changeLogResult.getCommandOutput() );
096        }
097
098        ChangeLogSet changeLogSet = changeLogResult.getChangeLog();
099
100        assertNotNull( changeLogSet );
101
102        assertEquals( changeLogSize, changeLogSet.getChangeSets().size() );
103    }
104}