use of io.confluent.ksql.rest.entity.ErrorEntity in project ksql by confluentinc.
the class ClientTest method shouldFailOnErrorEntityFromExecuteStatement.
@Test
public void shouldFailOnErrorEntityFromExecuteStatement() {
// Given
final ErrorEntity entity = new ErrorEntity("create connector;", "error msg");
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
// When
final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
ExecutionException.class, () -> javaClient.executeStatement("create connector;").get());
// Then
assertThat(e.getCause(), instanceOf(KsqlClientException.class));
assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_USAGE_DOC));
assertThat(e.getCause().getMessage(), containsString("Use the createConnector, dropConnector, describeConnector or listConnectors methods instead"));
}
use of io.confluent.ksql.rest.entity.ErrorEntity in project ksql by confluentinc.
the class ConsoleTest method shouldPrintErrorEntityLongJson.
@Test
public void shouldPrintErrorEntityLongJson() throws IOException {
// Given:
final KsqlEntity entity = new ErrorEntity("statementText", new ObjectMapper().writeValueAsString(ImmutableMap.of("foo", "bar", "message", "a " + StringUtils.repeat("really ", 20) + " long message")));
// When:
console.printKsqlEntityList(ImmutableList.of(entity));
// Then:
final String output = terminal.getOutputString();
Approvals.verify(output, approvalOptions);
}
use of io.confluent.ksql.rest.entity.ErrorEntity in project ksql by confluentinc.
the class ConnectExecutorTest method shouldReturnErrorIfConnectorTypeIsEmpty.
@Test
public void shouldReturnErrorIfConnectorTypeIsEmpty() {
// Given:
final CreateConnector createConnectorEmptyType = new CreateConnector("foo", ImmutableMap.of("connector.class", new StringLiteral(" ")), Type.SOURCE, false);
final ConfiguredStatement<CreateConnector> createConnectorEmptyTypeConfigured = ConfiguredStatement.of(PreparedStatement.of("CREATE SOURCE CONNECTOR foo WITH ('connector.class'=' ');", createConnectorEmptyType), SessionConfig.of(CONFIG, ImmutableMap.of()));
// When:
final Optional<KsqlEntity> entity = EXECUTOR.execute(createConnectorEmptyTypeConfigured, mock(SessionProperties.class), null, serviceContext).getEntity();
// Then:
assertThat("Expected non-empty response", entity.isPresent());
assertThat(entity.get(), instanceOf(ErrorEntity.class));
final String expectedError = "Validation error: Connector type cannot be empty";
assertThat(((ErrorEntity) entity.get()).getErrorMessage(), is(expectedError));
}
use of io.confluent.ksql.rest.entity.ErrorEntity in project ksql by confluentinc.
the class ConnectExecutorTest method shouldReturnErrorIfConnectorTypeIsMissing.
@Test
public void shouldReturnErrorIfConnectorTypeIsMissing() {
// Given:
final CreateConnector createConnectorMissingType = new CreateConnector("connector-name", ImmutableMap.of("foo", new StringLiteral("bar")), Type.SOURCE, false);
final ConfiguredStatement<CreateConnector> createConnectorMissingTypeConfigured = ConfiguredStatement.of(PreparedStatement.of("CREATE SOURCE CONNECTOR foo WITH ('foo'='bar');", createConnectorMissingType), SessionConfig.of(CONFIG, ImmutableMap.of()));
// When:
final Optional<KsqlEntity> entity = EXECUTOR.execute(createConnectorMissingTypeConfigured, mock(SessionProperties.class), null, serviceContext).getEntity();
// Then:
assertThat("Expected non-empty response", entity.isPresent());
assertThat(entity.get(), instanceOf(ErrorEntity.class));
final String expectedError = "Validation error: " + "Connector config {name=connector-name, foo=bar} contains no connector type";
assertThat(((ErrorEntity) entity.get()).getErrorMessage(), is(expectedError));
}
use of io.confluent.ksql.rest.entity.ErrorEntity in project ksql by confluentinc.
the class ConnectExecutorTest method shouldReturnErrorEntityOnValidationError.
@Test
public void shouldReturnErrorEntityOnValidationError() {
// Given:
givenValidationError();
givenCreationSuccess();
// When:
final Optional<KsqlEntity> entity = EXECUTOR.execute(CREATE_CONNECTOR_CONFIGURED, mock(SessionProperties.class), null, serviceContext).getEntity();
// Then:
assertThat("Expected non-empty response", entity.isPresent());
assertThat(entity.get(), instanceOf(ErrorEntity.class));
final String expectedError = "Validation error: name - Name is missing\n" + "hostname - Hostname is required. Some other error";
assertThat(((ErrorEntity) entity.get()).getErrorMessage(), is(expectedError));
}
Aggregations