ClientDelegator extends BaseDelegator implements IClientDelegator { @Override public IClient getClientTemplate(String clientName) throws ConnectionException, RequestException, AccessException { return getClientTemplate(clientName, false); } 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 getClientTemplate_shouldReturnConnectionExceptionThatWasThrownFromInnerGetClientTemplate() throws Exception { doThrow(ConnectionException.class) .when(clientDelegator) .getClientTemplate(eq(clientName), eq(false)); thrown.expect(ConnectionException.class); clientDelegator.getClientTemplate(clientName); }
@Test public void getClientTemplate_shouldReturnNonNullClient() throws Exception { doReturn(mockClient) .when(clientDelegator) .getClientTemplate(eq(clientName), eq(false)); IClient client = clientDelegator.getClientTemplate(clientName); assertThat(client, is(mockClient)); }
@Test public void getClientTemplate_ByNameAndAllowExistent_shouldReturnNonNullClient() throws Exception { doReturn(mockClient).when(clientDelegator) .getClientTemplate(eq(clientName), any(GetClientTemplateOptions.class)); IClient client = clientDelegator.getClientTemplate(clientName, true); assertThat(client, is(mockClient)); }
@Test public void getClientTemplate_byNameAndGetClientTemplateOptions_shouldThrowIllegalArgumentExceptionWhenClientNameIsBlank() throws P4JavaException { thrown.expect(IllegalArgumentException.class); clientDelegator.getClientTemplate(EMPTY, mock(GetClientTemplateOptions.class)); }
@Test public void getClientTemplate_byNameAndGetClientTemplateOptions_shouldReturnNonNullClient() throws P4JavaException { doReturn(resultMaps) .when(server) .execMapCmdList(eq(CLIENT.toString()), any(String[].class), any()); 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(false); when(resultMap.containsKey(MapKeys.ACCESS_KEY)).thenReturn(false); IClient client = clientDelegator.getClientTemplate( clientName, mock(GetClientTemplateOptions.class)); assertNotNull(client); }
@Test(expected = ConnectionException.class) public void getClientTemplate_shouldReturnConnectionExceptionThatWasThrownFromInnerGetClientTemplate() throws Exception { doThrow(ConnectionException.class).when(clientDelegator).getClientTemplate(eq(clientName), eq(false)); clientDelegator.getClientTemplate(clientName); }
@Test public void getClientTemplate_shouldReturnNonNullClient() throws Exception { doReturn(mockClient).when(clientDelegator).getClientTemplate(eq(clientName), eq(false)); IClient client = clientDelegator.getClientTemplate(clientName); assertThat(client, is(mockClient)); }
@Test(expected = ConnectionException.class) public void getClientTemplate_ByNameAndAllowExistent_shouldThrowConnectionExceptionThatWasThrownFromInnerMethodCall() throws Exception { doThrow(ConnectionException.class).when(clientDelegator) .getClientTemplate(any(String.class), any(GetClientTemplateOptions.class)); clientDelegator.getClientTemplate(clientName, false); }
@Test(expected = AccessException.class) public void getClientTemplate_ByNameAndAllowExistent_shouldThrowAccessExceptionThatWasThrownFromInnerMethodCall() throws Exception { doThrow(AccessException.class).when(clientDelegator).getClientTemplate(any(String.class), any(GetClientTemplateOptions.class)); clientDelegator.getClientTemplate(clientName, false); }
@Test(expected = RequestException.class) public void getClientTemplate_ByNameAndAllowExistent_shouldThrowRequestExceptionThatWasThrownFromInnerMethodCall() throws Exception { doThrow(RequestException.class).when(clientDelegator).getClientTemplate(any(String.class), any(GetClientTemplateOptions.class)); clientDelegator.getClientTemplate(clientName, false); }
@Test(expected = RequestException.class) public void getClientTemplate_ByNameAndAllowExistent_shouldThrowRequestExceptionWhenInnerMethodCallThrownP4JavaException() throws Exception { doThrow(P4JavaException.class).when(clientDelegator).getClientTemplate(any(String.class), any(GetClientTemplateOptions.class)); clientDelegator.getClientTemplate(clientName, false); }
@Test public void getClientTemplate_ByNameAndAllowExistent_shouldReturnNonNullClient() throws Exception { doReturn(mockClient).when(clientDelegator).getClientTemplate(eq(clientName), any(GetClientTemplateOptions.class)); IClient client = clientDelegator.getClientTemplate(clientName, true); assertThat(client, is(mockClient)); }
@Test(expected = IllegalArgumentException.class) public void getClientTemplate_byNameAndGetClientTemplateOptions_shouldThrowIllegalArgumentExceptionWhenClientNameIsBlank() throws P4JavaException { clientDelegator.getClientTemplate(EMPTY, mock(GetClientTemplateOptions.class)); }
@SuppressWarnings("unchecked") @Test public void getClientTemplate_byNameAndGetClientTemplateOptions_shouldReturnNonNullClient() throws P4JavaException { doReturn(resultMaps).when(server).execMapCmdList(eq(CLIENT.toString()), any(String[].class), (Map<String, Object>) any()); 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(false); when(resultMap.containsKey(MapKeys.ACCESS_KEY)).thenReturn(false); IClient client = clientDelegator.getClientTemplate(clientName, mock(GetClientTemplateOptions.class)); assertNotNull(client); }