use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class RemoteVisualTests method testManageAdvancedRemote.
/**
* <p><b>Description:</b> Tests corner case when user tries to add an existing remote.</p>
* <p><b>Bug ID:</b> EXM-40858</p>
*
* @author Alex_Smarandache
*
* @throws Exception
*/
public void testManageAdvancedRemote() 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();
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);
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(firstRemoteName));
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());
final OKCancelDialog confirmDialog = (OKCancelDialog) findDialog(Tags.ADD_REMOTE);
assertNotNull(confirmDialog);
SwingUtilities.invokeLater(() -> confirmDialog.getOkButton().doClick());
flushAWT();
assertEquals(1, model.getRowCount());
assertEquals(firstRemoteName, (String) model.getValueAt(0, 0));
assertEquals("https/custom_link.ro", (String) model.getValueAt(0, 1));
} finally {
frame.setVisible(false);
frame.dispose();
}
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitAccessTest method testPullWhileInConflictState.
/**
* <p><b>Description:</b> better message when trying to pull while having a conflict.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
* @author sorin_carbunaru
* @throws Exception
*/
public void testPullWhileInConflictState() throws Exception {
try {
Git gitMock = Mockito.mock(Git.class);
Repository repoMock = Mockito.mock(Repository.class);
StatusCommand statusCmdMock = Mockito.mock(StatusCommand.class);
Status statusMock = Mockito.mock(Status.class);
StoredConfig configMock = Mockito.mock(StoredConfig.class);
Mockito.when(repoMock.getRepositoryState()).thenReturn(RepositoryState.MERGING);
Mockito.when(repoMock.getConfig()).thenReturn(configMock);
Mockito.when(gitMock.getRepository()).thenReturn(repoMock);
Mockito.when(statusMock.getConflicting()).thenReturn(new HashSet<>(Arrays.asList("string1")));
Mockito.when(statusCmdMock.call()).thenReturn(statusMock);
Mockito.when(gitMock.status()).thenReturn(statusCmdMock);
GitAccess.getInstance().setGit(gitMock);
GitController gitCtrl = new GitController(GitAccess.getInstance());
Future<?> pullResp = gitCtrl.pull();
pullResp.get();
Thread.sleep(300);
assertEquals("Pull_when_repo_in_conflict", errMsg[0]);
} finally {
GitAccess.getInstance().setGit(null);
}
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_1.
/**
* <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager
* when repo is in conflict state.
* The branch checkout also generates a checkout conflict.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_1() throws Exception {
// Push from first repo
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
push("", "");
// Commit from second repo
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
file.createNewFile();
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("conflict");
// Change file on the new branch
gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
gitAccess.setBranch("new_branch");
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "altfel");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("commit on ew branch");
// move to main branch
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
// Pull to create conflict
PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
sleep(500);
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
// Simulate branch checkout from Git Branch Manager view
GitTreeNode node = new GitTreeNode(new TreePath(new String[] { "refs", "heads", "new_branch" }));
node.setUserObject("refs/heads/new_branch");
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(node);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CREATE_BRANCH) + "...")) {
SwingUtilities.invokeLater(() -> {
abstractAction.actionPerformed(null);
});
flushAWT();
JDialog createBranchDialog = findDialog(translator.getTranslation(Tags.CREATE_BRANCH));
JCheckBox checkoutBranchCheckBox = findCheckBox(createBranchDialog, Tags.CHECKOUT_BRANCH);
assertNotNull(checkoutBranchCheckBox);
checkoutBranchCheckBox.setSelected(true);
flushAWT();
JTextField branchNameTextField = findComponentNearJLabel(createBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
branchNameTextField.setText("a_new_day");
JButton okButton = findFirstButton(createBranchDialog, "Create");
if (okButton != null) {
okButton.setEnabled(true);
okButton.doClick();
}
break;
}
}
sleep(500);
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
assertEquals("Cannot_checkout_new_branch_when_having_conflicts", errMsg[0]);
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_succeed_1.
/**
* <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager
* when repo is in conflict state.
* This should succeed.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCheckoutNewBranchWhenRepoInConflict_succeed_1() throws Exception {
// Push test.txt from first repo
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
push("", "");
// Commit test.txt from second repo
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
file.createNewFile();
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("conflict");
// Change file.txt file on the new branch
gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
gitAccess.setBranch("new_branch");
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/file.txt"), "altfel");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "file.txt"));
gitAccess.commit("commit on nnew branch");
// move to main branch
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
// Pull to create conflict o text.txt
PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
sleep(500);
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
// Simulate branch checkout from Git Branch Manager view
GitTreeNode node = new GitTreeNode(new TreePath(new String[] { "refs", "heads", "new_branch" }));
node.setUserObject("refs/heads/new_branch");
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(node);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CREATE_BRANCH) + "...")) {
SwingUtilities.invokeLater(() -> {
abstractAction.actionPerformed(null);
});
flushAWT();
JDialog createBranchDialog = findDialog(translator.getTranslation(Tags.CREATE_BRANCH));
JCheckBox checkoutBranchCheckBox = findCheckBox(createBranchDialog, Tags.CHECKOUT_BRANCH);
assertNotNull(checkoutBranchCheckBox);
checkoutBranchCheckBox.setSelected(true);
flushAWT();
JTextField branchNameTextField = findComponentNearJLabel(createBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
branchNameTextField.setText("a_new_day");
JButton okButton = findFirstButton(createBranchDialog, "Create");
if (okButton != null) {
okButton.setEnabled(true);
okButton.doClick();
}
break;
}
}
sleep(500);
assertEquals("a_new_day", gitAccess.getRepository().getBranch());
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflictTest method testSwitchBranchWhenRepoInConflict_checkoutConflict_2.
/**
* <p><b>Description:</b> try to switch branch from Git Staging when repo is in conflict state.
* The branch witch also generates a checkout conflict.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
@Test
public void testSwitchBranchWhenRepoInConflict_checkoutConflict_2() throws Exception {
// Push from first repo
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
push("", "");
// Commit from second repo
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
file.createNewFile();
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("conflict");
// Change file on the new branch
gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
gitAccess.setBranch("new_branch");
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "altfel");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("commit on ew branch");
// move to main
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
// Pull to create conflict
PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
// Simulate branch checkout from Git Staging
GitController gitController = new GitController(gitAccess);
BranchSelectionCombo branchesCombo = new BranchSelectionCombo(gitController);
branchesCombo.refresh();
SwingUtilities.invokeLater(() -> branchesCombo.setSelectedIndex(1));
flushAWT();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
assertEquals("Branch_switch_when_repo_in_conflict_error_msg", errMsg[0]);
}
Aggregations