Search in sources :

Example 1 with CommitCharacteristics

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

the class GitHistoryActionsTest method testHistoryContextualActions.

/**
 * Tests the contextual actions that are presented for different types of changes.
 *
 * @throws Exception
 */
@Test
public void testHistoryContextualActions() throws Exception {
    URL script = getClass().getClassLoader().getResource("scripts/history_script_actions.txt");
    File wcTree = new File("target/gen/GitHistoryActionsTest_testHistoryContextualActions");
    RepoGenerationScript.generateRepository(script, wcTree);
    try {
        GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
        List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
        String dump = dumpHistory(commitsCharacteristics);
        String expected = "[ Changes. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second commit. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
        String regex = "(([0-9])|([0-2][0-9])|([3][0-1]))\\ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\ \\d{4}";
        expected = expected.replaceAll(regex, "DATE");
        dump = dump.replaceAll(regex, "DATE");
        assertEquals(expected, dump);
        HistoryViewContextualMenuPresenter presenter = new HistoryViewContextualMenuPresenter(null);
        List<Action> actions = new ArrayList<>();
        JPopupMenu jPopupMenu = Mockito.mock(JPopupMenu.class);
        // ////////////////////////
        // Changes.
        // ////////////////////////
        Iterator<CommitCharacteristics> iterator = commitsCharacteristics.iterator();
        CommitCharacteristics commitCharacteristic = iterator.next();
        List<FileStatus> changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
        String dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=CHANGED, fileLocation=file1.txt)\n" + "(changeType=REMOVED, fileLocation=file2.txt)\n" + "", dumpFS);
        // Assert the available actions for the changed file.
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, true);
        actions.removeIf(e -> e == null);
        assertEquals("[Compare_file_with_previous_version, " + "Compare_file_with_working_tree_version, " + "Open_this_version_of_filename, " + "Open_the_working_copy_version_of, " + "Reset_file_x_to_this_commit]", dumpActions(actions));
        // A deleted file.
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(1), commitCharacteristic, true);
        actions.removeIf(e -> e == null);
        presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
        assertEquals("[Open_previous_version]", dumpActions(actions));
        // Next COMMIT / REVISION
        commitCharacteristic = iterator.next();
        changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
        dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=ADD, fileLocation=file2.txt)\n" + "", dumpFS);
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, true);
        actions.removeIf(e -> e == null);
        presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
        assertEquals("[Compare_file_with_working_tree_version," + " Open_this_version_of_filename," + " Open_the_working_copy_version_of]", dumpActions(actions));
        // Next COMMIT / REVISION
        commitCharacteristic = iterator.next();
        changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
        dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=ADD, fileLocation=file1.txt)\n" + "", dumpFS);
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, true);
        actions.removeIf(e -> e == null);
        assertEquals("[Compare_file_with_working_tree_version, Open_this_version_of_filename," + " Open_the_working_copy_version_of, Reset_file_x_to_this_commit]", dumpActions(actions));
        actions = new ArrayList<>();
        // ////////////////////////
        // Changes.
        // ////////////////////////
        iterator = commitsCharacteristics.iterator();
        commitCharacteristic = iterator.next();
        changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
        dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=CHANGED, fileLocation=file1.txt)\n" + "(changeType=REMOVED, fileLocation=file2.txt)\n" + "", dumpFS);
        // Assert the available actions for the changed file.
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, false);
        actions.removeIf(e -> e == null);
        assertEquals("[Compare_with_previous_version, Compare_with_working_tree_version, " + "Open, Open_working_copy_version, Reset_file_to_this_commit]", dumpActions(actions));
        // A deleted file.
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(1), commitCharacteristic, false);
        actions.removeIf(e -> e == null);
        presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
        assertEquals("[Open_previous_version]", dumpActions(actions));
        // Next COMMIT / REVISION
        commitCharacteristic = iterator.next();
        changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
        dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=ADD, fileLocation=file2.txt)\n" + "", dumpFS);
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, false);
        actions.removeIf(e -> e == null);
        presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
        assertEquals("[Compare_with_working_tree_version, Open, Open_working_copy_version]", dumpActions(actions));
        // Next COMMIT / REVISION
        commitCharacteristic = iterator.next();
        changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
        dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=ADD, fileLocation=file1.txt)\n" + "", dumpFS);
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, false);
        actions.removeIf(e -> e == null);
        assertEquals("[Compare_with_working_tree_version, Open, Open_working_copy_version, Reset_file_to_this_commit]", dumpActions(actions));
        // ========================= Uncommitted changes ======================================
        File newFile = new File(wcTree, "newFile.xml");
        newFile.createNewFile();
        setFileContent(new File(wcTree, "file1.txt"), "branza");
        commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
        dump = dumpHistory(commitsCharacteristics);
        expected = "[ Uncommitted_changes , DATE , * , * , null , null ]\n" + "[ Changes. , DATE , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second commit. , DATE , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , DATE , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
        expected = expected.replaceAll(regex, "DATE");
        dump = dump.replaceAll(regex, "DATE");
        assertEquals(expected, dump);
        CommitCharacteristics uncommittedChanges = commitsCharacteristics.get(0);
        changedFiles = RevCommitUtil.getChangedFiles(uncommittedChanges.getCommitId());
        dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=UNTRACKED, fileLocation=newFile.xml)\n" + "(changeType=MODIFIED, fileLocation=file1.txt)\n" + "", dumpFS);
        // Assert the available actions for the untracked file.
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), uncommittedChanges, false);
        actions.removeIf(e -> e == null);
        assertEquals("[Open]", dumpActions(actions));
        // Assert the available actions for the modified file.
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(1), uncommittedChanges, false);
        actions.removeIf(e -> e == null);
        assertEquals("[Open_In_Compare, Open]", dumpActions(actions));
        // ====== DELETE a file =====
        Files.delete(new File(wcTree, "file1.txt").toPath());
        Files.delete(newFile.toPath());
        // Assuming the delete was performed outside Oxygen so we need to simulate
        // a window activation event that resets cache.
        GitAccess.getInstance().getStatusCache().resetCache();
        commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
        dump = dumpHistory(commitsCharacteristics);
        expected = "[ Uncommitted_changes , DATE , * , * , null , null ]\n" + "[ Changes. , DATE , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second commit. , DATE , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , DATE , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
        expected = expected.replaceAll(regex, "DATE");
        dump = dump.replaceAll(regex, "DATE");
        assertEquals(expected, dump);
        uncommittedChanges = commitsCharacteristics.get(0);
        changedFiles = RevCommitUtil.getChangedFiles(uncommittedChanges.getCommitId());
        dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=MISSING, fileLocation=file1.txt)\n" + "", dumpFS);
        // Assert the available actions for the missing file.
        actions.clear();
        actions = presenter.getFileContextualActions(changedFiles.get(0), uncommittedChanges, false);
        actions.removeIf(e -> e == null);
        assertEquals("[Open_previous_version]", dumpActions(actions));
    } finally {
        GitAccess.getInstance().closeRepo();
        FileUtils.deleteDirectory(wcTree);
    }
}
Also used : RenameTracker(com.oxygenxml.git.view.history.RenameTracker) Action(javax.swing.Action) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) JPopupMenu(javax.swing.JPopupMenu) File(java.io.File) HistoryViewContextualMenuPresenter(com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter) Test(org.junit.Test)

