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