Java Code Examples for org.camunda.commons.utils.IoUtil

The following examples show how to use org.camunda.commons.utils.IoUtil. These examples are extracted from open source projects. 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
@Test
public void shouldGet() {
  // given
  engineRule.startProcessInstance(processDefinition.getId(), VARIABLE_NAME_FILE, VARIABLE_VALUE_FILE);

  // when
  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(handler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  // then
  assertThat(task.getAllVariables().size()).isEqualTo(1);
  assertThat(IoUtil.inputStreamAsString(task.getVariable(VARIABLE_NAME_FILE)))
    .isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE));
}
 
Example 2
@Test
public void shouldGetAll() {
  // given
  Map<String, TypedValue> variables = new HashMap<>();
  variables.put(VARIABLE_NAME_FILE, VARIABLE_VALUE_FILE);
  variables.put(ANOTHER_VARIABLE_NAME_FILE, Variables.fileValue(VARIABLE_VALUE_FILE_NAME).file(ANOTHER_VARIABLE_VALUE_FILE).create());
  engineRule.startProcessInstance(processDefinition.getId(), variables);

  // when
  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(handler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);

  // then
  assertThat(task.getAllVariables().size()).isEqualTo(2);
  assertThat(IoUtil.inputStreamAsString((InputStream) task.getAllVariables().get(VARIABLE_NAME_FILE)))
    .isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE));
  assertThat(IoUtil.inputStreamAsString((InputStream) task.getAllVariables().get(ANOTHER_VARIABLE_NAME_FILE)))
    .isEqualTo(new String(ANOTHER_VARIABLE_VALUE_FILE));
}
 
Example 3
@Test
public void shouldVerifyDmnDecisionRequirementsGraph() {
  dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DRG_EXAMPLE_DMN));  
  DmnDecisionRequirementsGraph dmnDecisionRequirementsGraph = listener.getDmnDecisionRequirementsGraph();
  Definitions definitions = listener.getDefinitions();
  assertThat(dmnDecisionRequirementsGraph.getKey())
    .isEqualTo(definitions.getId())
    .isEqualTo("dish");
  assertThat(dmnDecisionRequirementsGraph.getName())
    .isEqualTo(definitions.getName())
    .isEqualTo("Dish");
  assertThat(dmnDecisionRequirementsGraph.getDecisions().size()).isEqualTo(3);
  assertThat(dmnDecisionRequirementsGraph.getDecision("dish-decision")).isNotNull();
  assertThat(dmnDecisionRequirementsGraph.getDecision("season")).isNotNull();
  assertThat(dmnDecisionRequirementsGraph.getDecision("guestCount")).isNotNull();
}
 
Example 4
@Test
public void shouldVerifyTransformedDmnDecision() {
  InputStream inputStream =  IoUtil.fileAsStream(DECISION_TRANSFORM_DMN);
  DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);
  dmnEngine.parseDecisionRequirementsGraph(modelInstance);
  
  DmnDecision dmnDecision = listener.getDmnDecision();
  Decision decision = listener.getDecision();

  assertThat(dmnDecision.getKey())
    .isEqualTo(decision.getId())
    .isEqualTo("decision1");
  
  assertThat(dmnDecision.getName())
    .isEqualTo(decision.getName())
    .isEqualTo("camunda");    
}
 
Example 5
Source Project: camunda-engine-dmn   Source File: DmnTransformTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldParseDecisionWithRequiredDecisions() {
  InputStream inputStream = IoUtil.fileAsStream(REQUIRED_DECISIONS_DMN);
  DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);

  DmnDecision buyProductDecision = dmnEngine.parseDecision("buyProduct", modelInstance);
  assertDecision(buyProductDecision, "buyProduct");

  Collection<DmnDecision> buyProductrequiredDecisions = buyProductDecision.getRequiredDecisions();
  assertThat(buyProductrequiredDecisions.size()).isEqualTo(1);

  DmnDecision buyComputerDecision = getDecision(buyProductrequiredDecisions, "buyComputer");
  assertThat(buyComputerDecision).isNotNull();

  Collection<DmnDecision> buyComputerRequiredDecision = buyComputerDecision.getRequiredDecisions();
  assertThat(buyComputerRequiredDecision.size()).isEqualTo(1);

  DmnDecision buyElectronicDecision = getDecision(buyComputerRequiredDecision, "buyElectronic");
  assertThat(buyElectronicDecision).isNotNull();

  assertThat(buyElectronicDecision.getRequiredDecisions().size()).isEqualTo(0);
}
 
