Search in sources :

Example 21 with SelectedResourcesProvider

use of com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider in project oxygen-git-client-addon by oxygenxml.

the class GitViewResourceContextualMenuActionsTest method testActionsEnablingState_10.

/**
 * <p><b>Description:</b> test the enabling state of the actions
 * from the contextual menu of the unstaged resources.</p>
 * <p><b>Bug ID:</b> EXM-40615</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testActionsEnablingState_10() throws Exception {
    GitResourceContextualMenu menu = new GitResourceContextualMenu(new SelectedResourcesProvider() {

        @Override
        public List<FileStatus> getOnlySelectedLeaves() {
            return getAllSelectedResources();
        }

        @Override
        public List<FileStatus> getAllSelectedResources() {
            List<FileStatus> fileStatuses = new ArrayList<>();
            fileStatuses.add(new FileStatus(GitChangeType.MISSING, "test.xml"));
            fileStatuses.add(new FileStatus(GitChangeType.UNTRACKED, "test2.xml"));
            return fileStatuses;
        }
    }, gitCtrl, null, // For unstaged resources
    false, Optional.of(RepositoryState.SAFE));
    assertEquals("\n" + "Open_In_Compare [DISABLED]\n" + "Open [DISABLED]\n" + "----\n" + "Stage [ENABLED]\n" + "Resolve_Conflict [DISABLED]\n" + "  Open_In_Compare [DISABLED]\n" + "  ----\n" + "  Resolve_Using_Mine [DISABLED]\n" + "  Resolve_Using_Theirs [DISABLED]\n" + "  Mark_Resolved [DISABLED]\n" + "  ----\n" + "  Restart_Merge [DISABLED]\n" + "Discard [ENABLED]\n" + "----\n" + "Show_history [DISABLED]\n" + "Show_blame [DISABLED]", PopupMenuSerializer.serializePopupStructure(menu, true, true));
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) SelectedResourcesProvider(com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider) ArrayList(java.util.ArrayList) List(java.util.List) GitResourceContextualMenu(com.oxygenxml.git.view.staging.GitResourceContextualMenu)

Example 22 with SelectedResourcesProvider

use of com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider in project oxygen-git-client-addon by oxygenxml.

the class GitViewResourceContextualMenuActionsTest method testActionsEnablingState_20.

/**
 * <p><b>Description:</b> test the enabling state of the actions
 * from the contextual menu of the submodules.</p>
 * <p><b>Bug ID:</b> EXM-40615</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testActionsEnablingState_20() throws Exception {
    GitResourceContextualMenu menu = new GitResourceContextualMenu(new SelectedResourcesProvider() {

        @Override
        public List<FileStatus> getOnlySelectedLeaves() {
            return getAllSelectedResources();
        }

        @Override
        public List<FileStatus> getAllSelectedResources() {
            List<FileStatus> fileStatuses = new ArrayList<>();
            fileStatuses.add(new FileStatus(GitChangeType.SUBMODULE, "test.xml"));
            return fileStatuses;
        }
    }, gitCtrl, null, // For staged resources
    true, Optional.of(RepositoryState.SAFE));
    assertEquals("\n" + "Open_In_Compare [ENABLED]\n" + "Open [ENABLED]\n" + "----\n" + "Unstage [ENABLED]\n" + "Resolve_Conflict [DISABLED]\n" + "  Open_In_Compare [ENABLED]\n" + "  ----\n" + "  Resolve_Using_Mine [DISABLED]\n" + "  Resolve_Using_Theirs [DISABLED]\n" + "  Mark_Resolved [DISABLED]\n" + "  ----\n" + "  Restart_Merge [DISABLED]\n" + "Discard [ENABLED]", PopupMenuSerializer.serializePopupStructure(menu, true, true));
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) SelectedResourcesProvider(com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider) ArrayList(java.util.ArrayList) List(java.util.List) GitResourceContextualMenu(com.oxygenxml.git.view.staging.GitResourceContextualMenu)

Example 23 with SelectedResourcesProvider

use of com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider in project oxygen-git-client-addon by oxygenxml.

the class RefreshProjectTest method testRefreshProjectOnDiscard_2.

/**
 * Refresh on discard. Multiple "untracked" resources discarded
 *
 * @throws Exception
 */
public void testRefreshProjectOnDiscard_2() throws Exception {
    File repoDir = new File(localTestRepoPath);
    repoDir.mkdirs();
    File file = new File(localTestRepoPath, "test.txt");
    file.createNewFile();
    file.deleteOnExit();
    new File(localTestRepoPath + "/subFolder").mkdir();
    File file2 = new File(localTestRepoPath, "subFolder/test2.txt");
    file2.createNewFile();
    file2.deleteOnExit();
    try {
        DiscardAction discardAction = new DiscardAction(new SelectedResourcesProvider() {

            @Override
            public List<FileStatus> getOnlySelectedLeaves() {
                return null;
            }

            @Override
            public List<FileStatus> getAllSelectedResources() {
                return Arrays.asList(new FileStatus(GitChangeType.UNTRACKED, "test.txt"), new FileStatus(GitChangeType.UNTRACKED, "subFolder/test2.txt"));
            }
        }, // A mock that does nothing.
        Mockito.mock(GitControllerBase.class));
        discardAction.actionPerformed(null);
        assertEquals(repoDir.getCanonicalFile().getAbsolutePath(), refreshedFolder.getAbsolutePath());
    } finally {
        FileUtils.deleteDirectory(repoDir);
    }
}
Also used : DiscardAction(com.oxygenxml.git.view.staging.actions.DiscardAction) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) SelectedResourcesProvider(com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider) List(java.util.List) File(java.io.File)

