/** * 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); } }
/** * Test the registration of the method sensor type. */ @Test public void registerMethodSensorType() { final long methodSensorId = 30; long platformId = 1; final String fqcName = "class"; when(methodSensorTypeIdentDao.findIdByClassNameAndPlatformId(fqcName, platformId)).thenReturn(Collections.<Long> emptyList()); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { MethodSensorTypeIdent methodSensorIdent = (MethodSensorTypeIdent) invocation.getArguments()[0]; methodSensorIdent.setId(Long.valueOf(methodSensorId)); methodSensorIdent.setFullyQualifiedClassName(fqcName); return null; } }).when(methodSensorTypeIdentDao).saveOrUpdate((MethodSensorTypeIdent) anyObject()); long registeredId = registrationService.registerMethodSensorTypeIdent(platformId, fqcName, Collections.<String, Object> emptyMap()); assertThat(registeredId, is(equalTo(methodSensorId))); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<MethodSensorTypeIdent> methodSensorArgument = ArgumentCaptor.forClass(MethodSensorTypeIdent.class); verify(methodSensorTypeIdentDao, times(1)).saveOrUpdate(methodSensorArgument.capture()); assertThat(methodSensorArgument.getValue().getFullyQualifiedClassName(), is(equalTo(fqcName))); assertThat(methodSensorArgument.getValue().getPlatformIdent().getId(), is(equalTo(platformId))); verify(platformIdentCache, times(1)).markDirty(platformId); }
/** * Test that the registration of the {@link MethodSensorTypeIdent} will be correct if * properties are provided. */ @SuppressWarnings("unchecked") @Test public void registerMethodSensorTypeWithSettings() { 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.<Long> emptyList()); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { MethodSensorTypeIdent methodSensorIdent = (MethodSensorTypeIdent) invocation.getArguments()[0]; methodSensorIdent.setId(Long.valueOf(methodSensorId)); methodSensorIdent.setFullyQualifiedClassName(fqcName); return null; } }).when(methodSensorTypeIdentDao).saveOrUpdate((MethodSensorTypeIdent) anyObject()); long registeredId = registrationService.registerMethodSensorTypeIdent(platformId, fqcName, settings); assertThat(registeredId, is(equalTo(methodSensorId))); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<MethodSensorTypeIdent> methodSensorArgument = ArgumentCaptor.forClass(MethodSensorTypeIdent.class); verify(methodSensorTypeIdentDao, times(1)).saveOrUpdate(methodSensorArgument.capture()); assertThat(methodSensorArgument.getValue().getSettings(), is(settings)); }