Example 6
Source Project: camunda-engine-dmn   Source File: ParseDecisionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailIfDecisionDrgIdIsMissing() {
  try {
    InputStream inputStream = IoUtil.fileAsStream(MISSING_DECISION_REQUIREMENT_DIAGRAM_ID_DMN);
    dmnEngine.parseDecisionRequirementsGraph(inputStream);

    failBecauseExceptionWasNotThrown(DmnTransformException.class);
  }
  catch (DmnTransformException e) {
    assertThat(e)
      .hasCauseExactlyInstanceOf(DmnTransformException.class)
      .hasMessageStartingWith("DMN-02016")
      .hasMessageContaining("DMN-02017")
      .hasMessageContaining("DRD with Missing Id");
  }
}
 
Example 7
Source Project: camunda-bpm-platform   Source File: TaskListenerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateTaskListenerOnAttachmentDelete() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TaskListener.EVENTNAME_UPDATE);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  Attachment attachment = taskService.createAttachment("foo", task.getId(), null, "bar", "baz", IoUtil.stringAsInputStream("foo"));

  // when
  taskService.deleteAttachment(attachment.getId());

  // then
  assertEquals(2, RecorderTaskListener.getTotalEventCount());
  assertEquals(2, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_UPDATE)); // create and delete attachment
}
 
Example 8
@Test
@DecisionResource(resource = DMN_FILE)
public void shouldGetExecutedDecisionElements() {
  evaluateDecision(35, "Weekend",IoUtil.fileAsStream(DMN_FILE));

  DmnDecisionEvaluationEvent evaluationEvent = listener.getEvaluationEvent();
  assertThat(evaluationEvent).isNotNull();
  assertThat(evaluationEvent.getExecutedDecisionElements()).isEqualTo(24L);

  DmnDecisionLogicEvaluationEvent dmnDecisionTableEvaluationEvent = getDmnDecisionTable(evaluationEvent.getRequiredDecisionResults(),"Season");
  assertThat(dmnDecisionTableEvaluationEvent).isNotNull();
  assertThat(dmnDecisionTableEvaluationEvent.getExecutedDecisionElements()).isEqualTo(6L);

  dmnDecisionTableEvaluationEvent = getDmnDecisionTable(evaluationEvent.getRequiredDecisionResults(),"GuestCount");
  assertThat(dmnDecisionTableEvaluationEvent).isNotNull();
  assertThat(dmnDecisionTableEvaluationEvent.getExecutedDecisionElements()).isEqualTo(6L);

}
 
Example 9
@Test
@DecisionResource(resource = DMN_FILE)
public void shouldVerifyRootDecisionResult() {
  evaluateDecision(35, "Weekend", IoUtil.fileAsStream(DMN_FILE));

  assertThat(listener.getEvaluationEvent()).isNotNull();
  DmnDecisionTableEvaluationEvent decisionResult = (DmnDecisionTableEvaluationEvent) listener.getEvaluationEvent().getDecisionResult();
  assertThat(decisionResult).isNotNull();
  assertThat(decisionResult.getDecision().getKey()).isEqualTo("Dish");

  List<DmnEvaluatedInput> inputs = decisionResult.getInputs();
  assertThat(inputs.size()).isEqualTo(2);
  assertThat(inputs.get(0).getName()).isEqualTo("Season");
  assertThat(inputs.get(0).getValue().getValue()).isEqualTo("Summer");
  assertThat(inputs.get(1).getName()).isEqualTo("How many guests");
  assertThat(inputs.get(1).getValue().getValue()).isEqualTo(15);

  assertThat(decisionResult.getMatchingRules().size()).isEqualTo(1);
  Map<String, DmnEvaluatedOutput> outputEntries = decisionResult.getMatchingRules().get(0).getOutputEntries();
  assertThat(outputEntries.size()).isEqualTo(1);
  assertThat(outputEntries.containsKey("desiredDish")).isTrue();
  assertThat(outputEntries.get("desiredDish").getValue().getValue()).isEqualTo("Light salad");
  assertThat(decisionResult.getExecutedDecisionElements()).isEqualTo(12L);

}
 
