use of com.oxygenxml.git.view.history.RenameTracker in project oxygen-git-client-addon by oxygenxml.
the class GitHistoryActionsTest method testHistoryContextualActions.
/**
* Tests the contextual actions that are presented for different types of changes.
*
* @throws Exception
*/
@Test
public void testHistoryContextualActions() throws Exception {
URL script = getClass().getClassLoader().getResource("scripts/history_script_actions.txt");
File wcTree = new File("target/gen/GitHistoryActionsTest_testHistoryContextualActions");
RepoGenerationScript.generateRepository(script, wcTree);
try {
GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
String dump = dumpHistory(commitsCharacteristics);
String expected = "[ Changes. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second commit. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
String regex = "(([0-9])|([0-2][0-9])|([3][0-1]))\\ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\ \\d{4}";
expected = expected.replaceAll(regex, "DATE");
dump = dump.replaceAll(regex, "DATE");
assertEquals(expected, dump);
HistoryViewContextualMenuPresenter presenter = new HistoryViewContextualMenuPresenter(null);
List<Action> actions = new ArrayList<>();
JPopupMenu jPopupMenu = Mockito.mock(JPopupMenu.class);
// ////////////////////////
// Changes.
// ////////////////////////
Iterator<CommitCharacteristics> iterator = commitsCharacteristics.iterator();
CommitCharacteristics commitCharacteristic = iterator.next();
List<FileStatus> changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
String dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=CHANGED, fileLocation=file1.txt)\n" + "(changeType=REMOVED, fileLocation=file2.txt)\n" + "", dumpFS);
// Assert the available actions for the changed file.
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, true);
actions.removeIf(e -> e == null);
assertEquals("[Compare_file_with_previous_version, " + "Compare_file_with_working_tree_version, " + "Open_this_version_of_filename, " + "Open_the_working_copy_version_of, " + "Reset_file_x_to_this_commit]", dumpActions(actions));
// A deleted file.
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(1), commitCharacteristic, true);
actions.removeIf(e -> e == null);
presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
assertEquals("[Open_previous_version]", dumpActions(actions));
// Next COMMIT / REVISION
commitCharacteristic = iterator.next();
changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=ADD, fileLocation=file2.txt)\n" + "", dumpFS);
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, true);
actions.removeIf(e -> e == null);
presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
assertEquals("[Compare_file_with_working_tree_version," + " Open_this_version_of_filename," + " Open_the_working_copy_version_of]", dumpActions(actions));
// Next COMMIT / REVISION
commitCharacteristic = iterator.next();
changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=ADD, fileLocation=file1.txt)\n" + "", dumpFS);
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, true);
actions.removeIf(e -> e == null);
assertEquals("[Compare_file_with_working_tree_version, Open_this_version_of_filename," + " Open_the_working_copy_version_of, Reset_file_x_to_this_commit]", dumpActions(actions));
actions = new ArrayList<>();
// ////////////////////////
// Changes.
// ////////////////////////
iterator = commitsCharacteristics.iterator();
commitCharacteristic = iterator.next();
changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=CHANGED, fileLocation=file1.txt)\n" + "(changeType=REMOVED, fileLocation=file2.txt)\n" + "", dumpFS);
// Assert the available actions for the changed file.
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, false);
actions.removeIf(e -> e == null);
assertEquals("[Compare_with_previous_version, Compare_with_working_tree_version, " + "Open, Open_working_copy_version, Reset_file_to_this_commit]", dumpActions(actions));
// A deleted file.
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(1), commitCharacteristic, false);
actions.removeIf(e -> e == null);
presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
assertEquals("[Open_previous_version]", dumpActions(actions));
// Next COMMIT / REVISION
commitCharacteristic = iterator.next();
changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=ADD, fileLocation=file2.txt)\n" + "", dumpFS);
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, false);
actions.removeIf(e -> e == null);
presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristic);
assertEquals("[Compare_with_working_tree_version, Open, Open_working_copy_version]", dumpActions(actions));
// Next COMMIT / REVISION
commitCharacteristic = iterator.next();
changedFiles = RevCommitUtil.getChangedFiles(commitCharacteristic.getCommitId());
dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=ADD, fileLocation=file1.txt)\n" + "", dumpFS);
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), commitCharacteristic, false);
actions.removeIf(e -> e == null);
assertEquals("[Compare_with_working_tree_version, Open, Open_working_copy_version, Reset_file_to_this_commit]", dumpActions(actions));
// ========================= Uncommitted changes ======================================
File newFile = new File(wcTree, "newFile.xml");
newFile.createNewFile();
setFileContent(new File(wcTree, "file1.txt"), "branza");
commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
dump = dumpHistory(commitsCharacteristics);
expected = "[ Uncommitted_changes , DATE , * , * , null , null ]\n" + "[ Changes. , DATE , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second commit. , DATE , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , DATE , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
expected = expected.replaceAll(regex, "DATE");
dump = dump.replaceAll(regex, "DATE");
assertEquals(expected, dump);
CommitCharacteristics uncommittedChanges = commitsCharacteristics.get(0);
changedFiles = RevCommitUtil.getChangedFiles(uncommittedChanges.getCommitId());
dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=UNTRACKED, fileLocation=newFile.xml)\n" + "(changeType=MODIFIED, fileLocation=file1.txt)\n" + "", dumpFS);
// Assert the available actions for the untracked file.
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), uncommittedChanges, false);
actions.removeIf(e -> e == null);
assertEquals("[Open]", dumpActions(actions));
// Assert the available actions for the modified file.
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(1), uncommittedChanges, false);
actions.removeIf(e -> e == null);
assertEquals("[Open_In_Compare, Open]", dumpActions(actions));
// ====== DELETE a file =====
Files.delete(new File(wcTree, "file1.txt").toPath());
Files.delete(newFile.toPath());
// Assuming the delete was performed outside Oxygen so we need to simulate
// a window activation event that resets cache.
GitAccess.getInstance().getStatusCache().resetCache();
commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
dump = dumpHistory(commitsCharacteristics);
expected = "[ Uncommitted_changes , DATE , * , * , null , null ]\n" + "[ Changes. , DATE , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second commit. , DATE , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , DATE , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
expected = expected.replaceAll(regex, "DATE");
dump = dump.replaceAll(regex, "DATE");
assertEquals(expected, dump);
uncommittedChanges = commitsCharacteristics.get(0);
changedFiles = RevCommitUtil.getChangedFiles(uncommittedChanges.getCommitId());
dumpFS = dumpFS(changedFiles);
assertEquals("(changeType=MISSING, fileLocation=file1.txt)\n" + "", dumpFS);
// Assert the available actions for the missing file.
actions.clear();
actions = presenter.getFileContextualActions(changedFiles.get(0), uncommittedChanges, false);
actions.removeIf(e -> e == null);
assertEquals("[Open_previous_version]", dumpActions(actions));
} finally {
GitAccess.getInstance().closeRepo();
FileUtils.deleteDirectory(wcTree);
}
}
use of com.oxygenxml.git.view.history.RenameTracker in project oxygen-git-client-addon by oxygenxml.
the class GitHistoryActionsTest method testOpenPreviousVersion_MergedBranches.
/**
* A commit with a removed file. The commit has 2 parents (it's a merge).
*
* @throws Exception If it fails.
*/
@Test
public void testOpenPreviousVersion_MergedBranches() throws Exception {
URL script = getClass().getClassLoader().getResource("scripts/history_script_actions_branches_merged.txt");
File wcTree = new File("target/gen/GitHistoryActionsTest_testHistoryActions_MergedBranches");
RepoGenerationScript.generateRepository(script, wcTree);
try {
GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
String dump = dumpHistory(commitsCharacteristics);
String expected = "[ Merge branch 'main' , 19 Nov 2019 , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2, 3] ]\n" + "[ Change file1.txt on Feature branch. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [4] ]\n" + "[ Delete file2.txt main branch. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First commit. , 19 Nov 2019 , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]\n" + "";
String regex = "(([0-9])|([0-2][0-9])|([3][0-1]))\\ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\ \\d{4}";
expected = expected.replaceAll(regex, "DATE");
dump = expected.replaceAll(regex, "DATE");
assertEquals(expected, dump);
HistoryViewContextualMenuPresenter presenter = new HistoryViewContextualMenuPresenter(null);
List<Action> actions = new ArrayList<>();
JPopupMenu jPopupMenu = Mockito.mock(JPopupMenu.class);
// ////////////////////////
// Changes.
// ////////////////////////
Iterator<CommitCharacteristics> iterator = commitsCharacteristics.iterator();
CommitCharacteristics commitCharacteristics = iterator.next();
List<FileStatus> changes = RevCommitUtil.getChangedFiles(commitCharacteristics.getCommitId());
String dumpFS = dumpFS(changes);
assertEquals("(changeType=REMOVED, fileLocation=file2.txt)\n" + "", dumpFS);
// A deleted file.
actions.clear();
actions = presenter.getFileContextualActions(changes.get(0), commitCharacteristics, true);
presenter.populateContextualActionsHistoryContext(jPopupMenu, "file2.txt", commitCharacteristics);
assertEquals("[Open_previous_version]", dumpActions(actions));
final StringBuilder b = new StringBuilder();
Mockito.when(PluginWorkspaceProvider.getPluginWorkspace().open((URL) Mockito.any())).thenAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
b.append(invocation.getArguments()[0].toString());
return null;
}
});
actions.get(0).actionPerformed(null);
assertTrue("Previous version URL was not detected", b.toString().length() > 0);
try (InputStream openStream = new URL(b.toString()).openStream()) {
assertEquals("[file 2 content]", IOUtils.readLines(openStream).toString());
}
} finally {
GitAccess.getInstance().closeRepo();
FileUtils.deleteDirectory(wcTree);
}
}
use of com.oxygenxml.git.view.history.RenameTracker in project oxygen-git-client-addon by oxygenxml.
the class GitHistoryTest method testHistory_ResourceUntouched.
/**
* Tests the history can be shown for a resource that is not modified.
*
* @throws Exception
*/
@Test
public void testHistory_ResourceUntouched() throws Exception {
URL script = getClass().getClassLoader().getResource("scripts/history_script.txt");
File wcTree = new File("target/gen/testHistory_ResourceUntouched");
RepoGenerationScript.generateRepository(script, wcTree);
try {
GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, "root.txt", new RenameTracker());
String dump = dumpHistory(commitsCharacteristics);
String expected = "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , null ]\n";
expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
assertEquals("root.txt was created and changed in the last two commit", expected, dump);
} finally {
GitAccess.getInstance().closeRepo();
FileUtils.deleteDirectory(wcTree);
}
}
use of com.oxygenxml.git.view.history.RenameTracker in project oxygen-git-client-addon by oxygenxml.
the class GitHistoryTest method testHistory.
/**
* Tests the commit revisions retrieval.
*
* @throws Exception
*/
@Test
public void testHistory() throws Exception {
URL script = getClass().getClassLoader().getResource("scripts/history_script.txt");
File wcTree = new File("target/gen/GitHistoryTest_testHistory");
RepoGenerationScript.generateRepository(script, wcTree);
try {
FileUtils.writeStringToFile(new File(wcTree, "root.txt"), "changed", "UTF-8");
GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
String dump = dumpHistory(commitsCharacteristics);
String expected = "[ Uncommitted_changes , {date} , * , * , null , null ]\n" + "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]\n" + "";
expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
assertEquals(expected, dump);
commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, "root.txt", new RenameTracker());
dump = dumpHistory(commitsCharacteristics);
expected = "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , null ]\n" + "";
expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
assertEquals("root.txt was created and changed in the last two commit", expected, dump);
} finally {
GitAccess.getInstance().closeRepo();
FileUtils.deleteDirectory(wcTree);
}
}
use of com.oxygenxml.git.view.history.RenameTracker in project oxygen-git-client-addon by oxygenxml.
the class GitHistoryTest method testHistoryBranch.
/**
* We have a repository with multiple branches. The history should present the history for the current branch only.
*
* @throws Exception If it fails.
*/
@Test
public void testHistoryBranch() throws Exception {
URL script = getClass().getClassLoader().getResource("scripts/history_script_branches.txt");
File wcTree = new File("target/gen/GitHistoryTest_testHistoryBranch");
RepoGenerationScript.generateRepository(script, wcTree);
try {
GitAccess.getInstance().setRepositorySynchronously(wcTree.getAbsolutePath());
GitAccess.getInstance().setBranch("main");
List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
String dump = dumpHistory(commitsCharacteristics);
String expected = "[ Changed on main branch. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , [5] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 5 , AlexJitianu , null ]\n" + "";
expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
assertEquals(expected, dump);
Map<String, List<String>> branchMap = GitAccess.getInstance().getBranchMap(GitAccess.getInstance().getRepository(), ConfigConstants.CONFIG_KEY_LOCAL);
// ---------------
// Assert the branch names.
// ----------------
final StringBuilder mapDump = new StringBuilder();
branchMap.forEach((k, v) -> {
mapDump.append(getAssertableID(k)).append(" -> ").append(v.toString()).append("\n");
});
assertEquals("6 -> [feature]\n" + "1 -> [main]\n" + "", mapDump.toString());
GitAccess.getInstance().setBranch("feature");
commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
dump = dumpHistory(commitsCharacteristics);
expected = "[ Changed on feature branch. , {date} , Alex <alex_jitianu@sync.ro> , 6 , AlexJitianu , [7] ]\n" + "[ Feature branch commit. , {date} , Alex <alex_jitianu@sync.ro> , 7 , AlexJitianu , [2] ]\n" + "[ Root file changed. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Root file. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ Changes. , {date} , Alex <alex_jitianu@sync.ro> , 4 , AlexJitianu , [5] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 5 , AlexJitianu , null ]\n" + "";
expected = expected.replaceAll("\\{date\\}", DATE_FORMAT.format(new Date()));
assertEquals(expected, dump);
} finally {
GitAccess.getInstance().closeRepo();
FileUtils.deleteDirectory(wcTree);
}
}
Aggregations