@Override protected Void performRemoteCall(IAgentService service) throws Exception { service.unregister(platformIdent); return null; } };
@Test(expectedExceptions = { BusinessException.class }) public void businessException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(BusinessException.class).when(agentService).unregister(anyLong()); long platformId = 10L; try { connection.unregister(platformId); } finally { verify(agentService, times(1)).unregister(platformId); verifyNoMoreInteractions(agentService); } }
@Test public void unregister() throws Exception { when(client.isConnected()).thenReturn(true); long platformId = 10L; connection.unregister(platformId); verify(agentService, times(1)).unregister(platformId); verifyNoMoreInteractions(agentService); }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void timeout() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(TimeoutException.class).when(agentService).unregister(anyLong()); long platformId = 10L; try { connection.unregister(platformId); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(true)); throw e; } finally { verify(agentService, times(1)).unregister(platformId); verifyNoMoreInteractions(agentService); } }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void remoteException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(RuntimeException.class).when(agentService).unregister(anyLong()); long platformId = 10L; try { connection.unregister(platformId); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(false)); throw e; } finally { // fail fast call, only one attempt verify(agentService, times(1)).unregister(platformId); verifyNoMoreInteractions(agentService); verify(client).close(); } }