Skip to main content
summaryrefslogtreecommitdiffstats
blob: dbad6b5280c1fbbed721644cd6604ff000a7986f (plain) (blame)
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
102
103
104
105
106
107
108
109
110
111
112
113
package org.eclipse.mylar.tasklist.tests;

import java.io.File;

import junit.framework.TestCase;

import org.eclipse.mylar.core.InteractionEvent;
import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.core.internal.MylarContext;
import org.eclipse.mylar.core.internal.MylarContextManager;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
import org.eclipse.mylar.tasklist.Task;
import org.eclipse.mylar.tasklist.TaskListManager;
import org.eclipse.mylar.tasklist.ui.wizards.TaskDataExportWizard;
import org.eclipse.mylar.tasklist.ui.wizards.TaskDataExportWizardPage;
import org.eclipse.swt.widgets.Shell;

/**
 * Test case for the Task Export Wizard
 * 
 * @author Wesley Coelho
 */
public class TaskDataExportTest extends TestCase{

	private TaskDataExportWizard wizard = null;
	private TaskDataExportWizardPage wizardPage = null;
	private File destinationDir = null;
	private ITask task1 = null;
	private TaskListManager manager = MylarTasklistPlugin.getTaskListManager(); 
	
	protected void setUp() throws Exception {
		super.setUp();
		
		//Create the export wizard
		wizard = new TaskDataExportWizard();
		wizard.addPages();
		wizard.createPageControls(new Shell());
		wizardPage = (TaskDataExportWizardPage) wizard.getPage(TaskDataExportWizardPage.PAGE_NAME);
		assertNotNull(wizardPage);
		
		//Create test export destination directory
		destinationDir = new File(MylarPlugin.getDefault().getMylarDataDirectory() + File.separator + "TestDir");
		destinationDir.mkdir();
		assertTrue(destinationDir.exists());
		
		//Create a task and context with an interaction event to be saved
		task1 = new Task(MylarTasklistPlugin.getTaskListManager().genUniqueTaskId(), "Export Test Task", true);
		manager.addRootTask(task1);
		MylarContext mockContext = MylarPlugin.getContextManager().loadContext(task1.getHandleIdentifier(), task1.getPath());
		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(), task1.getPath());
		File taskFile = new File(MylarPlugin.getDefault().getMylarDataDirectory() + File.separator + task1.getPath() + MylarContextManager.FILE_EXTENSION);
		assertTrue(MylarPlugin.getContextManager().hasContext(task1.getPath()));
		assertTrue(taskFile.exists());
	}

	/** Tests the wizard when it has been asked to export all task data to a zip file*/
	public void testExportAllToZip(){
		
		//Set parameters in the wizard to simulate a user setting them and clicking "Finish"
		wizardPage.setParameters(true, true, true, true, true, destinationDir.getPath());
		wizard.performFinish();
		
		//Check that the task list file was exported
		File destZipFile =  new File(destinationDir + File.separator
				+ TaskDataExportWizard.ZIP_FILE_NAME);	
		assertTrue(destZipFile.exists());
	}

	/** Tests the wizard when it has been asked to export all task data */
	public void testExportAll(){
		
		//Set parameters in the wizard to simulate a user setting them and clicking "Finish"
		wizardPage.setParameters(true, true, true, true, false, destinationDir.getPath());
		wizard.performFinish();
		
		//Check that the task list file was exported
		File destTaskListFile =  new File(destinationDir + File.separator
				+ MylarTasklistPlugin.DEFAULT_TASK_LIST_FILE);	
		assertTrue(destTaskListFile.exists());
		
		//Check that the activity history file was exported
		File destActivationHistoryFile = new File(destinationDir
				+ File.separator
				+ MylarContextManager.CONTEXT_HISTORY_FILE_NAME
				+ MylarContextManager.FILE_EXTENSION);
		assertTrue(destActivationHistoryFile.exists());
		
		//Check that the task context file created in setUp() was exported
		File destTaskContextFile = new File(destinationDir + File.separator + task1.getPath() + MylarContextManager.FILE_EXTENSION);
		assertTrue(destTaskContextFile.exists());
	}
	
	protected void tearDown() throws Exception{
		
		//Delete the test destination folder
		
		File[] files = destinationDir.listFiles();
		for (File file : files) {
			file.delete();
		}
		
		destinationDir.delete();
		assertFalse(destinationDir.exists());
		
		super.tearDown();
	}
}

Back to the top