use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchManagementTest method testBranchesTreeFilterAllBranches.
/**
* <p><b>Description:</b> Tests the filter for branches on a tree with both local and remote branches.</p>
* <p><b>Bug ID:</b> EXM-41701</p>
*
* @author bogdan_draghici
*
* @throws Exception
*/
@Test
public void testBranchesTreeFilterAllBranches() 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 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.setRepositorySynchronously(REMOTE_TEST_REPOSITORY);
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.");
gitAccess.createBranch(REMOTE_BRANCH_NAME1);
gitAccess.createBranch(REMOTE_BRANCH_NAME2);
gitAccess.setRepositorySynchronously(LOCAL_TEST_REPOSITORY);
gitAccess.fetch();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(Mockito.mock(GitControllerBase.class));
branchManagementPanel.refreshBranches();
flushAWT();
branchManagementPanel.filterTree("ewu82m");
flushAWT();
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
StringBuilder actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n", actualTree.toString());
branchManagementPanel.filterTree("ai");
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + " refs/remotes/\n" + " refs/remotes/origin/\n" + " refs/remotes/origin/" + GitAccess.DEFAULT_BRANCH_NAME + "\n", actualTree.toString());
branchManagementPanel.filterTree("Branch");
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/LocalBranch\n" + " refs/heads/LocalBranch2\n" + " refs/remotes/\n" + " refs/remotes/origin/\n" + " refs/remotes/origin/RemoteBranch\n" + " refs/remotes/origin/RemoteBranch2\n", actualTree.toString());
branchManagementPanel.filterTree("2");
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/LocalBranch2\n" + " refs/remotes/\n" + " refs/remotes/origin/\n" + " refs/remotes/origin/RemoteBranch2\n" + "", actualTree.toString());
branchManagementPanel.filterTree("al");
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/LocalBranch\n" + " refs/heads/LocalBranch2\n" + "", actualTree.toString());
branchManagementPanel.filterTree("Rem");
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/remotes/\n" + " refs/remotes/origin/\n" + " refs/remotes/origin/RemoteBranch\n" + " refs/remotes/origin/RemoteBranch2\n" + "", actualTree.toString());
branchManagementPanel.filterTree("ai");
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + " refs/remotes/\n" + " refs/remotes/origin/\n" + " refs/remotes/origin/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + "", actualTree.toString());
branchManagementPanel.filterTree("a");
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/LocalBranch\n" + " refs/heads/LocalBranch2\n" + " refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\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.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchManagementTest method testBranchesTreeToolTipsMultipleRemotes.
/**
* <p><b>Description:</b> Tests the tool tips for branches that contain slashes
* in their names with a custom remote.</p>
* <p><b>Bug ID:</b> EXM-49458</p>
*
* @author Alex_Smarandache
*
* @throws Exception
*/
@Test
public void testBranchesTreeToolTipsMultipleRemotes() throws Exception {
final String localTestRepository = "target/test-resources/GitAccessCheckoutNewBranch/localRepository";
final String remoteTestRepository = "target/test-resources/GitAccessCheckoutNewBranch/remoteRepository";
// Creates the remote repository.
createRepository(remoteTestRepository);
remoteRepository = gitAccess.getRepository();
// Creates the local repository.
createRepository(localTestRepository);
localRepository = gitAccess.getRepository();
bindLocalToRemote(localRepository, remoteRepository, "fork", "main");
// Local repo
File file = new File(localTestRepository + "local.txt");
file.createNewFile();
setFileContent(file, "local content");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch("the/breanci");
// Local repo again
gitAccess.setRepositorySynchronously(localTestRepository);
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(Mockito.mock(GitControllerBase.class));
branchManagementPanel.refreshBranches();
flushAWT();
JTree tree = branchManagementPanel.getTree();
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
DefaultMutableTreeNode leaf = root.getFirstLeaf();
JLabel rendererLabel = (JLabel) tree.getCellRenderer().getTreeCellRendererComponent(tree, leaf, false, true, true, 3, true);
assertEquals("breanci", rendererLabel.getText());
assertEquals("<html><p>Local_branch the/breanci<br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu <alex_jitianu@sync.ro><br> " + "- Date: {date}</p></html>".replaceAll("\\{date\\}", DATE_FORMAT.format(new Date())), rendererLabel.getToolTipText());
leaf = leaf.getNextLeaf();
rendererLabel = (JLabel) tree.getCellRenderer().getTreeCellRendererComponent(tree, leaf, false, true, true, 4, true);
assertEquals("<html><p>Local_branch main<br>" + // Also has upstream
"Upstream_branch fork/main<br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu <alex_jitianu@sync.ro><br> " + "- Date: {date}</p></html>".replaceAll("\\{date\\}", DATE_FORMAT.format(new Date())), rendererLabel.getToolTipText());
assertNull(leaf.getNextLeaf());
}
use of com.oxygenxml.git.view.GitTreeNode 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();
}
}
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchMergingTest method testBranchMergingWithConflict.
/**
* <p><b>Description:</b>Tests the branch merging. Conflict happens.</p>
* <p><b>Bug ID:</b> EXM-43410</p>
*
* @author gabriel_nedianu
*
* @throws Exception
*/
public void testBranchMergingWithConflict() throws Exception {
JDialog conflictMergeDialog = 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 and create a new branch
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
refreshSupport.call();
gitAccess.commit("First local commit on main.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
refreshSupport.call();
// ------------- Checkout branch: LOCAL_BRANCH_NAME1 -------------
gitAccess.setBranch(LOCAL_BRANCH_NAME1);
// Commit on this branch
setFileContent(file1, "local file 1 on new branch");
setFileContent(file2, "local file 2 on new branch");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
refreshSupport.call();
gitAccess.commit("Commit on secondary branch");
refreshSupport.call();
// ------------- Move to the main branch and commit something there ---------------
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
setFileContent(file1, "local file 1 modifications");
setFileContent(file2, "local file 2 modifications");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
refreshSupport.call();
gitAccess.commit("2nd commit on main branch");
refreshSupport.call();
// Merge secondary branch into main
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
GitTreeNode secondaryBranchNode = (GitTreeNode) root.getFirstLeaf();
String secondaryBranchPath = (String) secondaryBranchNode.getUserObject();
assertTrue(secondaryBranchPath.contains(Constants.R_HEADS));
refreshSupport.call();
List<AbstractAction> actionsForSecondaryBranch = branchTreeMenuActionsProvider.getActionsForNode(secondaryBranchNode);
for (AbstractAction action : actionsForSecondaryBranch) {
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();
flushAWT();
sleep(200);
waitForScheduler();
conflictMergeDialog = findDialog(translator.getTranslation(Tags.MERGE_CONFLICTS_TITLE));
System.out.println(conflictMergeDialog);
assertNotNull(conflictMergeDialog);
assertTrue(TestUtil.read(file1.toURI().toURL()).contains("<<<<<<< HEAD\n" + "local file 1 modifications\n" + "=======\n" + "local file 1 on new branch\n" + ">>>>>>>"));
assertTrue(TestUtil.read(file2.toURI().toURL()).contains("<<<<<<< HEAD\n" + "local file 2 modifications\n" + "=======\n" + "local file 2 on new branch\n" + ">>>>>>>"));
} finally {
if (conflictMergeDialog != null) {
conflictMergeDialog.setVisible(false);
conflictMergeDialog.dispose();
}
}
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchMergingTest method testBranchMerging.
/**
* <p><b>Description:</b>Tests the branch merging.</p>
* <p><b>Bug ID:</b> EXM-43410</p>
*
* @author gabriel_nedianu
*
* @throws Exception
*/
public void testBranchMerging() throws Exception {
File file = new File(LOCAL_TEST_REPOSITORY, "local.txt");
file.createNewFile();
setFileContent(file, "local content");
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
// Make the first commit for the local repository on the main branch
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
// ------------- Checkout the other branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
refreshSupport.call();
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
GitTreeNode firstLeaf = (GitTreeNode) root.getFirstLeaf();
String firstLeafPath = (String) firstLeaf.getUserObject();
assertTrue(firstLeafPath.contains(Constants.R_HEADS));
String[] branchPath = firstLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME1, branchPath[branchPath.length - 1]);
refreshSupport.call();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CHECKOUT))) {
abstractAction.actionPerformed(null);
break;
}
}
refreshSupport.call();
flushAWT();
sleep(300);
assertEquals(LOCAL_BRANCH_NAME1, gitAccess.getRepository().getBranch());
// Change file on the secondary branch
setFileContent(file, "local content for merging");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("Branch commit 10");
refreshSupport.call();
// Move back to the main branch
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getBranchInfo().getBranchName());
refreshSupport.call();
// Merge LocalBranch into main
List<AbstractAction> actionsForSecondaryBranch = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
for (AbstractAction action : actionsForSecondaryBranch) {
if (action != null) {
String actionName = action.getValue(AbstractAction.NAME).toString();
if ("Merge_Branch1_Into_Branch2".equals(actionName)) {
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);
assertEquals("local content for merging", TestUtil.read(file.toURI().toURL()));
}
Aggregations