Example 2 with CommitCharacteristics

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

the class GitHistoryActionsTest method testHistoryUncommittedChangesActions.

/**
 * Tests the uncommitted changes to see if they have any contextual actions.
 *
 * @throws Exception
 */
@Test
public void testHistoryUncommittedChangesActions() throws Exception {
    URL script = getClass().getClassLoader().getResource("scripts/history_script_actions.txt");
    File wcTree = new File("target/gen/GitHistoryActionsTest_testHistoryUncommitedChangesActions");
    RepoGenerationScript.generateRepository(script, wcTree);
    File file = new File(wcTree, "file.txt");
    file.createNewFile();
    setFileContent(file, "modified content");
    try {
        GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
        HistoryViewContextualMenuPresenter presenter = new HistoryViewContextualMenuPresenter(null);
        // ////////////////////////
        // Changes.
        // ////////////////////////
        CommitCharacteristics commitCharacteristic = GitAccess.UNCOMMITED_CHANGES;
        List<FileStatus> changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
        String dumpFS = dumpFS(changedFiles);
        assertEquals("(changeType=UNTRACKED, fileLocation=file.txt)\n" + "", dumpFS);
        // Assert the available actions for the changed file.
        JPopupMenu jPopupMenu = new JPopupMenu();
        presenter.populateContextualActionsHistoryContext(jPopupMenu, null, GitAccess.UNCOMMITED_CHANGES);
        assertEquals(0, jPopupMenu.getComponentCount());
    } finally {
        GitAccess.getInstance().closeRepo();
        FileUtils.deleteDirectory(wcTree);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) File(java.io.File) HistoryViewContextualMenuPresenter(com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) JPopupMenu(javax.swing.JPopupMenu) Test(org.junit.Test)

Example 3 with CommitCharacteristics

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

the class GitHistoryActionsTest method testOpenPreviousVersion_MergedBranches.

/**
 * A commit with a removed file. The commit has 2 parents (it's a merge).
 *
 * @throws Exception If it fails.
 */
@Test
public void testOpenPreviousVersion_MergedBranches() throws Exception {
    URL script = getClass().getClassLoader().getResource("scripts/history_script_actions_branches_merged.txt");
    File wcTree = new File("target/gen/GitHistoryActionsTest_testHistoryActions_MergedBranches");
    RepoGenerationScript.generateRepository(script, wcTree);
    try {
        GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
        List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
        String dump = dumpHistory(commitsCharacteristics);
        String expected = "[ Merge branch 'main' , 19 Nov 2019 , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2, 3] ]\n" + "[ Change file1.txt on Feature branch. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [4] ]\n" + "[ Delete file2.txt main branch. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First commit. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]\n" + "";
        String regex = "(([0-9])|([0-2][0-9])|([3][0-1]))\\ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\ \\d{4}";
        expected = expected.replaceAll(regex, "DATE");
        dump = expected.replaceAll(regex, "DATE");
        assertEquals(expected, dump);
        HistoryViewContextualMenuPresenter presenter = new HistoryViewContextualMenuPresenter(null);
        List<Action> actions = new ArrayList<>();
        JPopupMenu jPopupMenu = Mockito.mock(JPopupMenu.class);
        // ////////////////////////
        // Changes.
        // ////////////////////////
        Iterator<CommitCharacteristics> iterator = commitsCharacteristics.iterator();
        CommitCharacteristics commitCharacteristics = iterator.next();
        List<FileStatus> changes = RevCommitUtil.getChangedFiles(commitCharacteristics.getCommitId());
        String dumpFS = dumpFS(changes);
        assertEquals("(changeType=REMOVED, fileLocation=file2.txt)\n" + "", dumpFS);
        // A deleted file.
        actions.clear();
        actions = presenter.getFileContextualActions(changes.get(0), commitCharacteristics, true);
        presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristics);
        assertEquals("[Open_previous_version]", dumpActions(actions));
        final StringBuilder b = new StringBuilder();
        Mockito.when(PluginWorkspaceProvider.getPluginWorkspace().open((URL) Mockito.any())).thenAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                b.append(invocation.getArguments()[0].toString());
                return null;
            }
        });
        actions.get(0).actionPerformed(null);
        assertTrue("Previous version URL was not detected", b.toString().length() > 0);
        try (InputStream openStream = new URL(b.toString()).openStream()) {
            assertEquals("[file 2 content]", IOUtils.readLines(openStream).toString());
        }
    } finally {
        GitAccess.getInstance().closeRepo();
        FileUtils.deleteDirectory(wcTree);
    }
}
Also used : RenameTracker(com.oxygenxml.git.view.history.RenameTracker) Action(javax.swing.Action) FileStatus(com.oxygenxml.git.service.entities.FileStatus) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) JPopupMenu(javax.swing.JPopupMenu) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) HistoryViewContextualMenuPresenter(com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter) Test(org.junit.Test)

