Task attachment unit test: no content

Hi, I’m working on a Unit test using FlowableRule. I have a TaskListener configured as follows:

    <userTask id="myTask" name="My Task" >
        <extensionElements>
            <flowable:taskListener
                    event="complete"
                    class="com...MyTask" />
        </extensionElements>
    </userTask>

Test:

    TaskService taskService = FlowableRule.getTaskService();

    String taskId = taskService.createTaskQuery().singleResult().getId();
    taskService.complete(taskId);

    List<Attachment> taskAttachments = FlowableRule.getTaskService().getTaskAttachments(taskId);
    AttachmentEntity attachment = (AttachmentEntity) taskAttachments.get(0);
    Assert.assertNotNull(attachment.getContent());

id is not null
content is null

How can I get the content populated in FlowableRule tests?

Thanks

This works:

FlowableRule.getTaskService().getAttachmentContent(attachment.getId());

What? Bug or feature? Why can’t I get the attachment content from the attachment itself?

That is by design: the Attachment interface does not have a getContent() method. That’s why you have to cast to the AttachmentEntity to get it, which is not part of the API.
The reason for this is that getting the content needs to be done within a transaction. In this snippet:

AttachmentEntity attachment = (AttachmentEntity) taskAttachments.get(0);
Assert.assertNotNull(attachment.getContent());

there is no transaction as this is a simple Entity class that only holds data. However, the getAttachmentContent does wrap it in a transaction as it passed through the service.