use of io.confluent.ksql.rest.entity.KsqlStatementErrorMessage in project ksql by confluentinc.
the class KsqlResourceTest method shouldThrowOnDenyListValidatorWhenTerminateCluster.
@Test
public void shouldThrowOnDenyListValidatorWhenTerminateCluster() {
final Map<String, Object> terminateStreamProperties = ImmutableMap.of(DELETE_TOPIC_LIST_PROP, Collections.singletonList("Foo"));
// Given:
doThrow(new KsqlException("deny override")).when(denyListPropertyValidator).validateAll(terminateStreamProperties);
// When:
final EndpointResponse response = ksqlResource.terminateCluster(securityContext, VALID_TERMINATE_REQUEST);
// Then:
verify(denyListPropertyValidator).validateAll(terminateStreamProperties);
assertThat(response.getStatus(), equalTo(INTERNAL_SERVER_ERROR.code()));
assertThat(response.getEntity(), instanceOf(KsqlStatementErrorMessage.class));
assertThat(((KsqlStatementErrorMessage) response.getEntity()).getMessage(), containsString("deny override"));
}
use of io.confluent.ksql.rest.entity.KsqlStatementErrorMessage in project ksql by confluentinc.
the class KsqlRestExceptionMatchers method exceptionStatementErrorMessage.
/**
* Matches a {@code KsqlRestException} where the response entity holds a
* {@link KsqlStatementErrorMessage} that matches the supplied matcher.
*
* @param expected - see {@link io.confluent.ksql.rest.entity.KsqlStatementErrorMessageMatchers}
* @return the matcher.
*/
public static Matcher<? super KsqlRestException> exceptionStatementErrorMessage(final Matcher<? super KsqlStatementErrorMessage> expected) {
return new TypeSafeDiagnosingMatcher<KsqlRestException>() {
@Override
protected boolean matchesSafely(final KsqlRestException actual, final Description mismatchDescription) {
final Object entity = actual.getResponse().getEntity();
if (!(entity instanceof KsqlStatementErrorMessage)) {
mismatchDescription.appendText("but entity was instance of ").appendValue(entity.getClass());
return false;
}
final KsqlStatementErrorMessage errorMessage = (KsqlStatementErrorMessage) entity;
if (!expected.matches(errorMessage)) {
expected.describeMismatch(errorMessage, mismatchDescription);
return false;
}
return true;
}
@Override
public void describeTo(final Description description) {
description.appendText(KsqlStatementErrorMessage.class.getSimpleName() + " where ").appendDescriptionOf(expected);
}
};
}
use of io.confluent.ksql.rest.entity.KsqlStatementErrorMessage in project ksql by confluentinc.
the class FailureHandler method handleError.
private static void handleError(final HttpServerResponse response, final int statusCode, final int errorCode, final String errMsg, final Optional<String> statement) {
if (statement.isPresent()) {
final KsqlStatementErrorMessage errorResponse = new KsqlStatementErrorMessage(errorCode, errMsg, statement.get(), new KsqlEntityList());
final Buffer buffer = ServerUtils.serializeObject(errorResponse);
response.setStatusCode(statusCode).end(buffer);
} else {
final KsqlErrorMessage errorResponse = new KsqlErrorMessage(errorCode, errMsg);
final Buffer buffer = ServerUtils.serializeObject(errorResponse);
response.setStatusCode(statusCode).end(buffer);
}
}
Aggregations