<commit_before>package com.treetank.access;

import static org.junit.Assert.assertEquals;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.treetank.ITestConstants;
import com.treetank.TestHelper;
import com.treetank.api.IDatabase;
import com.treetank.api.ISession;
import com.treetank.api.IWriteTransaction;
import com.treetank.exception.TreetankException;
import com.treetank.utils.DocumentCreater;

public final class RevertTest {

    @Before
    public void setUp() throws TreetankException {
        TestHelper.deleteEverything();
    }

    @After
    public void tearDown() throws TreetankException {
        TestHelper.closeEverything();
    }

    @Test
    public void test() throws TreetankException {
        final IDatabase database = Database.openDatabase(ITestConstants.PATH1);
        final ISession session = database.getSession();
        final IWriteTransaction wtx = session.beginWriteTransaction();
        TestCase.assertEquals(0L, wtx.getRevisionNumber());

        DocumentCreater.create(wtx);
        wtx.commit();
        assertEquals(1L, wtx.getRevisionNumber());
        wtx.moveToDocumentRoot();
        assertEquals(1, wtx.getNode().getChildCount());

        wtx.moveToFirstChild();
        wtx.remove();
        assertEquals(0, wtx.getNode().getChildCount());
        wtx.commit();

        wtx.moveToDocumentRoot();
        TestCase.assertEquals(2L, wtx.getRevisionNumber());
        assertEquals(0, wtx.getNode().getChildCount());
        wtx.revertTo(0);
        TestCase.assertEquals(1L, wtx.getRevisionNumber());
        assertEquals(1, wtx.getNode().getChildCount());
        wtx.commit();
        TestCase.assertEquals(2L, wtx.getRevisionNumber());
        assertEquals(1, wtx.getNode().getChildCount());
        wtx.close();

        session.close();
        database.close();
    }

}<commit_msg>RESOLVED - task 46: Revert for WriteTransaction to given revision  https://projects.uni-konstanz.de/issues/show/46<commit_after>package com.treetank.access;

import static org.junit.Assert.assertEquals;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.treetank.ITestConstants;
import com.treetank.TestHelper;
import com.treetank.api.IDatabase;
import com.treetank.api.IReadTransaction;
import com.treetank.api.ISession;
import com.treetank.api.IWriteTransaction;
import com.treetank.exception.TreetankException;
import com.treetank.utils.DocumentCreater;

public final class RevertTest {

    @Before
    public void setUp() throws TreetankException {
        TestHelper.deleteEverything();
    }

    @After
    public void tearDown() throws TreetankException {
        TestHelper.closeEverything();
    }

    @Test
    public void test() throws TreetankException {
        final IDatabase database = Database.openDatabase(ITestConstants.PATH1);
        final ISession session = database.getSession();
        final IWriteTransaction wtx = session.beginWriteTransaction();
        TestCase.assertEquals(0L, wtx.getRevisionNumber());

        DocumentCreater.create(wtx);
        wtx.commit();
        assertEquals(1L, wtx.getRevisionNumber());
        wtx.moveToDocumentRoot();
        assertEquals(1, wtx.getNode().getChildCount());

        wtx.moveToFirstChild();
        wtx.remove();
        assertEquals(0, wtx.getNode().getChildCount());
        wtx.commit();

        wtx.moveToDocumentRoot();
        TestCase.assertEquals(2L, wtx.getRevisionNumber());
        assertEquals(0, wtx.getNode().getChildCount());
        wtx.revertTo(0);
        TestCase.assertEquals(1L, wtx.getRevisionNumber());
        assertEquals(1, wtx.getNode().getChildCount());
        wtx.moveToFirstChild();
        wtx.remove();
        assertEquals(0, wtx.getNode().getChildCount());
        wtx.commit();
        TestCase.assertEquals(2L, wtx.getRevisionNumber());
        assertEquals(0, wtx.getNode().getChildCount());
        wtx.close();

        final IReadTransaction rtxRev0 = session.beginReadTransaction(0);
        final IReadTransaction rtxRev1 = session.beginReadTransaction(1);
        assertEquals(1, rtxRev0.getNode().getChildCount());
        assertEquals(0, rtxRev1.getNode().getChildCount());

        rtxRev0.close();
        rtxRev1.close();

        session.close();
        database.close();
    }
}
{'fraction_non_alphanumeric': 0.11929744525547445, 'fraction_numerical': 0.008895985401459854, 'mean_word_length': 3.3545183714001987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5622347', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1269, 'n_words': 219}