Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexei.trebounskikh2018-07-19 20:02:20 -0400
committeralexei.trebounskikh2018-08-01 14:01:21 -0400
commitf422548545a931cd4ab2d7d3ba9068607828d902 (patch)
tree5f08ea47d1cb251f45ede54d34666678bf49baf2 /org.eclipse.mylyn.tasks.tests
parent724035d03db2865890766125a6bc7931cfacbf21 (diff)
downloadorg.eclipse.mylyn.tasks-f422548545a931cd4ab2d7d3ba9068607828d902.tar.gz
org.eclipse.mylyn.tasks-f422548545a931cd4ab2d7d3ba9068607828d902.tar.xz
org.eclipse.mylyn.tasks-f422548545a931cd4ab2d7d3ba9068607828d902.zip
537208: Task data filename can get too long
* moved file-related operations to a separate class * file name is only encoded if required * file name is trimmed to stay below 255 characters * encoded file name always used if file already exists * added unit tests for file-related methods Change-Id: I8b536b3a3df8168b997aa9be1ec82b9f7e314dfd Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=537208 Signed-off-by: alexei.trebounskikh <alexei.trebounskikh@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataFileManagerTest.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataFileManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataFileManagerTest.java
new file mode 100644
index 000000000..9eb169632
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataFileManagerTest.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests;
+
+import java.io.File;
+
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.mylyn.internal.tasks.core.data.TaskDataFileManager;
+import org.eclipse.mylyn.tasks.core.ITask;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Alexei Trebounskikh
+ */
+public class TaskDataFileManagerTest extends TestCase {
+
+ private class TestTaskDataFileManager extends TaskDataFileManager {
+ public String getFileName(ITask task, boolean fileExists) {
+ return super.getFileName(task, name -> fileExists);
+ }
+
+ }
+
+ private final TestTaskDataFileManager fileManager = new TestTaskDataFileManager();
+
+ public void testShortFileName() {
+ // <max, exists, not requires encoding == encoded anyway for backwards compatibility
+ assertEquals("11111%2520", fileManager.getFileName(TaskTestUtil.createMockTask("11111%20"), true));
+ // <max, does not exist, not requires encoding == not encoded
+ assertEquals("11111%20", fileManager.getFileName(TaskTestUtil.createMockTask("11111%20"), false));
+ // <max, does not exist, requires encoding == encoded
+ assertEquals("11111%2520%2B", fileManager.getFileName(TaskTestUtil.createMockTask("11111%20+"), false));
+ // <max, exists, requires encoding == encoded
+ assertEquals("11111%2520%2B", fileManager.getFileName(TaskTestUtil.createMockTask("11111%20+"), true));
+ }
+
+ public void testLongFileNameThatDoesNotRequireEncoding() {
+ // >max, does not exist, not requires encoding == not encoded + trimmed
+ String str = StringUtils.repeat("1", 256);
+ assertEquals(StringUtils.repeat("1", 242) + ".71634944",
+ fileManager.getFileName(TaskTestUtil.createMockTask(str), false));
+
+ // >max, exists, not requires encoding == use as is
+ assertEquals(str, fileManager.getFileName(TaskTestUtil.createMockTask(str), true));
+ }
+
+ public void testLongFileNameThatRequiresEncoding() {
+ // >max, does not exist, requires encoding == encoded + trimmed
+ String str = "+" + StringUtils.repeat("1", 255);
+ String result = fileManager.getFileName(TaskTestUtil.createMockTask(str), false);
+ assertEquals("%2B" + StringUtils.repeat("1", 237) + ".3664039548", result);
+
+ // >max, exists, requires encoding == encoded + NOT trimmed
+ result = fileManager.getFileName(TaskTestUtil.createMockTask(str), true);
+ assertEquals(str.replaceAll("\\+", "%2B"), result);
+ }
+
+ public void testGetSetDataPath() {
+ final String path = "path";
+ fileManager.setDataPath(path);
+ assertEquals(path, fileManager.getDataPath());
+ }
+
+ public void testGetFile() {
+ final String path = "path";
+ fileManager.setDataPath(path);
+
+ final String taskId = "taskId";
+ final File result = fileManager.getFile("url", TaskTestUtil.createMockTask(taskId), "kind");
+ assertTrue(result.getPath().matches("^" + path + "\\S+" + taskId + "\\.\\S+$"));
+ }
+}

Back to the top