Search in sources :

Example 36 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class FlatView7Test method testToolbarComponentsTooltips.

/**
 * <p><b>Description:</b> Test the tooltips of the pull/push buttons and branch label.</p>
 * <p><b>Bug ID:</b> EXM-45599, EXM-44564</p>
 *
 * @author sorin_carbunaru
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
@Test
public void testToolbarComponentsTooltips() throws Exception {
    // Set toolbar panel
    stagingPanel.setToolbarPanelFromTests(new ToolbarPanel((GitController) stagingPanel.getGitController(), gitActionsManager));
    // Create repositories
    String localTestRepository = "target/test-resources/test_EXM_45599_local";
    String localTestRepository_2 = "target/test-resources/test_EXM_45599_local_2";
    String remoteTestRepository = "target/test-resources/test_EXM_45599_remote";
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    bindLocalToRemote(localRepo, remoteRepo);
    Repository localRepo_2 = createRepository(localTestRepository_2);
    bindLocalToRemote(localRepo_2, remoteRepo);
    sleep(500);
    pushOneFileToRemote(localTestRepository, "init.txt", "hello");
    flushAWT();
    BranchSelectionCombo branchesCombo = stagingPanel.getBranchesCombo();
    branchesCombo.refresh();
    flushAWT();
    // Create local branch
    Git git = GitAccess.getInstance().getGit();
    git.branchCreate().setName("new_branch").call();
    GitAccess.getInstance().setBranch("new_branch");
    ToolbarPanel toolbarPanel = stagingPanel.getToolbarPanel();
    branchesCombo.refresh();
    flushAWT();
    refreshSupport.call();
    flushAWT();
    assertEquals("<html>Cannot_pull<br>No_remote_branch.</html>", toolbarPanel.getPullMenuButton().getToolTipText());
    assertEquals("<html>Push_to_create_and_track_remote_branch</html>", toolbarPanel.getPushButton().getToolTipText());
    assertEquals("<html>Local_branch <b>new_branch</b>.<br>Upstream_branch <b>No_upstream_branch</b>.<br></html>", branchesCombo.getToolTipText());
    // Push to create the remote branch
    ((GitController) stagingPanel.getGitController()).push();
    waitForScheluerBetter();
    branchesCombo.refresh();
    flushAWT();
    refreshSupport.call();
    flushAWT();
    // Tooltip texts changed
    assertEquals("<html>Pull_merge_from.<br>Toolbar_Panel_Information_Status_Up_To_Date<br><br></html>", toolbarPanel.getPullMenuButton().getToolTipText());
    assertEquals("<html>Push_to.<br>Nothing_to_push<br><br></html>", toolbarPanel.getPushButton().getToolTipText());
    assertEquals("<html>Local_branch <b>new_branch</b>.<br>Upstream_branch <b>origin/new_branch</b>.<br>" + "Toolbar_Panel_Information_Status_Up_To_Date<br>Nothing_to_push</html>", branchesCombo.getToolTipText());
    GitAccess.getInstance().setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    flushAWT();
    // Commit a new file locally
    commitOneFile(localTestRepository, "anotherFile.txt", "");
    waitForScheluerBetter();
    // Commit to remote
    commitOneFile(remoteTestRepository, "anotherFile_2.txt", "");
    waitForScheluerBetter();
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository);
    flushAWT();
    GitAccess.getInstance().fetch();
    branchesCombo.refresh();
    refreshSupport.call();
    flushAWT();
    // Tooltip texts changed again
    String expected = "<html>Pull_merge_from.<br>One_commit_behind<br><br>&#x25AA; Date, Hour &ndash; AlexJitianu (2 files)" + "<br>&nbsp;&nbsp;&nbsp;New file: anotherFile_2.txt<br></html>";
    String regexDate = "(([0-9])|([0-2][0-9])|([3][0-1]))\\ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\ \\d{4}";
    String regexHour = "(\\d\\d:\\d\\d)";
    String actual = toolbarPanel.getPullMenuButton().getToolTipText();
    actual = actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour");
    assertEquals(expected, actual);
    expected = "<html>Push_to.<br>One_commit_ahead<br><br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile.txt<br></html>";
    actual = toolbarPanel.getPushButton().getToolTipText();
    actual = actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour");
    assertEquals(expected, actual);
    actual = branchesCombo.getToolTipText();
    assertEquals("<html>Local_branch <b>" + GitAccess.DEFAULT_BRANCH_NAME + "</b>.<br>Upstream_branch <b>origin/" + GitAccess.DEFAULT_BRANCH_NAME + "</b>.<br>" + "One_commit_behind<br>One_commit_ahead</html>", branchesCombo.getToolTipText());
    // Commit a new change locally
    commitOneFile(localTestRepository, "anotherFile.txt", "changed");
    waitForScheluerBetter();
    // Commit to remote
    commitOneFile(remoteTestRepository, "anotherFile_2.txt", "changed");
    waitForScheluerBetter();
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository);
    GitAccess.getInstance().fetch();
    branchesCombo.refresh();
    flushAWT();
    refreshSupport.call();
    flushAWT();
    expected = "<html>Pull_merge_from.<br>Commits_behind<br><br>&#x25AA; Date, Hour &ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile_2.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (2 files)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile_2.txt<br></html>";
    actual = toolbarPanel.getPullMenuButton().getToolTipText();
    assertEquals(expected, actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour"));
    expected = "<html>Push_to.<br>Commits_ahead<br><br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile.txt<br></html>";
    actual = toolbarPanel.getPushButton().getToolTipText();
    assertEquals(expected, actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour"));
    assertEquals("<html>Local_branch <b>" + GitAccess.DEFAULT_BRANCH_NAME + "</b>.<br>Upstream_branch <b>origin/" + GitAccess.DEFAULT_BRANCH_NAME + "</b>.<br>" + "Commits_behind<br>Commits_ahead</html>", branchesCombo.getToolTipText());
    // Commit a new change locally
    commitOneFile(localTestRepository, "anotherFile200000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000" + ".txt", "changed2");
    waitForScheluerBetter();
    // Commit to remote
    commitOneFile(remoteTestRepository, "anotherFile300000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000" + ".txt", "changed3");
    waitForScheluerBetter();
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository);
    GitAccess.getInstance().fetch();
    branchesCombo.refresh();
    flushAWT();
    refreshSupport.call();
    flushAWT();
    expected = "<html>Pull_merge_from.<br>Commits_behind<br><br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile300000000000000000000000000000000000000...<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile_2.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (2 files)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile_2.txt<br></html>";
    actual = toolbarPanel.getPullMenuButton().getToolTipText();
    assertEquals(expected, actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour"));
    expected = "<html>Push_to.<br>Commits_ahead<br><br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile200000000000000000000000000000000000000...<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile.txt<br></html>";
    actual = toolbarPanel.getPushButton().getToolTipText();
    assertEquals(expected, actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour"));
    String[] filesForCommit = { "6anotherFile45.txt", "5anotherFile45.txt", "4anotherFile45.txt", "3anotherFile45.txt", "2anotherFile45.txt", "1anotherFile45.txt", "anotherFil233e45.txt", "anotherFil333e45.txt", "anotherFileee45.txt", "anotherFile45w.txt" };
    for (int i = 0; i < filesForCommit.length; i++) {
        // Commit a new change locally
        commitOneFile(localTestRepository, filesForCommit[i], "changed");
        waitForScheluerBetter();
        // Commit to remote
        commitOneFile(remoteTestRepository, "_" + filesForCommit[i], "changed");
        waitForScheluerBetter();
    }
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository);
    GitAccess.getInstance().fetch();
    branchesCombo.refresh();
    flushAWT();
    refreshSupport.call();
    flushAWT();
    expected = "<html>Pull_merge_from.<br>Commits_behind<br><br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: _anotherFile45w.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: _anotherFileee45.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: _anotherFil333e45.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: _anotherFil233e45.txt<br>&#x25AA; [...] " + "&ndash; N_More_Commits<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (2 files)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile_2.txt<br><br>See_all_commits_in_Git_History</html>";
    actual = toolbarPanel.getPullMenuButton().getToolTipText();
    assertEquals(expected, actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour"));
    expected = "<html>Push_to.<br>Commits_ahead<br><br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile45w.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFileee45.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFil333e45.txt<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFil233e45.txt<br>&#x25AA; [...] " + "&ndash; N_More_Commits<br>&#x25AA; Date, Hour " + "&ndash; AlexJitianu (1 file)<br>&nbsp;&nbsp;&nbsp;New file: anotherFile.txt<br><br>See_all_commits_in_Git_History</html>";
    actual = toolbarPanel.getPushButton().getToolTipText();
    assertEquals(expected.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour"), actual.replaceAll(regexDate, "Date").replaceAll(regexHour, "Hour"));
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) GitController(com.oxygenxml.git.view.event.GitController) Test(org.junit.Test)

Example 37 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class FlatViewTest method testDontEnableSubmoduleButtonForEveryPushOrPull.

/**
 * <p><b>Description:</b> don't activate the submodule selection button every time you push/pull.</p>
 * <p><b>Bug ID:</b> EXM-40740</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testDontEnableSubmoduleButtonForEveryPushOrPull() throws Exception {
    // TODO - review this with Alex
    final boolean[] hasSubmodules = new boolean[1];
    hasSubmodules[0] = false;
    GitController gitController = (GitController) stagingPanel.getGitController();
    final GitActionsManager gitActionsManager = new GitActionsManager(gitController, null, null, null) {

        @Override
        protected boolean hasRepositorySubmodules() {
            return hasSubmodules[0];
        }

        @Override
        protected boolean hasRepository() {
            return true;
        }
    };
    final AbstractAction submoduleActions = gitActionsManager.getSubmoduleAction();
    gitActionsManager.refreshActionsStates();
    // ================= No submodules ====================
    Future<?> pull2 = gitController.pull();
    pull2.get();
    gitActionsManager.refreshActionsStates();
    assertFalse(submoduleActions.isEnabled());
    // ================= Set submodule ====================
    Future<?> pull = gitController.pull();
    hasSubmodules[0] = true;
    pull.get();
    flushAWT();
    gitActionsManager.refreshActionsStates();
    flushAWT();
    assertTrue(submoduleActions.isEnabled());
}
Also used : GitController(com.oxygenxml.git.view.event.GitController) AbstractAction(javax.swing.AbstractAction) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 38 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class DiffPresenterTest method testRebasingFileDiff.

@Test
public void testRebasingFileDiff() throws Exception {
    // The local repositories.
    String localTestRepository1 = "target/test-resources/local1";
    String localTestRepository2 = "target/test-resources/local2";
    // The remote repository.
    String remoteTestRepository = "target/test-resources/remote";
    GitAccess gitAccess = GitAccess.getInstance();
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo1 = createRepository(localTestRepository1);
    Repository localRepo2 = createRepository(localTestRepository2);
    // -------------
    // Set up the repositories for a rebase conflict
    // -------------
    // ----------------
    // LOCAL 1
    // ----------------
    // Bind the local repository 1 to the remote one.
    bindLocalToRemote(localRepo1, remoteRepo);
    gitAccess.setRepositorySynchronously(localTestRepository1);
    // Create a new file for the first repository.
    File localFile1 = new File(localTestRepository1 + "/test.txt");
    localFile1.createNewFile();
    // Modify the newly created file.
    setFileContent(localFile1, "initial content");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("First commit.");
    // Send it to remote/upstream.
    push("", "");
    // ----------------
    // LOCAL 2
    // ----------------
    // Bind the local repository 2 to the remote one.
    bindLocalToRemote(localRepo2, remoteRepo);
    gitAccess.setRepositorySynchronously(localTestRepository2);
    // Receive changes from remote/upstream.
    PullResponse pull = pull("", "", PullType.MERGE_FF, false);
    assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
    // Create new file for second repository.
    File local2File = new File(localTestRepository2, "test.txt");
    assertEquals("initial content", TestUtil.read(local2File.toURI().toURL()));
    // Modify the file.
    setFileContent(local2File, "changed in local 2, resolved");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    gitAccess.commit("Second commit");
    // Send it to remote/upstream.
    push("", "");
    // ----------------
    // LOCAL 1
    // ----------------
    gitAccess.setRepositorySynchronously(localTestRepository1);
    // Modify the file.
    setFileContent(localFile1, "changed in local 1, conflict content, original");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    // Commit the file.
    gitAccess.commit("Third commit, with conflict");
    // ------------
    // Rebase conflict prepared and will happen after the pull.
    // ------------
    final StringBuilder pullWithConflictsSB = new StringBuilder();
    boolean[] wasRebaseInterrupted = new boolean[1];
    final String[] pullFailedMessage = new String[1];
    GitController pc = new GitController(gitAccess) {

        @Override
        protected void showPullFailedBecauseOfCertainChanges(List<String> changes, String message) {
            pullFailedMessage[0] = message;
        }

        @Override
        protected void showPullSuccessfulWithConflicts(PullResponse response) {
            pullWithConflictsSB.append(response);
        }

        @Override
        protected void showRebaseInProgressDialog() {
            wasRebaseInterrupted[0] = true;
        }
    };
    final StringBuilder b = new StringBuilder();
    TestUtil.collectPushPullEvents(pc, b);
    // Get conflict
    pc.pull(PullType.REBASE).get();
    assertNull(pullFailedMessage[0]);
    assertFalse(wasRebaseInterrupted[0]);
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflictsSB.toString());
    assertTrue(TestUtil.read(localFile1.toURI().toURL()).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
    leftDiff = null;
    rightDiff = null;
    // Mock the GitController
    GitControllerBase gitCtrl = Mockito.mock(GitControllerBase.class);
    FileStatus fileStatus = new FileStatus(GitChangeType.CONFLICT, "test.txt");
    // Invoke DIFF over the changed file.
    DiffPresenter.showDiff(fileStatus, gitCtrl);
    assertNotNull(leftDiff);
    assertNotNull(rightDiff);
    // Verify that each side has the proper tag and content.
    assertTrue(leftDiff.toString().contains("MineResolved"));
    assertTrue(rightDiff.toString().contains("MineOriginal"));
    assertEquals("changed in local 2, resolved", TestUtil.read(leftDiff));
    assertEquals("changed in local 1, conflict content, original", TestUtil.read(rightDiff));
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) Repository(org.eclipse.jgit.lib.Repository) GitAccess(com.oxygenxml.git.service.GitAccess) FileStatus(com.oxygenxml.git.service.entities.FileStatus) PullResponse(com.oxygenxml.git.service.PullResponse) GitController(com.oxygenxml.git.view.event.GitController) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 39 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class RemoteVisualTests method testManageBasicsRemote.

/**
 * <p><b>Description:</b> Tests the action for manage remote from remote button of git staging toolbar.</p>
 * <p><b>Bug ID:</b> EXM-40858</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testManageBasicsRemote() throws Exception {
    gitAccess.setRepositorySynchronously(LOCAL_REPO);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        refreshSupport.call();
        flushAWT();
        SwingUtilities.invokeLater(() -> gitActionsManager.getManageRemoteRepositoriesAction().actionPerformed(null));
        flushAWT();
        // -----> TEST ADD REMOTE OPTION <----- //
        RemotesRepositoryDialog[] manageRemoteDialog = new RemotesRepositoryDialog[1];
        manageRemoteDialog[0] = (RemotesRepositoryDialog) findDialog(Tags.REMOTES_DIALOG_TITLE);
        assertNotNull(manageRemoteDialog);
        flushAWT();
        RemotesTableModel model = manageRemoteDialog[0].getModel();
        final String firstRemoteName = (String) model.getValueAt(0, 0);
        final String firstRemoteURL = (String) model.getValueAt(0, 1);
        assertEquals(1, model.getRowCount());
        JButton doAddButton = findFirstButton(manageRemoteDialog[0], Tags.ADD + "...");
        assertNotNull(doAddButton);
        SwingUtilities.invokeLater(() -> doAddButton.doClick());
        flushAWT();
        OKCancelDialog addRemoteDialog = (OKCancelDialog) findDialog(Tags.ADD_REMOTE);
        assertNotNull(addRemoteDialog);
        flushAWT();
        JTextField remoteNameTF = TestUtil.findFirstTextField(addRemoteDialog);
        assertNotNull(remoteNameTF);
        SwingUtilities.invokeLater(() -> remoteNameTF.setText("Custom remote"));
        flushAWT();
        JTextField[] remoteURLTF = new JTextField[1];
        remoteURLTF[0] = TestUtil.findNthTextField(addRemoteDialog, 2);
        assertNotNull(remoteURLTF[0]);
        SwingUtilities.invokeLater(() -> remoteURLTF[0].setText("https/custom_link.ro"));
        flushAWT();
        sleep(500);
        SwingUtilities.invokeLater(() -> addRemoteDialog.getOkButton().doClick());
        flushAWT();
        assertEquals(2, model.getRowCount());
        assertEquals("Custom remote", (String) model.getValueAt(1, 0));
        assertEquals("https/custom_link.ro", (String) model.getValueAt(1, 1));
        flushAWT();
        SwingUtilities.invokeLater(() -> manageRemoteDialog[0].getOkButton().doClick());
        // Test if the remotes has been saved after confirmation.
        SwingUtilities.invokeLater(() -> gitActionsManager.getManageRemoteRepositoriesAction().actionPerformed(null));
        flushAWT();
        manageRemoteDialog[0] = (RemotesRepositoryDialog) findDialog(Tags.REMOTES_DIALOG_TITLE);
        assertNotNull(manageRemoteDialog);
        flushAWT();
        model = manageRemoteDialog[0].getModel();
        assertEquals(2, model.getRowCount());
        assertEquals("Custom remote", (String) model.getValueAt(0, 0));
        assertEquals("https/custom_link.ro", (String) model.getValueAt(0, 1));
        // -----> TEST EDIT REMOTE OPTION <----- //
        JTable[] table = new JTable[1];
        table[0] = manageRemoteDialog[0].getTable();
        SwingUtilities.invokeLater(() -> table[0].addRowSelectionInterval(0, 0));
        flushAWT();
        JButton editButton = findFirstButton(manageRemoteDialog[0], Tags.EDIT);
        assertNotNull(editButton);
        SwingUtilities.invokeLater(() -> editButton.doClick());
        flushAWT();
        OKCancelDialog editRemoteDialog = (OKCancelDialog) findDialog(Tags.EDIT_REMOTE);
        assertNotNull(editRemoteDialog);
        flushAWT();
        remoteURLTF[0] = TestUtil.findNthTextField(editRemoteDialog, 2);
        assertNotNull(remoteURLTF[0]);
        SwingUtilities.invokeLater(() -> remoteURLTF[0].setText("https/edit_link.ro"));
        flushAWT();
        sleep(500);
        SwingUtilities.invokeLater(() -> editRemoteDialog.getOkButton().doClick());
        flushAWT();
        model = manageRemoteDialog[0].getModel();
        assertEquals(2, model.getRowCount());
        assertEquals("Custom remote", (String) model.getValueAt(0, 0));
        assertEquals("https/edit_link.ro", (String) model.getValueAt(0, 1));
        flushAWT();
        SwingUtilities.invokeLater(() -> manageRemoteDialog[0].getOkButton().doClick());
        // Test if the remotes has been saved after confirmation.
        SwingUtilities.invokeLater(() -> gitActionsManager.getManageRemoteRepositoriesAction().actionPerformed(null));
        flushAWT();
        manageRemoteDialog[0] = (RemotesRepositoryDialog) findDialog(Tags.REMOTES_DIALOG_TITLE);
        assertNotNull(manageRemoteDialog);
        flushAWT();
        model = manageRemoteDialog[0].getModel();
        assertEquals(2, model.getRowCount());
        assertEquals("Custom remote", (String) model.getValueAt(0, 0));
        assertEquals("https/edit_link.ro", (String) model.getValueAt(0, 1));
        // -----> TEST DELETE REMOTE OPTION <----- //
        table[0] = manageRemoteDialog[0].getTable();
        SwingUtilities.invokeLater(() -> table[0].addRowSelectionInterval(0, 0));
        flushAWT();
        JButton deleteButton = findFirstButton(manageRemoteDialog[0], Tags.DELETE);
        assertNotNull(deleteButton);
        SwingUtilities.invokeLater(() -> deleteButton.doClick());
        flushAWT();
        OKCancelDialog deleteRemoteDialog = (OKCancelDialog) findDialog(Tags.DELETE_REMOTE);
        assertNotNull(deleteRemoteDialog);
        flushAWT();
        sleep(500);
        SwingUtilities.invokeLater(() -> deleteRemoteDialog.getOkButton().doClick());
        flushAWT();
        model = manageRemoteDialog[0].getModel();
        assertEquals(1, model.getRowCount());
        assertEquals(firstRemoteName, (String) model.getValueAt(0, 0));
        assertEquals(firstRemoteURL, (String) model.getValueAt(0, 1));
        flushAWT();
        SwingUtilities.invokeLater(() -> manageRemoteDialog[0].getOkButton().doClick());
        // Test if the remotes has been saved after confirmation.
        SwingUtilities.invokeLater(() -> gitActionsManager.getManageRemoteRepositoriesAction().actionPerformed(null));
        flushAWT();
        manageRemoteDialog[0] = (RemotesRepositoryDialog) findDialog(Tags.REMOTES_DIALOG_TITLE);
        assertNotNull(manageRemoteDialog);
        flushAWT();
        model = manageRemoteDialog[0].getModel();
        assertEquals(1, model.getRowCount());
        assertEquals(firstRemoteName, (String) model.getValueAt(0, 0));
        assertEquals(firstRemoteURL, (String) model.getValueAt(0, 1));
        table[0] = manageRemoteDialog[0].getTable();
        SwingUtilities.invokeLater(() -> table[0].addRowSelectionInterval(0, 0));
        flushAWT();
        JButton eButton = findFirstButton(manageRemoteDialog[0], Tags.EDIT);
        assertNotNull(eButton);
        SwingUtilities.invokeLater(() -> eButton.doClick());
        flushAWT();
        OKCancelDialog eRemoteDialog = (OKCancelDialog) findDialog(Tags.EDIT_REMOTE);
        assertNotNull(eRemoteDialog);
        flushAWT();
        remoteURLTF[0] = TestUtil.findNthTextField(eRemoteDialog, 2);
        assertNotNull(remoteURLTF[0]);
        SwingUtilities.invokeLater(() -> remoteURLTF[0].setText("https/edit_link_test.ro"));
        flushAWT();
        sleep(500);
        SwingUtilities.invokeLater(() -> eRemoteDialog.getOkButton().doClick());
        flushAWT();
        model = manageRemoteDialog[0].getModel();
        assertEquals(1, model.getRowCount());
        assertEquals(firstRemoteName, (String) model.getValueAt(0, 0));
        assertEquals("https/edit_link_test.ro", (String) model.getValueAt(0, 1));
        flushAWT();
        SwingUtilities.invokeLater(() -> manageRemoteDialog[0].getCancelButton().doClick());
        // Test if the remotes has not been saved after the user cancel dialog.
        SwingUtilities.invokeLater(() -> gitActionsManager.getManageRemoteRepositoriesAction().actionPerformed(null));
        flushAWT();
        manageRemoteDialog[0] = (RemotesRepositoryDialog) findDialog(Tags.REMOTES_DIALOG_TITLE);
        assertNotNull(manageRemoteDialog);
        flushAWT();
        model = manageRemoteDialog[0].getModel();
        assertEquals(1, model.getRowCount());
        assertEquals(firstRemoteName, (String) model.getValueAt(0, 0));
        assertEquals(firstRemoteURL, (String) model.getValueAt(0, 1));
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : JButton(javax.swing.JButton) OKCancelDialog(ro.sync.exml.workspace.api.standalone.ui.OKCancelDialog) GitController(com.oxygenxml.git.view.event.GitController) RemotesTableModel(com.oxygenxml.git.view.remotes.RemotesTableModel) JTextField(javax.swing.JTextField) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager) JFrame(javax.swing.JFrame) RemotesRepositoryDialog(com.oxygenxml.git.view.remotes.RemotesRepositoryDialog) JTable(javax.swing.JTable) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel)

Example 40 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class RemoteVisualTests method testEditGitConfigFile.

/**
 * <p><b>Description:</b> Tests the "Edit config" action from remote button of git staging toolbar.</p>
 * <p><b>Bug ID:</b> EXM-40858</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testEditGitConfigFile() throws Exception {
    String[] urlString = new String[1];
    String[] textTypeString = new String[1];
    ColorTheme colorTheme = Mockito.mock(ColorTheme.class);
    Mockito.when(colorTheme.isDarkTheme()).thenReturn(false);
    StandalonePluginWorkspace pluginWSMock = Mockito.mock(StandalonePluginWorkspace.class);
    Mockito.when(pluginWSMock.open((URL) Mockito.any(), (String) Mockito.any(), (String) Mockito.any())).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            urlString[0] = ((URL) invocation.getArgument(0)).toURI().toString();
            textTypeString[0] = (String) invocation.getArgument(2);
            return true;
        }
    });
    Mockito.when(pluginWSMock.getColorTheme()).thenReturn(colorTheme);
    PluginWorkspaceProvider.setPluginWorkspace(pluginWSMock);
    gitAccess.setRepositorySynchronously(LOCAL_REPO);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        refreshSupport.call();
        flushAWT();
        SwingUtilities.invokeLater(() -> gitActionsManager.getEditConfigAction().actionPerformed(null));
        flushAWT();
        assertTrue(urlString[0].endsWith("target/test-resources/GitAccessRemote/localRepository/.git/config"));
        assertEquals("text/plain", textTypeString[0]);
    } finally {
        frame.setVisible(false);
        frame.dispose();
        PluginWorkspaceProvider.setPluginWorkspace(null);
    }
}
Also used : GitController(com.oxygenxml.git.view.event.GitController) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager) JFrame(javax.swing.JFrame) ColorTheme(ro.sync.exml.workspace.api.util.ColorTheme) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel)

Aggregations

GitController (com.oxygenxml.git.view.event.GitController)66 File (java.io.File)54 FileStatus (com.oxygenxml.git.service.entities.FileStatus)48 JButton (javax.swing.JButton)29 Test (org.junit.Test)28 JDialog (javax.swing.JDialog)24 Repository (org.eclipse.jgit.lib.Repository)21 AbstractAction (javax.swing.AbstractAction)19 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)18 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)18 JFrame (javax.swing.JFrame)15 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)14 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)13 ArrayList (java.util.ArrayList)12 List (java.util.List)12 JTextField (javax.swing.JTextField)10 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)8 BranchTreeMenuActionsProvider (com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider)7 ToolbarPanel (com.oxygenxml.git.view.staging.ToolbarPanel)7 JCheckBox (javax.swing.JCheckBox)7