/** * {@inheritDoc} */ @Override public List<PlatformSensorTypeConfig> getPlatformSensorTypes() throws StorageException { ensureConfigurationExists(); List<PlatformSensorTypeConfig> result = new ArrayList<PlatformSensorTypeConfig>(1); if (CollectionUtils.isNotEmpty(agentConfiguration.getPlatformSensorTypeConfigs())) { result.addAll(agentConfiguration.getPlatformSensorTypeConfigs()); } return result; }
@Test public void notDefined() throws StorageException { when(agentConfiguration.getPlatformSensorTypeConfigs()).thenReturn(null); List<PlatformSensorTypeConfig> platformSensorTypes = configurationStorage.getPlatformSensorTypes(); assertThat(platformSensorTypes, is(empty())); } }
@Test public void defined() throws StorageException { PlatformSensorTypeConfig platformSensorTypeConfig = mock(PlatformSensorTypeConfig.class); when(agentConfiguration.getPlatformSensorTypeConfigs()).thenReturn(Collections.singletonList(platformSensorTypeConfig)); List<PlatformSensorTypeConfig> platformSensorTypes = configurationStorage.getPlatformSensorTypes(); assertThat(platformSensorTypes, hasSize(1)); assertThat(platformSensorTypes, hasItem(platformSensorTypeConfig)); }
@Test public void configurePlatformSensorNotActive() throws Exception { long agentId = 13L; IPlatformSensorConfig platformSensorConfig = mock(IPlatformSensorConfig.class); when(platformSensorConfig.isActive()).thenReturn(false); when(environment.getPlatformSensorConfigs()).thenReturn(Collections.singletonList(platformSensorConfig)); AgentConfig agentConfiguration = creator.environmentToConfiguration(environment, agentId); Collection<PlatformSensorTypeConfig> sensorTypeConfigs = agentConfiguration.getPlatformSensorTypeConfigs(); assertThat(sensorTypeConfigs, is(empty())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(eisc.getClassName()), eq(eisc.getParameters())); verify(registrationService).registerMethodSensorTypeIdent(anyLong(), eq(closeableHttpAsyncCLient.getClassName()), eq(closeableHttpAsyncCLient.getParameters())); verifyNoMoreInteractions(registrationService); }
@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); }