Example 24 with SelectedResourcesProvider

use of com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider in project oxygen-git-client-addon by oxygenxml.

the class RefreshProjectTest method testRefreshProjectOnDiscard_3.

/**
 * Refresh on submodule discard.
 *
 * @throws Exception
 */
@PrepareForTest({ GitAccess.class })
public void testRefreshProjectOnDiscard_3() throws Exception {
    File repoDir = new File(localTestRepoPath);
    repoDir.mkdirs();
    File subModule = new File(localTestRepoPath, "subModule");
    subModule.mkdir();
    try {
        GitAccess gitAccessMock = PowerMockito.mock(GitAccess.class);
        Whitebox.setInternalState(GitAccess.class, "instance", gitAccessMock);
        SubmoduleAccess submoduleAccess = Mockito.mock(SubmoduleAccess.class);
        Mockito.doNothing().when(submoduleAccess).discardSubmodule();
        PowerMockito.when(gitAccessMock.getSubmoduleAccess()).thenReturn(submoduleAccess);
        DiscardAction discardAction = new DiscardAction(new SelectedResourcesProvider() {

            @Override
            public List<FileStatus> getOnlySelectedLeaves() {
                return null;
            }

            @Override
            public List<FileStatus> getAllSelectedResources() {
                return Arrays.asList(new FileStatus(GitChangeType.SUBMODULE, "subModule"));
            }
        }, // A mock that does nothing.
        Mockito.mock(GitControllerBase.class));
        discardAction.actionPerformed(null);
        assertEquals(subModule.getCanonicalFile().getAbsolutePath(), refreshedFolder.getAbsolutePath());
    } finally {
        FileUtils.deleteDirectory(repoDir);
    }
}
Also used : DiscardAction(com.oxygenxml.git.view.staging.actions.DiscardAction) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitAccess(com.oxygenxml.git.service.GitAccess) FileStatus(com.oxygenxml.git.service.entities.FileStatus) SelectedResourcesProvider(com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider) List(java.util.List) File(java.io.File) SubmoduleAccess(com.oxygenxml.git.service.SubmoduleAccess) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with SelectedResourcesProvider

use of com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider in project oxygen-git-client-addon by oxygenxml.

the class RefreshProjectTest method testRefreshProjectOnDiscard_1.

/**
 * Refresh on discard. Only one "added" resource discarded.
 *
 * @throws Exception
 */
public void testRefreshProjectOnDiscard_1() throws Exception {
    File repoDir = new File(localTestRepoPath);
    repoDir.mkdirs();
    File file = new File(localTestRepoPath, "test.txt");
    file.createNewFile();
    file.deleteOnExit();
    try {
        DiscardAction discardAction = new DiscardAction(new SelectedResourcesProvider() {

            @Override
            public List<FileStatus> getOnlySelectedLeaves() {
                return null;
            }

            @Override
            public List<FileStatus> getAllSelectedResources() {
                return Arrays.asList(new FileStatus(GitChangeType.ADD, "test.txt"));
            }
        }, // A mock that does nothing.
        Mockito.mock(GitControllerBase.class));
        discardAction.actionPerformed(null);
        assertEquals(repoDir.getCanonicalFile().getAbsolutePath(), refreshedFolder.getAbsolutePath());
    } finally {
        FileUtils.deleteDirectory(repoDir);
    }
}
Also used : DiscardAction(com.oxygenxml.git.view.staging.actions.DiscardAction) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) SelectedResourcesProvider(com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider) List(java.util.List) File(java.io.File)

Aggregations

SelectedResourcesProvider (com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider)27 List (java.util.List)27 FileStatus (com.oxygenxml.git.service.entities.FileStatus)26 ArrayList (java.util.ArrayList)22 GitResourceContextualMenu (com.oxygenxml.git.view.staging.GitResourceContextualMenu)21 File (java.io.File)6 Repository (org.eclipse.jgit.lib.Repository)6 DiscardAction (com.oxygenxml.git.view.staging.actions.DiscardAction)5 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)3 GitAccess (com.oxygenxml.git.service.GitAccess)1 SubmoduleAccess (com.oxygenxml.git.service.SubmoduleAccess)1 HistoryController (com.oxygenxml.git.view.history.HistoryController)1 ShowBlameForUnstagedResourceAction (com.oxygenxml.git.view.staging.actions.ShowBlameForUnstagedResourceAction)1 URL (java.net.URL)1 JTextArea (javax.swing.JTextArea)1 Highlight (javax.swing.text.Highlighter.Highlight)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1