/** * {@inheritDoc} */ @Override public String toString() { return getId() + " :: class: " + getClassName(); }
/** * {@inheritDoc} */ @Override public void afterPropertiesSet() throws Exception { for (PlatformSensorTypeConfig config : configurationStorage.getPlatformSensorTypes()) { if (config.getClassName().equals(this.getClass().getName())) { this.init(config); break; } } }
@Test void platformSensorTypeConfigFound() throws Exception { PlatformSensorTypeConfig platformSensorTypeConfigA = Mockito.mock(PlatformSensorTypeConfig.class); PlatformSensorTypeConfig platformSensorTypeConfigB = Mockito.mock(PlatformSensorTypeConfig.class); when(platformSensorTypeConfigA.getClassName()).thenReturn("A"); when(platformSensorTypeConfigB.getClassName()).thenReturn("rocks.inspectit.agent.java.sensor.platform.AbstractPlatformSensorFakeImpl"); when(this.configurationStorage.getPlatformSensorTypes()).thenReturn(Arrays.asList(platformSensorTypeConfigA, platformSensorTypeConfigB)); this.cut.afterPropertiesSet(); assertThat(this.cut.getSensorTypeConfig(), sameInstance(platformSensorTypeConfigB)); }
@Test void noPlatformSensorTypeConfigFound() throws Exception { PlatformSensorTypeConfig platformSensorTypeConfigA = Mockito.mock(PlatformSensorTypeConfig.class); when(platformSensorTypeConfigA.getClassName()).thenReturn("A"); when(this.configurationStorage.getPlatformSensorTypes()).thenReturn(Arrays.asList(platformSensorTypeConfigA)); this.cut.afterPropertiesSet(); verifyZeroInteractions(this.sensorTypeConfig); }
@Test void initExistingPlatformSensorData() throws Exception { PlatformSensorTypeConfig platformSensorTypeConfigA = Mockito.mock(PlatformSensorTypeConfig.class); when(platformSensorTypeConfigA.getClassName()).thenReturn("rocks.inspectit.agent.java.sensor.platform.AbstractPlatformSensorFakeImpl"); when(this.configurationStorage.getPlatformSensorTypes()).thenReturn(Arrays.asList(platformSensorTypeConfigA)); when(this.platformManager.getPlatformId()).thenReturn(1337L); when(platformSensorTypeConfigA.getId()).thenReturn(73L); this.cut.afterPropertiesSet(); SystemSensorData systemSensorData = this.cut.getSystemSensorData(); verify(systemSensorData).setPlatformIdent(1337L); verify(systemSensorData).setSensorTypeIdent(73L); }
@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); }