Example 4 with CommitCharacteristics

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

the class TagsVisualTests method testCreateTagsDialog.

/**
 * <p><b>Description:</b> Tests that the "Create Tags" dialog can't have wrong title values</p>
 * <p><b>Bug ID:</b> EXM-46109</p>
 *
 * @author gabriel_nedianu
 *
 * @throws Exception
 */
public void testCreateTagsDialog() throws Exception {
    createCommits(5);
    // Make 1 tag then make the others with the CreateTag Dialog
    List<CommitCharacteristics> commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String commitIdForTag1 = commitsCharacteristics.get(0).getCommitId();
    gitAccess.tagCommit("Tag1", "MesajTag1", commitIdForTag1);
    String commitIdForTag2 = commitsCharacteristics.get(3).getCommitId();
    // Create a tag with a custom name and message and not push, after this create one pushed then verify if they were corectly added to the Show Dialog
    CreateTagDialog createTagDialog;
    SwingUtilities.invokeLater(() -> {
        new CreateTagDialog();
    });
    flushAWT();
    createTagDialog = (CreateTagDialog) findDialog(Tags.CREATE_TAG);
    createTagDialog.getTagTitleField().setText("TagCreated");
    createTagDialog.getTagMessageField().setText("Mesaj Tag De Test");
    createTagDialog.setVisible(false);
    flushAWT();
    sleep(500);
    createTagDialog.getOkButton().doClick();
    String tagTitle = createTagDialog.getTagTitle();
    String tagMessage = createTagDialog.getTagMessage();
    if (createTagDialog.getResult() == OKCancelDialog.RESULT_OK) {
        gitAccess.tagCommit(tagTitle, tagMessage, commitIdForTag2);
        if (createTagDialog.shouldPushNewTag()) {
            gitAccess.pushTag(tagTitle);
        }
    }
    createTagDialog.dispose();
    flushAWT();
    SwingUtilities.invokeLater(() -> {
        new CreateTagDialog();
    });
    flushAWT();
    String commitIdForTag3 = commitsCharacteristics.get(2).getCommitId();
    CreateTagDialog createTagDialog2 = (CreateTagDialog) findDialog(Tags.CREATE_TAG);
    createTagDialog2.getTagTitleField().setText("Tag2Created");
    createTagDialog2.getTagMessageField().setText("Mesaj Tag De Test2");
    createTagDialog2.getPushCheckbox().setSelected(true);
    createTagDialog2.setVisible(false);
    flushAWT();
    sleep(500);
    createTagDialog2.getOkButton().doClick();
    String tagTitle2 = createTagDialog2.getTagTitle();
    String tagMessage2 = createTagDialog2.getTagMessage();
    if (createTagDialog2.getResult() == OKCancelDialog.RESULT_OK) {
        gitAccess.tagCommit(tagTitle2, tagMessage2, commitIdForTag3);
        if (createTagDialog2.shouldPushNewTag()) {
            gitAccess.pushTag(tagTitle2);
        }
    }
    // Verify if the tags were created
    assertTrue(gitAccess.existsTag("Tag1"));
    assertTrue(gitAccess.existsTag("TagCreated"));
    assertTrue(gitAccess.existsTag("Tag2Created"));
}
Also used : CreateTagDialog(com.oxygenxml.git.view.tags.CreateTagDialog) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics)

