/** * Test that the registration of the {@link MethodSensorTypeIdent} will be correct if * properties are provided. */ @SuppressWarnings("unchecked") @Test public void registerExistingMethodSensorTypeWithSettings() { final long methodSensorId = 30; long platformId = 1; final String fqcName = "class"; String regEx = "myRegEx"; String regExTemplate = "myRegExTemplate"; Map<String, Object> settings = MapUtils.putAll(new HashMap<String, Object>(), new String[][] { { "regEx", regEx }, { "regExTemplate", regExTemplate } }); when(methodSensorTypeIdentDao.findIdByClassNameAndPlatformId(fqcName, platformId)).thenReturn(Collections.singletonList(methodSensorId)); long registeredId = registrationService.registerMethodSensorTypeIdent(platformId, fqcName, settings); assertThat(registeredId, is(equalTo(methodSensorId))); verify(methodSensorTypeIdentDao, times(1)).updateParameters(methodSensorId, settings); } }
/** * {@inheritDoc} */ @Override @MethodLog public long registerMethodSensorTypeIdent(long platformId, String fullyQualifiedClassName, Map<String, Object> parameters) { MethodSensorTypeIdent methodSensorTypeIdent; try { List<Long> methodSensorTypeIdents = methodSensorTypeIdentDao.findIdByClassNameAndPlatformId(fullyQualifiedClassName, platformId); if (1 == methodSensorTypeIdents.size()) { Long id = methodSensorTypeIdents.get(0); methodSensorTypeIdentDao.updateParameters(id, parameters); return id; } else { // only if the new sensor is registered we need to update the platform ident PlatformIdent platformIdent = new PlatformIdent(); platformIdent.setId(platformId); methodSensorTypeIdent = new MethodSensorTypeIdent(); methodSensorTypeIdent.setPlatformIdent(platformIdent); methodSensorTypeIdent.setFullyQualifiedClassName(fullyQualifiedClassName); methodSensorTypeIdent.setSettings(parameters); methodSensorTypeIdentDao.saveOrUpdate(methodSensorTypeIdent); return methodSensorTypeIdent.getId(); } } finally { platformIdentCache.markDirty(platformId); } }