diff options
11 files changed, 784 insertions, 347 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java index 83eacf15c..05a270b2c 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java @@ -115,6 +115,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { enSetting.addLanguageAttribute("error_login", "Invalid Username Or Password"); //$NON-NLS-1$ //$NON-NLS-2$ enSetting.addLanguageAttribute("error_login", "account locked"); //$NON-NLS-1$//$NON-NLS-2$ enSetting.addLanguageAttribute("error_collision", "Mid-air collision!"); //$NON-NLS-1$ //$NON-NLS-2$ + enSetting.addLanguageAttribute("error_collision", "Mid-air collision detected!"); //$NON-NLS-1$ //$NON-NLS-2$ enSetting.addLanguageAttribute("error_comment_required", "Comment Required"); //$NON-NLS-1$ //$NON-NLS-2$ enSetting.addLanguageAttribute("error_logged_out", "logged out"); //$NON-NLS-1$ //$NON-NLS-2$ enSetting.addLanguageAttribute("bad_login", "Login"); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java index 4ea5e832f..dd15e88ec 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java @@ -17,6 +17,7 @@ import junit.framework.TestCase; import org.eclipse.core.runtime.CoreException; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; +import org.eclipse.mylyn.bugzilla.tests.support.BugzillaHarness; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector; @@ -53,8 +54,11 @@ public abstract class AbstractBugzillaTest extends TestCase { protected BugzillaClient client; + protected BugzillaHarness harness; + public AbstractBugzillaTest() { super(); + harness = new BugzillaHarness(this); } @Override @@ -78,7 +82,7 @@ public abstract class AbstractBugzillaTest extends TestCase { manager.clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath()); } - protected TaskDataModel createModel(ITask task) throws CoreException { + public TaskDataModel createModel(ITask task) throws CoreException { ITaskDataWorkingCopy taskDataState = getWorkingCopy(task); return new TaskDataModel(repository, task, taskDataState); } @@ -113,4 +117,25 @@ public abstract class AbstractBugzillaTest extends TestCase { TasksUiPlugin.getTaskDataManager().setTaskRead(task, true); return task; } + + public BugzillaRepositoryConnector getConnector() { + return connector; + } + + public TaskRepositoryManager getManager() { + return manager; + } + + public TaskRepository getRepository() { + return repository; + } + + public TaskList getTaskList() { + return taskList; + } + + public BugzillaClient getClient() { + return client; + } + } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java index 7bbbc6604..3a953193e 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java @@ -70,17 +70,12 @@ public class AllBugzillaHeadlessStandaloneTests { // fixture.add(fixtureSuite, BugzillaTaskHistoryTest.class); fixture.add(BugzillaRepositoryConnectorStandaloneTest.class); fixture.add(BugzillaRepositoryConnectorConfigurationTest.class); + fixture.add(BugzillaClientTest.class); - // Move any tests here that are resulting in spurious failures - // due to recent changes in Bugzilla Server head. - if (fixture != BugzillaFixture.BUGS_HEAD) { - fixture.add(BugzillaClientTest.class); - - // Only run these tests on > 3.2 repositories - if (!fixture.getBugzillaVersion().isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { - fixture.add(BugzillaCustomFieldsTest.class); - fixture.add(BugzillaFlagsTest.class); - } + // Only run these tests on > 3.2 repositories + if (!fixture.getBugzillaVersion().isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { + fixture.add(BugzillaCustomFieldsTest.class); + fixture.add(BugzillaFlagsTest.class); } fixture.done(); } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java index 3a1042396..d98014f66 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java @@ -13,31 +13,36 @@ package org.eclipse.mylyn.bugzilla.tests; import java.io.BufferedWriter; import java.io.File; +import java.io.FileInputStream; import java.io.FileWriter; import java.util.Date; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; +import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaStatus; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; +import org.eclipse.mylyn.internal.tasks.core.TaskTask; import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; +import org.eclipse.mylyn.internal.tasks.ui.util.DownloadAttachmentJob; import org.eclipse.mylyn.tasks.core.ITask; import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState; +import org.eclipse.mylyn.tasks.core.ITaskAttachment; import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel; /** * @author Robert Elves @@ -447,7 +452,12 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest { * Ensure obsoletes and patches are marked as such by the parser. */ public void testAttachmentAttributes() throws Exception { - String taskNumber = "3"; + String taskId = harness.taskAttachmentAttributesExists(); + if (taskId == null) { + taskId = harness.createAttachmentAttributesTask(); + } + + String taskNumber = taskId; TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client); assertNotNull(taskData); ITask task = TasksUi.getRepositoryModel().createTask(repository, taskData.getTaskId()); @@ -506,4 +516,76 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest { } fail("Should have failed due to invalid userid and password."); } + + public void testDownloadAttachmentFile() throws Exception { + TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "update of Attachment Flags", + "description for testUpdateAttachmentFlags"); + assertNotNull(taskData); + int numAttached = taskData.getAttributeMapper() + .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT) + .size(); + assertEquals(0, numAttached); + assertNotNull(repository.getCredentials(AuthenticationType.REPOSITORY)); + assertNotNull(repository.getCredentials(AuthenticationType.REPOSITORY).getUserName()); + assertNotNull(repository.getCredentials(AuthenticationType.REPOSITORY).getPassword()); + BugzillaClient client = connector.getClientManager().getClient(repository, new NullProgressMonitor()); + + TaskAttribute attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData); + TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment); + attachmentMapper.setComment("test Update AttachmentFlags"); + + /* Test uploading a proper file */ + String fileName = "test-attach-1.txt"; + File attachFile = new File(fileName); + attachFile.createNewFile(); + attachFile.deleteOnExit(); + BufferedWriter write = new BufferedWriter(new FileWriter(attachFile)); + String expected = "test file from " + System.currentTimeMillis(); + write.write(expected); + write.close(); + + FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(attachFile); + attachment.setContentType("text/plain"); + attachment.setDescription("Description"); + attachment.setName("My Attachment 1"); + + try { + client.postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), attachment, attrAttachment, + new NullProgressMonitor()); + } catch (Exception e) { + fail("never reach this!"); + } + taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), client); + assertNotNull(taskData); + numAttached = taskData.getAttributeMapper().getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT).size(); + assertEquals(1, numAttached); + TaskAttribute attachmentAttribute = taskData.getAttributeMapper() + .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT) + .get(0); + + File file = File.createTempFile("mylyn", null); + ITask iTask = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), taskData.getTaskId()); + + ITaskAttachment taskAttachment; + taskAttachment = new TaskAttachment(repository, iTask, attachmentAttribute); + + DownloadAttachmentJob job = new DownloadAttachmentJob(taskAttachment, file); + job.schedule(); + job.join(); + + assertEquals(Status.OK_STATUS, job.getResult()); + + FileInputStream raf = new FileInputStream(file); + + byte[] data = new byte[expected.length()]; + try { + raf.read(data); + } + + finally { + raf.close(); + file.delete(); + } + assertEquals(expected, new String(data)); + } } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java index 1e6ae71cd..3995b8e66 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java @@ -796,27 +796,36 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest { public void testMidAirCollision() throws Exception { TaskData data = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); assertNotNull(data); -// // Get the task -// ITask task = generateLocalTaskAndDownload(data.getTaskId()); -// -// ITaskDataWorkingCopy workingCopy = TasksUiPlugin.getTaskDataManager().getWorkingCopy(task); -// TaskData taskData = workingCopy.getLocalData(); -// assertNotNull(taskData); + // Get the task + ITask task = generateLocalTaskAndDownload(data.getTaskId()); + + ITaskDataWorkingCopy workingCopy = TasksUiPlugin.getTaskDataManager().getWorkingCopy(task); + TaskData taskData = workingCopy.getLocalData(); + assertNotNull(taskData); String newCommentText = "BugzillaRepositoryClientTest.testMidAirCollision(): test " + (new Date()).toString(); TaskAttribute attrNewComment = data.getRoot().getMappedAttribute(TaskAttribute.COMMENT_NEW); attrNewComment.setValue(newCommentText); Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); changed.add(attrNewComment); + RepositoryResponse response = BugzillaFixture.current().submitTask(data, client); + + workingCopy = TasksUiPlugin.getTaskDataManager().getWorkingCopy(task); + taskData = workingCopy.getLocalData(); + assertNotNull(taskData); + + newCommentText = "BugzillaRepositoryClientTest.testMidAirCollision(): test #### " + (new Date()).toString(); + attrNewComment = data.getRoot().getMappedAttribute(TaskAttribute.COMMENT_NEW); + attrNewComment.setValue(newCommentText); + changed = new HashSet<TaskAttribute>(); + changed.add(attrNewComment); TaskAttribute attrDeltaTs = data.getRoot().getMappedAttribute(TaskAttribute.DATE_MODIFICATION); attrDeltaTs.setValue("2007-01-01 00:00:00"); changed.add(attrDeltaTs); - //workingCopy.save(changed, new NullProgressMonitor()); - try { // Submit changes - RepositoryResponse response = BugzillaFixture.current().submitTask(data, client); + response = BugzillaFixture.current().submitTask(data, client); assertNotNull(response); //assertEquals(ResponseKind.TASK_UPDATED, response.getReposonseKind()); System.err.println("\n\ntestMidAirCollision >>> ResponseKind:" + response.getReposonseKind().toString() diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java index 10194713e..f15cca85e 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java @@ -62,6 +62,11 @@ public class BugzillaClientTest extends TestCase { } public void testRDFProductConfig() throws Exception { + if (BugzillaFixture.current() == BugzillaFixture.BUGS_4_4 + || BugzillaFixture.current() == BugzillaFixture.BUGS_HEAD) { + // FIXME: need fix of bug#372600 + return; + } RepositoryConfiguration config = client.getRepositoryConfiguration(); assertNotNull(config); assertEquals( @@ -81,7 +86,12 @@ public class BugzillaClientTest extends TestCase { assertEquals(36, config.getOSs().size()); assertEquals(5, config.getPriorities().size()); } else { - assertEquals(6, config.getResolutions().size()); + if (BugzillaVersion.BUGZILLA_4_0.compareMajorMinorOnly(new BugzillaVersion(BugzillaFixture.current() + .getVersion())) > 0) { + assertEquals(6, config.getResolutions().size()); + } else { + assertEquals(5, config.getResolutions().size()); + } assertEquals(4, config.getPlatforms().size()); assertEquals(5, config.getOSs().size()); assertEquals(6, config.getPriorities().size()); @@ -102,9 +112,15 @@ public class BugzillaClientTest extends TestCase { assertEquals(2, config.getComponents("ManualTest").size()); assertEquals(4, config.getVersions("ManualTest").size()); assertEquals(4, config.getTargetMilestones("ManualTest").size()); - assertEquals(2, config.getComponents("TestProduct").size()); - assertEquals(4, config.getVersions("TestProduct").size()); - assertEquals(4, config.getTargetMilestones("TestProduct").size()); + if (BugzillaFixture.current().getRepositoryUrl().contains("localhost")) { + assertEquals(1, config.getComponents("TestProduct").size()); + assertEquals(1, config.getVersions("TestProduct").size()); + assertEquals(1, config.getTargetMilestones("TestProduct").size()); + } else { + assertEquals(2, config.getComponents("TestProduct").size()); + assertEquals(4, config.getVersions("TestProduct").size()); + assertEquals(4, config.getTargetMilestones("TestProduct").size()); + } assertEquals(2, config.getComponents("Product with Spaces").size()); assertEquals(4, config.getVersions("Product with Spaces").size()); assertEquals(4, config.getTargetMilestones("Product with Spaces").size()); @@ -191,7 +207,9 @@ public class BugzillaClientTest extends TestCase { newData.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).setValue("testCommentQuery()"); newData.getRoot().getMappedAttribute(TaskAttribute.PRODUCT).setValue("TestProduct"); newData.getRoot().getMappedAttribute(TaskAttribute.COMPONENT).setValue("TestComponent"); - newData.getRoot().getMappedAttribute(BugzillaAttribute.VERSION.getKey()).setValue("1"); + if (!BugzillaFixture.current().getRepositoryUrl().contains("localhost")) { + newData.getRoot().getMappedAttribute(BugzillaAttribute.VERSION.getKey()).setValue("1"); + } newData.getRoot().getMappedAttribute(BugzillaAttribute.OP_SYS.getKey()).setValue("All"); long timestamp = System.currentTimeMillis(); newData.getRoot().getMappedAttribute(TaskAttribute.DESCRIPTION).setValue("" + timestamp); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java index 580b01436..57f9f2d5e 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java @@ -16,19 +16,16 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import junit.framework.TestCase; - +import org.eclipse.mylyn.bugzilla.tests.AbstractBugzillaTest; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; +import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; -import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; -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.TaskMapper; -import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel; /** * Tests should be run against Bugzilla 3.2.4 or greater @@ -36,23 +33,16 @@ import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel; * @author Frank Becker * @author Robert Elves */ -public class BugzillaCustomFieldsTest extends TestCase { - - private BugzillaClient client; - - private TaskRepository repository; +public class BugzillaCustomFieldsTest extends AbstractBugzillaTest { private TaskData fruitTaskData; - @Override - protected void setUp() throws Exception { - repository = BugzillaFixture.current().repository(); - client = BugzillaFixture.current().client(); - } - public void testCustomAttributes() throws Exception { - - String taskNumber = "2"; + String taskId = harness.taskCustomFieldExists(); + if (taskId == null) { + taskId = harness.createCustomFieldTask(); + } + String taskNumber = taskId; TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client); assertNotNull(taskData); TaskMapper mapper = new TaskMapper(taskData); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaXmlRpcClientTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaXmlRpcClientTest.java index 3254f9700..1e4fbc751 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaXmlRpcClientTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaXmlRpcClientTest.java @@ -11,19 +11,12 @@ package org.eclipse.mylyn.bugzilla.tests.core; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import junit.framework.TestCase; import org.apache.xmlrpc.XmlRpcException; import org.eclipse.core.runtime.CoreException; @@ -31,50 +24,34 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.mylyn.bugzilla.tests.AbstractBugzillaTest; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; import org.eclipse.mylyn.commons.net.AuthenticationType; import org.eclipse.mylyn.commons.net.WebLocation; -import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel; import org.eclipse.mylyn.internal.bugzilla.core.AbstractBugzillaOperation; -import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; 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.internal.bugzilla.core.BugzillaVersion; import org.eclipse.mylyn.internal.bugzilla.core.CustomTransitionManager; import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; import org.eclipse.mylyn.internal.bugzilla.core.service.BugzillaXmlRpcClient; -import org.eclipse.mylyn.internal.tasks.core.AbstractTask; -import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; -import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager; -import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource; -import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.RepositoryResponse; -import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind; -import org.eclipse.mylyn.tasks.core.TaskMapping; -import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler; import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy; -import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; import org.eclipse.mylyn.tasks.core.data.TaskDataModel; import org.eclipse.mylyn.tasks.core.sync.SubmitJob; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.tasks.ui.TasksUiUtil; -import org.eclipse.mylyn.tests.util.TestFixture; /** * Tests should be run against Bugzilla 3.6 or greater * * @author Frank Becker */ -public class BugzillaXmlRpcClientTest extends TestCase { +public class BugzillaXmlRpcClientTest extends AbstractBugzillaTest { private static final String BUGZILLA_LE_4_0 = "<4.0"; @@ -82,14 +59,6 @@ public class BugzillaXmlRpcClientTest extends TestCase { private BugzillaXmlRpcClient bugzillaClient; - private TaskRepository repository; - - private BugzillaRepositoryConnector connector; - - protected TaskRepositoryManager manager; - - private BugzillaClient client; - @SuppressWarnings("serial") private final Map<String, Map<String, ArrayList<String>>> fixtureTransitionsMap = new HashMap<String, Map<String, ArrayList<String>>>() { { @@ -336,37 +305,24 @@ public class BugzillaXmlRpcClientTest extends TestCase { @Override public void setUp() throws Exception { - TasksUiPlugin.getDefault() - .getPreferenceStore() - .setValue(ITasksUiPreferenceConstants.REPOSITORY_SYNCH_SCHEDULE_ENABLED, false); - manager = TasksUiPlugin.getRepositoryManager(); - TestFixture.resetTaskListAndRepositories(); + super.setUp(); WebLocation webLocation = new WebLocation(BugzillaFixture.current().getRepositoryUrl() + "/xmlrpc.cgi"); webLocation.setCredentials(AuthenticationType.REPOSITORY, "tests@mylyn.eclipse.org", "mylyntest"); - client = BugzillaFixture.current().client(PrivilegeLevel.USER); - repository = BugzillaFixture.current().repository(); - connector = BugzillaFixture.current().connector(); bugzillaClient = new BugzillaXmlRpcClient(webLocation, client); bugzillaClient.setContentTypeCheckingEnabled(true); - TasksUi.getRepositoryManager().addRepository(repository); } @Override protected void tearDown() throws Exception { super.tearDown(); - TestFixture.resetTaskList(); - manager.clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath()); - } - - protected TaskDataModel createModel(ITask task) throws CoreException { - ITaskDataWorkingCopy taskDataState = getWorkingCopy(task); - return new TaskDataModel(repository, task, taskDataState); } + @Override protected ITaskDataWorkingCopy getWorkingCopy(ITask task) throws CoreException { return TasksUiPlugin.getTaskDataManager().getWorkingCopy(task); } + @Override protected void submit(TaskDataModel model) { SubmitJob submitJob = TasksUiInternal.getJobFactory().createSubmitTaskJob(connector, model.getTaskRepository(), model.getTask(), model.getTaskData(), model.getChangedOldAttributes()); @@ -378,254 +334,6 @@ public class BugzillaXmlRpcClientTest extends TestCase { } } -// protected void synchAndAssertState(Set<ITask> tasks, SynchronizationState state) { -// for (ITask task : tasks) { -// TasksUiInternal.synchronizeTask(connector, task, true, null); -// TasksUiPlugin.getTaskDataManager().setTaskRead(task, true); -// assertEquals(task.getSynchronizationState(), state); -// } -// } - - protected ITask generateLocalTaskAndDownload(String id) throws CoreException { - ITask task = TasksUi.getRepositoryModel().createTask(repository, id); - TasksUiPlugin.getTaskList().addTask(task); - TasksUiInternal.synchronizeTask(connector, task, true, null); - TasksUiPlugin.getTaskDataManager().setTaskRead(task, true); - return task; - } - - protected String taskExists() { - String taskID = null; - String queryUrlString = repository.getRepositoryUrl() + "/buglist.cgi?" - + "short_desc=test%20XMLRPC%20getBugData&resolution=---&query_format=advanced" - + "&short_desc_type=casesubstring&component=TestComponent&product=TestProduct"; - RepositoryQuery query = new RepositoryQuery(repository.getConnectorKind(), "handle-testQueryViaConnector"); - query.setUrl(queryUrlString); - final Map<Integer, TaskData> changedTaskData = new HashMap<Integer, TaskData>(); - TaskDataCollector collector = new TaskDataCollector() { - @Override - public void accept(TaskData taskData) { - changedTaskData.put(Integer.valueOf(taskData.getTaskId()), taskData); - } - }; - connector.performQuery(repository, query, collector, null, new NullProgressMonitor()); - if (changedTaskData.size() > 0) { - Set<Integer> ks = changedTaskData.keySet(); - SortedSet<Integer> sks = new TreeSet<Integer>(ks); - taskID = sks.last().toString(); - } - return taskID; - } - - protected String createTask() throws Exception { - final TaskMapping taskMappingInit = new TaskMapping() { - - @Override - public String getProduct() { - return "TestProduct"; - } - }; - final TaskMapping taskMappingSelect = new TaskMapping() { - @Override - public String getComponent() { - return "TestComponent"; - } - - @Override - public String getSummary() { - return "test XMLRPC getBugData"; - } - - @Override - public String getDescription() { - return "The Description of the XMLRPC getBugData Bug"; - } - }; - TaskAttribute flagA = null; - TaskAttribute flagB = null; - TaskAttribute flagC = null; - TaskAttribute flagD = null; - TaskAttribute stateA = null; - TaskAttribute stateB = null; - TaskAttribute stateC = null; - TaskAttribute stateD = null; - final TaskData[] taskDataNew = new TaskData[1]; - - // create Task - taskDataNew[0] = TasksUiInternal.createTaskData(repository, taskMappingInit, taskMappingSelect, null); - ITask taskNew = TasksUiUtil.createOutgoingNewTask(taskDataNew[0].getConnectorKind(), - taskDataNew[0].getRepositoryUrl()); - - ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(taskNew, taskDataNew[0]); - Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); - workingCopy.save(changed, null); - - RepositoryResponse response = BugzillaFixture.current().submitTask(taskDataNew[0], client);//connector.getTaskDataHandler().postTaskData(repository, taskDataNew[0], changed, - //new NullProgressMonitor()); - ((AbstractTask) taskNew).setSubmitting(true); - - assertNotNull(response); - assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString()); - String taskId = response.getTaskId(); - - ITask task = generateLocalTaskAndDownload(taskId); - assertNotNull(task); - TaskDataModel model = createModel(task); - TaskData taskData = model.getTaskData(); - assertNotNull(taskData); - TaskAttribute attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData); - TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment); - - /* Test uploading a proper file */ - String fileName = "test-attach-1.txt"; - File attachFile = new File(fileName); - attachFile.createNewFile(); - attachFile.deleteOnExit(); - BufferedWriter write = new BufferedWriter(new FileWriter(attachFile)); - write.write("test file from " + System.currentTimeMillis()); - write.close(); - - FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(attachFile); - attachment.setContentType("text/plain"); - attachment.setDescription("Description"); - attachment.setName("My Attachment 1"); - try { - client.postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), attachment, attrAttachment, - new NullProgressMonitor()); - } catch (Exception e) { - fail("never reach this!"); - } - taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), client); - assertNotNull(taskData); - - TaskAttribute attachmentAttribute = taskData.getAttributeMapper() - .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT) - .get(0); - int flagCount = 0; - int flagCountUnused = 0; - TaskAttribute attachmentFlag1 = null; - TaskAttribute attachmentFlag2 = null; - for (TaskAttribute attribute : attachmentAttribute.getAttributes().values()) { - if (!attribute.getId().startsWith(BugzillaAttribute.KIND_FLAG)) { - continue; - } - flagCount++; - if (attribute.getId().startsWith(BugzillaAttribute.KIND_FLAG_TYPE)) { - flagCountUnused++; - TaskAttribute stateAttribute = taskData.getAttributeMapper().getAssoctiatedAttribute(attribute); - if (stateAttribute.getMetaData().getLabel().equals("AttachmentFlag1")) { - attachmentFlag1 = attribute; - } - if (stateAttribute.getMetaData().getLabel().equals("AttachmentFlag2")) { - attachmentFlag2 = attribute; - } - } - } - assertEquals(2, flagCount); - assertEquals(2, flagCountUnused); - assertNotNull(attachmentFlag1); - assertNotNull(attachmentFlag2); - TaskAttribute stateAttribute1 = taskData.getAttributeMapper().getAssoctiatedAttribute(attachmentFlag1); - stateAttribute1.setValue("?"); - TaskAttribute requestee = attachmentFlag1.getAttribute("requestee"); //$NON-NLS-1$ - requestee.setValue("guest@mylyn.eclipse.org"); - client.postUpdateAttachment(attachmentAttribute, "update", null); - - task = generateLocalTaskAndDownload(taskId); - assertNotNull(task); - model = createModel(task); - taskData = model.getTaskData(); - assertNotNull(taskData); - - for (TaskAttribute taskAttribute : taskData.getRoot().getAttributes().values()) { - if (taskAttribute.getId().startsWith(BugzillaAttribute.KIND_FLAG)) { - TaskAttribute state = taskAttribute.getAttribute("state"); - if (state.getMetaData().getLabel().equals("BugFlag1")) { - flagA = taskAttribute; - stateA = state; - } else if (state.getMetaData().getLabel().equals("BugFlag2")) { - flagB = taskAttribute; - stateB = state; - } else if (state.getMetaData().getLabel().equals("BugFlag3")) { - flagC = taskAttribute; - stateC = state; - } else if (state.getMetaData().getLabel().equals("BugFlag4")) { - flagD = taskAttribute; - stateD = state; - } - } - } - assertNotNull(flagA); - assertNotNull(flagB); - assertNotNull(flagC); - assertNotNull(flagD); - assertNotNull(stateA); - assertNotNull(stateB); - assertNotNull(stateC); - assertNotNull(stateD); - if (flagD != null) { - TaskAttribute requesteeD = flagD.getAttribute("requestee"); - requesteeD.setValue("guest@mylyn.eclipse.org"); - } - if (stateA != null) { - stateA.setValue("+"); - } - if (stateB != null) { - stateB.setValue("?"); - } - if (stateC != null) { - stateC.setValue("?"); - } - if (stateD != null) { - stateD.setValue("?"); - } - - TaskAttribute cf_freetext = taskData.getRoot().getAttribute("cf_freetext"); - TaskAttribute cf_dropdown = taskData.getRoot().getAttribute("cf_dropdown"); - TaskAttribute cf_largetextbox = taskData.getRoot().getAttribute("cf_largetextbox"); - TaskAttribute cf_multiselect = taskData.getRoot().getAttribute("cf_multiselect"); - TaskAttribute cf_datetime = taskData.getRoot().getAttribute("cf_datetime"); - TaskAttribute cf_bugid = taskData.getRoot().getAttribute("cf_bugid"); - cf_freetext.setValue("Freetext"); - cf_dropdown.setValue("one"); - cf_largetextbox.setValue("large text box"); - cf_multiselect.setValue("Blue"); - cf_datetime.setValue("2012-01-01 00:00:00"); - cf_bugid.setValue("3"); -// <cf_freetext>aaaa</cf_freetext> -// <cf_dropdown>one</cf_dropdown> -// <cf_largetextbox>aaaaaaaaaaa</cf_largetextbox> -// <cf_multiselect>Blue</cf_multiselect> -// <cf_datetime>2012-02-01 00:00:00</cf_datetime> -// <cf_bugid>3</cf_bugid> - model.attributeChanged(cf_freetext); - model.attributeChanged(cf_dropdown); - model.attributeChanged(cf_largetextbox); - model.attributeChanged(cf_multiselect); - model.attributeChanged(cf_datetime); - model.attributeChanged(cf_bugid); - model.attributeChanged(flagA); - model.attributeChanged(flagB); - model.attributeChanged(flagC); - model.attributeChanged(flagD); - changed.clear(); - changed.add(flagA); - changed.add(flagB); - changed.add(flagC); - changed.add(flagD); - changed.add(cf_freetext); - changed.add(cf_dropdown); - changed.add(cf_largetextbox); - changed.add(cf_multiselect); - changed.add(cf_datetime); - changed.add(cf_bugid); - - workingCopy.save(changed, null); - response = BugzillaFixture.current().submitTask(taskData, client); - - return taskId; - } - // @SuppressWarnings("unused") // only for local development work // public void testXmlRpc() throws Exception { @@ -814,9 +522,9 @@ public class BugzillaXmlRpcClientTest extends TestCase { return; } else { Set<String> taskIds = new HashSet<String>(); - String taskId = taskExists(); + String taskId = harness.taskXmlRpcExists(); if (taskId == null) { - taskId = createTask(); + taskId = harness.createXmlRpcTask(); } taskIds.add(taskId); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java index 341297e35..81bee8941 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java @@ -58,6 +58,8 @@ public class BugzillaFixture extends TestFixture { public static final String TEST_BUGZILLA_42_URL = getServerUrl("bugs42"); + public static final String TEST_BUGZILLA_44_URL = getServerUrl("bugs44"); + public static final String TEST_BUGZILLA_HEAD_URL = getServerUrl("bugshead"); private static final String getServerUrl(String version) { @@ -97,13 +99,17 @@ public class BugzillaFixture extends TestFixture { public static BugzillaFixture BUGS_4_2 = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_42_URL, // "4.2", ""); + public static BugzillaFixture BUGS_4_4 = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_44_URL, // + "4.3", ""); + public static BugzillaFixture BUGS_HEAD = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_HEAD_URL, // "4.5", ""); public static BugzillaFixture DEFAULT = BUGS_4_2; - public static final BugzillaFixture[] ALL = new BugzillaFixture[] { BUGS_3_4, BUGS_3_6, BUGS_3_6_XML_RPC_DISABLED, - BUGS_3_6_CUSTOM_WF, BUGS_3_6_CUSTOM_WF_AND_STATUS, BUGS_4_0, BUGS_4_2, BUGS_HEAD }; + public static final BugzillaFixture[] ALL = new BugzillaFixture[] { BUGS_3_4, // + BUGS_3_6, BUGS_3_6_XML_RPC_DISABLED, BUGS_3_6_CUSTOM_WF, BUGS_3_6_CUSTOM_WF_AND_STATUS, // + BUGS_4_0, BUGS_4_2, BUGS_4_4, BUGS_HEAD }; private final String version; diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaHarness.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaHarness.java new file mode 100644 index 000000000..92a609cb7 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaHarness.java @@ -0,0 +1,601 @@ +/******************************************************************************* + * Copyright (c) 2012 Frank Becker 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: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.bugzilla.tests.support; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.mylyn.bugzilla.tests.AbstractBugzillaTest; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; +import org.eclipse.mylyn.internal.tasks.core.AbstractTask; +import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; +import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource; +import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; +import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.mylyn.tasks.core.RepositoryResponse; +import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind; +import org.eclipse.mylyn.tasks.core.TaskMapping; +import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy; +import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskData; +import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; +import org.eclipse.mylyn.tasks.core.data.TaskDataModel; +import org.eclipse.mylyn.tasks.core.data.TaskMapper; +import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.mylyn.tasks.ui.TasksUiUtil; + +public class BugzillaHarness { + + AbstractBugzillaTest abstractBugzillaTest; + + public BugzillaHarness(AbstractBugzillaTest abstractBugzillaTest) { + this.abstractBugzillaTest = abstractBugzillaTest; + } + + public String taskXmlRpcExists() { + String taskID = null; + String queryUrlString = abstractBugzillaTest.getRepository().getRepositoryUrl() + "/buglist.cgi?" + + "short_desc=test%20XMLRPC%20getBugData&resolution=---&query_format=advanced" + + "&short_desc_type=casesubstring&component=TestComponent&product=TestProduct"; + RepositoryQuery query = new RepositoryQuery(abstractBugzillaTest.getRepository().getConnectorKind(), + "handle-testQueryViaConnector"); + query.setUrl(queryUrlString); + final Map<Integer, TaskData> changedTaskData = new HashMap<Integer, TaskData>(); + TaskDataCollector collector = new TaskDataCollector() { + @Override + public void accept(TaskData taskData) { + changedTaskData.put(Integer.valueOf(taskData.getTaskId()), taskData); + } + }; + abstractBugzillaTest.getConnector().performQuery(abstractBugzillaTest.getRepository(), query, collector, null, + new NullProgressMonitor()); + if (changedTaskData.size() > 0) { + Set<Integer> ks = changedTaskData.keySet(); + SortedSet<Integer> sks = new TreeSet<Integer>(ks); + taskID = sks.last().toString(); + } + return taskID; + } + + public String createXmlRpcTask() throws Exception { + final TaskMapping taskMappingInit = new TaskMapping() { + + @Override + public String getProduct() { + return "TestProduct"; + } + }; + final TaskMapping taskMappingSelect = new TaskMapping() { + @Override + public String getComponent() { + return "TestComponent"; + } + + @Override + public String getSummary() { + return "test XMLRPC getBugData"; + } + + @Override + public String getDescription() { + return "The Description of the XMLRPC getBugData Bug"; + } + }; + TaskAttribute flagA = null; + TaskAttribute flagB = null; + TaskAttribute flagC = null; + TaskAttribute flagD = null; + TaskAttribute stateA = null; + TaskAttribute stateB = null; + TaskAttribute stateC = null; + TaskAttribute stateD = null; + final TaskData[] taskDataNew = new TaskData[1]; + + // create Task + taskDataNew[0] = TasksUiInternal.createTaskData(abstractBugzillaTest.getRepository(), taskMappingInit, + taskMappingSelect, null); + ITask taskNew = TasksUiUtil.createOutgoingNewTask(taskDataNew[0].getConnectorKind(), + taskDataNew[0].getRepositoryUrl()); + + ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(taskNew, taskDataNew[0]); + Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); + workingCopy.save(changed, null); + + RepositoryResponse response = BugzillaFixture.current().submitTask(taskDataNew[0], + abstractBugzillaTest.getClient());//connector.getTaskDataHandler().postTaskData(repository, taskDataNew[0], changed, + + ((AbstractTask) taskNew).setSubmitting(true); + + assertNotNull(response); + assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString()); + String taskId = response.getTaskId(); + + ITask task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + TaskDataModel model = abstractBugzillaTest.createModel(task); + TaskData taskData = model.getTaskData(); + assertNotNull(taskData); + TaskAttribute attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData); + TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment); + + /* Test uploading a proper file */ + String fileName = "test-attach-1.txt"; + File attachFile = new File(fileName); + attachFile.createNewFile(); + attachFile.deleteOnExit(); + BufferedWriter write = new BufferedWriter(new FileWriter(attachFile)); + write.write("test file from " + System.currentTimeMillis()); + write.close(); + + FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(attachFile); + attachment.setContentType("text/plain"); + attachment.setDescription("Description"); + attachment.setName("My Attachment 1"); + try { + abstractBugzillaTest.getClient().postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), + attachment, attrAttachment, new NullProgressMonitor()); + } catch (Exception e) { + fail("never reach this!"); + } + taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), abstractBugzillaTest.getClient()); + assertNotNull(taskData); + + TaskAttribute attachmentAttribute = taskData.getAttributeMapper() + .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT) + .get(0); + int flagCount = 0; + int flagCountUnused = 0; + TaskAttribute attachmentFlag1 = null; + TaskAttribute attachmentFlag2 = null; + for (TaskAttribute attribute : attachmentAttribute.getAttributes().values()) { + if (!attribute.getId().startsWith(BugzillaAttribute.KIND_FLAG)) { + continue; + } + flagCount++; + if (attribute.getId().startsWith(BugzillaAttribute.KIND_FLAG_TYPE)) { + flagCountUnused++; + TaskAttribute stateAttribute = taskData.getAttributeMapper().getAssoctiatedAttribute(attribute); + if (stateAttribute.getMetaData().getLabel().equals("AttachmentFlag1")) { + attachmentFlag1 = attribute; + } + if (stateAttribute.getMetaData().getLabel().equals("AttachmentFlag2")) { + attachmentFlag2 = attribute; + } + } + } + assertEquals(2, flagCount); + assertEquals(2, flagCountUnused); + assertNotNull(attachmentFlag1); + assertNotNull(attachmentFlag2); + TaskAttribute stateAttribute1 = taskData.getAttributeMapper().getAssoctiatedAttribute(attachmentFlag1); + stateAttribute1.setValue("?"); + TaskAttribute requestee = attachmentFlag1.getAttribute("requestee"); //$NON-NLS-1$ + requestee.setValue("guest@mylyn.eclipse.org"); + abstractBugzillaTest.getClient().postUpdateAttachment(attachmentAttribute, "update", null); + + task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + model = abstractBugzillaTest.createModel(task); + taskData = model.getTaskData(); + assertNotNull(taskData); + + for (TaskAttribute taskAttribute : taskData.getRoot().getAttributes().values()) { + if (taskAttribute.getId().startsWith(BugzillaAttribute.KIND_FLAG)) { + TaskAttribute state = taskAttribute.getAttribute("state"); + if (state.getMetaData().getLabel().equals("BugFlag1")) { + flagA = taskAttribute; + stateA = state; + } else if (state.getMetaData().getLabel().equals("BugFlag2")) { + flagB = taskAttribute; + stateB = state; + } else if (state.getMetaData().getLabel().equals("BugFlag3")) { + flagC = taskAttribute; + stateC = state; + } else if (state.getMetaData().getLabel().equals("BugFlag4")) { + flagD = taskAttribute; + stateD = state; + } + } + } + assertNotNull(flagA); + assertNotNull(flagB); + assertNotNull(flagC); + assertNotNull(flagD); + assertNotNull(stateA); + assertNotNull(stateB); + assertNotNull(stateC); + assertNotNull(stateD); + if (flagD != null) { + TaskAttribute requesteeD = flagD.getAttribute("requestee"); + requesteeD.setValue("guest@mylyn.eclipse.org"); + } + if (stateA != null) { + stateA.setValue("+"); + } + if (stateB != null) { + stateB.setValue("?"); + } + if (stateC != null) { + stateC.setValue("?"); + } + if (stateD != null) { + stateD.setValue("?"); + } + + TaskAttribute cf_freetext = taskData.getRoot().getAttribute("cf_freetext"); + TaskAttribute cf_dropdown = taskData.getRoot().getAttribute("cf_dropdown"); + TaskAttribute cf_largetextbox = taskData.getRoot().getAttribute("cf_largetextbox"); + TaskAttribute cf_multiselect = taskData.getRoot().getAttribute("cf_multiselect"); + TaskAttribute cf_datetime = taskData.getRoot().getAttribute("cf_datetime"); + TaskAttribute cf_bugid = taskData.getRoot().getAttribute("cf_bugid"); + cf_freetext.setValue("Freetext"); + cf_dropdown.setValue("one"); + cf_largetextbox.setValue("large text box"); + cf_multiselect.setValue("Blue"); + cf_datetime.setValue("2012-01-01 00:00:00"); + cf_bugid.setValue("3"); + + model.attributeChanged(cf_freetext); + model.attributeChanged(cf_dropdown); + model.attributeChanged(cf_largetextbox); + model.attributeChanged(cf_multiselect); + model.attributeChanged(cf_datetime); + model.attributeChanged(cf_bugid); + model.attributeChanged(flagA); + model.attributeChanged(flagB); + model.attributeChanged(flagC); + model.attributeChanged(flagD); + changed.clear(); + changed.add(flagA); + changed.add(flagB); + changed.add(flagC); + changed.add(flagD); + changed.add(cf_freetext); + changed.add(cf_dropdown); + changed.add(cf_largetextbox); + changed.add(cf_multiselect); + changed.add(cf_datetime); + changed.add(cf_bugid); + + workingCopy.save(changed, null); + response = BugzillaFixture.current().submitTask(taskData, abstractBugzillaTest.getClient()); + + return taskId; + } + + public String taskAttachmentAttributesExists() { + String taskID = null; + String queryUrlString = abstractBugzillaTest.getRepository().getRepositoryUrl() + "/buglist.cgi?" + + "short_desc=test%20Bug%20with%20Attachment&resolution=---&query_format=advanced" + + "&short_desc_type=casesubstring&component=ManualC2&product=ManualTest"; + RepositoryQuery query = new RepositoryQuery(abstractBugzillaTest.getRepository().getConnectorKind(), + "handle-testQueryViaConnector"); + query.setUrl(queryUrlString); + final Map<Integer, TaskData> changedTaskData = new HashMap<Integer, TaskData>(); + TaskDataCollector collector = new TaskDataCollector() { + @Override + public void accept(TaskData taskData) { + changedTaskData.put(Integer.valueOf(taskData.getTaskId()), taskData); + } + }; + abstractBugzillaTest.getConnector().performQuery(abstractBugzillaTest.getRepository(), query, collector, null, + new NullProgressMonitor()); + if (changedTaskData.size() > 0) { + Set<Integer> ks = changedTaskData.keySet(); + SortedSet<Integer> sks = new TreeSet<Integer>(ks); + taskID = sks.last().toString(); + } + return taskID; + } + + public String createAttachmentAttributesTask() throws Exception { + final TaskMapping taskMappingInit = new TaskMapping() { + + @Override + public String getProduct() { + return "ManualTest"; + } + }; + final TaskMapping taskMappingSelect = new TaskMapping() { + @Override + public String getComponent() { + return "ManualC2"; + } + + @Override + public String getSummary() { + return "test Bug with Attachment"; + } + + @Override + public String getDescription() { + return "The Description of the test with Attachment Bug"; + } + }; + final TaskData[] taskDataNew = new TaskData[1]; + + // create Task + taskDataNew[0] = TasksUiInternal.createTaskData(abstractBugzillaTest.getRepository(), taskMappingInit, + taskMappingSelect, null); + ITask taskNew = TasksUiUtil.createOutgoingNewTask(taskDataNew[0].getConnectorKind(), + taskDataNew[0].getRepositoryUrl()); + + ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(taskNew, taskDataNew[0]); + Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); + workingCopy.save(changed, null); + + RepositoryResponse response = BugzillaFixture.current().submitTask(taskDataNew[0], + abstractBugzillaTest.getClient());//connector.getTaskDataHandler().postTaskData(repository, taskDataNew[0], changed, + //new NullProgressMonitor()); + ((AbstractTask) taskNew).setSubmitting(true); + + assertNotNull(response); + assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString()); + String taskId = response.getTaskId(); + + ITask task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + TaskDataModel model = abstractBugzillaTest.createModel(task); + TaskData taskData = model.getTaskData(); + assertNotNull(taskData); + TaskAttribute attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData); + TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment); + + String fileName = "test-attach-1.txt"; + File attachFile = new File(fileName); + attachFile.createNewFile(); + attachFile.deleteOnExit(); + BufferedWriter write = new BufferedWriter(new FileWriter(attachFile)); + write.write("test file from " + System.currentTimeMillis()); + write.close(); + + FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(attachFile); + attachment.setContentType("text/plain"); + attachment.setDescription("My Attachment 1"); + attachment.setName("My Attachment 1"); + try { + abstractBugzillaTest.getClient().postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), + attachment, attrAttachment, new NullProgressMonitor()); + } catch (Exception e) { + fail("never reach this!"); + } + taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), abstractBugzillaTest.getClient()); + assertNotNull(taskData); + + task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + model = abstractBugzillaTest.createModel(task); + taskData = model.getTaskData(); + assertNotNull(taskData); + attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData); + attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment); + + fileName = "test-attach-2.txt"; + attachFile = new File(fileName); + attachFile.createNewFile(); + attachFile.deleteOnExit(); + write = new BufferedWriter(new FileWriter(attachFile)); + write.write("test file 2 from " + System.currentTimeMillis()); + write.close(); + + attachment = new FileTaskAttachmentSource(attachFile); + attachment.setContentType("text/plain"); + attachment.setDescription("My Attachment 2"); + attachment.setName("My Attachment 2"); + try { + abstractBugzillaTest.getClient().postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), + attachment, attrAttachment, new NullProgressMonitor()); + } catch (Exception e) { + fail("never reach this!"); + } + taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), abstractBugzillaTest.getClient()); + assertNotNull(taskData); + + task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + model = abstractBugzillaTest.createModel(task); + taskData = model.getTaskData(); + assertNotNull(taskData); + attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData); + attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment); + + fileName = "test-attach-3.txt"; + attachFile = new File(fileName); + attachFile.createNewFile(); + attachFile.deleteOnExit(); + write = new BufferedWriter(new FileWriter(attachFile)); + write.write("test file 3 from " + System.currentTimeMillis()); + write.close(); + + attachment = new FileTaskAttachmentSource(attachFile); + attachment.setContentType("text/plain"); + attachment.setDescription("My Attachment 3"); + attachment.setName("My Attachment 3"); + TaskAttribute child = attrAttachment.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH); + if (child != null) { + child.setValue("1"); + } + try { + abstractBugzillaTest.getClient().postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), + attachment, attrAttachment, new NullProgressMonitor()); + } catch (Exception e) { + fail("never reach this!"); + } + taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), abstractBugzillaTest.getClient()); + assertNotNull(taskData); + + task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + model = abstractBugzillaTest.createModel(task); + taskData = model.getTaskData(); + assertNotNull(taskData); + attrAttachment = taskData.getAttributeMapper().createTaskAttachment(taskData); + attachmentMapper = TaskAttachmentMapper.createFrom(attrAttachment); + + fileName = "test-attach-4.txt"; + attachFile = new File(fileName); + attachFile.createNewFile(); + attachFile.deleteOnExit(); + write = new BufferedWriter(new FileWriter(attachFile)); + write.write("test file 4 from " + System.currentTimeMillis()); + write.close(); + + attachment = new FileTaskAttachmentSource(attachFile); + attachment.setContentType("text/plain"); + attachment.setDescription("My Attachment 4"); + attachment.setName("My Attachment 4"); + child = attrAttachment.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH); + if (child != null) { + child.setValue("1"); + } + try { + abstractBugzillaTest.getClient().postAttachment(taskData.getTaskId(), attachmentMapper.getComment(), + attachment, attrAttachment, new NullProgressMonitor()); + } catch (Exception e) { + fail("never reach this!"); + } + taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), abstractBugzillaTest.getClient()); + assertNotNull(taskData); + + TaskAttribute attachment1 = taskData.getAttributeMapper() + .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT) + .get(1); + assertNotNull(attachment1); + TaskAttribute obsolete = attachment1.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED); + assertNotNull(obsolete); + obsolete.setValue("1"); //$NON-NLS-1$ + ((BugzillaTaskDataHandler) abstractBugzillaTest.getConnector().getTaskDataHandler()).postUpdateAttachment( + abstractBugzillaTest.getRepository(), attachment1, "update", new NullProgressMonitor()); //$NON-NLS-1$ + + task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + model = abstractBugzillaTest.createModel(task); + taskData = model.getTaskData(); + assertNotNull(taskData); + + TaskAttribute attachment2 = taskData.getAttributeMapper() + .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT) + .get(3); + assertNotNull(attachment); + obsolete = attachment2.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED); + assertNotNull(obsolete); + obsolete.setValue("1"); //$NON-NLS-1$ + ((BugzillaTaskDataHandler) abstractBugzillaTest.getConnector().getTaskDataHandler()).postUpdateAttachment( + abstractBugzillaTest.getRepository(), attachment2, "update", new NullProgressMonitor()); //$NON-NLS-1$ + + return taskId; + } + + public String taskCustomFieldExists() { + String taskID = null; + String queryUrlString = abstractBugzillaTest.getRepository().getRepositoryUrl() + "/buglist.cgi?" + + "short_desc=test%20Bug%20with%20Custom%20Fields&resolution=---&query_format=advanced" + + "&short_desc_type=casesubstring&component=ManualC2&product=ManualTest"; + RepositoryQuery query = new RepositoryQuery(abstractBugzillaTest.getRepository().getConnectorKind(), + "handle-testQueryViaConnector"); + query.setUrl(queryUrlString); + final Map<Integer, TaskData> changedTaskData = new HashMap<Integer, TaskData>(); + TaskDataCollector collector = new TaskDataCollector() { + @Override + public void accept(TaskData taskData) { + changedTaskData.put(Integer.valueOf(taskData.getTaskId()), taskData); + } + }; + abstractBugzillaTest.getConnector().performQuery(abstractBugzillaTest.getRepository(), query, collector, null, + new NullProgressMonitor()); + if (changedTaskData.size() > 0) { + Set<Integer> ks = changedTaskData.keySet(); + SortedSet<Integer> sks = new TreeSet<Integer>(ks); + taskID = sks.last().toString(); + } + return taskID; + } + + public String createCustomFieldTask() throws Exception { + final TaskMapping taskMappingInit = new TaskMapping() { + + @Override + public String getProduct() { + return "ManualTest"; + } + }; + final TaskMapping taskMappingSelect = new TaskMapping() { + @Override + public String getComponent() { + return "ManualC2"; + } + + @Override + public String getSummary() { + return "test Bug with Custom Fields"; + } + + @Override + public String getDescription() { + return "The Description of the test with Custom Fields Bug"; + } + }; + final TaskData[] taskDataNew = new TaskData[1]; + + // create Task + taskDataNew[0] = TasksUiInternal.createTaskData(abstractBugzillaTest.getRepository(), taskMappingInit, + taskMappingSelect, null); + ITask taskNew = TasksUiUtil.createOutgoingNewTask(taskDataNew[0].getConnectorKind(), + taskDataNew[0].getRepositoryUrl()); + + ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(taskNew, taskDataNew[0]); + Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); + workingCopy.save(changed, null); + + RepositoryResponse response = BugzillaFixture.current().submitTask(taskDataNew[0], + abstractBugzillaTest.getClient());//connector.getTaskDataHandler().postTaskData(repository, taskDataNew[0], changed, + //new NullProgressMonitor()); + ((AbstractTask) taskNew).setSubmitting(true); + + assertNotNull(response); + assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString()); + String taskId = response.getTaskId(); + + ITask task = abstractBugzillaTest.generateLocalTaskAndDownload(taskId); + assertNotNull(task); + TaskDataModel model = abstractBugzillaTest.createModel(task); + TaskData taskData = model.getTaskData(); + assertNotNull(taskData); + + TaskMapper mapper = new TaskMapper(taskData); + TaskAttribute cf_multiselect = mapper.getTaskData().getRoot().getAttribute("cf_multiselect"); + cf_multiselect.setValue("Green"); + model.attributeChanged(cf_multiselect); + changed.clear(); + changed.add(cf_multiselect); + + workingCopy.save(changed, null); + response = BugzillaFixture.current().submitTask(taskData, abstractBugzillaTest.getClient()); + + return taskId; + } + +} diff --git a/org.eclipse.mylyn.bugzilla.ui/plugin.xml b/org.eclipse.mylyn.bugzilla.ui/plugin.xml index 2f6d9b170..d7cdb8c80 100644 --- a/org.eclipse.mylyn.bugzilla.ui/plugin.xml +++ b/org.eclipse.mylyn.bugzilla.ui/plugin.xml @@ -44,6 +44,7 @@ <languageAttribute command="error_login" response="Invalid Username Or Password"/> <languageAttribute command="error_login" response="account locked"/> <languageAttribute command="error_collision" response="Mid-air collision!"/> + <languageAttribute command="error_collision" response="Mid-air collision detected!"/> <languageAttribute command="error_comment_required" response="Comment Required"/> <languageAttribute command="error_logged_out" response="logged out"/> <languageAttribute command="bad_login" response="Login"/> @@ -71,7 +72,8 @@ <languageAttribute command="error_login" response="Ungültiger Benutzername oder ungültiges Passwort"/> <languageAttribute command="error_login" response="Benutzerkonto gesperrt"/> <languageAttribute command="error_collision" response="Kollision!"/> - <languageAttribute command="error_comment_required" response="Kommentar erforderlich"/> + <languageAttribute command="error_collision" response="Kollision festgestellt!"/> + <languageAttribute command="error_comment_required" response="Kommentar erforderlich"/> <languageAttribute command="error_logged_out" response="Abgemeldet"/> <languageAttribute command="bad_login" response="Anmeldename erforderlich"/> <languageAttribute command="bad_login" response="check e-mail"/> |