Example 5 with CommitCharacteristics

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

the class GitHistoryTest method testHistory_ResourceUntouched.

/**
 * Tests the history can be shown for a resource that is not modified.
 *
 * @throws Exception
 */
@Test
public void testHistory_ResourceUntouched() throws Exception {
    URL script = getClass().getClassLoader().getResource("scripts/history_script.txt");
    File wcTree = new File("target/gen/testHistory_ResourceUntouched");
    RepoGenerationScript.generateRepository(script, wcTree);
    try {
        GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
        List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, "root.txt", new RenameTracker());
        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 , null ]\n";
        expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
        assertEquals("root.txt was created and changed in the last two commit", expected, dump);
    } finally {
        GitAccess.getInstance().closeRepo();
        FileUtils.deleteDirectory(wcTree);
    }
}
Also used : RenameTracker(com.oxygenxml.git.view.history.RenameTracker) File(java.io.File) URL(java.net.URL) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) Date(java.util.Date) Test(org.junit.Test)

Aggregations

CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)37 File (java.io.File)24 Test (org.junit.Test)22 URL (java.net.URL)21 FileStatus (com.oxygenxml.git.service.entities.FileStatus)17 HistoryCommitTableModel (com.oxygenxml.git.view.history.HistoryCommitTableModel)16 JTable (javax.swing.JTable)16 Date (java.util.Date)12 Action (javax.swing.Action)11 RenameTracker (com.oxygenxml.git.view.history.RenameTracker)9 GitController (com.oxygenxml.git.view.event.GitController)8 HistoryTableAffectedFilesModel (com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel)8 HistoryViewContextualMenuPresenter (com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter)8 JPopupMenu (javax.swing.JPopupMenu)8 IOException (java.io.IOException)7 List (java.util.List)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 GitAccess (com.oxygenxml.git.service.GitAccess)6 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)6 Semaphore (java.util.concurrent.Semaphore)6