Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2013-01-27 13:56:31 -0500
committerSteffen Pingel2013-04-27 20:18:04 -0400
commitc8191bd67f7137f0e8403f6a4e6206fafc53fcab (patch)
treebca67fa88a3cd331231201cf2c74d8fbe0d1e8ea /org.eclipse.mylyn.bugzilla.tests/src
parentcd9abb53f4c6021f16268c24a739e0b6d832c5ee (diff)
downloadorg.eclipse.mylyn.tasks-c8191bd67f7137f0e8403f6a4e6206fafc53fcab.tar.gz
org.eclipse.mylyn.tasks-c8191bd67f7137f0e8403f6a4e6206fafc53fcab.tar.xz
org.eclipse.mylyn.tasks-c8191bd67f7137f0e8403f6a4e6206fafc53fcab.zip
395029: Bugzilla should support streaming for attachments
Change-Id: I9f80f423f926b36a69d0af15f4e92902ba78aaaa Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=395029
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.tests/src')
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java65
1 files changed, 65 insertions, 0 deletions
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 7bd841aa1..4e927728f 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
@@ -590,4 +590,69 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
assertEquals(expected, new String(data));
}
+ public void testDownloadNonExsistingAttachmentFile() 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);
+
+ attachmentAttribute.setValue("99999999");
+ File file = File.createTempFile("mylyn", null);
+ ITask iTask = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), taskData.getTaskId());
+
+ ITaskAttachment taskAttachment;
+ taskAttachment = new TaskAttachment(repository, iTask, attachmentAttribute);
+
+ OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
+ try {
+ AttachmentUtil.downloadAttachment(taskAttachment, out, new NullProgressMonitor());
+ } catch (CoreException e) {
+ String message = e.getMessage();
+ assertTrue(message.startsWith("invalid attachment id: "));
+ } catch (Exception e) {
+ fail("CoreException expected");
+ } finally {
+ out.close();
+ }
+ }
}

Back to the top