ClientClusterManagementService implements ClusterManagementService { @Override public <T extends AbstractConfiguration<?>> ClusterManagementRealizationResult create(T config) { ClusterManagementRealizationResult result = transport.submitMessage(config, config.getCreationCommandType()); assertSuccessful(result); return result; } ClientClusterManagementService(ClusterManagementServiceTransport transport); @Override ClusterManagementRealizationResult create(T config); @Override ClusterManagementRealizationResult delete(
      T config); @Override ClusterManagementRealizationResult update(
      T config); @Override ClusterManagementListResult<T, R> list(
      T config); @Override ClusterManagementGetResult<T, R> get(
      T config); @Override ClusterManagementOperationResult<A, V> start(
      A op); @Override ClusterManagementOperationResult<A, V> get(
      A opType, String opId); @Override CompletableFuture<ClusterManagementOperationResult<A, V>> getFuture(
      A opType, String opId); @Override ClusterManagementListOperationsResult<A, V> list(
      A opType); @Override boolean isConnected(); @Override void close();  }
@Test public void createCallsSubmitMessageAndReturnsResult() { when(serviceTransport.submitMessage(any(), any())).thenReturn(successRealizationResult); when(configuration.getCreationCommandType()).thenReturn(CommandType.CREATE); ClusterManagementRealizationResult realizationResult = service.create(configuration); assertThat(realizationResult).isSameAs(successRealizationResult); verify(serviceTransport).submitMessage(same(configuration), same(CommandType.CREATE)); }
@Test public void createWithNullResultThrows() { when(serviceTransport.submitMessage(any(), any())).thenReturn(null); assertThatThrownBy(() -> service.create(configuration)) .hasMessageContaining("Unable to parse server response."); }
@Test public void createWithFailedResult() { ClusterManagementRealizationResult realizationResult = mock(ClusterManagementRealizationResult.class); when(realizationResult.isSuccessful()).thenReturn(false); when(serviceTransport.submitMessage(any(), any())).thenReturn(realizationResult); Throwable throwable = catchThrowable(() -> service.create(configuration)); assertThat(throwable).isInstanceOf(ClusterManagementException.class); assertThat(((ClusterManagementException) throwable).getResult()).isSameAs(realizationResult); }