org.camunda.bpm.engine.impl.util.IoUtil Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.util.IoUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #2
Source File: ProcessDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
      .expect()
        .statusCode(Status.OK.getStatusCode())
        .contentType("image/png")
        .header("Content-Disposition", "attachment; filename=\"" +
            MockProvider.EXAMPLE_PROCESS_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
      .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
  verify(repositoryServiceMock).getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "process diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example #3
Source File: DecisionDefinitionDeployerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
  "org/camunda/bpm/engine/test/dmn/deployment/DecisionDefinitionDeployerTest.testDecisionDiagramResource.dmn11.xml",
  "org/camunda/bpm/engine/test/dmn/deployment/DecisionDefinitionDeployerTest.testDecisionDiagramResource.png"
})
@Test
public void getDecisionDiagramResource() {
  String resourcePrefix = "org/camunda/bpm/engine/test/dmn/deployment/DecisionDefinitionDeployerTest.testDecisionDiagramResource";

  DecisionDefinition decisionDefinition = repositoryService.createDecisionDefinitionQuery().singleResult();

  assertEquals(resourcePrefix + ".dmn11.xml", decisionDefinition.getResourceName());
  assertEquals("decision", decisionDefinition.getKey());

  String diagramResourceName = decisionDefinition.getDiagramResourceName();
  assertEquals(resourcePrefix + ".png", diagramResourceName);

  InputStream diagramStream = repositoryService.getResourceAsStream(decisionDefinition.getDeploymentId(), diagramResourceName);
  final byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
  assertEquals(2540, diagramBytes.length);
}
 
Example #4
Source File: BpmnDeploymentTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={
  "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg"
})
public void testProcessDiagramResource() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

  assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName());
  assertTrue(processDefinition.hasStartFormKey());

  String diagramResourceName = processDefinition.getDiagramResourceName();
  assertEquals("org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName);

  InputStream diagramStream = repositoryService.getResourceAsStream(deploymentId, "org/camunda/bpm/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg");
  byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
  assertEquals(33343, diagramBytes.length);
}
 
Example #5
Source File: CaseInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testPostSingleFileVariableWithEncodingAndMimeType() throws Exception {
  byte[] value = "some text".getBytes();
  String variableKey = "aVariableKey";
  String encoding = "utf-8";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", MockProvider.EXAMPLE_CASE_INSTANCE_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype + "; encoding="+encoding)
    .multiPart("valueType", "File", "text/plain")
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_CASE_INSTANCE_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(caseServiceMock).withCaseExecution(MockProvider.EXAMPLE_CASE_INSTANCE_ID);
  verify(caseExecutionCommandBuilderMock).setVariable(eq(variableKey), captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(encoding));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
 
Example #6
Source File: DecisionRequirementsDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void decisionRequirementsDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID)
    .expect()
      .statusCode(Status.OK.getStatusCode())
      .contentType("image/png")
      .header("Content-Disposition", "attachment; filename=\"" +
          MockProvider.EXAMPLE_DECISION_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  verify(repositoryServiceMock).getDecisionRequirementsDefinition(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID);
  verify(repositoryServiceMock).getDecisionRequirementsDiagram(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID);

  byte[] expected = IoUtil.readInputStream(new FileInputStream(getFile()), "decision requirements diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example #7
Source File: ResourceLoadingSecurityFilter.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadFilterRules(FilterConfig filterConfig) throws ServletException {
  String configFileName = filterConfig.getInitParameter("configFile");
  Resource resource = resourceLoader.getResource("classpath:" +webappProperty.getWebjarClasspath() + configFileName);
  InputStream configFileResource;
  try {
    configFileResource = resource.getInputStream();
  } catch (IOException e1) {
    throw new ServletException("Could not read security filter config file '" + configFileName + "': no such resource in servlet context.");
  }
  try {
    filterRules = FilterRules.load(configFileResource);
  } catch (Exception e) {
    throw new RuntimeException("Exception while parsing '" + configFileName + "'", e);
  } finally {
    IoUtil.closeSilently(configFileResource);
  }
}
 
Example #8
Source File: ParseProcessesXmlStep.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected boolean isEmptyFile(URL url) {

    InputStream inputStream = null;

    try {
      inputStream = url.openStream();
      return inputStream.available() == 0;

    }
    catch (IOException e) {
      throw LOG.exceptionWhileReadingProcessesXml(url.toString(), e);
    }
    finally {
      IoUtil.closeSilently(inputStream);

    }
  }
 
Example #9
Source File: CmmnDeployerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.cmmn",
    "org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.png" })
