Search in sources :

Example 6 with JideToggleButton

use of com.jidesoft.swing.JideToggleButton in project oxygen-git-client-addon by oxygenxml.

the class FlatView5Test method testAmendCommitThatWasPushed_editCommitMesage.

/**
 * <p><b>Description:</b> Amend commit that was pushed. Edit commit message.</p>
 * <p><b>Bug ID:</b> EXM-41392</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testAmendCommitThatWasPushed_editCommitMesage() throws Exception {
    // Create repositories
    String localTestRepository = "target/test-resources/testAmendCommitThatWasPushed_2_local";
    String remoteTestRepository = "target/test-resources/testAmendCommitThatWasPushed_2_remote";
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    bindLocalToRemote(localRepo, remoteRepo);
    pushOneFileToRemote(localTestRepository, "init.txt", "hello");
    flushAWT();
    // Create a new file
    new File(localTestRepository).mkdirs();
    createNewFile(localTestRepository, "test.txt", "content");
    // No amend by default
    CommitAndStatusPanel commitPanel = stagingPanel.getCommitPanel();
    JideToggleButton amendBtn = commitPanel.getAmendLastCommitToggle();
    assertFalse(amendBtn.isSelected());
    // >>> Stage
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // >>> Commit the test file
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
    SwingUtilities.invokeLater(() -> {
        commitPanel.getCommitMessageArea().setText("FIRST COMMIT MESSAGE");
        commitPanel.getCommitButton().doClick();
    });
    waitForScheluerBetter();
    assertEquals(1, GitAccess.getInstance().getPushesAhead());
    // >>> Push
    push("", "");
    waitForScheluerBetter();
    refreshSupport.call();
    waitForScheluerBetter();
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
    SwingUtilities.invokeLater(() -> {
        commitPanel.getCommitMessageArea().setText("SECOND COMMIT MESSAGE");
    });
    flushAWT();
    PluginWorkspace pluginWSMock = Mockito.mock(StandalonePluginWorkspace.class);
    Mockito.when(pluginWSMock.showConfirmDialog(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any())).thenReturn(0);
    PluginWorkspaceProvider.setPluginWorkspace(pluginWSMock);
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(true));
    waitForScheluerBetter();
    flushAWT();
    // The amend was cancelled. We must not see the first commit message.
    assertEquals("SECOND COMMIT MESSAGE", commitPanel.getCommitMessageArea().getText());
    // Not enabled because we have don't have staged files.
    assertFalse(commitPanel.getCommitButton().isEnabled());
    assertFalse(amendBtn.isSelected());
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JideToggleButton(com.jidesoft.swing.JideToggleButton) File(java.io.File)

Example 7 with JideToggleButton

use of com.jidesoft.swing.JideToggleButton in project oxygen-git-client-addon by oxygenxml.

the class FlatView9Test method testAmendCommitThatWasPushed_changeFileContent.

/**
 * <p><b>Description:</b> Amend commit that was pushed. Change file content.</p>
 * <p><b>Bug ID:</b> EXM-41392</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testAmendCommitThatWasPushed_changeFileContent() throws Exception {
    // Create repositories
    String localTestRepository = "target/test-resources/testAmendCommitThatWasPushed_1_local";
    String remoteTestRepository = "target/test-resources/testAmendCommitThatWasPushed_1_remote";
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    bindLocalToRemote(localRepo, remoteRepo);
    pushOneFileToRemote(localTestRepository, "init.txt", "hello");
    flushAWT();
    // Create a new file
    new File(localTestRepository).mkdirs();
    File file = createNewFile(localTestRepository, "test.txt", "content");
    // No amend by default
    CommitAndStatusPanel commitPanel = stagingPanel.getCommitPanel();
    JideToggleButton amendBtn = commitPanel.getAmendLastCommitToggle();
    assertFalse(amendBtn.isSelected());
    // >>> Stage
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // >>> Commit the test file
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
    SwingUtilities.invokeLater(() -> {
        commitPanel.getCommitMessageArea().setText("FIRST COMMIT MESSAGE");
        commitPanel.getCommitButton().doClick();
    });
    waitForScheluerBetter();
    assertEquals(1, GitAccess.getInstance().getPushesAhead());
    // >>> Push
    push("", "");
    waitForScheluerBetter();
    refreshSupport.call();
    waitForScheluerBetter();
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
    // Change the file again.
    setFileContent(file, "modified");
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    flushAWT();
    SwingUtilities.invokeLater(() -> {
        commitPanel.getCommitMessageArea().setText("SECOND COMMIT MESSAGE");
    });
    flushAWT();
    PluginWorkspace pluginWSMock = Mockito.mock(StandalonePluginWorkspace.class);
    Mockito.when(pluginWSMock.showConfirmDialog(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any())).thenReturn(0);
    PluginWorkspaceProvider.setPluginWorkspace(pluginWSMock);
    assertTrue(commitPanel.getCommitButton().isEnabled());
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(true));
    waitForScheluerBetter();
    flushAWT();
    // The amend was cancelled. We must not see the first commit message.
    assertEquals("SECOND COMMIT MESSAGE", commitPanel.getCommitMessageArea().getText());
    // Still enabled because we have a staged file
    assertTrue(commitPanel.getCommitButton().isEnabled());
    assertFalse(amendBtn.isSelected());
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JideToggleButton(com.jidesoft.swing.JideToggleButton) File(java.io.File) Test(org.junit.Test)

Aggregations

JideToggleButton (com.jidesoft.swing.JideToggleButton)7 FileStatus (com.oxygenxml.git.service.entities.FileStatus)5 File (java.io.File)5 Repository (org.eclipse.jgit.lib.Repository)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 DiffEntry (org.eclipse.jgit.diff.DiffEntry)2 Test (org.junit.Test)2 PluginWorkspace (ro.sync.exml.workspace.api.PluginWorkspace)2 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)2 RepoNotInitializedException (com.oxygenxml.git.service.RepoNotInitializedException)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1