Example 10
@Test
public void shouldVerifyDmnDecisionRequirementsGraph() {
  dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DRG_EXAMPLE_DMN));  
  DmnDecisionRequirementsGraph dmnDecisionRequirementsGraph = listener.getDmnDecisionRequirementsGraph();
  Definitions definitions = listener.getDefinitions();
  assertThat(dmnDecisionRequirementsGraph.getKey())
    .isEqualTo(definitions.getId())
    .isEqualTo("dish");
  assertThat(dmnDecisionRequirementsGraph.getName())
    .isEqualTo(definitions.getName())
    .isEqualTo("Dish");
  assertThat(dmnDecisionRequirementsGraph.getDecisions().size()).isEqualTo(3);
  assertThat(dmnDecisionRequirementsGraph.getDecision("dish-decision")).isNotNull();
  assertThat(dmnDecisionRequirementsGraph.getDecision("season")).isNotNull();
  assertThat(dmnDecisionRequirementsGraph.getDecision("guestCount")).isNotNull();
}
 
Example 11
@Test
public void shouldVerifyTransformedDmnDecision() {
  InputStream inputStream =  IoUtil.fileAsStream(DECISION_TRANSFORM_DMN);
  DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);
  dmnEngine.parseDecisionRequirementsGraph(modelInstance);
  
  DmnDecision dmnDecision = listener.getDmnDecision();
  Decision decision = listener.getDecision();

  assertThat(dmnDecision.getKey())
    .isEqualTo(decision.getId())
    .isEqualTo("decision1");
  
  assertThat(dmnDecision.getName())
    .isEqualTo(decision.getName())
    .isEqualTo("camunda");    
}
 
Example 12
Source Project: camunda-bpm-platform   Source File: DmnTransformTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldParseDecisionWithRequiredDecisions() {
  InputStream inputStream = IoUtil.fileAsStream(REQUIRED_DECISIONS_DMN);
  DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);

  DmnDecision buyProductDecision = dmnEngine.parseDecision("buyProduct", modelInstance);
  assertDecision(buyProductDecision, "buyProduct");

  Collection<DmnDecision> buyProductrequiredDecisions = buyProductDecision.getRequiredDecisions();
  assertThat(buyProductrequiredDecisions.size()).isEqualTo(1);

  DmnDecision buyComputerDecision = getDecision(buyProductrequiredDecisions, "buyComputer");
  assertThat(buyComputerDecision).isNotNull();

  Collection<DmnDecision> buyComputerRequiredDecision = buyComputerDecision.getRequiredDecisions();
  assertThat(buyComputerRequiredDecision.size()).isEqualTo(1);

  DmnDecision buyElectronicDecision = getDecision(buyComputerRequiredDecision, "buyElectronic");
  assertThat(buyElectronicDecision).isNotNull();

  assertThat(buyElectronicDecision.getRequiredDecisions().size()).isEqualTo(0);
}
 
Example 13
Source Project: camunda-bpm-platform   Source File: DmnTransformTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldTransformDecisionRequirementsGraph() {
  InputStream inputStream = IoUtil.fileAsStream(REQUIRED_DECISIONS_DMN);
  DmnDecisionRequirementsGraph drg = dmnEngine.parseDecisionRequirementsGraph(inputStream);

  assertThat(drg).isNotNull();
  assertThat(drg.getKey()).isEqualTo("buy-decision");
  assertThat(drg.getName()).isEqualTo("Buy Decision");
  assertThat(drg.getDecisionKeys())
    .hasSize(3)
    .contains("buyProduct", "buyComputer", "buyElectronic");

  Collection<DmnDecision> decisions = drg.getDecisions();
  assertThat(decisions)
    .hasSize(3)
    .extracting("key")
    .contains("buyProduct", "buyComputer", "buyElectronic");
}
 
Example 14
Source Project: camunda-bpm-platform   Source File: ParseDecisionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailIfDecisionDrgIdIsMissing() {
  try {
    InputStream inputStream = IoUtil.fileAsStream(MISSING_DECISION_REQUIREMENT_DIAGRAM_ID_DMN);
    dmnEngine.parseDecisionRequirementsGraph(inputStream);

    failBecauseExceptionWasNotThrown(DmnTransformException.class);
  }
  catch (DmnTransformException e) {
    assertThat(e)
      .hasCauseExactlyInstanceOf(DmnTransformException.class)
      .hasMessageStartingWith("DMN-02016")
      .hasMessageContaining("DMN-02017")
      .hasMessageContaining("DRD with Missing Id");
  }
}
 