public void testCaseDiagramResource() {
  final CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();

  assertEquals("org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.cmmn", caseDefinition.getResourceName());
  assertEquals("Case_1", caseDefinition.getKey());

  final String diagramResourceName = caseDefinition.getDiagramResourceName();
  assertEquals("org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.png", diagramResourceName);

  final InputStream diagramStream = repositoryService.getResourceAsStream(deploymentId,
      "org/camunda/bpm/engine/test/cmmn/deployment/CmmnDeploymentTest.testCaseDiagramResource.png");
  final byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
  assertEquals(2540, diagramBytes.length);
}
 
Example #10
Source File: DecisionDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecisionDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID)
      .expect()
        .statusCode(Status.OK.getStatusCode())
        .contentType("image/png")
        .header("Content-Disposition", "attachment; filename=\"" +
            MockProvider.EXAMPLE_DECISION_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
      .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getDecisionDefinition(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);
  verify(repositoryServiceMock).getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "decision diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example #11
Source File: FileUtil.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void writeStringToFile(String value, String filePath, boolean deleteFile) {

    BufferedOutputStream outputStream = null;
    try {
      File file = new File(filePath);
      if (file.exists() && deleteFile) {
        file.delete();
      }

      outputStream = new BufferedOutputStream(new FileOutputStream(file, true));
      outputStream.write(value.getBytes());
      outputStream.flush();

    } catch (Exception e) {
      throw new PerfTestException("Could not write report to file", e);
    } finally {
      IoUtil.closeSilently(outputStream);
    }

  }
 
Example #12
Source File: DbSqlSession.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void executeSchemaResource(String operation, String component, String resourceName, boolean isOptional) {
  InputStream inputStream = null;
  try {
    inputStream = ReflectUtil.getResourceAsStream(resourceName);
    if (inputStream == null) {
      if (isOptional) {
        LOG.missingSchemaResource(resourceName, operation);
      } else {
        throw LOG.missingSchemaResourceException(resourceName, operation);
      }
    } else {
      executeSchemaResource(operation, component, resourceName, inputStream);
    }

  } finally {
    IoUtil.closeSilently(inputStream);
  }
}
 
Example #13
Source File: ProcessDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID).getDiagramResourceName())
    .thenReturn(null);
  when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))
    .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
    .expect()
    .statusCode(Status.OK.getStatusCode())
    .contentType("application/octet-stream")
    .header("Content-Disposition", "attachment; filename=\"" + null + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "process diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example #14
Source File: OSGiProcessApplicationScanner.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
protected void addResource(URL source, Map<String, byte[]> resourceMap, String resourceRootPath, String resourceName) {

    String resourcePath = (resourceRootPath == null ? "" : resourceRootPath).concat(resourceName);

    log.log(Level.FINEST, "discovered process resource {0}", resourcePath);

    InputStream inputStream = null;

    try {
      inputStream = source.openStream();
      byte[] bytes = IoUtil.readInputStream(inputStream, resourcePath);

      resourceMap.put(resourcePath, bytes);

    } catch (IOException e) {
      throw new ProcessEngineException("Could not open file for reading " + source + ". " + e.getMessage(), e);
    } finally {
      if (inputStream != null) {
        IoUtil.closeSilently(inputStream);
      }
    }
  }
 
Example #15
Source File: ResourceLoadingSecurityFilter.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadFilterRules(FilterConfig filterConfig, String applicationPath) throws ServletException {
  String configFileName = filterConfig.getInitParameter("configFile");
  Resource resource = resourceLoader.getResource("classpath:" +webappProperty.getWebjarClasspath() + configFileName);
  InputStream configFileResource;
  try {
    configFileResource = resource.getInputStream();
  } catch (IOException e1) {
    throw new ServletException("Could not read security filter config file '" + configFileName + "': no such resource in servlet context.");
  }
  try {
    filterRules = FilterRules.load(configFileResource, applicationPath);
  } catch (Exception e) {
    throw new RuntimeException("Exception while parsing '" + configFileName + "'", e);
  } finally {
    IoUtil.closeSilently(configFileResource);
  }
}
 
Example #16
Source File: SpinObjectValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected byte[] serializeToByteArray(Object deserializedObject) throws Exception {
  DataFormatMapper mapper = dataFormat.getMapper();
  DataFormatWriter writer = dataFormat.getWriter();

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  OutputStreamWriter outWriter = new OutputStreamWriter(out, Context.getProcessEngineConfiguration().getDefaultCharset());
  BufferedWriter bufferedWriter = new BufferedWriter(outWriter);

  try {
    Object mappedObject = mapper.mapJavaToInternal(deserializedObject);
    writer.writeToWriter(bufferedWriter, mappedObject);
    return out.toByteArray();
  }
  finally {
    IoUtil.closeSilently(out);
    IoUtil.closeSilently(outWriter);
    IoUtil.closeSilently(bufferedWriter);
  }
}
 
Example #17
Source File: SpinObjectValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected Object deserializeFromByteArray(byte[] bytes, String objectTypeName) throws Exception {
  ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
  DataFormatMapper mapper = dataFormat.getMapper();
  DataFormatReader reader = dataFormat.getReader();

  ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
  InputStreamReader inReader = new InputStreamReader(bais, processEngineConfiguration.getDefaultCharset());
  BufferedReader bufferedReader = new BufferedReader(inReader);

  try {
    Object mappedObject = reader.readInput(bufferedReader);
    return mapper.mapInternalToJava(mappedObject, objectTypeName, getValidator(processEngineConfiguration));
  }
  finally{
    IoUtil.closeSilently(bais);
    IoUtil.closeSilently(inReader);
    IoUtil.closeSilently(bufferedReader);
  }
}
 
Example #18
Source File: SpinValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected byte[] serializeToByteArray(Object deserializedObject) throws Exception {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  OutputStreamWriter outWriter = new OutputStreamWriter(out, Context.getProcessEngineConfiguration().getDefaultCharset());
  BufferedWriter bufferedWriter = new BufferedWriter(outWriter);

  try {
    Spin<?> wrapper = (Spin<?>) deserializedObject;
    wrapper.writeToWriter(bufferedWriter);
    return out.toByteArray();
  }
  finally {
    IoUtil.closeSilently(out);
    IoUtil.closeSilently(outWriter);
    IoUtil.closeSilently(bufferedWriter);
  }
}
 
Example #19
Source File: SpinValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected Object deserializeFromByteArray(byte[] object, ValueFields valueFields) throws Exception {
  ByteArrayInputStream bais = new ByteArrayInputStream(object);
  InputStreamReader inReader = new InputStreamReader(bais, Context.getProcessEngineConfiguration().getDefaultCharset());
  BufferedReader bufferedReader = new BufferedReader(inReader);

  try {
    Object wrapper = dataFormat.getReader().readInput(bufferedReader);
    return dataFormat.createWrapperInstance(wrapper);
  }
  finally{
    IoUtil.closeSilently(bais);
    IoUtil.closeSilently(inReader);
    IoUtil.closeSilently(bufferedReader);
  }

}
 
Example #20
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCaseDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID).getDiagramResourceName())
    .thenReturn(null);
  when(repositoryServiceMock.getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_CASE_DEFINITION_ID)
    .expect()
    .statusCode(Status.OK.getStatusCode())
    .contentType("application/octet-stream")
    .header("Content-Disposition", "attachment; filename=\"" + null + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "case diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example #21
Source File: CaseDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCaseDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_CASE_DEFINITION_ID)
      .expect()
        .statusCode(Status.OK.getStatusCode())
        .contentType("image/png")
        .header("Content-Disposition", "attachment; filename=\"" +
            MockProvider.EXAMPLE_CASE_DEFINITION_DIAGRAM_RESOURCE_NAME + "\"")
      .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID);
  verify(repositoryServiceMock).getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "case diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example #22
