Search in sources :

Example 36 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementTest method testBranchesTreeStructureRemoteMainOnly.

/**
 * <p><b>Description:</b> Tests the structure of a tree with only main remote branch.</p>
 * <p><b>Bug ID:</b> EXM-41701</p>
 *
 * @author bogdan_draghici
 *
 * @throws Exception
 */
public void testBranchesTreeStructureRemoteMainOnly() throws Exception {
    gitAccess.setRepositorySynchronously(REMOTE_TEST_REPOSITORY);
    File file = new File(REMOTE_TEST_REPOSITORY + "remote.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, "remote.txt"));
    gitAccess.commit("First remote commit.");
    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" + "", actualTree.toString());
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) JTree(javax.swing.JTree) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) File(java.io.File)

Example 37 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementTest method testBranchesTreeCustomRemote.

/**
 * <p><b>Description:</b> Tests the filter for branches on a tree with both local and remote branches with more remotes.</p>
 * <p><b>Bug ID:</b>  EXM-49458</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
@Test
public void testBranchesTreeCustomRemote() throws Exception {
    bindLocalToRemote(localRepository, remoteRepository, "fork", "main");
    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/fork/\n" + "      refs/remotes/fork/" + GitAccess.DEFAULT_BRANCH_NAME + "\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/fork/\n" + "      refs/remotes/fork/RemoteBranch\n" + "      refs/remotes/fork/RemoteBranch2\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/fork/\n" + "      refs/remotes/fork/RemoteBranch2\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/fork/\n" + "      refs/remotes/fork/RemoteBranch\n" + "      refs/remotes/fork/RemoteBranch2\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/fork/\n" + "      refs/remotes/fork/" + GitAccess.DEFAULT_BRANCH_NAME + "\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/fork/\n" + "      refs/remotes/fork/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + "      refs/remotes/fork/RemoteBranch\n" + "      refs/remotes/fork/RemoteBranch2\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());
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) File(java.io.File) Test(org.junit.Test)

Example 38 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementTest method testBranchesTreeFilterLocalBranchesOnly.

/**
 * <p><b>Description:</b> Tests the filter for branches on a tree with only local branches.</p>
 * <p><b>Bug ID:</b> EXM-41701</p>
 *
 * @author bogdan_draghici
 *
 * @throws Exception
 */
@Test
public void testBranchesTreeFilterLocalBranchesOnly() 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();
    branchManagementPanel.filterTree("hedz");
    flushAWT();
    GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
    StringBuilder actualTree = new StringBuilder();
    serializeTree(actualTree, root);
    assertEquals("localRepository\n", actualTree.toString());
    branchManagementPanel.filterTree("Local");
    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("in");
    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", actualTree.toString());
    branchManagementPanel.filterTree("h2");
    flushAWT();
    root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
    actualTree = new StringBuilder();
    serializeTree(actualTree, root);
    assertEquals("localRepository\n" + "  refs/heads/\n" + "    refs/heads/LocalBranch2\n", actualTree.toString());
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) File(java.io.File) Test(org.junit.Test)

Example 39 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementTest method testBranchesTreeToolTipsDeletedBranch.

