/** * {@inheritDoc} */ @Override public JmxSensorTypeIdent load(Long id) { return getEntityManager().find(JmxSensorTypeIdent.class, id); }
/** * Test the registration of the JMX sensor type ident. */ @Test public void registerJmxSensorTypeIdent() { final long jmxSensorId = 50; long platformId = 1; String fqcName = "class"; when(jmxSensorTypeIdentDao.findIdByExample(eq(platformId), (JmxSensorTypeIdent) anyObject())).thenReturn(Collections.<Long> emptyList()); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { JmxSensorTypeIdent jmxSensorTypeIdent = (JmxSensorTypeIdent) invocation.getArguments()[0]; jmxSensorTypeIdent.setId(Long.valueOf(jmxSensorId)); return null; } }).when(jmxSensorTypeIdentDao).saveOrUpdate((JmxSensorTypeIdent) anyObject()); long registeredId = registrationService.registerJmxSensorTypeIdent(platformId, fqcName); assertThat(registeredId, is(equalTo(jmxSensorId))); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<JmxSensorTypeIdent> jmxSensorArgument = ArgumentCaptor.forClass(JmxSensorTypeIdent.class); verify(jmxSensorTypeIdentDao, times(1)).saveOrUpdate(jmxSensorArgument.capture()); assertThat(jmxSensorArgument.getValue().getFullyQualifiedClassName(), is(equalTo(fqcName))); assertThat(jmxSensorArgument.getValue().getPlatformIdent().getId(), is(equalTo(platformId))); verify(platformIdentCache, times(1)).markDirty(platformId); } }
/** * {@inheritDoc} */ @Override public List<Long> findIdByExample(long platformId, JmxSensorTypeIdent jmxSensorTypeIdent) { TypedQuery<Long> query = getEntityManager().createNamedQuery(JmxSensorTypeIdent.FIND_ID_BY_PLATFORM, Long.class); query.setParameter("platformIdentId", platformId); return query.getResultList(); }