Search in sources :

Example 41 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class KsqlResourceTest method shouldFailUnsetPropertyOnInvalidPropertyName.

@Test
public void shouldFailUnsetPropertyOnInvalidPropertyName() {
    // When:
    final KsqlErrorMessage response = makeFailingRequest("UNSET 'ksql.unknown.property';", BAD_REQUEST.code());
    // Then:
    assertThat(response, instanceOf(KsqlStatementErrorMessage.class));
    assertThat(response.getErrorCode(), is(Errors.ERROR_CODE_BAD_STATEMENT));
    assertThat(response.getMessage(), containsString("Unknown property"));
}
Also used : KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 42 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class ServerStateTest method shouldReturnErrorWhenInitializing.

@Test
public void shouldReturnErrorWhenInitializing() {
    // Given:
    final KsqlErrorMessage error = new KsqlErrorMessage(12345, "bad stuff is happening");
    serverState.setInitializingReason(error);
    // When:
    final Optional<EndpointResponse> result = serverState.checkReady();
    // Then:
    assertThat(result.isPresent(), is(true));
    final EndpointResponse response = result.get();
    final EndpointResponse expected = Errors.serverNotReady(error);
    assertThat(response.getStatus(), equalTo(expected.getStatus()));
    assertThat(response.getEntity(), equalTo(expected.getEntity()));
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 43 with KsqlErrorMessage

use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.

the class KsqlRestExceptionMatchers method exceptionErrorMessage.

/**
 * Matches a {@code KsqlRestException} where the response entity holds a {@link KsqlErrorMessage}
 * that matches the supplied matcher.
 *
 * @param expected - see {@link io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers}
 * @return the matcher.
 */
public static Matcher<? super KsqlRestException> exceptionErrorMessage(final Matcher<? super KsqlErrorMessage> expected) {
    return new TypeSafeDiagnosingMatcher<KsqlRestException>() {

        @Override
        protected boolean matchesSafely(final KsqlRestException actual, final Description mismatchDescription) {
            final Object entity = actual.getResponse().getEntity();
            if (!(entity instanceof KsqlErrorMessage)) {
                mismatchDescription.appendText("but entity was instance of ").appendValue(entity.getClass());
                return false;
            }
            final KsqlErrorMessage errorMessage = (KsqlErrorMessage) entity;
            if (!expected.matches(errorMessage)) {
                expected.describeMismatch(errorMessage, mismatchDescription);
                return false;
            }
            return true;
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText(KsqlErrorMessage.class.getSimpleName() + " where ").appendDescriptionOf(expected);
        }
    };
}
Also used : Description(org.hamcrest.Description) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher)

Aggregations

KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)43 Test (org.junit.Test)35 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)5 KsqlStatementErrorMessage (io.confluent.ksql.rest.entity.KsqlStatementErrorMessage)5 IntegrationTest (io.confluent.common.utils.IntegrationTest)4 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)4 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)3 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)3 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)3 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)3 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 Query (io.confluent.ksql.parser.tree.Query)2 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2