blob: cf92cd34011ac8ddb882151d081352a84181c8c0 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 - 2006 University Of British Columbia and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* University Of British Columbia - initial API and implementation
*******************************************************************************/
package org.eclipse.mylar.tests.integration;
import java.io.File;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTask;
import org.eclipse.mylar.internal.core.MylarContextManager;
import org.eclipse.mylar.internal.monitor.MylarMonitorPlugin;
import org.eclipse.mylar.provisional.core.InteractionEvent;
import org.eclipse.mylar.provisional.core.MylarPlugin;
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
import org.eclipse.mylar.provisional.tasklist.ITask;
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
import org.eclipse.mylar.provisional.tasklist.Task;
import org.eclipse.mylar.provisional.tasklist.TaskListManager;
/**
* Tests changes to the main mylar data directory location.
*
* @author Wesley Coelho
* @author Mik Kersten (rewrites)
*/
public class ChangeDataDirTest extends TestCase {
private String newDataDir = null;
private final String defaultDir = MylarPlugin.getDefault().getDefaultDataDirectory();
private TaskListManager manager = MylarTaskListPlugin.getTaskListManager();
protected void setUp() throws Exception {
super.setUp();
newDataDir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + '/'
+ ChangeDataDirTest.class.getSimpleName();
File dir = new File(newDataDir);
dir.mkdir();
dir.deleteOnExit();
manager.resetTaskList();
assertTrue(manager.getTaskList().isEmpty());
MylarTaskListPlugin.getDefault().getTaskListSaveManager().saveTaskList(true);
}
protected void tearDown() throws Exception {
super.tearDown();
manager.resetTaskList();
MylarPlugin.getDefault().setDataDirectory(defaultDir);
}
public void testMonitorFileMove() {
MylarMonitorPlugin.getDefault().startMonitoring();
MylarMonitorPlugin.getDefault().getInteractionLogger().interactionObserved(
InteractionEvent.makeCommand("id", "delta"));
String oldPath = MylarMonitorPlugin.getDefault().getInteractionLogger().getOutputFile().getAbsolutePath();
assertTrue(new File(oldPath).exists());
MylarPlugin.getDefault().setDataDirectory(newDataDir);
assertFalse(new File(oldPath).exists());
String newPath = MylarMonitorPlugin.getDefault().getInteractionLogger().getOutputFile().getAbsolutePath();
assertTrue(new File(newPath).exists());
assertTrue(MylarMonitorPlugin.getDefault().getInteractionLogger().getOutputFile().exists());
String monitorFileName = MylarMonitorPlugin.MONITOR_LOG_NAME + MylarContextManager.CONTEXT_FILE_EXTENSION;
List<String> newFiles = Arrays.asList(new File(newDataDir).list());
assertTrue(newFiles.toString(), newFiles.contains(monitorFileName));
List<String> filesLeft = Arrays.asList(new File(defaultDir).list());
assertFalse(filesLeft.toString(), filesLeft.contains(monitorFileName));
MylarMonitorPlugin.getDefault().stopMonitoring();
}
public void testDefaultDataDirectoryMove() {
String workspaceRelativeDir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + '/'
+ ".mylar";
assertEquals(defaultDir, workspaceRelativeDir);
MylarPlugin.getDefault().setDataDirectory(newDataDir);
assertEquals(MylarPlugin.getDefault().getDataDirectory(), newDataDir);
}
public void testTaskMove() {
String handle = "task-1";
ITask task = new Task(handle, "label", true);
manager.getTaskList().moveToRoot(task);
ITask readTaskBeforeMove = manager.getTaskList().getTask(handle);
MylarTaskListPlugin.getDefault().getTaskListSaveManager().copyDataDirContentsTo(newDataDir);
MylarPlugin.getDefault().setDataDirectory(newDataDir);
ITask readTaskAfterMove = manager.getTaskList().getTask(handle);
assertNotNull(readTaskAfterMove);
assertEquals(readTaskBeforeMove.getCreationDate(), readTaskAfterMove.getCreationDate());
}
// TODO: delete? using lastOpened date wrong
public void testBugzillaTaskMove() {
String handle = AbstractRepositoryTask.getHandle("server", 1);
BugzillaTask bugzillaTask = new BugzillaTask(handle, "bug1", true);
String refreshDate = (new Date()).toString();
bugzillaTask.setModifiedDateStamp(refreshDate);
addBugzillaTask(bugzillaTask);
BugzillaTask readTaskBeforeMove = (BugzillaTask) manager.getTaskList().getTask(handle);
assertNotNull(readTaskBeforeMove);
assertEquals(refreshDate, readTaskBeforeMove.getLastModifiedDateStamp());
MylarTaskListPlugin.getDefault().getTaskListSaveManager().copyDataDirContentsTo(newDataDir);
MylarPlugin.getDefault().setDataDirectory(newDataDir);
BugzillaTask readTaskAfterMove = (BugzillaTask) manager.getTaskList().getTask(handle);
assertNotNull(readTaskAfterMove);
assertEquals(refreshDate, readTaskAfterMove.getLastModifiedDateStamp());
}
private void addBugzillaTask(BugzillaTask newTask) {
// AbstractRepositoryClient client =
// MylarTaskListPlugin.getRepositoryManager().getRepositoryClient(BugzillaPlugin.REPOSITORY_KIND);
// client.addTaskToArchive(newTask);
// TODO: put back?
// MylarTaskListPlugin.getTaskListManager().getTaskList().internalAddTask(newTask);
// BugzillaTaskHandler handler = new BugzillaTaskHandler();
// handler.addTaskToArchive(newTask);
MylarTaskListPlugin.getTaskListManager().getTaskList().moveToRoot(newTask);
}
// /**
// * Tests moving the main mylar data directory to another location (Without
// * copying existing data to the new directory)
// */
// public void testChangeMainDataDir() {
//
// ITask mainDataDirTask = createAndSaveTask("Main Task", false);
//
// // MylarPlugin.getDefault().setDataDirectory(newDataDir);
// assertEquals(0, manager.getTaskList().getRootTasks().size());
//
// // Check that the main data dir task isn't in the list or the folder
// File taskFile = new File(MylarPlugin.getDefault().getDataDirectory() +
// File.separator
// + mainDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
// assertFalse(taskFile.exists());
// assertNull(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(),
// false));
//
// // Check that a newly created task appears in the right place (method
// // will check)
// ITask newDataDirTask = createAndSaveTask("New Data Dir", false);
// taskFile = new File(MylarPlugin.getDefault().getDataDirectory() +
// File.separator
// + newDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
// assertTrue(taskFile.exists());
//
// // Check for other the tasklist file in the new dir
// File destTaskListFile = new
// File(MylarPlugin.getDefault().getDataDirectory() + File.separator
// + MylarTaskListPlugin.DEFAULT_TASK_LIST_FILE);
// assertTrue(destTaskListFile.exists());
//
// // Switch back to the main task directory
// MylarPlugin.getDefault().setDataDirectory(MylarPlugin.getDefault().getDefaultDataDirectory());
//
// // Check that the previously created main dir task is in the task list
// and its file exists
// assertNotNull(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(),
// false));
// taskFile = new File(MylarPlugin.getDefault().getDataDirectory() +
// File.separator
// + mainDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
// assertTrue(taskFile.exists());
//
// // Check that the task created in the "New Data Dir" isn't there now
// // that we're back to the main dir
// assertNull(manager.getTaskForHandle(newDataDirTask.getHandleIdentifier(),
// false));
//
// }
//
// /**
// * Creates a task with an interaction event and checks that it has been
// * properly saved in the currently active data directory
// */
// protected ITask createAndSaveTask(String taskName, boolean
// createBugzillaTask) {
//
// // Create the task and add it to the root of the task list
// BugzillaTask newTask = null;
// if (!createBugzillaTask) {
// String handle =
// MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle();
// newTask = new BugzillaTask(handle, "bug1", true, true);//new
// Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(),
// taskName, true);
// manager.moveToRoot(newTask);
// } else {
// newTask = new
// BugzillaTask(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(),
// taskName, true,
// true);
// addBugzillaTask(newTask);
// }
//
// MylarContext mockContext =
// MylarPlugin.getContextManager().loadContext(newTask.getHandleIdentifier(),
// newTask.getContextPath());
// InteractionEvent event = new InteractionEvent(InteractionEvent.Kind.EDIT,
// "structureKind", "handle", "originId");
// mockContext.parseEvent(event);
// MylarPlugin.getContextManager().contextActivated(mockContext);
//
// // Save the context file and check that it exists
// MylarPlugin.getContextManager().saveContext(mockContext.getId(),
// newTask.getContextPath());
// File taskFile = new File(MylarPlugin.getDefault().getDataDirectory() +
// File.separator
// + newTask.getContextPath() + MylarContextManager.CONTEXT_FILE_EXTENSION);
// assertTrue(MylarPlugin.getContextManager().hasContext(newTask.getContextPath()));
// assertTrue(taskFile.exists());
//
// return newTask;
// }
//
// /**
// * Same as above but using bugzilla tasks Tests moving the main mylar data
// * directory to another location (Without copying existing data to the new
// * directory)
// */
// public void testChangeMainDataDirBugzilla() {
//
// // Create a task in the main dir and context with an interaction event
// // to be saved
// ITask mainDataDirTask = createAndSaveTask("Main Task", true);
//
// // Set time to see if the right task data is returned by the registry
// // mechanism
// mainDataDirTask.setElapsedTime(ELAPSED_TIME1);
//
// // Save tasklist
// MylarTaskListPlugin.getDefault().getTaskListSaveManager().saveTaskListAndContexts();
//
// // Temp check that the task is there
// assertNotNull(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(),
// false));
//
// // Switch task directory
// MylarPlugin.getDefault().setDataDirectory(newDataDir);
//
// // Check that there are no tasks in the tasklist after switching to the
// // empty dir
// assertTrue(manager.getTaskList().getRootTasks().size() == 0);
//
// // Check that the main data dir task isn't in the list or the folder
// File taskFile = new File(MylarPlugin.getDefault().getDataDirectory() +
// File.separator
// + mainDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
// assertFalse(taskFile.exists());
// assertNull(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(),
// false));
//
// // Check that a newly created task appears in the right place (method
// // will check)
// ITask newDataDirTask = createAndSaveTask("New Data Dir", true);
// taskFile = new File(MylarPlugin.getDefault().getDataDirectory() +
// File.separator
// + newDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
// assertTrue(taskFile.exists());
//
// // Check for tasklist file in the new dir
// File destTaskListFile = new
// File(MylarPlugin.getDefault().getDataDirectory() + File.separator
// + MylarTaskListPlugin.DEFAULT_TASK_LIST_FILE);
// assertTrue(destTaskListFile.exists());
//
// MylarPlugin.getDefault().setDataDirectory(MylarPlugin.getDefault().getDefaultDataDirectory());
//
// // Check that the previously created main dir task is in the task list
// // and its file exists
// assertNotNull(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(),
// false));
// taskFile = new File(MylarPlugin.getDefault().getDataDirectory() +
// File.separator
// + mainDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
// assertTrue(taskFile.exists());
//
// // Check that the elapsed time is still right
// assertTrue(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(),
// false).getElapsedTime() == ELAPSED_TIME1);
//
// // Check that the task created in the "New Data Dir" isn't there now
// // that we're back to the main dir
// assertNull(manager.getTaskForHandle(newDataDirTask.getHandleIdentifier(),
// false));
// }
}