1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*******************************************************************************
* 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.tasks.tests;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import junit.framework.TestCase;
import org.eclipse.mylar.internal.tasks.ui.TaskListBackupManager;
import org.eclipse.mylar.internal.tasks.ui.TaskListPreferenceConstants;
import org.eclipse.mylar.tasks.core.Task;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
/**
* @author Rob Elves
*/
public class TaskListBackupManagerTest extends TestCase {
private Task task1;
@Override
protected void setUp() throws Exception {
super.setUp();
task1 = new Task("handle", "label");
TasksUiPlugin.getTaskListManager().getTaskList().addTask(task1);
TasksUiPlugin.getTaskListManager().activateTask(task1);
TasksUiPlugin.getTaskListManager().deactivateTask(task1);
TasksUiPlugin.getTaskListManager().saveTaskList();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
// MylarTaskListPlugin.getMylarCorePrefs().setValue(TaskListPreferenceConstants.BACKUP_AUTOMATICALLY,
// false);
}
public void testAutoBackupDisabled() throws InterruptedException {
TaskListBackupManager backupManager = TasksUiPlugin.getDefault().getBackupManager();
// MylarTaskListPlugin.getMylarCorePrefs().setValue(TaskListPreferenceConstants.BACKUP_AUTOMATICALLY,
// false);
TasksUiPlugin.getDefault().getPreferenceStore().setValue(TaskListPreferenceConstants.BACKUP_SCHEDULE, 1);
TasksUiPlugin.getDefault().getPreferenceStore().setValue(TaskListPreferenceConstants.BACKUP_LAST, 0f);
assertEquals(0, TasksUiPlugin.getDefault().getPreferenceStore()
.getLong(TaskListPreferenceConstants.BACKUP_LAST));
backupManager.start(5);
Thread.sleep(3000);
assertEquals(0, TasksUiPlugin.getDefault().getPreferenceStore()
.getLong(TaskListPreferenceConstants.BACKUP_LAST));
}
public void testAutoBackupEnabled() throws InterruptedException, InvocationTargetException, IOException {
TaskListBackupManager backupManager = TasksUiPlugin.getDefault().getBackupManager();
String backupFolder = TasksUiPlugin.getDefault().getBackupFolderPath();
// String backupFolder =
// MylarTaskListPlugin.getMylarCorePrefs().getDefaultString(
// TaskListPreferenceConstants.BACKUP_FOLDER);
File backupFileFolder = new File(backupFolder);
deleteBackupFolder(backupFileFolder);
// MylarTaskListPlugin.getMylarCorePrefs().setValue(TaskListPreferenceConstants.BACKUP_FOLDER,
// backupFolder);
TasksUiPlugin.getDefault().getPreferenceStore().setValue(TaskListPreferenceConstants.BACKUP_SCHEDULE, 1);
TasksUiPlugin.getDefault().getPreferenceStore().setValue(TaskListPreferenceConstants.BACKUP_LAST, 0f);
// MylarTaskListPlugin.getMylarCorePrefs().setValue(TaskListPreferenceConstants.BACKUP_AUTOMATICALLY,
// true);
backupManager.backupNow(true);
assertFalse(TasksUiPlugin.getDefault().getPreferenceStore().getLong(TaskListPreferenceConstants.BACKUP_LAST) == 0);
assertTrue(backupFileFolder.exists());
assertTrue(backupFileFolder.isDirectory());
assertTrue(backupFileFolder.listFiles().length == 1);
// Test removal of old backups
TasksUiPlugin.getDefault().getPreferenceStore().setValue(TaskListPreferenceConstants.BACKUP_MAXFILES, 0);
backupManager.removeOldBackups(backupFileFolder);
assertEquals(0, backupFileFolder.listFiles().length);
// TODO: Test that OLDEST backups are deleted first.
}
private void deleteBackupFolder(File backupFileFolder) {
if (backupFileFolder.exists()) {
for (File file : backupFileFolder.listFiles()) {
file.delete();
}
backupFileFolder.delete();
}
}
}
|