public void testChangeLogCommand()

in maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/changelog/ChangeLogCommandTckTest.java [64:135]


    public void testChangeLogCommand() throws Exception {
        Thread.sleep(1000);
        ScmProvider provider = getScmManager().getProviderByRepository(getScmRepository());
        ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());

        ChangeLogScmResult firstResult =
                provider.changeLog(getScmRepository(), fileSet, null, null, 0, (ScmBranch) null, null);
        assertTrue(
                firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n"
                        + firstResult.getCommandOutput(),
                firstResult.isSuccess());

        // for svn and git the repo get recreated for each test and therefore initial changelog size is 1
        int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
        assertTrue("Unexpected initial log size", firstLogSize >= 1);

        // Make a timestamp that we know are after initial revision but before the second
        Date timeBeforeSecond = new Date(); // Current time

        // pause a couple seconds... [SCM-244]
        Thread.sleep(2000);

        // Make a change to the readme.txt and commit the change
        this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
        ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
        CheckInScmResult checkInResult = provider.checkIn(getScmRepository(), fileSet, COMMIT_MSG);
        assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());

        ScmTagParameters scmTagParameters = new ScmTagParameters();
        TagScmResult tagResult = provider.tag(getScmRepository(), fileSet, COMMIT_TAG, scmTagParameters);
        assertTrue("Unable to tag the changes in the repository", tagResult.isSuccess());

        ChangeLogScmRequest changeLogScmRequest = new ChangeLogScmRequest(getScmRepository(), fileSet);
        ChangeLogScmResult secondResult = provider.changeLog(changeLogScmRequest);
        assertTrue(secondResult.getProviderMessage(), secondResult.isSuccess());

        List<ChangeSet> changeSets = secondResult.getChangeLog().getChangeSets();

        int expectedChangeSets = firstLogSize + 1;
        boolean lastCommitIsCausedByTagging = false;
        int lastCodeCommitIndex = 0;

        if (isTagAnExtraCommit()) {
            // This is for example Mercurial which creates an extra commit after tagging.
            lastCommitIsCausedByTagging = true;
            expectedChangeSets += 1;
            lastCodeCommitIndex = 1;
        }

        assertEquals(expectedChangeSets, changeSets.size());

        // Check if the tag has been retrieved again
        ChangeSet changeSetWithTag = changeSets.get(lastCodeCommitIndex);
        assertEquals(Collections.singletonList(COMMIT_TAG), changeSetWithTag.getTags());

        // Now only retrieve the changelog after timeBeforeSecondChangeLog
        Date currentTime = new Date();
        changeLogScmRequest = new ChangeLogScmRequest(getScmRepository(), fileSet);
        changeLogScmRequest.setStartDate(timeBeforeSecond);
        changeLogScmRequest.setEndDate(currentTime);
        changeLogScmRequest.setScmBranch(new ScmBranch(""));
        ChangeLogScmResult thirdResult = provider.changeLog(changeLogScmRequest);

        // Thorough assert of the last result
        assertTrue(thirdResult.getProviderMessage(), thirdResult.isSuccess());

        List<ChangeSet> thirdChangeSets = thirdResult.getChangeLog().getChangeSets();
        assertEquals(lastCommitIsCausedByTagging ? 2 : 1, thirdChangeSets.size());
        ChangeSet changeset = thirdChangeSets.get(lastCodeCommitIndex);
        assertTrue(changeset.getDate().after(timeBeforeSecond));
        assertTrue(changeset.getComment().startsWith(COMMIT_MSG));
    }