Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 106990 | Differences between
and this patch

Collapse All | Expand All

(-)CollabNetRegularExpressionTest.java (-1 / +8 lines)
Lines 54-60 Link Here
54
	private static final RegularExpression reColVal7 = new RegularExpression("<span class=\"summary\">([^>]+)</span>",
54
	private static final RegularExpression reColVal7 = new RegularExpression("<span class=\"summary\">([^>]+)</span>",
55
			"i");
55
			"i");
56
56
57
	public void testMatchV220() throws IOException {
57
	public void testMatchCollabNetV1() throws IOException {
58
		BufferedReader in = new BufferedReader(new StringReader(EXAMPLE_REPORT));
58
		BufferedReader in = new BufferedReader(new StringReader(EXAMPLE_REPORT));
59
		Match match = new Match();
59
		Match match = new Match();
60
		BugzillaSearchHit hit = createHit(new NullProgressMonitor(), in, match,
60
		BugzillaSearchHit hit = createHit(new NullProgressMonitor(), in, match,
Lines 138-143 Link Here
138
	public static String readSeverity(String line) {
138
	public static String readSeverity(String line) {
139
		Match match = new Match();
139
		Match match = new Match();
140
		if (reColVal1.matches(line, match)) {
140
		if (reColVal1.matches(line, match)) {
141
			assertEquals("nor", match.getCapturedText(1));
141
			return match.getCapturedText(1);
142
			return match.getCapturedText(1);
142
		} else {
143
		} else {
143
			return "none";
144
			return "none";
Lines 147-152 Link Here
147
	public static String readPriority(String line) {
148
	public static String readPriority(String line) {
148
		Match match = new Match();
149
		Match match = new Match();
149
		if (reColVal2.matches(line, match)) {
150
		if (reColVal2.matches(line, match)) {
151
			assertEquals("priority", match.getCapturedText(1));
150
			return match.getCapturedText(1);
152
			return match.getCapturedText(1);
151
		} else {
153
		} else {
152
			return "none";
154
			return "none";
Lines 156-161 Link Here
156
	public static String readPlatform(String line) {
158
	public static String readPlatform(String line) {
157
		Match match = new Match();
159
		Match match = new Match();
158
		if (reColVal3.matches(line, match)) {
160
		if (reColVal3.matches(line, match)) {
161
			assertEquals("platform", match.getCapturedText(1));
159
			return match.getCapturedText(1);
162
			return match.getCapturedText(1);
160
		} else {
163
		} else {
161
			return "none";
164
			return "none";
Lines 165-170 Link Here
165
	public static String readOwner(String line) {
168
	public static String readOwner(String line) {
166
		Match match = new Match();
169
		Match match = new Match();
167
		if (reColVal4.matches(line, match)) {
170
		if (reColVal4.matches(line, match)) {
171
			assertEquals("owner", match.getCapturedText(1));
168
			return match.getCapturedText(1);
172
			return match.getCapturedText(1);
169
		} else {
173
		} else {
170
			return "none";
174
			return "none";
Lines 174-179 Link Here
174
	public static String readStatus(String line) {
178
	public static String readStatus(String line) {
175
		Match match = new Match();
179
		Match match = new Match();
176
		if (reColVal5.matches(line, match)) {
180
		if (reColVal5.matches(line, match)) {
181
			assertEquals("status", match.getCapturedText(1));
177
			return match.getCapturedText(1);
182
			return match.getCapturedText(1);
178
		} else {
183
		} else {
179
			return "none";
184
			return "none";
Lines 183-188 Link Here
183
	public static String readResolution(String line) {
188
	public static String readResolution(String line) {
184
		Match match = new Match();
189
		Match match = new Match();
185
		if (reColVal6.matches(line, match)) {
190
		if (reColVal6.matches(line, match)) {
191
			assertEquals("resolution", match.getCapturedText(1));
186
			return match.getCapturedText(1);
192
			return match.getCapturedText(1);
187
		} else {
193
		} else {
188
			return "none";
194
			return "none";
Lines 192-197 Link Here
192
	public static String readSummary(String line) {
198
	public static String readSummary(String line) {
193
		Match match = new Match();
199
		Match match = new Match();
194
		if (reColVal7.matches(line, match)) {
200
		if (reColVal7.matches(line, match)) {
201
			assertEquals("summary", match.getCapturedText(1));
195
			return match.getCapturedText(1);
202
			return match.getCapturedText(1);
196
		} else {
203
		} else {
197
			return "none";
204
			return "none";
(-)SharedTaskFolderTest.java (-210 lines)
Removed Link Here
1
package org.eclipse.mylar.sandbox.tests;
2
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileOutputStream;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.OutputStream;
9
10
import junit.framework.TestCase;
11
12
import org.eclipse.mylar.core.InteractionEvent;
13
import org.eclipse.mylar.core.MylarPlugin;
14
import org.eclipse.mylar.internal.core.MylarContext;
15
import org.eclipse.mylar.internal.monitor.reports.MylarReportsPlugin;
16
import org.eclipse.mylar.internal.sandbox.MylarSandboxPlugin;
17
import org.eclipse.mylar.internal.sandbox.share.SwitchTaskDataFolderAction;
18
import org.eclipse.mylar.internal.tasklist.ITask;
19
import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin;
20
import org.eclipse.mylar.internal.tasklist.Task;
21
import org.eclipse.mylar.internal.tasklist.TaskListManager;
22
23
/**
24
 * Tests changing the shared task directory
25
 * currently in use.
26
 * 
27
 * @author Wesley Coelho
28
 */
29
public class SharedTaskFolderTest extends TestCase{
30
31
	private File sharedDataRootDir = null;
32
	private File bobsDataDir = null;
33
	private File jillsDataDir = null;
34
	private String originalMainDataDir = null;
35
	private String originalSharedDataDir = null;
36
	private TaskListManager manager = MylarTaskListPlugin.getTaskListManager(); 
37
	
38
	/**
39
	 * Set up a shared task directory structure by creating some data
40
	 * in the main directory and copying it to the shared directories.
41
	 */
42
	protected void setUp() throws Exception {
43
		super.setUp();
44
		
45
		//Get the original main data directory so that it can be reset later
46
		originalMainDataDir = MylarPlugin.getDefault().getDataDirectory();
47
		
48
		//Create a task to make sure there is some data in the main directory
49
		createAndSaveTask("Task1");
50
		
51
		//Create the shared data directory structure
52
		sharedDataRootDir = new File(MylarPlugin.getDefault().getDataDirectory() + File.separator + "SharedDataDir");
53
		sharedDataRootDir.mkdir();
54
		assertTrue(sharedDataRootDir.exists());	
55
		
56
		bobsDataDir = new File(sharedDataRootDir.getPath() + File.separator + "Bob");
57
		bobsDataDir.mkdir();
58
		assertTrue(bobsDataDir.exists());
59
		
60
		jillsDataDir = new File(sharedDataRootDir.getPath() + File.separator + "Jill");
61
		jillsDataDir.mkdir();
62
		assertTrue(jillsDataDir.exists());
63
64
		//Start the shared data dirs off with copies of the main data
65
		File mainDataDir = new File(originalMainDataDir);
66
		for ( File currFile : mainDataDir.listFiles()) {
67
			File destFile = new File(bobsDataDir.getPath() + File.separator + currFile.getName());
68
			copy(currFile, destFile);
69
			destFile = new File(jillsDataDir.getPath() + File.separator + currFile.getName());
70
			copy(currFile, destFile);
71
		}
72
		
73
		//Set the shared data dir
74
		originalSharedDataDir = MylarSandboxPlugin.getDefault().getSharedDataDirectoryManager().getSharedDataDirectory();
75
		MylarReportsPlugin.getDefault().getPreferenceStore().setValue(MylarReportsPlugin.SHARED_TASK_DATA_ROOT_DIR, sharedDataRootDir.getPath());
76
		MylarSandboxPlugin.getDefault().getSharedDataDirectoryManager().setSharedDataDirectory(sharedDataRootDir.getPath());
77
		assertFalse(MylarPlugin.getDefault().getDataDirectory().equals(sharedDataRootDir.getPath()));
78
	}
79
	
80
	/**
81
	 * Tests moving the main mylar data directory to another location
82
	 */
83
	public void testSharedDataDirSwitching(){
84
		SwitchTaskDataFolderAction switchAction = new SwitchTaskDataFolderAction();
85
		
86
		//Create a task to appear in the main data dir only
87
		ITask mainDataDirTask = createAndSaveTask("Main Dir Task");
88
		
89
		//Check the options of folders to switch to
90
		String[] sharedDataFolderOptions = switchAction.getFolderStrings();
91
		//Note that index 0 is a string indicating a switch back to the main data directory
92
		assertTrue(sharedDataFolderOptions[0].equals("Bob"));
93
		assertTrue(sharedDataFolderOptions[1].equals("Jill"));
94
		
95
		//Switch to Bob's folder
96
		switchAction.switchTaskDataFolder(sharedDataFolderOptions[0]);
97
		
98
		//Check that the task created in the main data dir isn't there
99
		File mainDataDirTaskFile = MylarPlugin.getContextManager().getFileForContext(mainDataDirTask.getHandleIdentifier());
100
//		File mainDataDirTaskFile = new File(MylarPlugin.getDefault().getDataDirectory() + File.separator + mainDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
101
		assertFalse(mainDataDirTaskFile.exists());
102
		assertNull(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(), false));
103
		
104
		fail(); // uncomment below
105
		//Create a new task in bob's task data folder only and check that it exists in the right place
106
//		ITask bobsTask = createAndSaveTask("Bob's Task");
107
//		
108
//		File bobsTaskFile = new File(bobsDataDir.getPath() + File.separator + 
109
//				MylarPlugin.getContextManager().getFileForContext(mainDataDirTask.getHandleIdentifier()).getName());
110
//		assertTrue(bobsTaskFile.exists());
111
//		bobsTaskFile = new File(MylarPlugin.getDefault().getDataDirectory() + File.separator + bobsTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
112
//		assertTrue(bobsTaskFile.exists());
113
//		assertNotNull(manager.getTaskForHandle(bobsTask.getHandleIdentifier(), false));
114
//		
115
//		//Switch to Jill's folder
116
//		switchAction.switchTaskDataFolder(sharedDataFolderOptions[1]);
117
//		
118
//		//Check that Bob's task isn't there
119
//		bobsTaskFile = new File(MylarPlugin.getDefault().getDataDirectory() + File.separator + bobsTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
120
//		assertFalse(bobsTaskFile.exists());
121
//		assertNull(manager.getTaskForHandle(bobsTask.getHandleIdentifier(), false));		
122
//		
123
//		//Switch back to Bob's folder
124
//		switchAction.switchTaskDataFolder(sharedDataFolderOptions[0]);
125
//		
126
//		//Check that bob's task is still there
127
//		bobsTaskFile = new File(MylarPlugin.getDefault().getDataDirectory() + File.separator + bobsTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
128
//		assertTrue(bobsTaskFile.exists());
129
//		assertNotNull(manager.getTaskForHandle(bobsTask.getHandleIdentifier(), false));			
130
//		
131
//		//Switch back to the main data folder
132
//		sharedDataFolderOptions = switchAction.getFolderStrings();
133
//		switchAction.switchTaskDataFolder(sharedDataFolderOptions[0]);
134
//		
135
//		//Check that the main task is there
136
//		mainDataDirTaskFile = new File(MylarPlugin.getDefault().getDataDirectory() + File.separator + mainDataDirTask.getContextPath() + MylarTaskListPlugin.FILE_EXTENSION);
137
//		assertTrue(mainDataDirTaskFile.exists());
138
//		assertNotNull(manager.getTaskForHandle(mainDataDirTask.getHandleIdentifier(), false));			
139
		
140
	}
141
		
142
	/**
143
	 * Creates a task with an interaction event and checks that it has
144
	 * been properly saved in the currently active data directory
145
	 */
146
	protected ITask createAndSaveTask(String taskName){
147
		
148
		//Create the task and add it to the root of the task list
149
		ITask newTask = new Task(MylarTaskListPlugin.getTaskListManager().genUniqueTaskHandle(), taskName, true);
150
		manager.moveToRoot(newTask);
151
		MylarContext mockContext = MylarPlugin.getContextManager().loadContext(newTask.getHandleIdentifier());//, newTask.getContextPath());
152
		InteractionEvent event = new InteractionEvent(InteractionEvent.Kind.EDIT,"structureKind","handle","originId");
153
		mockContext.parseEvent(event);
154
		MylarPlugin.getContextManager().contextActivated(mockContext);
155
156
		fail(); // uncomment below
157
//		//Save the context file and check that it exists
158
//		MylarPlugin.getContextManager().saveContext(mockContext.getId());//, newTask.getContextPath());
159
//		File taskFile = new File(MylarPlugin.getDefault().getDataDirectory() + File.separator + newTask.getContextPath() + MylarContextManager.CONTEXT_FILE_EXTENSION);
160
//		assertTrue(MylarPlugin.getContextManager().hasContext(newTask.getContextPath()));
161
//		assertTrue(taskFile.exists());			
162
		
163
		return newTask;
164
	}
165
		
166
	protected void tearDown() throws Exception{
167
		
168
		//Reset the shared directory to the original value
169
		MylarSandboxPlugin.getDefault().getSharedDataDirectoryManager().setSharedDataDirectory(originalSharedDataDir);
170
		MylarReportsPlugin.getDefault().getPreferenceStore().setValue(MylarReportsPlugin.SHARED_TASK_DATA_ROOT_DIR, originalSharedDataDir);
171
		
172
		//Delete the test shared data directories
173
		deleteDir(bobsDataDir);
174
		deleteDir(jillsDataDir);
175
		deleteDir(sharedDataRootDir);
176
		
177
		super.tearDown();
178
	}
179
	
180
	private void deleteDir(File targetDir){
181
		File[] files = targetDir.listFiles();
182
		for (File file : files) {
183
			file.delete();
184
		}
185
		
186
		targetDir.delete();
187
		assertFalse(targetDir.exists());
188
	}
189
	
190
	// Note: Copied from MylarTaskListPlugin
191
	private boolean copy(File src, File dst) {
192
		try {
193
			InputStream in = new FileInputStream(src);
194
			OutputStream out = new FileOutputStream(dst);
195
196
			// Transfer bytes from in to out
197
			byte[] buf = new byte[1024];
198
			int len;
199
			while ((len = in.read(buf)) > 0) {
200
				out.write(buf, 0, len);
201
			}
202
			in.close();
203
			out.close();
204
			return true;
205
		} catch (IOException ioe) {
206
			return false;
207
		}
208
	}
209
	
210
}
(-).project (+11 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>tests</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
	</buildSpec>
9
	<natures>
10
	</natures>
11
</projectDescription>

Return to bug 106990