@Override protected InstrumentationDefinition performRemoteCall(IAgentService service) throws Exception { return agentService.analyze(platformIdent, hash, type); } };
@Override protected Collection<JmxAttributeDescriptor> performRemoteCall(IAgentService service) throws Exception { return agentService.analyzeJmxAttributes(platformIdent, descriptors); } };
@Override protected List<IAgentMessage<?>> performRemoteCall(IAgentService service) throws Exception { return agentService.fetchAgentMessages(platformIdent); } };
@Override protected Void performRemoteCall(IAgentService service) throws Exception { service.unregister(platformIdent); return null; } };
@Override protected AgentConfig performRemoteCall(IAgentService service) throws Exception { return agentService.register(networkInterfaces, agentName, version); } };
/** * {@inheritDoc} */ @Override protected Void performRemoteCall(IAgentService remoteObject) throws Exception { remoteObject.instrumentationApplied(platformIdent, methodToSensorMap); 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 register() throws Exception { AgentConfig agentConfiguration = mock(AgentConfig.class); when(client.isConnected()).thenReturn(true); doReturn(agentConfiguration).when(agentService).register(Matchers.<List<String>> any(), anyString(), anyString()); String agentName = "agentName"; String version = "version"; AgentConfig receivedAgentConfiguration = connection.register(agentName, version); assertThat(receivedAgentConfiguration, is(agentConfiguration)); verify(agentService, times(1)).register(Matchers.<List<String>> any(), eq(agentName), eq(version)); verifyNoMoreInteractions(agentService); }
@Test public void instrumentationApplied() throws Exception { when(client.isConnected()).thenReturn(true); Map<Long, long[]> methodToSensorMap = mock(Map.class); when(methodToSensorMap.isEmpty()).thenReturn(false); long id = 7; connection.instrumentationApplied(id, methodToSensorMap); verify(agentService, times(1)).instrumentationApplied(id, methodToSensorMap); verifyNoMoreInteractions(agentService); }
@Test public void analyzeAndInstrument() throws Exception { InstrumentationDefinition instrumentationResult = mock(InstrumentationDefinition.class); when(client.isConnected()).thenReturn(true); doReturn(instrumentationResult).when(agentService).analyze(anyLong(), anyString(), Matchers.<Type> any()); long id = 7; String hash = "hash"; Type type = mock(Type.class); InstrumentationDefinition receivedResult = connection.analyze(id, hash, type); assertThat(receivedResult, is(instrumentationResult)); verify(agentService, times(1)).analyze(id, hash, type); 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 public void analyzeJmxAttributes() throws Exception { Collection<JmxAttributeDescriptor> result = mock(Collection.class); when(client.isConnected()).thenReturn(true); doReturn(result).when(agentService).analyzeJmxAttributes(anyLong(), Matchers.<Collection<JmxAttributeDescriptor>> any()); long id = 7; Collection<JmxAttributeDescriptor> descriptors = Collections.emptyList(); Collection<JmxAttributeDescriptor> receivedResult = connection.analyzeJmxAttributes(id, descriptors); assertThat(receivedResult, is(result)); verify(agentService, times(1)).analyzeJmxAttributes(id, descriptors); verifyNoMoreInteractions(agentService); }
@Test(expectedExceptions = { BusinessException.class }) public void businessException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(BusinessException.class).when(agentService).register(Matchers.<List<String>> any(), anyString(), anyString()); String agentName = "agentName"; String version = "version"; try { connection.register(agentName, version); } finally { verify(agentService, times(1)).register(Matchers.<List<String>> any(), eq(agentName), eq(version)); verifyNoMoreInteractions(agentService); } }
@Test public void fetchAgentMessages() throws Exception { IAgentMessage<?> message = mock(IAgentMessage.class); List<IAgentMessage<?>> messages = Arrays.<IAgentMessage<?>> asList(message); when(client.isConnected()).thenReturn(true); long id = 7; when(agentService.fetchAgentMessages(id)).thenReturn(messages); List<IAgentMessage<?>> result = connection.fetchAgentMessages(id); assertThat(result, is(equalTo(messages))); verify(agentService).fetchAgentMessages(id); verifyNoMoreInteractions(agentService); }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void timeout() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(TimeoutException.class).when(agentService).instrumentationApplied(anyLong(), Matchers.<Map<Long, long[]>> any()); Map<Long, long[]> methodToSensorMap = mock(Map.class); when(methodToSensorMap.isEmpty()).thenReturn(false); long id = 7; try { connection.instrumentationApplied(id, methodToSensorMap); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(true)); throw e; } finally { verify(agentService, times(1)).instrumentationApplied(id, methodToSensorMap); verifyNoMoreInteractions(agentService); } }
@Test(expectedExceptions = { BusinessException.class }) public void businessException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(BusinessException.class).when(agentService).analyze(anyLong(), anyString(), Matchers.<Type> any()); long id = 7; String hash = "hash"; Type type = mock(Type.class); try { connection.analyze(id, hash, type); } finally { verify(agentService, times(1)).analyze(id, hash, type); 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 = { BusinessException.class }) public void businessException() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(BusinessException.class).when(agentService).analyzeJmxAttributes(anyLong(), Matchers.<Collection<JmxAttributeDescriptor>> any()); long id = 7; Collection<JmxAttributeDescriptor> descriptors = Collections.emptyList(); try { connection.analyzeJmxAttributes(id, descriptors); } finally { verify(agentService, times(1)).analyzeJmxAttributes(id, descriptors); verifyNoMoreInteractions(agentService); } }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void timeout() throws Exception { when(client.isConnected()).thenReturn(true); doThrow(TimeoutException.class).when(agentService).register(Matchers.<List<String>> any(), anyString(), anyString()); String agentName = "agentName"; String version = "version"; try { connection.register(agentName, version); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(true)); throw e; } finally { verify(agentService, times(1)).register(Matchers.<List<String>> any(), eq(agentName), eq(version)); verifyNoMoreInteractions(agentService); } }
@Test(expectedExceptions = { ServerUnavailableException.class }) public void timeout() throws Exception { when(client.isConnected()).thenReturn(true); long id = 7; when(agentService.fetchAgentMessages(id)).thenThrow(TimeoutException.class); try { connection.fetchAgentMessages(id); } catch (ServerUnavailableException e) { assertThat(e.isServerTimeout(), is(true)); throw e; } finally { verify(agentService).fetchAgentMessages(id); verifyNoMoreInteractions(agentService); } }