ClientDelegator extends BaseDelegator implements IClientDelegator { @Override public IClient getClient(final String clientName) throws ConnectionException, RequestException, AccessException { Validate.notBlank(clientName, "Null or empty client name passed in updateClient()"); List<Map<String, Object>> resultMaps = execMapCmdList( CLIENT, new String[]{"-o", clientName}, null); return getClientOrNullFromHelixResultMap( resultMaps, null, server, new BiPredicate<Map<String, Object>, GetClientTemplateOptions>() { @Override public boolean test(Map<String, Object> map, GetClientTemplateOptions opts) { return isExistClientOrLabelOrUser(map); } }, rethrowFunction( new FunctionWithException<Map<String, Object>, Boolean>() { @Override public Boolean apply(Map<String, Object> map) throws P4JavaException { return !handleErrorStr(map) && !isInfoMessage(map); } } ) ); } 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 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 getClient_shouldThrowNullPointerExceptionWhenClientNameIsNull() throws Exception { clientName = null; expectThrows(NullPointerException.class, () -> clientDelegator.getClient(clientName)); }
@Test public void getClient_shouldReturnNonNullIClientWithGivenName() throws Exception { doReturn(resultMaps).when(server) .execMapCmdList(eq(CLIENT.toString()), eq(new String[]{"-o", clientName}), eq(null)); when(resultMap.get(E_FAILED)).thenReturn(EMPTY); when(resultMap.get(CODE0)).thenReturn(MESSAGE_CODE_NOT_IN_INFO_RANGE); when(resultMap.containsKey(MapKeys.UPDATE_KEY)).thenReturn(true); IClient client = clientDelegator.getClient(clientName); assertNotNull(client); }
@Test public void getClient_ByClientSummary_shouldReturnNullPointerExceptionWhenClientSummaryIsNull() throws Exception { clientSummary = null; expectThrows(NullPointerException.class, () -> clientDelegator.getClient(clientSummary)); }
@Test public void getClient_ByClientSummary_shouldReturnNonNullClient() throws Exception { doReturn(mockClient).when(clientDelegator).getClient(any(String.class)); IClient client = clientDelegator.getClient(clientSummary); assertThat(client, is(mockClient)); verify(clientSummary).getName(); }