) { try { final RestResponse restResponse = restClient.makeRootRequest(); if (restResponse.isErroneous()) { final KsqlErrorMessage ksqlError = restResponse.getErrorMessage();
@Test public void shouldOutputNewServerDetails() { expect(restClient.makeRootRequest()).andReturn(RestResponse.successful(SERVER_INFO)); replay(restClient); command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal); assertThat(out.toString(), containsString("Server now: " + VALID_SERVER_ADDRESS)); }
@Test public void shouldPrintErrorOnErrorResponseFromRestClient() { expect(restClient.makeRootRequest()).andReturn(RestResponse.erroneous( Errors.ERROR_CODE_SERVER_ERROR, "it is broken")); replay(restClient); command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal); assertThat(out.toString(), containsString("it is broken")); }
@Test public void shouldPrintServerAddressWhenEmptyStringArg() throws Exception { expect(restClient.makeRootRequest()).andReturn(RestResponse.successful(SERVER_INFO)); expect(restClient.getServerAddress()).andReturn(new URI(INITIAL_SERVER_ADDRESS)); restClient.setServerAddress(anyString()); expectLastCall().andThrow(new AssertionError("should not set address")); replay(restClient); command.execute(ImmutableList.of(), terminal); assertThat(out.toString(), equalTo(INITIAL_SERVER_ADDRESS + "\n")); }
@Test public void shouldPrintErrorWhenCantConnectToNewAddress() { expect(restClient.makeRootRequest()).andThrow( new KsqlRestClientException("Failed to connect", new ProcessingException("Boom"))); replay(restClient); command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal); assertThat(out.toString(), containsString("Boom")); assertThat(out.toString(), containsString("Failed to connect")); }
@Test public void shouldRestClientServerAddressWhenNonEmptyStringArg() { expect(restClient.makeRootRequest()).andReturn(RestResponse.successful(SERVER_INFO)); restClient.setServerAddress(VALID_SERVER_ADDRESS); expectLastCall(); replay(restClient); command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal); verify(restClient); }
@Test public void shouldPrintErrorIfCantConnectToRestServer() throws Exception { givenRunInteractivelyWillExit(); final KsqlRestClient mockRestClient = EasyMock.mock(KsqlRestClient.class); EasyMock.expect(mockRestClient.makeRootRequest()).andThrow(new KsqlRestClientException("Boom", new ProcessingException(""))); EasyMock.expect(mockRestClient.getServerInfo()).andReturn( RestResponse.of(new ServerInfo("1.x", "testClusterId", "testServiceId"))); EasyMock.expect(mockRestClient.getServerAddress()).andReturn(new URI("http://someserver:8008")).anyTimes(); EasyMock.replay(mockRestClient); new Cli(1L, 1L, mockRestClient, console) .runInteractively(); assertThat(terminal.getOutputString(), containsString("Remote server address may not be valid")); }
@Test public void shouldPrintErrorOnUnsupportedAPI() throws Exception { givenRunInteractivelyWillExit(); final KsqlRestClient mockRestClient = EasyMock.mock(KsqlRestClient.class); EasyMock.expect(mockRestClient.makeRootRequest()).andReturn( RestResponse.erroneous( new KsqlErrorMessage( Errors.toErrorCode(NOT_ACCEPTABLE.getStatusCode()), "Minimum supported client version: 1.0"))); EasyMock.expect(mockRestClient.getServerInfo()).andReturn( RestResponse.of(new ServerInfo("1.x", "testClusterId", "testServiceId"))); EasyMock.expect(mockRestClient.getServerAddress()).andReturn(new URI("http://someserver:8008")); EasyMock.replay(mockRestClient); new Cli(1L, 1L, mockRestClient, console) .runInteractively(); Assert.assertThat( terminal.getOutputString(), containsString("This CLI version no longer supported")); Assert.assertThat( terminal.getOutputString(), containsString("Minimum supported client version: 1.0")); }