Search in sources :

Example 1 with HistoryCommitTableModel

use of com.oxygenxml.git.view.history.HistoryCommitTableModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanel2Test method testMultipleSelectionHistoryActions.

/**
 * Tests the actions presented for multiple selection in the history panel.
 *
 * EXM-44448
 *
 * @throws Exception If it fails.
 */
@Test
public void testMultipleSelectionHistoryActions() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/file_content_script.txt"), new File("target/gen/HistoryPanelTest/testMultipleSelectionHistoryActions"));
    List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String dump = dumpHistory(commitsCharacteristics, true);
    String expected = "[ Third. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dump);
    historyPanel.showRepositoryHistory();
    waitForScheduler();
    flushAWT();
    sleep(300);
    JTable historyTable = historyPanel.getHistoryTable();
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    dump = dumpHistory(model.getAllCommits(), true);
    assertEquals(expected, dump);
    // ---------------
    // Invoke the Diff action to see if the built URLs are O.K.
    // ---------------
    CommitCharacteristics cc1 = model.getAllCommits().get(0);
    CommitCharacteristics cc3 = model.getAllCommits().get(2);
    FileStatus fileStatus = new FileStatus(GitChangeType.CHANGED, "file1.txt");
    Action action = getCompareWithEachOther(fileStatus, cc1, cc3);
    action.actionPerformed(null);
    assertEquals("Unexpected number of URLs intercepted in the comparison support:" + urls2compare.toString(), 2, urls2compare.size());
    URL left = urls2compare.get(0);
    URL right = urls2compare.get(1);
    assertEquals("git://" + cc1.getCommitId() + "/file1.txt", left.toString());
    assertEquals("git://" + cc3.getCommitId() + "/file1.txt", right.toString());
    // ///////////////
    // Test the open multiple files
    // ////////////////
    CommitCharacteristics cc2 = model.getAllCommits().get(1);
    Action open = getOpenFileAction(fileStatus, cc1, cc2, cc3);
    open.actionPerformed(null);
    assertEquals("[" + "git://" + cc1.getCommitId() + "/file1.txt" + ", " + "git://" + cc2.getCommitId() + "/file1.txt" + ", " + "git://" + cc3.getCommitId() + "/file1.txt" + "]", toOpen.toString());
}
Also used : Action(javax.swing.Action) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTable(javax.swing.JTable) File(java.io.File) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) URL(java.net.URL) Test(org.junit.Test)

Example 2 with HistoryCommitTableModel

use of com.oxygenxml.git.view.history.HistoryCommitTableModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanel4RevertTest method testRevertCommit.

/**
 * <p><b>Description:</b> create new branch starting from a commit from the history table.</p>
 *
 * @author Tudosie Razvan
 *
 * @throws Exception
 */
@Test
public void testRevertCommit() throws Exception {
    URL script = getClass().getClassLoader().getResource("scripts/history_script.txt");
    File wcTree = new File("target/gen/HistoryPanelTest/testAffectedFiles");
    RepoGenerationScript.generateRepository(script, wcTree);
    try {
        GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
        List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
        String dump = dumpHistory(commitsCharacteristics);
        String expected = "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]\n";
        expected = replaceDate(expected);
        assertEquals(expected, dump);
        historyPanel.showRepositoryHistory();
        flushAWT();
        JTable historyTable = historyPanel.getHistoryTable();
        HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
        dump = dumpHistory(model.getAllCommits());
        assertEquals(expected, dump);
        // Checkout commit as new branch
        CommitCharacteristics commitCharacteristics = model.getAllCommits().get(2);
        dump = dumpHistory(Arrays.asList(commitCharacteristics));
        expected = replaceDate("[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n");
        assertEquals(expected, dump);
        GitAccess.getInstance().revertCommit(commitCharacteristics.getCommitId());
        waitForScheduler();
        sleep(400);
        // Check the history of the new branch
        commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
        dump = dumpHistory(commitsCharacteristics);
        expected = "[ Revert \"Changes.\"\n" + "\n" + "This reverts commit " + commitCharacteristics.getCommitId() + ".\n" + " , {date} , AlexJitianu <alex_jitianu@sync.ro> , 5 , AlexJitianu , [1] ]\n" + "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]\n";
        expected = replaceDate(expected);
        assertEquals(expected, dump);
        assertEquals(1, noOfRefreshes);
    } finally {
        GitAccess.getInstance().closeRepo();
        FileUtils.deleteDirectory(wcTree);
    }
}
Also used : HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) JTable(javax.swing.JTable) File(java.io.File) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) Test(org.junit.Test)

Example 3 with HistoryCommitTableModel

use of com.oxygenxml.git.view.history.HistoryCommitTableModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanelQuickSearchTest method testSearchAuthorAndMessage.

/**
 * Tests when we search with the author name and the message of the commit
 *
 * @throws Exception If it fails.
 */