/**
 * <p><b>Description:</b> Tests the tool tips for deleted branches on a tree with both local and remote branches.</p>
 * <p><b>Bug ID:</b> EXM-48768</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
@Test
public void testBranchesTreeToolTipsDeletedBranch() 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(LOCAL_BRANCH_NAME1);
    gitAccess.createBranch(LOCAL_BRANCH_NAME2);
    // Remote repo
    gitAccess.setRepositorySynchronously(REMOTE_TEST_REPOSITORY);
    file = new File(REMOTE_TEST_REPOSITORY + "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    gitAccess.createBranch(REMOTE_BRANCH_NAME1);
    gitAccess.createBranch(REMOTE_BRANCH_NAME2);
    // Local repo again
    gitAccess.setRepositorySynchronously(LOCAL_TEST_REPOSITORY);
    gitAccess.fetch();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(Mockito.mock(GitControllerBase.class));
    branchManagementPanel.refreshBranches();
    flushAWT();
    JTree tree = branchManagementPanel.getTree();
    gitAccess.deleteBranch(LOCAL_BRANCH_NAME2);
    GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
    DefaultMutableTreeNode leaf = root.getFirstLeaf();
    JLabel rendererLabel = (JLabel) tree.getCellRenderer().getTreeCellRendererComponent(tree, leaf, false, true, true, 2, true);
    assertEquals("<html><p>Local_branch LocalBranch<br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu &lt;alex_jitianu@sync.ro&gt;<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, 3, true);
    assertNull(rendererLabel.getToolTipText());
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) JTree(javax.swing.JTree) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JLabel(javax.swing.JLabel) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 40 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchManagementTest method testBranchesTreeToolTips.

/**
 * <p><b>Description:</b> Tests the tool tips for branches on a tree with both local and remote branches.</p>
 * <p><b>Bug ID:</b> EXM-46438</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
@Test
public void testBranchesTreeToolTips() 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(LOCAL_BRANCH_NAME1);
    gitAccess.createBranch(LOCAL_BRANCH_NAME2);
    // Remote repo
    gitAccess.setRepositorySynchronously(REMOTE_TEST_REPOSITORY);
    file = new File(REMOTE_TEST_REPOSITORY + "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    gitAccess.createBranch(REMOTE_BRANCH_NAME1);
    gitAccess.createBranch(REMOTE_BRANCH_NAME2);
    // Local repo again
    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) (branchManagementPanel.getTree().getModel().getRoot());
    DefaultMutableTreeNode leaf = root.getFirstLeaf();
    JLabel rendererLabel = (JLabel) tree.getCellRenderer().getTreeCellRendererComponent(tree, leaf, false, true, true, 2, true);
    assertEquals("<html><p>Local_branch LocalBranch<br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu &lt;alex_jitianu@sync.ro&gt;<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, 3, true);
    assertEquals("<html><p>Local_branch LocalBranch2<br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu &lt;alex_jitianu@sync.ro&gt;<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 &lt;alex_jitianu@sync.ro&gt;<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, 7, true);
    String remoteURL = gitAccess.getRemoteURLFromConfig();
    assertEquals("<html><p>Remote_branch origin/main<br>" + "Clone_Repository_Dialog_Url_Label: " + "<a href=\"" + remoteURL + "\">" + remoteURL + "</a><br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu &lt;alex_jitianu@sync.ro&gt;<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, 8, true);
    assertEquals("<html><p>Remote_branch origin/RemoteBranch<br>" + "Clone_Repository_Dialog_Url_Label: " + "<a href=\"" + remoteURL + "\">" + remoteURL + "</a><br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu &lt;alex_jitianu@sync.ro&gt;<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, 9, true);
    assertEquals("<html><p>Remote_branch origin/RemoteBranch2<br>" + "Clone_Repository_Dialog_Url_Label: " + "<a href=\"" + remoteURL + "\">" + remoteURL + "</a><br><br>" + "Last_Commit_Details:<br>" + "- Author: AlexJitianu &lt;alex_jitianu@sync.ro&gt;<br> " + "- Date: {date}</p></html>".replaceAll("\\{date\\}", DATE_FORMAT.format(new Date())), rendererLabel.getToolTipText());
    assertNull(leaf.getNextLeaf());
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) JTree(javax.swing.JTree) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JLabel(javax.swing.JLabel) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Aggregations

GitTreeNode (com.oxygenxml.git.view.GitTreeNode)49 FileStatus (com.oxygenxml.git.service.entities.FileStatus)33 File (java.io.File)30 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)23 AbstractAction (javax.swing.AbstractAction)19 GitController (com.oxygenxml.git.view.event.GitController)18 JButton (javax.swing.JButton)15 TreePath (javax.swing.tree.TreePath)14 Test (org.junit.Test)14 JDialog (javax.swing.JDialog)13 JTree (javax.swing.JTree)8 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)7 BranchTreeMenuActionsProvider (com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider)7 JTextField (javax.swing.JTextField)7 JCheckBox (javax.swing.JCheckBox)6 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 JLabel (javax.swing.JLabel)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4