Search in sources :

Example 6 with HistoryCommitTableModel

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

the class HistoryPanel2Test method testActionsOnRenamedFile.

/**
 * Test the contextual actions presented for revisions preceding a rename.
 * EXM-44300
 *
 * @throws Exception If it fails.
 */
@Test
public void testActionsOnRenamedFile() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/EXM-44300/script.txt"), new File("target/gen/HistoryPanelTest/testActionsOnRenamedFile"));
    List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String dump = dumpHistory(commitsCharacteristics, true);
    String expected = "[ Fourth , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Third (Rename) , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Second , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First , {date} , Alex <alex_jitianu@sync.ro> , 4 , 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);
    // ---------------
    // Assert the available actions.
    // ---------------
    CommitCharacteristics cc = commitsCharacteristics.get(2);
    assertEquals("Second", cc.getCommitMessage());
    List<Action> actions = getAllActions(new FileStatus(GitChangeType.MODIFIED, "file_renamed.txt"), cc);
    List<Object> collect = actions.stream().map(t -> t.getValue(Action.NAME)).collect(Collectors.toList());
    assertEquals("[Compare_file_with_previous_version, " + "Compare_file_with_working_tree_version, Open_this_version_of_filename, " + "Open_the_working_copy_version_of, Create_branch..., " + "Create_Tag..., Checkout..., Revert_Commit, Reset_branch_to_this_commit...]", collect.toString());
}
Also used : CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) HistoryStrategy(com.oxygenxml.git.view.history.HistoryStrategy) URL(java.net.URL) Test(org.junit.Test) Action(javax.swing.Action) Collectors(java.util.stream.Collectors) FileStatus(com.oxygenxml.git.service.entities.FileStatus) File(java.io.File) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) List(java.util.List) GitAccess(com.oxygenxml.git.service.GitAccess) JTable(javax.swing.JTable) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) 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) Test(org.junit.Test)

Example 7 with HistoryCommitTableModel

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

the class HistoryPanel2Test method testAffectedFiles_ShowCopyRenames.

/**
 * Tests the affected files presented when a revision is selected inside the history panel.
 *
 * @throws Exception If it fails.
 */
@Test
public void testAffectedFiles_ShowCopyRenames() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/history_script_follow_move.txt"), new File("target/gen/HistoryPanelTest/testAffectedFiles_ShowCopyRenames"));
    List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String dump = dumpHistory(commitsCharacteristics, true);
    String expected = "[ Move , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Initial , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dump);
    historyPanel.showRepositoryHistory();
    waitForScheduler();
    flushAWT();
    sleep(500);
    JTable historyTable = historyPanel.getHistoryTable();
    HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
    dump = dumpHistory(model.getAllCommits(), true);
    assertEquals(expected, dump);
    // -----------
    // Select an entry in the revision table.
    // -----------
    expected = "[ Move , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]";
    expected = replaceDate(expected);
    selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 0, expected);
    // -----------
    // Assert the affected files
    // -----------
    assertAffectedFiles(historyPanel, "(changeType=RENAME, fileLocation=child/file.txt)\n");
    // ---------------
    // Invoke the Diff action to see if the built URLs are O.K.
    // ---------------
    HistoryTableAffectedFilesModel affectedFilesModel = (HistoryTableAffectedFilesModel) historyPanel.getAffectedFilesTable().getModel();
    FileStatus fileStatus = affectedFilesModel.getFilesStatuses().get(0);
    CommitCharacteristics cc = model.getAllCommits().get(0);
    Action action = getCompareWithPreviousAction(fileStatus, cc);
    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://" + model.getAllCommits().get(0).getCommitId() + "/child/file.txt", left.toString());
    assertEquals("git://" + model.getAllCommits().get(1).getCommitId() + "/file.txt", right.toString());
}
Also used : HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) 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 8 with HistoryCommitTableModel

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

the class HistoryPanel2Test method testAffectedFiles_ShowRenames.

/**
 * Tests the affected files presented when a revision is selected inside the history panel.
 *
 * @throws Exception If it fails.
 */
@Test
public void testAffectedFiles_ShowRenames() throws Exception {
    generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/history_script_rename.txt"), new File("target/gen/HistoryPanelTest/testAffectedFiles_ShowRenames"));
    List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String dump = dumpHistory(commitsCharacteristics, true);
    String expected = "[ Rename. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 2 , 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);
    // -----------
    // Select an entry in the revision table.
    // -----------
    expected = "[ Rename. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]";
    expected = replaceDate(expected);
    selectAndAssertRevision(historyTable, historyPanel.getAffectedFilesTable(), 0, expected);
    // -----------
    // Assert the affected files
    // -----------
    assertAffectedFiles(historyPanel, "(changeType=RENAME, fileLocation=file_renamed.txt)\n");
    // ---------------
    // Invoke the Diff action to see if the built URLs are O.K.
    // ---------------
    HistoryTableAffectedFilesModel affectedFilesModel = (HistoryTableAffectedFilesModel) historyPanel.getAffectedFilesTable().getModel();
    FileStatus fileStatus = affectedFilesModel.getFilesStatuses().get(0);
    CommitCharacteristics cc = model.getAllCommits().get(0);
    Action action = getCompareWithPreviousAction(fileStatus, cc);
    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://" + model.getAllCommits().get(0).getCommitId() + "/file_renamed.txt", left.toString());
    assertEquals("git://" + model.getAllCommits().get(1).getCommitId() + "/file.txt", right.toString());
}
Also used : HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) 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 9 with HistoryCommitTableModel

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

the class HistoryPanel3Test method testCreateBranchFromCommit.

/**
 * <p><b>Description:</b> create new branch starting from a commit from the history table.</p>
 * <p><b>Bug ID:</b> EXM-45710-</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testCreateBranchFromCommit() 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().checkoutCommitAndCreateBranch("new_branch", commitCharacteristics.getCommitId());
        waitForScheduler();
        sleep(400);
        assertEquals("new_branch", GitAccess.getInstance().getBranchInfo().getBranchName());
        // Check the history of the new branch
        commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
        dump = dumpHistory(commitsCharacteristics);
        expected = "[ 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);
    } 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 10 with HistoryCommitTableModel

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

the class HistoryPanelQuickSearchTest method testSearchNoMatch.

/**
 * Tests search with a word that could not be found in the history list
 *
 * @throws Exception If it fails.
 */
@Test
public void testSearchNoMatch() 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();
    model.filterChanged("nimic");
    sleep(300);
    String dump = dumpHistory(model.getAllCommits(), true);
    assertEquals("", dump);
}
Also used : HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) JTable(javax.swing.JTable) File(java.io.File) 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