use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class BranchActionsTest method testContextualMenuActionsOnCurrentBranch.
/**
*<p><b>Description:</b>Tests the action created on the current Branch</p>
* <p><b>Bug ID:</b> EXM-43410</p>
*
* @author gabriel_nedianu
*
* @throws Exception
*/
public void testContextualMenuActionsOnCurrentBranch() throws Exception {
File file = new File(LOCAL_TEST_REPOSITORY + "local.txt");
file.createNewFile();
setFileContent(file, "local content");
// Make the first commit for the local repository
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
// Verify we are on main branch
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
GitTreeNode mainBranchNode = (GitTreeNode) root.getFirstLeaf();
String mainBranchPath = (String) mainBranchNode.getUserObject();
assertEquals("refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME, mainBranchPath);
// ------------- Verify the actions on the selected branch -------------
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(mainBranchNode);
int noOfActions = actionsForNode.size();
assertEquals(1, noOfActions);
String actionName = (String) actionsForNode.get(0).getValue(AbstractAction.NAME);
assertEquals(translator.getTranslation(Tags.CREATE_BRANCH) + "...", actionName);
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class BranchActionsTest method testCreateLocalBranchAction.
/**
* Tests the action of creating a new branch from a local branch.
*
* @throws Exception
*/
public void testCreateLocalBranchAction() throws Exception {
boolean initialIsCheckoutNewBranch = OptionsManager.getInstance().isCheckoutNewlyCreatedLocalBranch();
try {
File file = new File(LOCAL_TEST_REPOSITORY + "local.txt");
file.createNewFile();
setFileContent(file, "local content");
// Make the first commit for the local repository and create a branch for it.
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
gitAccess.createBranch(LOCAL_BRANCH_NAME2);
gitAccess.fetch();
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
// ------------- Create branch LOCAL_BRANCH_COPY_NAME from first branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitTreeNode firstLeaf = (GitTreeNode) root.getFirstLeaf();
String firstLeafPath = (String) firstLeaf.getUserObject();
assertTrue(firstLeafPath.contains(Constants.R_HEADS));
String[] split = firstLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME1, split[split.length - 1]);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
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(LOCAL_BRANCH_COPY_NAME);
JButton okButton = findFirstButton(createBranchDialog, "Create");
if (okButton != null) {
okButton.setEnabled(true);
okButton.doClick();
}
break;
}
}
sleep(500);
gitAccess.fetch();
branchManagementPanel.refreshBranches();
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
StringBuilder actualTree = new StringBuilder();
BranchManagementTest.serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/LocalBranch\n" + " refs/heads/LocalBranch2\n" + " refs/heads/LocalBranchCopy\n" + " refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\n", actualTree.toString());
assertEquals("LocalBranchCopy", gitAccess.getBranchInfo().getBranchName());
} finally {
OptionsManager.getInstance().setCheckoutNewlyCreatedLocalBranch(initialIsCheckoutNewBranch);
}
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class BranchActionsTest method testCheckoutRemoteBranchAction.
/**
* Tests the action of checkout a remote branch.
*
* @throws Exception
*/
public void testCheckoutRemoteBranchAction() throws Exception {
gitAccess.setRepositorySynchronously(REMOTE_TEST_REPOSITORY);
File file = new File(REMOTE_TEST_REPOSITORY + "remote1.txt");
file.createNewFile();
setFileContent(file, "remote content");
// Make the first commit for the remote repository and create a branch for it.
gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
gitAccess.commit("First remote commit.");
// Create new remote branches
gitAccess.createBranch(REMOTE_BRANCH_NAME1);
gitAccess.createBranch(REMOTE_BRANCH_NAME2);
gitAccess.setRepositorySynchronously(LOCAL_TEST_REPOSITORY);
gitAccess.fetch();
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
// ------------- Checkout the last branch in the tree: REMOTE_BRANCH_NAME2, with the name REMOTE_BRANCH_NAME2_COPY-------------
GitTreeNode lastLeaf = (GitTreeNode) root.getLastLeaf();
String lastLeafPath = (String) lastLeaf.getUserObject();
assertTrue(lastLeafPath.contains(Constants.R_REMOTES));
String[] branchPath = lastLeafPath.split("/");
assertEquals(REMOTE_BRANCH_NAME2, branchPath[branchPath.length - 1]);
AbstractAction checkoutAction = branchTreeMenuActionsProvider.getCheckoutAction(lastLeaf);
if (checkoutAction != null) {
SwingUtilities.invokeLater(() -> {
checkoutAction.actionPerformed(null);
});
JDialog checkoutBranchDialog = findDialog(translator.getTranslation(Tags.CHECKOUT_BRANCH));
if (checkoutBranchDialog != null) {
JTextField branchNameTextField = findComponentNearJLabel(checkoutBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
branchNameTextField.setText(REMOTE_BRANCH_NAME2_COPY);
JButton firstButtonFound = findFirstButton(checkoutBranchDialog, "Checkout");
if (firstButtonFound != null) {
firstButtonFound.setEnabled(true);
firstButtonFound.doClick();
}
}
}
sleep(500);
gitAccess.fetch();
branchManagementPanel.refreshBranches();
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
StringBuilder actualTree = new StringBuilder();
BranchManagementTest.serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/RemoteBranch2Copy\n" + " refs/remotes/\n" + " refs/remotes/origin/\n" + " refs/remotes/origin/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + " refs/remotes/origin/RemoteBranch\n" + " refs/remotes/origin/RemoteBranch2\n" + "", actualTree.toString());
// ------------- Checkout the previous branch in the tree: REMOTE_BRANCH_NAME1, with the name REMOTE_BRANCH_NAME1_COPY-------------
GitTreeNode previousLeaf = (GitTreeNode) lastLeaf.getPreviousLeaf();
String previousLeafPath = (String) previousLeaf.getUserObject();
assertTrue(lastLeafPath.contains(Constants.R_REMOTES));
branchPath = previousLeafPath.split("/");
assertEquals(REMOTE_BRANCH_NAME1, branchPath[branchPath.length - 1]);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(previousLeaf);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CHECKOUT) + "...")) {
SwingUtilities.invokeLater(() -> {
abstractAction.actionPerformed(null);
});
JDialog checkoutDialog = findDialog(translator.getTranslation(Tags.CHECKOUT_BRANCH));
if (checkoutDialog != null) {
JTextField branchNameTextField = findComponentNearJLabel(checkoutDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
branchNameTextField.setText(REMOTE_BRANCH_NAME1_COPY);
JButton firstButtonFound = findFirstButton(checkoutDialog, "Checkout");
if (firstButtonFound != null) {
firstButtonFound.setEnabled(true);
firstButtonFound.doClick();
}
}
break;
}
}
sleep(500);
gitAccess.fetch();
branchManagementPanel.refreshBranches();
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
BranchManagementTest.serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/RemoteBranch2Copy\n" + " refs/heads/RemoteBranchCopy\n" + " refs/remotes/\n" + " refs/remotes/origin/\n" + " refs/remotes/origin/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + " refs/remotes/origin/RemoteBranch\n" + " refs/remotes/origin/RemoteBranch2\n" + "", actualTree.toString());
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class BranchActionsTest method testCreateLocalBranchAction_dontCheckout.
/**
* <p><b>Description:</b> create local branch but don't check it out.</p>
* <p><b>Bug ID:</b> EXM-47204</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCreateLocalBranchAction_dontCheckout() throws Exception {
boolean initialIsCheckoutNewBranch = OptionsManager.getInstance().isCheckoutNewlyCreatedLocalBranch();
try {
File file = new File(LOCAL_TEST_REPOSITORY + "local.txt");
file.createNewFile();
setFileContent(file, "local content");
// Make the first commit for the local repository and create a branch for it.
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
gitAccess.createBranch(LOCAL_BRANCH_NAME2);
gitAccess.fetch();
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
// ------------- Create branch LOCAL_BRANCH_COPY_NAME from first branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitTreeNode firstLeaf = (GitTreeNode) root.getFirstLeaf();
String firstLeafPath = (String) firstLeaf.getUserObject();
assertTrue(firstLeafPath.contains(Constants.R_HEADS));
String[] split = firstLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME1, split[split.length - 1]);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
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(false);
flushAWT();
JTextField branchNameTextField = findComponentNearJLabel(createBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
branchNameTextField.setText(LOCAL_BRANCH_COPY_NAME);
JButton okButton = findFirstButton(createBranchDialog, "Create");
if (okButton != null) {
okButton.setEnabled(true);
okButton.doClick();
}
break;
}
}
sleep(500);
gitAccess.fetch();
branchManagementPanel.refreshBranches();
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
StringBuilder actualTree = new StringBuilder();
BranchManagementTest.serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/LocalBranch\n" + " refs/heads/LocalBranch2\n" + " refs/heads/LocalBranchCopy\n" + " refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\n", actualTree.toString());
assertEquals(initialBranchName, gitAccess.getBranchInfo().getBranchName());
} finally {
OptionsManager.getInstance().setCheckoutNewlyCreatedLocalBranch(initialIsCheckoutNewBranch);
}
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class BranchMergingTest method testFailingBranchMerging.
/**
*<p><b>Description:</b>Tests the failing merging.</p>
* <p><b>Bug ID:</b> EXM-43410</p>
*
* @author gabriel_nedianu
*
* @throws Exception
*/
public void testFailingBranchMerging() throws Exception {
JDialog mergeFailDialog = null;
try {
File file1 = new File(LOCAL_TEST_REPOSITORY, "local1.txt");
File file2 = new File(LOCAL_TEST_REPOSITORY, "local2.txt");
file1.createNewFile();
file2.createNewFile();
setFileContent(file1, "local file 1 content");
setFileContent(file2, "local file 2 content");
// Make the first commit for the local repository, create a new branch and move on it
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
gitAccess.commit("First local commit on main.");
// Create new branch and commit some changes
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
gitAccess.setBranch(LOCAL_BRANCH_NAME1);
setFileContent(file1, "branch file1 modification ");
setFileContent(file2, "branch file2 modification ");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
gitAccess.commit("Commit on secondary branch");
// Move on main branch, make some uncommitted modifications
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
setFileContent(file1, "file1 something xx...xx...");
setFileContent(file2, "file2 something xx...xx...");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
// Try to merge the secondary branch into the default one - CHECKOUT CONFLICT
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
GitTreeNode secondaryBranchNode = (GitTreeNode) root.getFirstLeaf();
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(secondaryBranchNode);
for (AbstractAction action : actionsForNode) {
if (action != null) {
String actionName = action.getValue(AbstractAction.NAME).toString();
if ("Merge_Branch1_Into_Branch2".equals(actionName)) {
SwingUtilities.invokeLater(() -> action.actionPerformed(null));
break;
}
}
}
flushAWT();
sleep(300);
// Confirm merge dialog
JDialog mergeOkDialog = findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
JButton mergeOkButton = findFirstButton(mergeOkDialog, translator.getTranslation(Tags.MERGE));
mergeOkButton.doClick();
sleep(200);
mergeFailDialog = findDialog(translator.getTranslation(Tags.MERGE_FAILED_UNCOMMITTED_CHANGES_TITLE));
assertNotNull(mergeFailDialog);
mergeFailDialog.setVisible(false);
mergeFailDialog.dispose();
// Commit the changes on the main branch then make other uncommitted changes and try to merge again
// MERGE FAILED
gitAccess.commit("Commit on main branch");
setFileContent(file1, "file1 something modif");
setFileContent(file2, "file2 something modif");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(secondaryBranchNode);
for (AbstractAction action : actionsForNode) {
if (action != null) {
String actionName = action.getValue(AbstractAction.NAME).toString();
if ("Merge_Branch1_Into_Branch2".equals(actionName)) {
SwingUtilities.invokeLater(() -> action.actionPerformed(null));
break;
}
}
}
flushAWT();
sleep(300);
// Confirm merge dialog
mergeOkDialog = findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
mergeOkButton = findFirstButton(mergeOkDialog, translator.getTranslation(Tags.MERGE));
mergeOkButton.doClick();
sleep(200);
mergeFailDialog = findDialog(translator.getTranslation(Tags.MERGE_FAILED_UNCOMMITTED_CHANGES_TITLE));
assertNotNull(mergeFailDialog);
} finally {
if (mergeFailDialog != null) {
mergeFailDialog.setVisible(false);
mergeFailDialog.dispose();
}
}
}
Aggregations