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