Search in sources :

Example 1 with DmnEngineException

use of org.camunda.bpm.dmn.engine.DmnEngineException in project camunda-engine-dmn by camunda.

the class DmnEngineApiTest method shouldFailEvaluatingDecisionIfDecisionLogicIsNotSupported.

@Test
public void shouldFailEvaluatingDecisionIfDecisionLogicIsNotSupported() {
    DmnDecisionImpl decision = new DmnDecisionImpl();
    decision.setKey("decision");
    decision.setDecisionLogic(mock(DmnDecisionLogic.class));
    try {
        dmnEngine.evaluateDecision(decision, variables);
        failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (DmnEngineException e) {
        assertThat(e).hasMessageStartingWith("DMN-01012");
    }
}
Also used : DmnDecisionImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl) DmnDecisionLogic(org.camunda.bpm.dmn.engine.DmnDecisionLogic) DmnEngineException(org.camunda.bpm.dmn.engine.DmnEngineException) Test(org.junit.Test) DmnEngineTest(org.camunda.bpm.dmn.engine.test.DmnEngineTest)

Example 2 with DmnEngineException

use of org.camunda.bpm.dmn.engine.DmnEngineException in project camunda-bpm-platform by camunda.

the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecision_DmnEngineException.

@Test
public void testEvaluateDecision_DmnEngineException() {
    String message = "expected message";
    when(decisionEvaluationBuilderMock.evaluate()).thenThrow(new DmnEngineException(message));
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", Collections.emptyMap());
    given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON).body("type", is(RestException.class.getSimpleName())).body("message", containsString(message)).when().post(EVALUATE_DECISION_URL);
}
Also used : HashMap(java.util.HashMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) DmnEngineException(org.camunda.bpm.dmn.engine.DmnEngineException) Test(org.junit.Test)

Example 3 with DmnEngineException

use of org.camunda.bpm.dmn.engine.DmnEngineException in project camunda-bpm-platform by camunda.

the class DecisionDefinitionResourceImpl method evaluateDecision.

@Override
public List<Map<String, VariableValueDto>> evaluateDecision(UriInfo context, EvaluateDecisionDto parameters) {
    DecisionService decisionService = engine.getDecisionService();
    Map<String, Object> variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
    try {
        DmnDecisionResult decisionResult = decisionService.evaluateDecisionById(decisionDefinitionId).variables(variables).evaluate();
        return createDecisionResultDto(decisionResult);
    } catch (AuthorizationException e) {
        throw e;
    } catch (NotFoundException e) {
        String errorMessage = String.format("Cannot evaluate decision %s: %s", decisionDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.NOT_FOUND, e, errorMessage);
    } catch (NotValidException e) {
        String errorMessage = String.format("Cannot evaluate decision %s: %s", decisionDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.BAD_REQUEST, e, errorMessage);
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot evaluate decision %s: %s", decisionDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    } catch (DmnEngineException e) {
        String errorMessage = String.format("Cannot evaluate decision %s: %s", decisionDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    }
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) NotValidException(org.camunda.bpm.engine.exception.NotValidException) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) DmnEngineException(org.camunda.bpm.dmn.engine.DmnEngineException) DecisionService(org.camunda.bpm.engine.DecisionService)

Example 4 with DmnEngineException

use of org.camunda.bpm.dmn.engine.DmnEngineException in project camunda-bpm-platform by camunda.

the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecisionByKey_DmnEngineException.

@Test
public void testEvaluateDecisionByKey_DmnEngineException() {
    String message = "expected message";
    when(decisionEvaluationBuilderMock.evaluate()).thenThrow(new DmnEngineException(message));
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", Collections.emptyMap());
    given().pathParam("key", MockProvider.EXAMPLE_DECISION_DEFINITION_KEY).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON).body("type", is(RestException.class.getSimpleName())).body("message", containsString(message)).when().post(EVALUATE_DECISION_BY_KEY_URL);
}
Also used : HashMap(java.util.HashMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) DmnEngineException(org.camunda.bpm.dmn.engine.DmnEngineException) Test(org.junit.Test)

Aggregations

DmnEngineException (org.camunda.bpm.dmn.engine.DmnEngineException)4 RestException (org.camunda.bpm.engine.rest.exception.RestException)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DmnDecisionLogic (org.camunda.bpm.dmn.engine.DmnDecisionLogic)1 DmnDecisionResult (org.camunda.bpm.dmn.engine.DmnDecisionResult)1 DmnDecisionImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionImpl)1 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 DecisionService (org.camunda.bpm.engine.DecisionService)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)1 NotValidException (org.camunda.bpm.engine.exception.NotValidException)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1