Search in sources :

Example 6 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method createProcessInstanceAttachmentWithContent.

private void createProcessInstanceAttachmentWithContent(String processInstanceId) {
    taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
    List<Attachment> taskAttachments = taskService.getProcessInstanceAttachments(processInstanceId);
    assertEquals(1, taskAttachments.size());
    assertNotNull(taskService.getAttachmentContent(taskAttachments.get(0).getId()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Attachment(org.camunda.bpm.engine.task.Attachment)

Example 7 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testGetTaskAttachmentWithNullParameters.

@Test
public void testGetTaskAttachmentWithNullParameters() {
    int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
    if (historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
        Attachment attachment = taskService.getTaskAttachment(null, null);
        assertNull(attachment);
    }
}
Also used : Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test)

Example 8 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testGetTaskAttachmentContentByTaskIdAndAttachmentId.

@Test
public void testGetTaskAttachmentContentByTaskIdAndAttachmentId() {
    int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
    if (historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
        // create and save task
        Task task = taskService.newTask();
        taskService.saveTask(task);
        String taskId = task.getId();
        // Fetch the task again and update
        // add attachment
        Attachment attachment = taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
        String attachmentId = attachment.getId();
        // get attachment for taskId and attachmentId
        InputStream taskAttachmentContent = taskService.getTaskAttachmentContent(taskId, attachmentId);
        assertNotNull(taskAttachmentContent);
        byte[] byteContent = IoUtil.readInputStream(taskAttachmentContent, "weatherforcast");
        assertEquals("someContent", new String(byteContent));
        taskService.deleteTask(taskId, true);
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test)

Example 9 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testTaskAttachments.

@Test
public void testTaskAttachments() {
    int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
    if (historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
        Task task = taskService.newTask();
        task.setOwner("johndoe");
        taskService.saveTask(task);
        String taskId = task.getId();
        identityService.setAuthenticatedUserId("johndoe");
        // Fetch the task again and update
        taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", "http://weather.com");
        Attachment attachment = taskService.getTaskAttachments(taskId).get(0);
        assertEquals("weatherforcast", attachment.getName());
        assertEquals("temperatures and more", attachment.getDescription());
        assertEquals("web page", attachment.getType());
        assertEquals(taskId, attachment.getTaskId());
        assertEquals("someprocessinstanceid", attachment.getProcessInstanceId());
        assertEquals("http://weather.com", attachment.getUrl());
        assertNull(taskService.getAttachmentContent(attachment.getId()));
        // Finally, clean up
        taskService.deleteTask(taskId);
        assertEquals(0, taskService.getTaskComments(taskId).size());
        assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).list().size());
        taskService.deleteTask(taskId, true);
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test)

Example 10 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testCreateTaskAttachmentWithNullTaskId.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
@Test
public void testCreateTaskAttachmentWithNullTaskId() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Attachment attachment = taskService.createAttachment("web page", null, processInstance.getId(), "weatherforcast", "temperatures and more", new ByteArrayInputStream("someContent".getBytes()));
    Attachment fetched = taskService.getAttachment(attachment.getId());
    assertThat(fetched, is(notNullValue()));
    assertThat(fetched.getTaskId(), is(nullValue()));
    assertThat(fetched.getProcessInstanceId(), is(notNullValue()));
    taskService.deleteAttachment(attachment.getId());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Aggregations

Attachment (org.camunda.bpm.engine.task.Attachment)18 Test (org.junit.Test)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Task (org.camunda.bpm.engine.task.Task)6 Deployment (org.camunda.bpm.engine.test.Deployment)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)2 AttachmentDto (org.camunda.bpm.engine.rest.dto.task.AttachmentDto)2 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.anyString (org.mockito.Matchers.anyString)2 JsonPath (com.jayway.restassured.path.json.JsonPath)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)1 FormPart (org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart)1