Search in sources :

Example 11 with GitTreeNode

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);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 12 with GitTreeNode

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());
}
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 13 with GitTreeNode

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 &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());
    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)

Example 14 with GitTreeNode

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());
}
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 15 with GitTreeNode

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());
}
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)

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