Example 15
@Test
@DecisionResource(resource = DMN_FILE)
public void shouldGetExecutedDecisionElements() {
  evaluateDecision(35, "Weekend",IoUtil.fileAsStream(DMN_FILE));

  DmnDecisionEvaluationEvent evaluationEvent = listener.getEvaluationEvent();
  assertThat(evaluationEvent).isNotNull();
  assertThat(evaluationEvent.getExecutedDecisionElements()).isEqualTo(24L);

  DmnDecisionLogicEvaluationEvent dmnDecisionTableEvaluationEvent = getDmnDecisionTable(evaluationEvent.getRequiredDecisionResults(),"Season");
  assertThat(dmnDecisionTableEvaluationEvent).isNotNull();
  assertThat(dmnDecisionTableEvaluationEvent.getExecutedDecisionElements()).isEqualTo(6L);

  dmnDecisionTableEvaluationEvent = getDmnDecisionTable(evaluationEvent.getRequiredDecisionResults(),"GuestCount");
  assertThat(dmnDecisionTableEvaluationEvent).isNotNull();
  assertThat(dmnDecisionTableEvaluationEvent.getExecutedDecisionElements()).isEqualTo(6L);

}
 
Example 16
@Test
@DecisionResource(resource = DMN_FILE)
public void shouldVerifyRootDecisionResult() {
  evaluateDecision(35, "Weekend", IoUtil.fileAsStream(DMN_FILE));

  assertThat(listener.getEvaluationEvent()).isNotNull();
  DmnDecisionTableEvaluationEvent decisionResult = (DmnDecisionTableEvaluationEvent) listener.getEvaluationEvent().getDecisionResult();
  assertThat(decisionResult).isNotNull();
  assertThat(decisionResult.getDecision().getKey()).isEqualTo("Dish");

  List<DmnEvaluatedInput> inputs = decisionResult.getInputs();
  assertThat(inputs.size()).isEqualTo(2);
  assertThat(inputs.get(0).getName()).isEqualTo("Season");
  assertThat(inputs.get(0).getValue().getValue()).isEqualTo("Summer");
  assertThat(inputs.get(1).getName()).isEqualTo("How many guests");
  assertThat(inputs.get(1).getValue().getValue()).isEqualTo(15);

  assertThat(decisionResult.getMatchingRules().size()).isEqualTo(1);
  Map<String, DmnEvaluatedOutput> outputEntries = decisionResult.getMatchingRules().get(0).getOutputEntries();
  assertThat(outputEntries.size()).isEqualTo(1);
  assertThat(outputEntries.containsKey("desiredDish")).isTrue();
  assertThat(outputEntries.get("desiredDish").getValue().getValue()).isEqualTo("Light salad");
  assertThat(decisionResult.getExecutedDecisionElements()).isEqualTo(12L);

}
 
Example 17
Source Project: camunda-bpm-platform   Source File: FormServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/DeployedFormsProcess.bpmn20.xml",
    "org/camunda/bpm/engine/test/api/form/start.form",
    "org/camunda/bpm/engine/test/api/form/task.form" })
@Test
public void testGetDeployedStartForm() {
  // given
  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();

  // when
  InputStream deployedStartForm = formService.getDeployedStartForm(procDefId);

  // then
  assertNotNull(deployedStartForm);
  String fileAsString = IoUtil.fileAsString("org/camunda/bpm/engine/test/api/form/start.form");
  String deployedStartFormAsString = IoUtil.inputStreamAsString(deployedStartForm);
  assertEquals(deployedStartFormAsString, fileAsString);
}
 
Example 18
Source Project: camunda-bpm-platform   Source File: FormServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/EmbeddedDeployedFormsProcess.bpmn20.xml",
    "org/camunda/bpm/engine/test/api/form/start.form",
    "org/camunda/bpm/engine/test/api/form/task.form" })
@Test
public void testGetEmbeddedDeployedStartForm() {
  // given
  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();

  // when
  InputStream deployedStartForm = formService.getDeployedStartForm(procDefId);

  // then
  assertNotNull(deployedStartForm);
  String fileAsString = IoUtil.fileAsString("org/camunda/bpm/engine/test/api/form/start.form");
  String deployedStartFormAsString = IoUtil.inputStreamAsString(deployedStartForm);
  assertEquals(deployedStartFormAsString, fileAsString);
}
 
