001package org.apache.maven.scm.tck.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.ChangeSet;
023import org.apache.maven.scm.ScmBranch;
024import org.apache.maven.scm.ScmFileSet;
025import org.apache.maven.scm.ScmTckTestCase;
026import org.apache.maven.scm.ScmTestCase;
027import org.apache.maven.scm.ScmVersion;
028import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
029import org.apache.maven.scm.command.checkin.CheckInScmResult;
030import org.apache.maven.scm.provider.ScmProvider;
031
032import java.util.Date;
033
034/**
035 * Test Changlog command. <br>
036 * 1. Get initial log <br>
037 * 2. Add one revision <br>
038 * 3. Get the two logs <br>
039 * 4. Get the last log based on date <br>
040 * 5. Test last log for date and comment <br>
041 *
042 * @author <a href="mailto:torbjorn@smorgrav.org">Torbj�rn Eikli Sm�rgrav</a>
043 */
044public abstract class ChangeLogCommandTckTest
045    extends ScmTckTestCase
046{
047    private static final String COMMIT_MSG = "Second changelog";
048
049    public void testChangeLogCommand()
050        throws Exception
051    {
052        Thread.sleep( 1000 );
053        ScmProvider provider = getScmManager().getProviderByRepository( getScmRepository() );
054        ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
055
056        //We should have one log entry for the initial repository
057        ChangeLogScmResult firstResult =
058            provider.changeLog( getScmRepository(), fileSet, null, null, 0, (ScmBranch) null, null );
059        assertTrue( firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n" + firstResult.getCommandOutput(),
060                    firstResult.isSuccess() );
061        assertEquals( 1, firstResult.getChangeLog().getChangeSets().size() );
062
063        //Make a timestamp that we know are after initial revision but before the second
064        Date timeBeforeSecond = new Date(); //Current time
065
066        // pause a couple seconds... [SCM-244]
067        Thread.sleep( 2000 );
068
069        //Make a change to the readme.txt and commit the change
070        ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
071        CheckInScmResult checkInResult = provider.checkIn( getScmRepository(), fileSet, COMMIT_MSG );
072        assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() );
073
074        ChangeLogScmResult secondResult = provider.changeLog( getScmRepository(), fileSet, (ScmVersion) null, null );
075        assertTrue( secondResult.getProviderMessage(), secondResult.isSuccess() );
076        assertEquals( 2, secondResult.getChangeLog().getChangeSets().size() );
077
078        //Now only retrieve the changelog after timeBeforeSecondChangeLog
079        Date currentTime = new Date();
080        ChangeLogScmResult thirdResult = provider
081            .changeLog( getScmRepository(), fileSet, timeBeforeSecond, currentTime, 0, new ScmBranch( "" ) );
082
083        //Thorough assert of the last result
084        assertTrue( thirdResult.getProviderMessage(), thirdResult.isSuccess() );
085        assertEquals( 1, thirdResult.getChangeLog().getChangeSets().size() );
086        ChangeSet changeset = thirdResult.getChangeLog().getChangeSets().get( 0 );
087        assertTrue( changeset.getDate().after( timeBeforeSecond ) );
088        assertEquals( COMMIT_MSG, changeset.getComment() );
089    }
090}