Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2009-12-13 00:14:54 +0000
committerrelves2009-12-13 00:14:54 +0000
commitdb7a9729cf6fbfe1b81525c51573d4a3a395bc9c (patch)
tree3e77e2e74c1cdbccf6406dbf6e8530032b504957
parente939a835d0bdc5fd57cb217d0ef6aa3e7a5e9b20 (diff)
downloadorg.eclipse.mylyn.tasks-db7a9729cf6fbfe1b81525c51573d4a3a395bc9c.tar.gz
org.eclipse.mylyn.tasks-db7a9729cf6fbfe1b81525c51573d4a3a395bc9c.tar.xz
org.eclipse.mylyn.tasks-db7a9729cf6fbfe1b81525c51573d4a3a395bc9c.zip
NEW - bug 290465: fix Bugzilla test suite
https://bugs.eclipse.org/bugs/show_bug.cgi?id=290465
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java115
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java177
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java6
3 files changed, 83 insertions, 215 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java
index 5a265b50a..727930562 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java
@@ -38,9 +38,13 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper {
private final String dateFormat_1_TimeZone = "yyyy-MM-dd HH:mm:ss Z"; //$NON-NLS-1$
- private final String dateFormat_2_TimeZone = "yyyy-MM-dd HH:mm zzz"; //$NON-NLS-1$
+ private final String dateFormat_2_TimeZone = "yyyy-MM-dd HH:mm z"; //$NON-NLS-1$
- private final String dateFormat_3_TimeZone = "yyyy-MM-dd zzz"; //$NON-NLS-1$
+ private final String dateFormat_3_TimeZone = "yyyy-MM-dd z"; //$NON-NLS-1$
+
+ // Order is significant
+ private final String[] dateFormats = { dateFormat_1_TimeZone, dateFormat_1, dateFormat_2_TimeZone, dateFormat_2,
+ dateFormat_3_TimeZone, dateFormat_3 };
private final BugzillaRepositoryConnector connector;
@@ -84,112 +88,21 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper {
}
/**
- * Note: Date formatters constructed within method for thread safety
+ * Note: Date formatter constructed within method for thread safety
*/
protected Date getDate(String attributeId, String dateString) {
Date parsedDate = null;
- /**
- * Bugzilla < 2.22 uses "yyyy-MM-dd HH:mm" but later versions use "yyyy-MM-dd HH:mm:ss" Using lowest common
- * denominator "yyyy-MM-dd HH:mm"
- */
-
- RepositoryConfiguration repositoryConfiguration;
- BugzillaVersion bugzillaVersion = null;
- repositoryConfiguration = connector.getRepositoryConfiguration(getTaskRepository().getUrl());
- if (repositoryConfiguration != null) {
- bugzillaVersion = repositoryConfiguration.getInstallVersion();
- } else {
- bugzillaVersion = BugzillaVersion.MIN_VERSION;
- }
-
- SimpleDateFormat comment_creation_ts_Format;
- SimpleDateFormat attachment_creation_ts_Format;
-
- SimpleDateFormat comment_creation_ts_Format_Timezone;
- SimpleDateFormat attachment_creation_ts_Format_Timezone;
-
- try {
- if (attributeId.equals(BugzillaAttribute.DELTA_TS.getKey())) {
- parsedDate = new SimpleDateFormat(dateFormat_1_TimeZone).parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.CREATION_TS.getKey())) {
- if (bugzillaVersion.compareMajorMinorOnly(BugzillaVersion.BUGZILLA_2_22) < 0) {
- parsedDate = new SimpleDateFormat(dateFormat_2_TimeZone).parse(dateString);
- } else {
- parsedDate = new SimpleDateFormat(dateFormat_1_TimeZone).parse(dateString);
- }
- } else if (attributeId.equals(BugzillaAttribute.BUG_WHEN.getKey())) {
- if (bugzillaVersion.compareMajorMinorOnly(BugzillaVersion.BUGZILLA_2_22) < 0) {
- comment_creation_ts_Format_Timezone = new SimpleDateFormat(dateFormat_2_TimeZone);
- } else {
- comment_creation_ts_Format_Timezone = new SimpleDateFormat(dateFormat_1_TimeZone);
- }
- parsedDate = comment_creation_ts_Format_Timezone.parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.DATE.getKey())) {
- if (bugzillaVersion.compareMajorMinorOnly(BugzillaVersion.BUGZILLA_2_22) < 0) {
- attachment_creation_ts_Format_Timezone = new SimpleDateFormat(dateFormat_2_TimeZone);
- } else {
- attachment_creation_ts_Format_Timezone = new SimpleDateFormat(dateFormat_1_TimeZone);
- }
- parsedDate = attachment_creation_ts_Format_Timezone.parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.DEADLINE.getKey())) {
- parsedDate = new SimpleDateFormat(dateFormat_3_TimeZone).parse(dateString);
- } else if (attributeId.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
- parsedDate = new SimpleDateFormat(dateFormat_1_TimeZone).parse(dateString);
- }
- } catch (ParseException e) {
+ for (String format : dateFormats) {
try {
- if (attributeId.equals(BugzillaAttribute.DELTA_TS.getKey())) {
- parsedDate = new SimpleDateFormat(dateFormat_1).parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.CREATION_TS.getKey())) {
- parsedDate = new SimpleDateFormat(dateFormat_2).parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.BUG_WHEN.getKey())) {
- if (bugzillaVersion.compareMajorMinorOnly(BugzillaVersion.BUGZILLA_2_22) < 0) {
- comment_creation_ts_Format = new SimpleDateFormat(dateFormat_2);
- } else {
- comment_creation_ts_Format = new SimpleDateFormat(dateFormat_1);
- }
- parsedDate = comment_creation_ts_Format.parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.DATE.getKey())) {
- if (bugzillaVersion.compareMajorMinorOnly(BugzillaVersion.BUGZILLA_2_22) < 0) {
- attachment_creation_ts_Format = new SimpleDateFormat(dateFormat_2);
- } else {
- attachment_creation_ts_Format = new SimpleDateFormat(dateFormat_1);
- }
- parsedDate = attachment_creation_ts_Format.parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.DEADLINE.getKey())) {
- parsedDate = new SimpleDateFormat(dateFormat_3).parse(dateString);
- } else if (attributeId.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
- parsedDate = new SimpleDateFormat(dateFormat_1).parse(dateString);
- }
- } catch (ParseException e1) {
-
- try {
- // Fall back to legacy formats
- String delta_ts_format = dateFormat_1;
- String creation_ts_format = dateFormat_2;
- String deadline_format = dateFormat_3;
- String customAttribute_format = dateFormat_1;
- String comment_creation_ts_format = dateFormat_2;
- String attachment_creation_ts_format = dateFormat_2;
- if (attributeId.equals(BugzillaAttribute.DELTA_TS.getKey())) {
- parsedDate = new SimpleDateFormat(delta_ts_format).parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.CREATION_TS.getKey())) {
- parsedDate = new SimpleDateFormat(creation_ts_format).parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.BUG_WHEN.getKey())) {
- parsedDate = new SimpleDateFormat(comment_creation_ts_format).parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.DATE.getKey())) {
- parsedDate = new SimpleDateFormat(attachment_creation_ts_format).parse(dateString);
- } else if (attributeId.equals(BugzillaAttribute.DEADLINE.getKey())) {
- parsedDate = new SimpleDateFormat(deadline_format).parse(dateString);
- } else if (attributeId.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
- parsedDate = new SimpleDateFormat(customAttribute_format).parse(dateString);
- }
- } catch (ParseException e2) {
- }
+ SimpleDateFormat simleFormatter = new SimpleDateFormat(format);
+ parsedDate = simleFormatter.parse(dateString);
+ break;
+ } catch (ParseException e) {
+ } catch (NumberFormatException e) {
}
- } catch (NumberFormatException e) {
}
+
return parsedDate;
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java
index 105d05edc..6870d6d97 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaDateTimeTests.java
@@ -15,32 +15,46 @@ import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
+import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
-import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttributeMapper;
+import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient;
+import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
-import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tests.util.TestUtil.PrivilegeLevel;
/**
* @author Frank Becker
+ * @author Robert Elves
*/
public class BugzillaDateTimeTests extends AbstractBugzillaTest {
- public void testTimezones218() throws Exception {
- // could not test BugzillaAttribute.DEADLINE because not supported in 2.18.6
+ private TaskRepository repository;
+
+ private BugzillaRepositoryConnector connector;
+
+ @SuppressWarnings("unused")
+ private BugzillaClient client;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ client = BugzillaFixture.current().client(PrivilegeLevel.USER);
+ repository = BugzillaFixture.current().repository();
+ connector = BugzillaFixture.current().connector();
+ }
+
+ public void testDateFormatParsing() {
TimeZone defaultTimeZone = TimeZone.getDefault();
try {
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- init218();
- ITask task = generateLocalTaskAndDownload("10");
- assertNotNull(task);
- TaskDataModel model = createModel(task);
- TaskData taskData = model.getTaskData();
- assertNotNull(taskData);
-
- TaskAttribute attribute = taskData.getRoot().getAttribute(BugzillaAttribute.CREATION_TS.getKey());
- attribute.setValue(attribute.getValue() + " PST");
- assertEquals("2006-05-08 15:04 PST", attribute.getValue());
+
+ TaskData taskData = new TaskData(new BugzillaAttributeMapper(repository, connector), "bugzilla", "repourl",
+ "1");
+ TaskAttribute attribute = taskData.getRoot().createAttribute(BugzillaAttribute.CREATION_TS.getKey());
+ attribute.setValue("2006-05-08 15:04 PST");
Date date = taskData.getAttributeMapper().getDateValue(attribute);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
@@ -51,127 +65,68 @@ public class BugzillaDateTimeTests extends AbstractBugzillaTest {
assertEquals(4, calendar.get(Calendar.MINUTE));
assertEquals(0, calendar.get(Calendar.SECOND));
- attribute = taskData.getRoot().getAttribute(BugzillaAttribute.DELTA_TS.getKey());
- attribute.setValue(attribute.getValue() + " PST");
- assertEquals("2006-06-02 14:45:37 PST", attribute.getValue());
+ attribute.setValue("2006-05-08 15:04:11 PST");
date = taskData.getAttributeMapper().getDateValue(attribute);
+ calendar = Calendar.getInstance();
calendar.setTime(date);
assertEquals(2006, calendar.get(Calendar.YEAR));
- assertEquals(5, calendar.get(Calendar.MONTH));
- assertEquals(2, calendar.get(Calendar.DAY_OF_MONTH));
- assertEquals(22, calendar.get(Calendar.HOUR_OF_DAY));
- assertEquals(45, calendar.get(Calendar.MINUTE));
- assertEquals(37, calendar.get(Calendar.SECOND));
- TaskAttribute attachment = taskData.getAttributeMapper().getAttributesByType(taskData,
- TaskAttribute.TYPE_ATTACHMENT).get(0);
- assertNotNull(attachment);
-
- attribute = attachment.getAttribute(BugzillaAttribute.DATE.getKey());
- attribute.setValue(attribute.getValue() + " PST");
- assertEquals("2006-05-26 19:38 PST", attribute.getValue());
+ assertEquals(4, calendar.get(Calendar.MONTH));
+ assertEquals(8, calendar.get(Calendar.DAY_OF_MONTH));
+ assertEquals(23, calendar.get(Calendar.HOUR_OF_DAY));
+ assertEquals(4, calendar.get(Calendar.MINUTE));
+ assertEquals(11, calendar.get(Calendar.SECOND));
+
+ attribute.setValue("2006-05-08 15:04:11 -0800");
date = taskData.getAttributeMapper().getDateValue(attribute);
+ calendar = Calendar.getInstance();
calendar.setTime(date);
assertEquals(2006, calendar.get(Calendar.YEAR));
assertEquals(4, calendar.get(Calendar.MONTH));
- assertEquals(27, calendar.get(Calendar.DAY_OF_MONTH));
- assertEquals(3, calendar.get(Calendar.HOUR_OF_DAY));
- assertEquals(38, calendar.get(Calendar.MINUTE));
- assertEquals(0, calendar.get(Calendar.SECOND));
+ assertEquals(8, calendar.get(Calendar.DAY_OF_MONTH));
+ assertEquals(23, calendar.get(Calendar.HOUR_OF_DAY));
+ assertEquals(4, calendar.get(Calendar.MINUTE));
+ assertEquals(11, calendar.get(Calendar.SECOND));
- TaskAttribute comment = taskData.getAttributeMapper().getAttributesByType(taskData,
- TaskAttribute.TYPE_COMMENT).get(0);
- assertNotNull(comment);
- attribute = comment.getAttribute(BugzillaAttribute.BUG_WHEN.getKey());
- attribute.setValue(attribute.getValue() + " PST");
- assertEquals("2006-05-08 15:05 PST", attribute.getValue());
+ attribute.setValue("2006-05-08 15:04 -0800");
date = taskData.getAttributeMapper().getDateValue(attribute);
+ calendar = Calendar.getInstance();
calendar.setTime(date);
assertEquals(2006, calendar.get(Calendar.YEAR));
assertEquals(4, calendar.get(Calendar.MONTH));
assertEquals(8, calendar.get(Calendar.DAY_OF_MONTH));
assertEquals(23, calendar.get(Calendar.HOUR_OF_DAY));
- assertEquals(5, calendar.get(Calendar.MINUTE));
- assertEquals(0, calendar.get(Calendar.SECOND));
- } finally {
- TimeZone.setDefault(defaultTimeZone);
- }
- }
-
- public void testTimezones323() throws Exception {
- // could not test BugzillaAttribute.DEADLINE and CUSTOM_FIELDS because not supported in 3.2.3
- TimeZone defaultTimeZone = TimeZone.getDefault();
- try {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
- init323();
- ITask task = generateLocalTaskAndDownload("2");
- assertNotNull(task);
- TaskDataModel model = createModel(task);
- TaskData taskData = model.getTaskData();
- assertNotNull(taskData);
- TaskAttribute attribute = taskData.getRoot().getAttribute(BugzillaAttribute.CREATION_TS.getKey());
- attribute.setValue(attribute.getValue() + " PST");
- assertEquals("2009-02-12 13:40 PST", attribute.getValue());
- Date date = taskData.getAttributeMapper().getDateValue(attribute);
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- assertEquals(2009, calendar.get(Calendar.YEAR));
- assertEquals(1, calendar.get(Calendar.MONTH));
- assertEquals(12, calendar.get(Calendar.DAY_OF_MONTH));
- assertEquals(21, calendar.get(Calendar.HOUR_OF_DAY));
- assertEquals(40, calendar.get(Calendar.MINUTE));
+ assertEquals(4, calendar.get(Calendar.MINUTE));
assertEquals(0, calendar.get(Calendar.SECOND));
- attribute = taskData.getRoot().getAttribute(BugzillaAttribute.DELTA_TS.getKey());
- attribute.setValue(attribute.getValue() + " PST");
-// String val = attribute.getValue();
- assertEquals("2009-06-03 23:31:42 PST", attribute.getValue());
- date = taskData.getAttributeMapper().getDateValue(attribute);
- calendar.setTime(date);
- assertEquals(2009, calendar.get(Calendar.YEAR));
- assertEquals(5, calendar.get(Calendar.MONTH));
- assertEquals(4, calendar.get(Calendar.DAY_OF_MONTH));
- assertEquals(7, calendar.get(Calendar.HOUR_OF_DAY));
- assertEquals(31, calendar.get(Calendar.MINUTE));
- assertEquals(42, calendar.get(Calendar.SECOND));
- TaskAttribute attachment = taskData.getAttributeMapper().getAttributesByType(taskData,
- TaskAttribute.TYPE_ATTACHMENT).get(0);
- assertNotNull(attachment);
-
- attribute = attachment.getAttribute(BugzillaAttribute.DATE.getKey());
- attribute.setValue(attribute.getValue() + " PST");
- assertEquals("2009-05-07 17:07:56 PST", attribute.getValue());
+ attribute.setValue("2006-05-08 15:04:11");
date = taskData.getAttributeMapper().getDateValue(attribute);
+ calendar = Calendar.getInstance();
calendar.setTime(date);
- assertEquals(2009, calendar.get(Calendar.YEAR));
+ assertEquals(2006, calendar.get(Calendar.YEAR));
assertEquals(4, calendar.get(Calendar.MONTH));
assertEquals(8, calendar.get(Calendar.DAY_OF_MONTH));
- assertEquals(1, calendar.get(Calendar.HOUR_OF_DAY));
- assertEquals(7, calendar.get(Calendar.MINUTE));
- assertEquals(56, calendar.get(Calendar.SECOND));
-
- TaskAttribute comment = taskData.getAttributeMapper().getAttributesByType(taskData,
- TaskAttribute.TYPE_COMMENT).get(0);
- assertNotNull(comment);
- attribute = comment.getAttribute(BugzillaAttribute.BUG_WHEN.getKey());
- attribute.setValue(attribute.getValue() + " PST");
- assertEquals("2009-02-17 17:29:35 PST", attribute.getValue());
+ assertEquals(15, calendar.get(Calendar.HOUR_OF_DAY));
+ assertEquals(4, calendar.get(Calendar.MINUTE));
+ assertEquals(11, calendar.get(Calendar.SECOND));
+
+ attribute.setValue("2006-05-08 15:04");
date = taskData.getAttributeMapper().getDateValue(attribute);
+ calendar = Calendar.getInstance();
calendar.setTime(date);
- assertEquals(2009, calendar.get(Calendar.YEAR));
- assertEquals(1, calendar.get(Calendar.MONTH));
- assertEquals(18, calendar.get(Calendar.DAY_OF_MONTH));
- assertEquals(1, calendar.get(Calendar.HOUR_OF_DAY));
- assertEquals(29, calendar.get(Calendar.MINUTE));
- assertEquals(35, calendar.get(Calendar.SECOND));
-
- attribute = taskData.getRoot().getAttribute(BugzillaAttribute.DEADLINE.getKey());
- assertEquals("2009-06-24", attribute.getValue());
+ assertEquals(2006, calendar.get(Calendar.YEAR));
+ assertEquals(4, calendar.get(Calendar.MONTH));
+ assertEquals(8, calendar.get(Calendar.DAY_OF_MONTH));
+ assertEquals(15, calendar.get(Calendar.HOUR_OF_DAY));
+ assertEquals(4, calendar.get(Calendar.MINUTE));
+ assertEquals(0, calendar.get(Calendar.SECOND));
+
+ attribute.setValue("2006-05-08");
date = taskData.getAttributeMapper().getDateValue(attribute);
+ calendar = Calendar.getInstance();
calendar.setTime(date);
- assertEquals(2009, calendar.get(Calendar.YEAR));
- assertEquals(5, calendar.get(Calendar.MONTH));
- assertEquals(24, calendar.get(Calendar.DAY_OF_MONTH));
+ assertEquals(2006, calendar.get(Calendar.YEAR));
+ assertEquals(4, calendar.get(Calendar.MONTH));
+ assertEquals(8, calendar.get(Calendar.DAY_OF_MONTH));
assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
assertEquals(0, calendar.get(Calendar.MINUTE));
assertEquals(0, calendar.get(Calendar.SECOND));
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java
index b7f6146f3..de98a67e5 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java
@@ -125,9 +125,9 @@ public class BugzillaRepositoryConnectorStandaloneTest extends TestCase {
attribute.setValue("2009-09-04 12:00:::01 PDT");
assertFalse(connector.hasTaskChanged(repository, task, data));
- // Same times, bogus format (string compare)
- task.setAttribute(BugzillaAttribute.DELTA_TS.getKey(), "2009-09-04X12:00:::01 PDT");
- attribute.setValue("2009-09-04 12:00:::01 PDT");
+ // Different times, bogus format (string compare)
+ task.setAttribute(BugzillaAttribute.DELTA_TS.getKey(), "2009-09X-04X12:00:::01 PDT");
+ attribute.setValue("2009-X-03 12:00:::01 PDT");
assertTrue(connector.hasTaskChanged(repository, task, data));
}

Back to the top