@Test public void configurePlatformSensor() throws Exception { long agentId = 13L; long sensorId = 17L; String className = "className"; Map<String, Object> parameters = Collections.<String, Object> singletonMap("key", "value"); IPlatformSensorConfig platformSensorConfig = mock(IPlatformSensorConfig.class); when(platformSensorConfig.getClassName()).thenReturn(className); when(platformSensorConfig.getParameters()).thenReturn(parameters); when(platformSensorConfig.isActive()).thenReturn(true); when(environment.getPlatformSensorConfigs()).thenReturn(Collections.singletonList(platformSensorConfig)); when(registrationService.registerPlatformSensorTypeIdent(agentId, className)).thenReturn(sensorId); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<PlatformSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getPlatformSensorTypeConfigs(); assertThat(sensorTypeConfigs, hasSize(1)); PlatformSensorTypeConfig sensorTypeConfig = sensorTypeConfigs.iterator().next(); assertThat(sensorTypeConfig.getId(), is(sensorId)); assertThat(sensorTypeConfig.getClassName(), is(className)); assertThat(sensorTypeConfig.getParameters(), is(parameters)); verify(registrationService).registerPlatformSensorTypeIdent(agentId, className); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
/** * Creates the agent based {@link PlatformSensorTypeConfig} with correctly registered ID. * * @param platformId * ID of the agent. * @param platformSensorConfig * {@link IPlatformSensorConfig} defined in the {@link Environment}. * @return {@link PlatformSensorTypeConfig}. */ private PlatformSensorTypeConfig getPlatformSensorTypeConfig(long platformId, IPlatformSensorConfig platformSensorConfig) { long id = registrationService.registerPlatformSensorTypeIdent(platformId, platformSensorConfig.getClassName()); PlatformSensorTypeConfig platformSensorTypeConfig = new PlatformSensorTypeConfig(); platformSensorTypeConfig.setId(id); platformSensorTypeConfig.setClassName(platformSensorConfig.getClassName()); platformSensorTypeConfig.setParameters(platformSensorConfig.getParameters()); return platformSensorTypeConfig; }