Example 19
Source Project: camunda-bpm-platform   Source File: FormServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/DeployedFormsProcess.bpmn20.xml",
    "org/camunda/bpm/engine/test/api/form/start.form",
    "org/camunda/bpm/engine/test/api/form/task.form" })
@Test
public void testGetDeployedTaskForm() {
  // given
  runtimeService.startProcessInstanceByKey("FormsProcess");
  String taskId = taskService.createTaskQuery().singleResult().getId();

  // when
  InputStream deployedTaskForm = formService.getDeployedTaskForm(taskId);

  // then
  assertNotNull(deployedTaskForm);
  String fileAsString = IoUtil.fileAsString("org/camunda/bpm/engine/test/api/form/task.form");
  String deployedStartFormAsString = IoUtil.inputStreamAsString(deployedTaskForm);
  assertEquals(deployedStartFormAsString, fileAsString);
}
 
Example 20
Source Project: camunda-bpm-platform   Source File: FormServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/DeployedFormsCase.cmmn11.xml",
  "org/camunda/bpm/engine/test/api/form/task.form" })
@Test
public void testGetDeployedTaskForm_Case() {
  // given
  caseService.createCaseInstanceByKey("Case_1");
  String taskId = taskService.createTaskQuery().singleResult().getId();

  // when
  InputStream deployedTaskForm = formService.getDeployedTaskForm(taskId);

  // then
  assertNotNull(deployedTaskForm);
  String fileAsString = IoUtil.fileAsString("org/camunda/bpm/engine/test/api/form/task.form");
  String deployedStartFormAsString = IoUtil.inputStreamAsString(deployedTaskForm);
  assertEquals(deployedStartFormAsString, fileAsString);
}
 
Example 21
public BytesValue convertToTypedValue(UntypedValueImpl untypedValue) {
  byte[] byteArr = null;

  Object value = untypedValue.getValue();
  if (value instanceof byte[]) {
    byteArr = (byte[]) value;
  }
  else {
    byteArr = IoUtil.inputStreamAsByteArray((InputStream) value);
  }

  return Variables.byteArrayValue(byteArr);
}
 
Example 22
@Test
public void shouldGetTyped_Loaded() {
  // given
  engineRule.startProcessInstance(processDefinition.getId(), VARIABLE_NAME_FILE, VARIABLE_VALUE_FILE);

  client.subscribe(EXTERNAL_TASK_TOPIC_FOO)
    .handler(handler)
    .open();

  clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

  ExternalTask task = handler.getHandledTasks().get(0);
  DeferredFileValue deferredFileValue = task.getVariableTyped(VARIABLE_NAME_FILE);

  // assume
  assertThat(deferredFileValue.isLoaded()).isFalse();

  // when
  deferredFileValue.getValue();

  // then
  DeferredFileValue typedValue = task.getVariableTyped(VARIABLE_NAME_FILE);

  assertThat(typedValue.isLoaded()).isTrue();
  assertThat(IoUtil.inputStreamAsString(typedValue.getValue()))
    .isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE));
  assertThat(typedValue.getFilename()).isEqualTo(VARIABLE_VALUE_FILE_NAME);
  assertThat(typedValue.getType()).isEqualTo(FILE);
  assertThat(typedValue.getEncoding()).isNull();
  assertThat(typedValue.getMimeType()).isNull();
}
 
Example 23
@Test
public void shouldCallListener() {
  dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));  
  assertThat(listener.getDmnDecisionRequirementsGraph()).isNotNull();
  assertThat(listener.getDmnDecision()).isNotNull();
  assertThat(listener.getDmnInput()).isNotNull();
  assertThat(listener.getDmnOutput()).isNotNull();
  assertThat(listener.getDmnRule()).isNotNull();
}
 
Example 24
@Test
public void shouldVerifyTransformedDmnDecisions() {
  dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DRG_EXAMPLE_DMN));
  List<DmnDecision> transformedDecisions = listener.getTransformedDecisions();
  assertThat(transformedDecisions.size()).isEqualTo(3);
  
  assertThat(getDmnDecision(transformedDecisions, "dish-decision")).isNotNull();
  assertThat(getDmnDecision(transformedDecisions, "season")).isNotNull();
  assertThat(getDmnDecision(transformedDecisions, "guestCount")).isNotNull();

}
 
