if (errorMessageMatcher != null && !errorMessageMatcher.matches(error.getErrorMessage())) { matchers.add(errorMessageMatcher);
@Test public void messageErrorBinding() throws Exception { Error error = mock(Error.class); when(error.getErrorMessage()).thenReturn(Message.of(new Integer[] {1, 3, 6})); Optional opt = Optional.of(error); CoreEvent event = getEventWithError(opt); doReturn(testEvent().getMessage()).when(event).getMessage(); String expression = "error.errorMessage.payload reduce ($$ + $)"; TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build()); assertThat(result.getValue(), is(10)); }
@Test public void buildErrorFromCustomException() { Error error = builder(new ComposedErrorMessageAwareException(createStaticMessage(EXCEPTION_MESSAGE))) .errorType(mockErrorType) .build(); assertThat(error.getDescription(), is(EXCEPTION_MESSAGE)); assertThat(error.getDetailedDescription(), is(EXCEPTION_MESSAGE)); assertThat(error.getCause(), is(instanceOf(ComposedErrorMessageAwareException.class))); assertThat(error.getErrorType(), is(mockErrorType)); assertThat(error.getErrorMessage().getPayload().getValue(), is(TEST_PAYLOAD)); List<Error> childErrors = error.getChildErrors(); assertThat(childErrors, hasSize(2)); assertThat(childErrors.get(0).getCause(), is(instanceOf(RuntimeException.class))); assertThat(childErrors.get(1).getCause(), is(instanceOf(IOException.class))); }
@Test public void buildError() { String detailedDescription = "detailed description"; String description = "description"; ErrorType errorType = mockErrorType; Message errorMessage = of(null); IllegalArgumentException exception = new IllegalArgumentException("some message"); Error error = builder() .errorType(errorType) .description(description) .detailedDescription(detailedDescription) .exception(exception) .errorMessage(errorMessage) .build(); assertThat(error.getDescription(), is(description)); assertThat(error.getDetailedDescription(), is(detailedDescription)); assertThat(error.getCause(), is(exception)); assertThat(error.getErrorType(), is(errorType)); assertThat(error.getErrorMessage(), is(errorMessage)); assertThat(error.getChildErrors(), is(empty())); }
/** * Constructor to create a new builder using the information of another error for default error parametrization. * * @param e the error to base on */ private ErrorBuilder(Error e) { this.description = e.getDescription(); this.detailedDescription = e.getDetailedDescription(); this.exception = e.getCause(); this.errorType = e.getErrorType(); this.errorMessage = e.getErrorMessage(); this.errors = e.getChildErrors(); }
@Test public void messageErrorBinding() throws Exception { Error error = mock(Error.class); when(error.getErrorMessage()).thenReturn(Message.of(new Integer[] {1, 3, 6})); Optional opt = Optional.of(error); CoreEvent event = getEventWithError(opt); doReturn(testEvent().getMessage()).when(event).getMessage(); String expression = "error.errorMessage.payload reduce ($$ + $)"; TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build()); assertThat(result.getValue(), is(10)); }
@Test public void buildErrorFromCustomException() { Error error = builder(new ComposedErrorMessageAwareException(createStaticMessage(EXCEPTION_MESSAGE))) .errorType(mockErrorType) .build(); assertThat(error.getDescription(), is(EXCEPTION_MESSAGE)); assertThat(error.getDetailedDescription(), is(EXCEPTION_MESSAGE)); assertThat(error.getCause(), is(instanceOf(ComposedErrorMessageAwareException.class))); assertThat(error.getErrorType(), is(mockErrorType)); assertThat(error.getErrorMessage().getPayload().getValue(), is(TEST_PAYLOAD)); List<Error> childErrors = error.getChildErrors(); assertThat(childErrors, hasSize(2)); assertThat(childErrors.get(0).getCause(), is(instanceOf(RuntimeException.class))); assertThat(childErrors.get(1).getCause(), is(instanceOf(IOException.class))); }
@Test public void buildError() { String detailedDescription = "detailed description"; String description = "description"; ErrorType errorType = mockErrorType; Message errorMessage = of(null); IllegalArgumentException exception = new IllegalArgumentException("some message"); Error error = builder() .errorType(errorType) .description(description) .detailedDescription(detailedDescription) .exception(exception) .errorMessage(errorMessage) .build(); assertThat(error.getDescription(), is(description)); assertThat(error.getDetailedDescription(), is(detailedDescription)); assertThat(error.getCause(), is(exception)); assertThat(error.getErrorType(), is(errorType)); assertThat(error.getErrorMessage(), is(errorMessage)); assertThat(error.getChildErrors(), is(empty())); }