Search in sources :

Example 11 with HistoryCommitTableModel

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

the class HistoryPanelQuickSearchTest method testCommitDetails.

/**
 * Tests if the commit details are correct.
 * <br><br>
 * EXM-48899
 *
 * @author Alex_Smarandache
 *
 * @throws Exception If it fails.
 */
@Test
public void testCommitDetails() 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");
    historyTable.setRowSelectionInterval(0, 0);
    sleep(300);
    JTable affectedFiles = historyPanel.getAffectedFilesTable();
    CommitCharacteristics commitDetails = ((HistoryCommitTableModel) historyTable.getModel()).getAllCommits().get(0);
    List<FileStatus> changes = null;
    if (GitAccess.UNCOMMITED_CHANGES != commitDetails) {
        try {
            changes = RevCommitUtil.getChangedFiles(commitDetails.getCommitId());
        } catch (GitAPIException | RevisionSyntaxException | IOException e) {
            e.printStackTrace();
        }
    } else {
        changes = GitAccess.getInstance().getUnstagedFiles();
    }
    assertEquals(changes.size(), affectedFiles.getRowCount());
    for (int i = 0; i < changes.size(); i++) {
        assertEquals(changes.get(i), affectedFiles.getValueAt(i, 1));
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTable(javax.swing.JTable) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) IOException(java.io.IOException) File(java.io.File) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) Test(org.junit.Test)

Example 12 with HistoryCommitTableModel

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

the class HistoryPanelQuickSearchTest method testSearchMultipleCases.

/**
 * Tests multiple cases like user do not write in the search with the upper case(the message is in upper case),
 * search for a message,  but not in the right order...
 *
 * @throws Exception If it fails.
 */
@Test
public void testSearchMultipleCases() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/history_script_rename.txt"), new File("target/gen/HistoryPanelTest/testAffectedFiles_ShowRenames"));
    historyPanel.showRepositoryHistory();
    flushAWT();
    JTable historyTable = historyPanel.getHistoryTable();
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    // we search the message, but the message is not with uppercase
    model.filterChanged("FIRST COMMIT");
    sleep(300);
    String dump = dumpHistory(model.getAllCommits(), true);
    String expected = "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , null ]\n";
    assertEquals(expected, dump);
    sleep(100);
    // we go back to the original list
    model.filterChanged("");
    sleep(300);
    dump = dumpHistory(model.getAllCommits(), true);
    String expectedAll = "[ Rename. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [1] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , null ]\n" + "";
    assertEquals(expectedAll, dump);
    sleep(100);
    // we search for message but not in the right order
    model.filterChanged("commit First");
    sleep(300);
    dump = dumpHistory(model.getAllCommits(), true);
    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 13 with HistoryCommitTableModel

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

the class HistoryPanelTest method testAffectedFilesForeground.

/**
 * Tests the affected files foreground when a file or folder is searched.
 * <br><br>
 * EXM: EXM-48807
 *
 * @author Alex_Smarandache
 *
 * @throws Exception If it fails.
 */
