Search in sources :

Example 1 with OxygenGitPluginExtension

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

the class StatusCacheTest method testEditorSaveEvent.

/**
 * <p><b>Description:</b> Test that an editor save event drops the cache and
 * the status is recomputed.</p>
 * <p><b>Bug ID:</b> EXM-49363</p>
 *
 * @author alex_jitianu
 *
 * @throws Exception If it fails.
 */
public void testEditorSaveEvent() throws Exception {
    // Set up. Create required mocks.
    OxygenGitPluginExtension extension = new OxygenGitPluginExtension();
    PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
    JFrame mockFrame = new JFrame();
    Mockito.when(pluginWorkspace.getParentFrame()).thenReturn(mockFrame);
    List<WSEditorChangeListener> listeners = new ArrayList<>();
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            listeners.add(invocation.getArgument(0));
            return null;
        }
    }).when(pluginWorkspace).addEditorChangeListener((WSEditorChangeListener) Mockito.any(), Mockito.anyInt());
    // Intercept save event listeners.
    URL inRepoEditorLocation = Paths.get(REPOSITORY_PATH, "a.txt").toAbsolutePath().toUri().toURL();
    URL outsideRepoEditorLocation = Paths.get(REPOSITORY_PATH, "../b.txt").normalize().toAbsolutePath().toUri().toURL();
    List<WSEditorListener> inRepoListeners = installEditorSaveMock(pluginWorkspace, inRepoEditorLocation);
    List<WSEditorListener> outsideRepoListeners = installEditorSaveMock(pluginWorkspace, outsideRepoEditorLocation);
    // Make Git Client install all of its listeners on the workspace.
    extension.applicationStarted((StandalonePluginWorkspace) pluginWorkspace);
    GitStatus status = GitAccess.getInstance().getStatus();
    // Simulate editor open events for both files so save listeners are added on both.
    listeners.stream().forEach(l -> l.editorOpened(outsideRepoEditorLocation));
    listeners.stream().forEach(l -> l.editorOpened(inRepoEditorLocation));
    // The file outside the repo is saved.
    outsideRepoListeners.stream().forEach(l -> l.editorSaved(WSEditorListener.SAVE_OPERATION));
    GitStatus newstatus = GitAccess.getInstance().getStatus();
    assertTrue("The saved file is not from the repo. The status remains the same.", status == newstatus);
    // The file in the repo is saved.
    inRepoListeners.stream().forEach(l -> l.editorSaved(WSEditorListener.SAVE_OPERATION));
    newstatus = GitAccess.getInstance().getStatus();
    assertFalse("The saved file is from the repo. The status is recomputed.", status == newstatus);
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) ArrayList(java.util.ArrayList) URL(java.net.URL) WSEditorListener(ro.sync.exml.workspace.api.listeners.WSEditorListener) JFrame(javax.swing.JFrame) WSEditorChangeListener(ro.sync.exml.workspace.api.listeners.WSEditorChangeListener) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OxygenGitPluginExtension(com.oxygenxml.git.OxygenGitPluginExtension)

Example 2 with OxygenGitPluginExtension

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

the class StatusCacheTest method testWindowActivatedEvent.

/**
 * <p><b>Description:</b> Test that a window activated event drops the cache.</p>
 * <p><b>Bug ID:</b> EXM-49363</p>
 *
 * @author alex_jitianu
 *
 * @throws Exception If it fails.
 */
public void testWindowActivatedEvent() throws Exception {
    OxygenGitPluginExtension extension = new OxygenGitPluginExtension();
    PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
    JFrame mockFrame = new JFrame();
    Mockito.when(pluginWorkspace.getParentFrame()).thenReturn(mockFrame);
    extension.applicationStarted((StandalonePluginWorkspace) pluginWorkspace);
    GitStatus status = GitAccess.getInstance().getStatus();
    Arrays.stream(mockFrame.getWindowListeners()).forEach(l -> l.windowActivated(null));
    GitStatus newstatus = GitAccess.getInstance().getStatus();
    assertFalse("A window activated event should drop the cache", status == newstatus);
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) JFrame(javax.swing.JFrame) OxygenGitPluginExtension(com.oxygenxml.git.OxygenGitPluginExtension)

Example 3 with OxygenGitPluginExtension

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

the class StatusCacheTest method testGitEvent.

/**
 * <p><b>Description:</b> A git event resets the cache.</p>
 * <p><b>Bug ID:</b> EXM-49363</p>
 *
 * @author alex_jitianu
 *
 * @throws Exception If it fails.
 */
public void testGitEvent() throws Exception {
    OxygenGitPluginExtension extension = new OxygenGitPluginExtension();
    PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
    JFrame mockFrame = new JFrame();
    Mockito.when(pluginWorkspace.getParentFrame()).thenReturn(mockFrame);
    // These operations do not affect a status.
    List<GitOperation> exceptions = Arrays.asList(GitOperation.DELETE_BRANCH, GitOperation.PUSH);
    extension.applicationStarted((StandalonePluginWorkspace) pluginWorkspace);
    Arrays.stream(GitOperation.values()).forEach(op -> {
        GitStatus status = GitAccess.getInstance().getStatus();
        GitEventAdapter listener = new GitEventAdapter() {

            @Override
            public void operationSuccessfullyEnded(GitEventInfo info) {
                // When a normal listener receives a git event, if it requests the status it
                // should receive a newly computed status, not the stale one from cache.
                assertStatus(exceptions, op, status);
            }
        };
        GitListeners.getInstance().addGitListener(listener);
        GitListeners.getInstance().fireOperationSuccessfullyEnded(new GitEventInfo(op));
        GitListeners.getInstance().removeGitListener(listener);
        assertStatus(exceptions, op, status);
    });
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) GitOperation(com.oxygenxml.git.view.event.GitOperation) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) JFrame(javax.swing.JFrame) OxygenGitPluginExtension(com.oxygenxml.git.OxygenGitPluginExtension)

Aggregations

OxygenGitPluginExtension (com.oxygenxml.git.OxygenGitPluginExtension)3 JFrame (javax.swing.JFrame)3 PluginWorkspace (ro.sync.exml.workspace.api.PluginWorkspace)3 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)3 GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)1 GitOperation (com.oxygenxml.git.view.event.GitOperation)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 WSEditorChangeListener (ro.sync.exml.workspace.api.listeners.WSEditorChangeListener)1 WSEditorListener (ro.sync.exml.workspace.api.listeners.WSEditorListener)1