use of com.oxygenxml.git.view.event.WorkingCopyGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method repositoryOpened.
/**
* Actions to do after a repository was opened.
*
* @param workingCopy The WC.
*/
private void repositoryOpened(File workingCopy) {
// Start intercepting authentication requests.
AuthenticationInterceptor.bind(getHostName());
if (LOGGER.isDebugEnabled()) {
logSshKeyLoadingData();
}
fireOperationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, workingCopy));
}
use of com.oxygenxml.git.view.event.WorkingCopyGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitEditorVariables2Test method testCache.
/**
* <p><b>Description:</b> test Git editor variables cache.</p>
* <p><b>Bug ID:</b> EXM-46457</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCache() throws Exception {
Map<String, String> cache = editorVariablesResolver.getEditorVarsCacheFromTests();
assertTrue(cache.isEmpty());
String resolved = editorVariablesResolver.resolveEditorVariables("bla", null);
assertEquals("bla", resolved);
assertTrue(cache.isEmpty());
// Short branch - git access should be called
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("main", resolved);
assertEquals("{${git(short_branch_name)}=main}", cache.toString());
assertEquals(1, noOfShortBranchCalls);
// Short branch again - get it from cache
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("main", resolved);
assertEquals("{${git(short_branch_name)}=main}", cache.toString());
assertEquals(1, noOfShortBranchCalls);
// Full branch name - git access should be called
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("refs/heads/main", resolved);
assertEquals(2, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertEquals(1, noOfFullBranchCalls);
// Full branch name again - get it from the cache
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("refs/heads/main", resolved);
assertEquals(2, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertEquals(1, noOfFullBranchCalls);
// WC name + WC path + WC URL - get them from git access, but request the WC only once
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.WORKING_COPY_NAME_EDITOR_VAR + " " + GitEditorVariablesNames.WORKING_COPY_PATH_EDITOR_VAR + " " + GitEditorVariablesNames.WORKING_COPY_URL_EDITOR_VAR, null);
String expected = "EditorVariablesTest " + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath() + " " + new File(LOCAL_TEST_REPOSITORY).toURI().toURL();
assertEquals(expected, resolved);
assertEquals(5, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
assertEquals(1, noOfWCCalls);
// WC name + WC path + WC URL again- get them from git access
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.WORKING_COPY_NAME_EDITOR_VAR, null);
assertEquals("EditorVariablesTest", resolved);
assertEquals(5, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
assertEquals(1, noOfWCCalls);
// Simulate branch switch
editorVariablesResolver.getGitEventListenerFromTests().operationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CHECKOUT, ""));
assertEquals(3, cache.size());
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
// Short + full branch name again - take them from git access
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR + " " + GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("main refs/heads/main", resolved);
assertEquals(5, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
assertEquals(2, noOfShortBranchCalls);
assertEquals(2, noOfFullBranchCalls);
// Simulate repo switch
editorVariablesResolver.getGitEventListenerFromTests().operationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, new File(".")));
assertTrue(cache.isEmpty());
}
Aggregations