/** * {@inheritDoc} */ @Override @MethodLog public void addSensorTypeToMethod(long platformId, long methodSensorTypeId, long methodId) { try { Long id = methodIdentToSensorTypeDao.findId(methodId, methodSensorTypeId, true); if (null == id) { MethodIdent methodIdent = new MethodIdent(); methodIdent.setId(methodId); MethodSensorTypeIdent methodSensorTypeIdent = new MethodSensorTypeIdent(); methodSensorTypeIdent.setId(methodSensorTypeId); MethodIdentToSensorType methodIdentToSensorType = new MethodIdentToSensorType(methodIdent, methodSensorTypeIdent, null); methodIdentToSensorType.setTimestamp(new Timestamp(Calendar.getInstance().getTimeInMillis())); methodIdentToSensorTypeDao.saveOrUpdate(methodIdentToSensorType); } } finally { platformIdentCache.markDirty(platformId); } }
/** * Test the registering of the method sensor type to method occurring not for the first * time. */ @Test public void registerSensorTypeWithMethodSecondTime() { long platformId = 1; long methodId = 20; long methodSensorId = 50; long methodIdentToSensorTypeId = 100L; when(methodIdentToSensorTypeDao.findId(eq(methodId), eq(methodSensorId), anyBoolean())).thenReturn(methodIdentToSensorTypeId); registrationService.addSensorTypeToMethod(platformId, methodSensorId, methodId); verify(methodIdentToSensorTypeDao, times(1)).findId(methodId, methodSensorId, true); verify(platformIdentCache, times(1)).markDirty(platformId); verifyZeroInteractions(methodIdentDao); verifyZeroInteractions(methodSensorTypeIdentDao); } }
/** * Test the registering of the method sensor type to method occurring for the first time. */ @Test public void registerSensorTypeWithMethodFirstTime() { long platformId = 1; long methodId = 20; long methodSensorId = 50; when(methodIdentToSensorTypeDao.findId(eq(methodId), eq(methodSensorId), anyBoolean())).thenReturn(null); registrationService.addSensorTypeToMethod(platformId, methodSensorId, methodId); ArgumentCaptor<MethodIdentToSensorType> argument = ArgumentCaptor.forClass(MethodIdentToSensorType.class); verify(methodIdentToSensorTypeDao, times(1)).saveOrUpdate(argument.capture()); verify(methodIdentToSensorTypeDao, times(1)).findId(methodId, methodSensorId, true); verify(platformIdentCache, times(1)).markDirty(platformId); verifyZeroInteractions(methodIdentDao); verifyZeroInteractions(methodSensorTypeIdentDao); assertThat(argument.getValue().getMethodIdent().getId(), is(equalTo(methodId))); assertThat(argument.getValue().getMethodSensorTypeIdent().getId(), is(equalTo(methodSensorId))); }