use of com.oxygenxml.git.view.GitTreeNode 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.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchManagementTest method testBranchesTreeStructureRemoteBranchesOnly.
/**
* <p><b>Description:</b> Tests the structure of a tree with only remote branches.</p>
* <p><b>Bug ID:</b> EXM-41701</p>
*
* @author bogdan_draghici
*
* @throws Exception
*/
public void testBranchesTreeStructureRemoteBranchesOnly() 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();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(Mockito.mock(GitControllerBase.class));
branchManagementPanel.refreshBranches();
flushAWT();
JTree tree = branchManagementPanel.getTree();
GitTreeNode root = (GitTreeNode) tree.getModel().getRoot();
StringBuilder actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\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 testBranchesTreeToolTips_2.
/**
* <p><b>Description:</b> Tests the tool tips for branches that contain slashes
* in their names.</p>
* <p><b>Bug ID:</b> EXM-48643</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
@Test
public void testBranchesTreeToolTips_2() throws Exception {
// Local repo
File file = new File(LOCAL_TEST_REPOSITORY + "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(LOCAL_TEST_REPOSITORY);
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 origin/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 BranchManagementTest method testBranchesTreeStructureLocalBranchesOnly.
/**
* <p><b>Description:</b> Tests the structure of a tree with only local branches.</p>
* <p><b>Bug ID:</b> EXM-41701</p>
*
* @author bogdan_draghici
*
* @throws Exception
*/
public void testBranchesTreeStructureLocalBranchesOnly() 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.fetch();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(Mockito.mock(GitControllerBase.class));
branchManagementPanel.refreshBranches();
flushAWT();
JTree tree = branchManagementPanel.getTree();
GitTreeNode root = (GitTreeNode) tree.getModel().getRoot();
StringBuilder 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" + "", actualTree.toString());
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchManagementTest method testBranchesTreeFilterRemoteBranchesOnly.
/**
* <p><b>Description:</b> Tests the filter for branches on a tree with only remote branches.</p>
* <p><b>Bug ID:</b> EXM-41701</p>
*
* @author bogdan_draghici
*
* @throws Exception
*/
@Test
public void testBranchesTreeFilterRemoteBranchesOnly() 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();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(Mockito.mock(GitControllerBase.class));
branchManagementPanel.refreshBranches();
flushAWT();
branchManagementPanel.filterTree("rimotz");
flushAWT();
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
StringBuilder actualTree = new StringBuilder();
serializeTree(actualTree, root);
assertEquals("localRepository\n", actualTree.toString());
branchManagementPanel.filterTree("mote");
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("ain");
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/" + GitAccess.DEFAULT_BRANCH_NAME + "\n", actualTree.toString());
branchManagementPanel.filterTree("ch2");
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/RemoteBranch2\n", actualTree.toString());
branchManagementPanel.filterTree("te");
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());
}
Aggregations