Example 25
@Test
public void shouldVerifyTransformedInput() {
  dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));
  DmnDecisionTableInputImpl dmnInput = listener.getDmnInput();
  Input input = listener.getInput();
  
  assertThat(dmnInput.getId())
    .isEqualTo(input.getId())
    .isEqualTo("input1");
  
}
 
Example 26
@Test
public void shouldVerifyTransformedOutput() {
  dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));
  DmnDecisionTableOutputImpl dmnOutput = listener.getDmnOutput();
  Output output = listener.getOutput();
  
  assertThat(dmnOutput.getId())
    .isEqualTo(output.getId())
    .isEqualTo("output1");
  
}
 
Example 27
@Test
public void shouldVerifyTransformedRule() {
  dmnEngine.parseDecisionRequirementsGraph(IoUtil.fileAsStream(DECISION_TRANSFORM_DMN));
  DmnDecisionTableRuleImpl dmnRule = listener.getDmnRule();
  Rule rule = listener.getRule();

  assertThat(dmnRule.getId())
    .isEqualTo(rule.getId())
    .isEqualTo("rule");
  
}
 
Example 28
Source Project: camunda-engine-dmn   Source File: DmnTransformTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldParseDecisionsWithRequiredDecisions() {
  InputStream inputStream = IoUtil.fileAsStream(REQUIRED_DECISIONS_DMN);
  DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);

  List<DmnDecision> decisions = dmnEngine.parseDecisions(modelInstance);

  DmnDecision buyProductDecision = getDecision(decisions, "buyProduct");
  assertThat(buyProductDecision).isNotNull();
  Collection<DmnDecision> requiredProductDecisions = buyProductDecision.getRequiredDecisions();
  assertThat(requiredProductDecisions.size()).isEqualTo(1);

  DmnDecision requiredProductDecision = getDecision(requiredProductDecisions, "buyComputer");
  assertThat(requiredProductDecision).isNotNull();

  DmnDecision buyComputerDecision = getDecision(decisions, "buyComputer");
  assertThat(buyComputerDecision).isNotNull();
  Collection<DmnDecision> buyComputerRequiredDecisions = buyComputerDecision.getRequiredDecisions();
  assertThat(buyComputerRequiredDecisions.size()).isEqualTo(1);

  DmnDecision buyComputerRequiredDecision = getDecision(buyComputerRequiredDecisions, "buyElectronic");
  assertThat(buyComputerRequiredDecision).isNotNull();

  DmnDecision buyElectronicDecision = getDecision(decisions, "buyElectronic");
  assertThat(buyElectronicDecision).isNotNull();

  Collection<DmnDecision> buyElectronicRequiredDecisions = buyElectronicDecision.getRequiredDecisions();
  assertThat(buyElectronicRequiredDecisions.size()).isEqualTo(0);
}
 
Example 29
Source Project: camunda-engine-dmn   Source File: DmnTransformTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldParseDecisionWithMultipleRequiredDecisions() {
  InputStream inputStream = IoUtil.fileAsStream(MULTIPLE_REQUIRED_DECISIONS_DMN);
  DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);
  DmnDecision decision = dmnEngine.parseDecision("car",modelInstance);
  Collection<DmnDecision> requiredDecisions = decision.getRequiredDecisions();
  assertThat(requiredDecisions.size()).isEqualTo(2);

  DmnDecision carPriceDecision = getDecision(requiredDecisions, "carPrice");
  assertThat(carPriceDecision).isNotNull();

  DmnDecision carSpeedDecision = getDecision(requiredDecisions, "carSpeed");
  assertThat(carSpeedDecision).isNotNull();
}
 
Example 30
Source Project: camunda-engine-dmn   Source File: DmnTransformTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDetectLoopInParseDecisionWithRequiredDecision() {
  InputStream inputStream = IoUtil.fileAsStream(LOOP_REQUIRED_DECISIONS_DMN);
  DmnModelInstance modelInstance = Dmn.readModelFromStream(inputStream);

  try {
    decision = dmnEngine.parseDecision("buyProduct", modelInstance);
    failBecauseExceptionWasNotThrown(DmnTransformException.class);
  } catch(DmnTransformException e) {
    Assertions.assertThat(e)
    .hasMessageStartingWith("DMN-02004")
    .hasMessageContaining("DMN-02015")
    .hasMessageContaining("has a loop");
  }
}