ClientDelegator extends BaseDelegator implements IClientDelegator { static IClient getClientOrNullFromHelixResultMap( @Nullable final List<Map<String, Object>> resultMaps, @Nullable final GetClientTemplateOptions opts, @Nonnull final IOptionsServer server, @Nonnull final BiPredicate<Map<String, Object>, GetClientTemplateOptions> conditions, @Nonnull final Function<Map<String, Object>, Boolean> handle) throws AccessException, RequestException { IClient client = null; if (nonNull(resultMaps)) { for (Map<String, Object> map : resultMaps) { if (nonNull(map)) { if (handle.apply(map)) { if (conditions.test(map, opts)) { client = new Client(server, map); } } } } } return client; } ClientDelegator(IOptionsServer server); @Override IClient getClient(final String clientName); @Override IClient getClient(@Nonnull IClientSummary clientSummary); @Override IClient getClientTemplate(String clientName); @Override IClient getClientTemplate(final String clientName, final boolean allowExistent); @Override IClient getClientTemplate(
			@Nonnull String clientName,
			GetClientTemplateOptions getClientTemplateOptions); @Override String createClient(@Nonnull final IClient newClient); @Override void createTempClient(@Nonnull final IClient newClient); @Override String updateClient(@Nonnull final IClient client); @Override String updateClient(@Nonnull final IClient client, final boolean force); @Override String updateClient(@Nonnull final IClient client, final UpdateClientOptions opts); @Override String deleteClient(final String clientName, final boolean force); @Override String deleteClient(final String clientName, final DeleteClientOptions opts); String switchClientView(final String templateClientName,
								   final String targetClientName,
								   final SwitchClientViewOptions opts); @Override String switchStreamView(final String streamPath,
								   final String targetClientName,
								   final SwitchClientViewOptions opts);  }
@Test public void getClientOrNullFromHelixResultMap_shouldReturnNullWhenResultMapsIsNull() throws Exception { IClient client = ClientDelegator.getClientOrNullFromHelixResultMap( null, mock(GetClientTemplateOptions.class), server, mock(BiPredicate.class), mock(Function.class)); assertNull(client); }
@Test public void getClientOrNullFromHelixResultMap_shouldReturnNullWhenResultMapsIsEmpty() throws Exception { resultMaps = Collections.EMPTY_LIST; IClient client = ClientDelegator.getClientOrNullFromHelixResultMap( resultMaps, mock(GetClientTemplateOptions.class), server, mock(BiPredicate.class), mock(Function.class)); assertNull(client); }
@Test public void getClientOrNullFromHelixResultMap_shouldReturnNullBecauseAllResultMapIsInfoMessage() throws Exception { when(handle.apply(any())).thenReturn(true); IClient client = ClientDelegator.getClientOrNullFromHelixResultMap( resultMaps, mock(GetClientTemplateOptions.class), server, mock(BiPredicate.class), handle); assertNull(client); }
@Test public void getClientOrNullFromHelixResultMap_shouldReturnNullBecauseAllResultMapPredicateTestFailed() throws Exception { when(resultMap.get(E_FAILED)).thenReturn(EMPTY); BiPredicate<Map<String, Object>, GetClientTemplateOptions> conditions = mock(BiPredicate.class); when(conditions.test(any(), any())).thenReturn(false); when(handle.apply(any())).thenReturn(true); IClient client = ClientDelegator.getClientOrNullFromHelixResultMap( resultMaps, mock(GetClientTemplateOptions.class), server, conditions, handle); assertNull(client); }
@Test public void getClientOrNullFromHelixResultMap_shouldThrowAccessExceptionThatWasThrownFromHandleErrorStr() throws Exception { when(resultMap.get(E_FAILED)).thenReturn(EMPTY); thrown.expect(IllegalStateException.class); ClientDelegator.getClientOrNullFromHelixResultMap( resultMaps, mock(GetClientTemplateOptions.class), server, mock(BiPredicate.class), (o) -> { throw new IllegalStateException(); }); }
@Test public void getClientOrNullFromHelixResultMap_shouldReturnNonNullClient() throws Exception { when(resultMap.get(E_FAILED)).thenReturn(EMPTY); BiPredicate conditions = mock(BiPredicate.class); when(conditions.test(any(), any())).thenReturn(true); when(handle.apply(any())).thenReturn(true); IClient client = ClientDelegator.getClientOrNullFromHelixResultMap( resultMaps, mock(GetClientTemplateOptions.class), server, conditions, handle); assertNotNull(client); }