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        ChangeLogScmResult firstResult =
057            provider.changeLog( getScmRepository(), fileSet, null, null, 0, (ScmBranch) null, null );
058        assertTrue( firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n"
059                        + firstResult.getCommandOutput(), firstResult.isSuccess() );
060
061        // for svn and git the repo get recreated for each test and therefore initial changelog size is 1
062        int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
063        assertTrue( "Unexpected initial log size", firstLogSize >= 1 );
064
065        // Make a timestamp that we know are after initial revision but before the second
066        Date timeBeforeSecond = new Date(); //Current time
067
068        // pause a couple seconds... [SCM-244]
069        Thread.sleep( 2000 );
070
071        //Make a change to the readme.txt and commit the change
072        this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
073        ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
074        CheckInScmResult checkInResult = provider.checkIn( getScmRepository(), fileSet, COMMIT_MSG );
075        assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess() );
076
077        ChangeLogScmResult secondResult = provider.changeLog( getScmRepository(), fileSet, (ScmVersion) null, null );
078        assertTrue( secondResult.getProviderMessage(), secondResult.isSuccess() );
079        assertEquals( firstLogSize + 1, secondResult.getChangeLog().getChangeSets().size() );
080
081        //Now only retrieve the changelog after timeBeforeSecondChangeLog
082        Date currentTime = new Date();
083        ChangeLogScmResult thirdResult = provider
084            .changeLog( getScmRepository(), fileSet, timeBeforeSecond, currentTime, 0, new ScmBranch( "" ) );
085
086        //Thorough assert of the last result
087        assertTrue( thirdResult.getProviderMessage(), thirdResult.isSuccess() );
088        assertEquals( 1, thirdResult.getChangeLog().getChangeSets().size() );
089        ChangeSet changeset = thirdResult.getChangeLog().getChangeSets().get( 0 );
090        assertTrue( changeset.getDate().after( timeBeforeSecond ) );
091
092
093        assertEquals( COMMIT_MSG, changeset.getComment() );
094    }
095}