public Object get() { if (isSuccessful()) { return getResponse(); } else { return getErrorMessage(); } }
@Override public boolean hasNext() { if (bufferedRow != null) { return true; } return bufferNextRow(); }
public KsqlRestClient(final String serverAddress, final Map<String, Object> localProperties) { this(buildClient(), serverAddress, localProperties); }
@Test public void shouldHandleUnauthorizedOnGetRequests() { // Given: givenServerWillReturn(Status.UNAUTHORIZED); // When: final RestResponse<?> response = ksqlRestClient.getServerInfo(); // Then: assertThat(response.getErrorMessage().getErrorCode(), is(Errors.ERROR_CODE_UNAUTHORIZED)); assertThat(response.getErrorMessage().getMessage(), is("Could not authenticate successfully with the supplied credentials.")); }
@Test public void shouldHandleForbiddenOnPostRequests() { // Given: givenServerWillReturn(Status.FORBIDDEN); // When: final RestResponse<?> response = ksqlRestClient.makeKsqlRequest("whateva"); // Then: assertThat(response.getErrorMessage().getErrorCode(), is(Errors.ERROR_CODE_FORBIDDEN)); assertThat(response.getErrorMessage().getMessage(), is("You are forbidden from using this cluster.")); }
@Test public void shouldHandleSuccessOnGetRequests() { // Given: final ServerInfo expectedEntity = new ServerInfo("1", "cid", "sid"); givenServerWillReturn(expectedEntity); // When: final RestResponse<ServerInfo> response = ksqlRestClient.getServerInfo(); // Then: assertThat(response.get(), is(expectedEntity)); }
@Test public void shouldHandleSuccessOnPostRequests() { // Given: final KsqlEntityList expectedEntity = new KsqlEntityList(); givenServerWillReturn(expectedEntity); // When: final RestResponse<KsqlEntityList> response = ksqlRestClient.makeKsqlRequest("foo"); // Then: assertThat(response.get(), is(expectedEntity)); }
public RestResponse<ServerInfo> makeRootRequest() { return getServerInfo(); }
public static <R> RestResponse<R> of(final R response) { return successful(response); }
public static <R> RestResponse<R> of(final KsqlErrorMessage errorMessage) { return erroneous(errorMessage); }
public RestResponse<ServerInfo> getServerInfo() { return getRequest("/info", ServerInfo.class); }
public void setServerAddress(final String serverAddress) { this.serverAddress = parseServerAddress(serverAddress); }
public static <R> RestResponse<R> erroneous(final KsqlErrorMessage errorMessage) { return new Erroneous<>(errorMessage); }
public static <R> RestResponse<R> successful(final R response) { return new Successful<>(response); }
public KsqlRestClient(final String serverAddress, final Properties properties) { this(serverAddress, propertiesToMap(properties)); }
@Test public void shouldHandleNotFoundOnGetRequests() { // Given: givenServerWillReturn(Status.NOT_FOUND); // When: final RestResponse<?> response = ksqlRestClient.getServerInfo(); // Then: assertThat(response.getErrorMessage().getErrorCode(), is(404)); assertThat(response.getErrorMessage().getMessage(), containsString("Path not found. Path='/info'. " + "Check your ksql http url to make sure you are connecting to a ksql server.")); }
@Test public void shouldHandleNotFoundOnPostRequests() { // Given: givenServerWillReturn(Status.NOT_FOUND); // When: final RestResponse<?> response = ksqlRestClient.makeKsqlRequest("whateva"); // Then: assertThat(response.getErrorMessage().getErrorCode(), is(404)); assertThat(response.getErrorMessage().getMessage(), containsString("Path not found. Path='ksql'. " + "Check your ksql http url to make sure you are connecting to a ksql server.")); }
public RestResponse<CommandStatuses> makeStatusRequest() { return getRequest("status", CommandStatuses.class); }
@Test public void shouldHandleForbiddendOnGetRequests() { // Given: givenServerWillReturn(Status.FORBIDDEN); // When: final RestResponse<?> response = ksqlRestClient.getServerInfo(); // Then: assertThat(response.getErrorMessage().getErrorCode(), is(Errors.ERROR_CODE_FORBIDDEN)); assertThat(response.getErrorMessage().getMessage(), is("You are forbidden from using this cluster.")); }
@Test public void shouldHandleUnauthorizedOnPostRequests() { // Given: givenServerWillReturn(Status.UNAUTHORIZED); // When: final RestResponse<?> response = ksqlRestClient.makeKsqlRequest("whateva"); // Then: assertThat(response.getErrorMessage().getErrorCode(), is(Errors.ERROR_CODE_UNAUTHORIZED)); assertThat(response.getErrorMessage().getMessage(), is("Could not authenticate successfully with the supplied credentials.")); }