Search in sources :

Example 1 with KsqlStatementErrorMessage

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"));
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 2 with KsqlStatementErrorMessage

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);
        }
    };
}
Also used : Description(org.hamcrest.Description) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher)

Example 3 with KsqlStatementErrorMessage

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);
    }
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) Buffer(io.vertx.core.buffer.Buffer) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Aggregations

KsqlStatementErrorMessage (io.confluent.ksql.rest.entity.KsqlStatementErrorMessage)3 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)1 KsqlException (io.confluent.ksql.util.KsqlException)1 Buffer (io.vertx.core.buffer.Buffer)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Description (org.hamcrest.Description)1 TypeSafeDiagnosingMatcher (org.hamcrest.TypeSafeDiagnosingMatcher)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1