@Test
public void testAffectedFilesForeground() 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();
        waitForScheduler();
        flushAWT();
        sleep(300);
        JTable historyTable = historyPanel.getHistoryTable();
        HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
        dump = dumpHistory(model.getAllCommits());
        assertEquals(expected, dump);
        // -----------
        // Select an entry in the revision table.
        // -----------
        selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 2, "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]");
        // -----------
        // Assert the affected files
        // -----------
        assertAffectedFiles(historyPanel, "(changeType=ADD, fileLocation=f2/file1.txt)\n" + "(changeType=CHANGED, fileLocation=f2/file2.txt)\n" + "(changeType=REMOVED, fileLocation=f2/file4.txt)\n" + "(changeType=RENAME, fileLocation=f2/file3_renamed.txt)\n" + "");
        JTable affectedFiles = historyPanel.getAffectedFilesTable();
        TableCellRenderer render = affectedFiles.getDefaultRenderer(FileStatus.class);
        FileHistoryPresenter presentedPath = new FileHistoryPresenter("f2/file4.txt");
        ((HistoryAffectedFileCellRender) render).setFilePresenter(presentedPath);
        Color foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(0, 1), false, true, 0, 1).getForeground();
        assertEquals(UIUtil.NOT_SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(1, 1), false, true, 1, 1).getForeground();
        assertEquals(UIUtil.NOT_SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(2, 1), false, true, 2, 1).getForeground();
        assertEquals(UIUtil.SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(3, 1), false, true, 3, 1).getForeground();
        assertEquals(UIUtil.NOT_SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        presentedPath.setFilePath("f2");
        for (int i = 0; i < affectedFiles.getColumnCount(); i++) {
            foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(i, 1), false, true, 1, 1).getForeground();
            assertEquals(UIUtil.SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        }
        presentedPath.setFilePath(null);
        for (int i = 0; i < affectedFiles.getColumnCount(); i++) {
            foregroundColor = render.getTableCellRendererComponent(affectedFiles, affectedFiles.getValueAt(i, 1), false, true, 1, 1).getForeground();
            assertEquals(UIUtil.SEARCHED_FILES_COLOR_LIGHT_THEME, foregroundColor);
        }
    } finally {
        GitAccess.getInstance().closeRepo();
        FileUtils.deleteDirectory(wcTree);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) JTable(javax.swing.JTable) Color(java.awt.Color) FileHistoryPresenter(com.oxygenxml.git.view.history.FileHistoryPresenter) File(java.io.File) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) HistoryAffectedFileCellRender(com.oxygenxml.git.view.history.HistoryAffectedFileCellRender) Test(org.junit.Test)

Example 14 with HistoryCommitTableModel

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

the class HistoryPanelTest method testAffectedFiles.

/**
 * Tests the affected files presented when a revision is selected inside the history panel.
 *
 * @throws Exception If it fails.
 */
@Test
public void testAffectedFiles() 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();
        waitForScheduler();
        flushAWT();
        sleep(300);
        JTable historyTable = historyPanel.getHistoryTable();
        HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
        dump = dumpHistory(model.getAllCommits());
        assertEquals(expected, dump);
        // -----------
        // Select an entry in the revision table.
        // -----------
        selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 0, "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]");
        // -----------
        // Assert the affected files
        // -----------
        assertAffectedFiles(historyPanel, "(changeType=CHANGED, fileLocation=root.txt)\n");
        // -----------
        // Select an entry in the revision table.
        // -----------
        selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 1, "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]");
        // -----------
        // Assert the affected files
        // -----------
        assertAffectedFiles(historyPanel, "(changeType=ADD, fileLocation=root.txt)\n");
        // -----------
        // Select an entry in the revision table.
        // -----------
        selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 2, "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]");
        // -----------
        // Assert the affected files
        // -----------
        assertAffectedFiles(historyPanel, "(changeType=ADD, fileLocation=f2/file1.txt)\n" + "(changeType=CHANGED, fileLocation=f2/file2.txt)\n" + "(changeType=REMOVED, fileLocation=f2/file4.txt)\n" + "(changeType=RENAME, fileLocation=f2/file3_renamed.txt)\n" + "");
        // -----------
        // Select an entry in the revision table.
        // -----------
        selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 3, "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]");
        // -----------
        // Assert the affected files
        // -----------
        assertAffectedFiles(historyPanel, "(changeType=ADD, fileLocation=f1/file1.txt)\n" + "(changeType=ADD, fileLocation=f2/file2.txt)\n" + "(changeType=ADD, fileLocation=f2/file3.txt)\n" + "(changeType=ADD, fileLocation=f2/file4.txt)\n" + "(changeType=ADD, fileLocation=newProject.xpr)\n" + "");
    } 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)

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