Source File: RepositoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/repository/drg.dmn" })
public void testGetDecisionRequirementsModel() throws Exception {
  DecisionRequirementsDefinitionQuery query = repositoryService.createDecisionRequirementsDefinitionQuery();

  DecisionRequirementsDefinition decisionRequirementsDefinition = query.singleResult();
  String decisionRequirementsDefinitionId = decisionRequirementsDefinition.getId();

  InputStream decisionRequirementsModel = repositoryService.getDecisionRequirementsModel(decisionRequirementsDefinitionId);

  assertNotNull(decisionRequirementsModel);

  byte[] readInputStream = IoUtil.readInputStream(decisionRequirementsModel, "decisionRequirementsModel");
  String model = new String(readInputStream, "UTF-8");

  assertTrue(model.contains("<definitions id=\"dish\" name=\"Dish\" namespace=\"test-drg\""));
  IoUtil.closeSilently(decisionRequirementsModel);
}
 
Example #23
Source File: DecisionDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecisionDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
  // setup additional mock behavior
  File file = getFile("/processes/todo-process.png");
  when(repositoryServiceMock.getDecisionDefinition(MockProvider.EXAMPLE_DECISION_DEFINITION_ID).getDiagramResourceName())
    .thenReturn(null);
  when(repositoryServiceMock.getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))
      .thenReturn(new FileInputStream(file));

  // call method
  byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID)
    .expect()
    .statusCode(Status.OK.getStatusCode())
    .contentType("application/octet-stream")
    .header("Content-Disposition", "attachment; filename=\"" + null + "\"")
    .when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();

  // verify service interaction
  verify(repositoryServiceMock).getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);

  // compare input stream with response body bytes
  byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "decision diagram");
  Assert.assertArrayEquals(expected, actual);
}
 
