ClientDelegator extends BaseDelegator implements IClientDelegator { @Override public String updateClient(@Nonnull final IClient client) throws ConnectionException, RequestException, AccessException { Validate.notNull(client); List<Map<String, Object>> resultMaps = execMapCmdList( CLIENT, new String[]{"-i"}, InputMapper.map(client)); return parseCommandResultMapIfIsInfoMessageAsString(resultMaps); } 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 updateClient_shouldThrownNullPointerExceptionWhenClientIsNull() throws Exception { thrown.expect(NullPointerException.class); clientDelegator.updateClient(null); }
@Test public void updateClient_shouldThrowConnectionExceptionThatWasThrownFromParseCommandResultMapIfIsInfoMessageAsString() throws Exception { doThrow(ConnectionException.class) .when(server) .execMapCmdList(eq(CLIENT.toString()), eq(new String[]{"-i"}), any(Map.class)); thrown.expect(ConnectionException.class); clientDelegator.updateClient(mockClient); }
@Test public void updateClient_shouldReturnNonNullClient() throws Exception { when(server.execMapCmdList( eq(CLIENT.toString()), eq(new String[]{"-i"}), any(Map.class))).thenReturn(resultMaps); givenInfoMessageResultMap(); String actualClientName = clientDelegator.updateClient(mockClient); assertThat(actualClientName, is(clientName)); }
@Test public void updateClient_byClientAndForce_shouldReturnNonNullClient() throws Exception { doReturn(clientName) .when(clientDelegator) .updateClient(any(IClient.class), any(UpdateClientOptions.class)); String actualClientName = clientDelegator.updateClient(mockClient, false); assertThat(actualClientName, is(clientName)); }
@Test public void updateClient_byClientAndUpdateClientOptions_shouldThrownNullPointerExceptionWhenClientIsNull() throws P4JavaException { thrown.expect(NullPointerException.class); clientDelegator.updateClient(null, mock(UpdateClientOptions.class)); }
@Test public void updateClient_byClientAndUpdateClientOptions_shouldThrownIllegalArgumentExceptionWhenClientNameIsBlank() throws P4JavaException { when(mockClient.getName()).thenReturn(EMPTY); thrown.expect(IllegalArgumentException.class); clientDelegator.updateClient(mockClient, mock(UpdateClientOptions.class)); }
@Test public void updateClient_byClientAndUpdateClientOptions_shouldReturnNonNullClientName() throws P4JavaException { when(server.execMapCmdList( eq(CLIENT.toString()), any(String[].class), any(Map.class))).thenReturn(resultMaps); givenInfoMessageResultMap(); String actualClientName = clientDelegator.updateClient(mockClient, mock(UpdateClientOptions.class)); assertThat(actualClientName, is(clientName)); }
@Test(expected = NullPointerException.class) public void updateClient_shouldThrownNullPointerExceptionWhenClientIsNull() throws Exception { clientDelegator.updateClient(null); }
@SuppressWarnings("unchecked") @Test(expected = ConnectionException.class) public void updateClient_shouldThrowConnectionExceptionThatWasThrownFromParseCommandResultMapIfIsInfoMessageAsString() throws Exception { doThrow(ConnectionException.class).when(server).execMapCmdList(eq(CLIENT.toString()), eq(new String[] { "-i" }), any(Map.class)); clientDelegator.updateClient(mockClient); }
@SuppressWarnings("unchecked") @Test public void updateClient_shouldReturnNonNullClient() throws Exception { when(server.execMapCmdList(eq(CLIENT.toString()), eq(new String[] { "-i" }), any(Map.class))).thenReturn(resultMaps); givenInfoMessageResultMap(); String actualClientName = clientDelegator.updateClient(mockClient); assertThat(actualClientName, is(clientName)); }
@Test(expected = ConnectionException.class) public void updateClient_byClientAndForce_shouldThrowConnectionExceptionThatWasThrownFromInnerUpdateClientCall() throws Exception { doThrow(ConnectionException.class).when(clientDelegator).updateClient(any(IClient.class), any(UpdateClientOptions.class)); clientDelegator.updateClient(mockClient, false); }
@Test(expected = RequestException.class) public void updateClient_byClientAndForce_shouldThrowRequestExceptionThatWasThrownFromInnerUpdateClientCall() throws Exception { doThrow(RequestException.class).when(clientDelegator).updateClient(any(IClient.class), any(UpdateClientOptions.class)); clientDelegator.updateClient(mockClient, false); }
@Test(expected = AccessException.class) public void updateClient_byClientAndForce_shouldThrowAccessExceptionThatWasThrownFromInnerUpdateClientCall() throws Exception { doThrow(AccessException.class).when(clientDelegator).updateClient(any(IClient.class), any(UpdateClientOptions.class)); clientDelegator.updateClient(mockClient, false); }
@Test(expected = RequestException.class) public void updateClient_byClientAndForce_shouldThrowRequestExceptionWhenP4JavaExceptionWasThrowned() throws Exception { doThrow(P4JavaException.class).when(clientDelegator).updateClient(any(IClient.class), any(UpdateClientOptions.class)); clientDelegator.updateClient(mockClient, false); }
@Test public void updateClient_byClientAndForce_shouldReturnNonNullClient() throws Exception { doReturn(clientName).when(clientDelegator).updateClient(any(IClient.class), any(UpdateClientOptions.class)); String actualClientName = clientDelegator.updateClient(mockClient, false); assertThat(actualClientName, is(clientName)); }
@Test(expected = NullPointerException.class) public void updateClient_byClientAndUpdateClientOptions_shouldThrownNullPointerExceptionWhenClientIsNull() throws P4JavaException { clientDelegator.updateClient(null, mock(UpdateClientOptions.class)); }
@Test(expected = IllegalArgumentException.class) public void updateClient_byClientAndUpdateClientOptions_shouldThrownIllegalArgumentExceptionWhenClientNameIsBlank() throws P4JavaException { when(mockClient.getName()).thenReturn(EMPTY); clientDelegator.updateClient(mockClient, mock(UpdateClientOptions.class)); }
@SuppressWarnings("unchecked") @Test public void updateClient_byClientAndUpdateClientOptions_shouldReturnNonNullClientName() throws P4JavaException { when(server.execMapCmdList(eq(CLIENT.toString()), any(String[].class), any(Map.class))) .thenReturn(resultMaps); givenInfoMessageResultMap(); String actualClientName = clientDelegator.updateClient(mockClient, mock(UpdateClientOptions.class)); assertThat(actualClientName, is(clientName)); }