@Test
public void testSearchAuthorAndMessage() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/history_script_rename.txt"), new File("target/gen/HistoryPanelTest/testAffectedFiles_ShowRenames"));
    historyPanel.showRepositoryHistory();
    waitForScheduler();
    flushAWT();
    sleep(300);
    JTable historyTable = historyPanel.getHistoryTable();
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    model.filterChanged("alex rename");
    sleep(700);
    String dump = dumpHistory(model.getAllCommits(), true);
    String expected = "[ Rename. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n";
    assertEquals(expected, dump);
}
Also used : HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) JTable(javax.swing.JTable) File(java.io.File) Test(org.junit.Test)

Example 4 with HistoryCommitTableModel

use of com.oxygenxml.git.view.history.HistoryCommitTableModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanelTest method testChangeBranchEvent.

/**
 * TODO - pare sa fie ceva din resetarea cach-ului.
 * com.oxygenxml.git.service.GitAccess.getCommitsCharacteristics(HistoryStrategy, String, RenameTracker)
 * daca adaugam un resetCache
 *
 *  if (filePath == null && statusCache.getStatus().hasUncommittedChanges()) {
 *        revisions.add(UNCOMMITED_CHANGES);
 *      }
 *
 * pare sa mearga
 *
 * Changing branches fires notification.
 *
 * @throws Exception If it fails.
 */
public void testChangeBranchEvent() throws Exception {
    URL script = getClass().getClassLoader().getResource("scripts/git_branch_events.txt");
    File wcTree = new File("target/gen/GitHistoryTest_testChangeBranchEvent");
    generateRepositoryAndLoad(script, wcTree);
    List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String dump = dumpHistory(commitsCharacteristics);
    String expected = "[ New branch , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , null ]\n" + "";
    expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
    expected = replaceDate(expected);
    assertEquals(expected, dump);
    historyPanel.showRepositoryHistory();
    waitForScheduler();
    flushAWT();
    sleep(300);
    JTable historyTable = historyPanel.getHistoryTable();
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    dump = dumpHistory(model.getAllCommits());
    assertEquals(expected, dump);
    // =======================
    // Change branch.
    // =======================
    GitAccess.getInstance().setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    // History panel uses the scheduler to perform the change.
    ScheduledFuture<?> schedule = GitOperationScheduler.getInstance().schedule(() -> {
    });
    schedule.get();
    waitForScheduler();
    model = (HistoryCommitTableModel) historyTable.getModel();
    dump = dumpHistory(model.getAllCommits());
    expected = "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , null ]\n";
    expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
    assertEquals(expected, dump);
}
Also used : HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) JTable(javax.swing.JTable) File(java.io.File) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) Date(java.util.Date)

Example 5 with HistoryCommitTableModel

use of com.oxygenxml.git.view.history.HistoryCommitTableModel in project oxygen-git-client-addon by oxygenxml.

the class HistoryPanelTestBase method selectAndAssertRevision.

/**
 * Selects a specific revision in the history table and asserts its description.
 *
 * @param historyTable History table.
 * @param affectedTable The table that present the affected files from the commit selected in the history view.
 * @param row Which row to select.
 * @param expected The expected revision description.
 */
protected void selectAndAssertRevision(JTable historyTable, JTable affectedTable, int row, String expected) {
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    historyTable.getSelectionModel().clearSelection();
    Semaphore s = new Semaphore(0);
    TableModelListener l = new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.INSERT) {
                s.release();
            }
        }
    };
    affectedTable.getModel().addTableModelListener(l);
    historyTable.getSelectionModel().setSelectionInterval(row, row);
    // There is a timer involved.
    try {
        s.tryAcquire(3, TimeUnit.SECONDS);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    } finally {
        affectedTable.getModel().removeTableModelListener(l);
    }
    flushAWT();
    CommitCharacteristics selectedObject = (CommitCharacteristics) model.getValueAt(historyTable.getSelectedRow(), 1);
    assertEquals(replaceDate(expected), toString(selectedObject));
}
Also used : HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) Semaphore(java.util.concurrent.Semaphore) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics)

Aggregations

HistoryCommitTableModel (com.oxygenxml.git.view.history.HistoryCommitTableModel)14 File (java.io.File)13 JTable (javax.swing.JTable)13 Test (org.junit.Test)12 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)11 URL (java.net.URL)9 FileStatus (com.oxygenxml.git.service.entities.FileStatus)5 Action (javax.swing.Action)4 HistoryTableAffectedFilesModel (com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel)3 GitAccess (com.oxygenxml.git.service.GitAccess)1 GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)1 FileHistoryPresenter (com.oxygenxml.git.view.history.FileHistoryPresenter)1 HistoryAffectedFileCellRender (com.oxygenxml.git.view.history.HistoryAffectedFileCellRender)1 HistoryStrategy (com.oxygenxml.git.view.history.HistoryStrategy)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 Date (java.util.Date)1 List (java.util.List)1 Semaphore (java.util.concurrent.Semaphore)1 Collectors (java.util.stream.Collectors)1