Example #24
Source File: TaskVariableLocalRestResourceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSingleLocalFileVariableWithMimeType() throws Exception {

  byte[] value = "some text".getBytes();
  String base64 = Base64.encodeBase64String(value);
  String variableKey = "aVariableKey";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype)
    .multiPart("valueType", "File", "text/plain")
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(taskServiceMock).setVariableLocal(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey),
      captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(nullValue()));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
 
Example #25
Source File: TaskVariableRestResourceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSingleFileVariableWithMimeType() throws Exception {

  byte[] value = "some text".getBytes();
  String base64 = Base64.encodeBase64String(value);
  String variableKey = "aVariableKey";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype)
    .multiPart("valueType", "File", "text/plain")
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(taskServiceMock).setVariable(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey),
      captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(nullValue()));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
 
Example #26
Source File: TaskVariableRestResourceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSingleFileVariableWithEncodingAndMimeType() throws Exception {

  byte[] value = "some text".getBytes();
  String variableKey = "aVariableKey";
  String encoding = "utf-8";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype + "; encoding="+encoding)
    .multiPart("valueType", "File", "text/plain")
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_TASK_SINGLE_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(taskServiceMock).setVariable(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey),
      captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(encoding));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
 
Example #27
Source File: ProcessInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSingleFileVariableWithMimeType() throws Exception {

  byte[] value = "some text".getBytes();
  String variableKey = "aVariableKey";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype)
    .multiPart("valueType", "File", "text/plain")
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey),
      captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(nullValue()));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
 
Example #28
Source File: ProcessInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSingleFileVariableWithEncodingAndMimeType() throws Exception {

  byte[] value = "some text".getBytes();
  String variableKey = "aVariableKey";
  String encoding = "utf-8";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype + "; encoding="+encoding)
    .multiPart("valueType", "File", "text/plain")
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey),
      captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(encoding));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
 
Example #29
Source File: CaseExecutionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSingleFileVariable() throws Exception {

  byte[] value = "some text".getBytes();
  String variableKey = "aVariableKey";
  String encoding = "utf-8";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", MockProvider.EXAMPLE_CASE_EXECUTION_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype + "; encoding="+encoding)
    .header("accept", MediaType.APPLICATION_JSON)
    .multiPart("valueType", "File", "text/plain")
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_CASE_EXECUTION_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(caseServiceMock).withCaseExecution(MockProvider.EXAMPLE_CASE_EXECUTION_ID);
  verify(caseExecutionCommandBuilderMock).setVariable(eq(variableKey),
      captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(encoding));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}
 
Example #30
Source File: CaseExecutionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSingleLocalFileVariableWithMimeType() throws Exception {

  byte[] value = "some text".getBytes();
  String variableKey = "aVariableKey";
  String filename = "test.txt";
  String mimetype = MediaType.TEXT_PLAIN;

  given()
    .pathParam("id", MockProvider.EXAMPLE_CASE_EXECUTION_ID).pathParam("varId", variableKey)
    .multiPart("data", filename, value, mimetype)
    .multiPart("valueType", "File", "text/plain")
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(SINGLE_CASE_EXECUTION_LOCAL_BINARY_VARIABLE_URL);

  ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class);
  verify(caseServiceMock).withCaseExecution(MockProvider.EXAMPLE_CASE_EXECUTION_ID);
  verify(caseExecutionCommandBuilderMock).setVariableLocal(eq(variableKey),
      captor.capture());
  FileValue captured = captor.getValue();
  assertThat(captured.getEncoding(), is(nullValue()));
  assertThat(captured.getFilename(), is(filename));
  assertThat(captured.getMimeType(), is(mimetype));
  assertThat(IoUtil.readInputStream(captured.getValue(), null), is(value));
}