Task task = ( Task ) eval( new StringReader( str ), vars );
client.addTask( task, null, addTaskResponseHandler );
long taskId = addTaskResponseHandler.getTaskId();
Attachment attachment = new Attachment();
Date attachedAt = new Date( System.currentTimeMillis() );
attachment.setAttachedAt( attachedAt);
attachment.setAttachedBy( users.get( "luke" ) );
attachment.setName( "file1.txt" );
attachment.setAccessType( AccessType.Inline );
attachment.setContentType( "txt" );
byte[] bytes = "Ths is my attachment text1".getBytes();
Content content = new Content();
content.setContent( bytes );
BlockingAddAttachmentResponseHandler addAttachmentResponseHandler = new BlockingAddAttachmentResponseHandler();
client.addAttachment( taskId, attachment, content, addAttachmentResponseHandler);
assertTrue( addAttachmentResponseHandler.getAttachmentId() != attachment.getId() );
assertTrue( addAttachmentResponseHandler.getContentId() != attachment.getAttachmentContentId() );
BlockingGetTaskResponseHandler getTaskResponseHandler = new BlockingGetTaskResponseHandler();
client.getTask( taskId, getTaskResponseHandler );
Task task1 = getTaskResponseHandler.getTask();
assertNotSame(task, task1);
assertFalse( task.equals( task1) );
List<Attachment> attachments1 = task1.getTaskData().getAttachments();
assertEquals(1, attachments1.size() );
Attachment returnedAttachment = attachments1.get( 0 );
assertEquals( attachedAt, returnedAttachment.getAttachedAt() );
assertEquals( users.get( "luke" ), returnedAttachment.getAttachedBy() );
assertEquals( AccessType.Inline, returnedAttachment.getAccessType() );
assertEquals( "txt", returnedAttachment.getContentType() );
assertEquals( "file1.txt", returnedAttachment.getName() );
assertEquals( bytes.length, returnedAttachment.getSize() );
assertEquals( (long) addAttachmentResponseHandler.getAttachmentId(), (long) returnedAttachment.getId() );
assertEquals( (long) addAttachmentResponseHandler.getContentId(), (long) returnedAttachment.getAttachmentContentId() );
// Make the same as the returned tasks, so we can test equals
task.getTaskData().setAttachments( attachments1 );
task.getTaskData().setStatus( Status.Created );
assertEquals(task, task1);
BlockingGetContentResponseHandler getResponseHandler = new BlockingGetContentResponseHandler();
client.getContent( returnedAttachment.getAttachmentContentId(), getResponseHandler );
content = getResponseHandler.getContent();
assertEquals( "Ths is my attachment text1", new String( content.getContent() ) );
// test we can have multiple attachments
attachment = new Attachment();
attachedAt = new Date( System.currentTimeMillis() );
attachment.setAttachedAt( attachedAt);
attachment.setAttachedBy( users.get( "tony" ) );
attachment.setName( "file2.txt" );
attachment.setAccessType( AccessType.Inline );