AlarmServiceImpl implements AlarmService { @Override public void clearAlarmsOnNodeAndSubtree(ModelNodeId identifier, String mountKey) { AlarmChange alarmChange = AlarmChange.createForClearSubtree(identifier, mountKey); m_alarmQueue.addAlarmChanges(Collections.singletonList(alarmChange)); } AlarmServiceImpl(PersistenceManagerUtil persistenceManagerUtil, AlarmQueue alarmQueue); void init(); void close(); @Override void raiseAlarm(AlarmInfo alarm); @Override void raiseAlarms(List<AlarmInfo> alarmInfoList); @Override void clearAlarm(AlarmInfo alarm); @Override void clearAlarms(List<AlarmInfo> alarmInfoList); @Override @Transactional(value = TxType.REQUIRED, rollbackOn = {RuntimeException.class}) List<Alarm> getAlarms(PagingInput pagingInput); @Override @Transactional(value = TxType.REQUIRED, rollbackOn = {RuntimeException.class}) List<Alarm> getAlarms(PagingInput pagingInput, String deviceId); @Override void clearAlarmsOnNodeAndSubtree(ModelNodeId identifier, String mountKey); @Override void clearAlarmsOnDevice(String deviceId); @Override @Transactional(value = TxType.REQUIRED, rollbackOn = {RuntimeException.class}) List<Alarm> getAlarmsUnderResource(String resourceDbIdLike); @Override void updateAlarmsForResync(List<AlarmInfo> newRaiseAlarms, List<AlarmInfo> updateAlarms, List<AlarmInfo> clearAlarms); @Override void updateAlarmNotificationQNameToAdapterTypeVersion(QName alarmNotificationQName, String typeVersion); @Override void removeAlarmNotificationQNameToAdapterTypeVersion(QName alarmNotificationQName, String typeVersion); @Override Set<String> retrieveAdapterTypeVersionsFromAlarmNotificationQName(QName alarmNotificationQName);  }
@Test public void testClearAlarmsOnNodeAndSubtree() { Timestamp timestamp = new Timestamp(System.currentTimeMillis()); createAlarms(timestamp, 1); m_persistenceManager.getEntityDataStoreManager().beginTransaction(); List<Alarm> alarms = getAlarmsFor(0, 1); assertEquals(1, alarms.size()); m_alarmService.clearAlarmsOnNodeAndSubtree(MODEL_NODE_ID, MOUNT_KEY); m_alarmQueue.clearQueue(); alarms = getAlarmsFor(0, 1); m_persistenceManager.getEntityDataStoreManager().commitTransaction(); assertEquals(0, alarms.size()); verify(m_notificationService, times(1)).sendNotification(eq(AlarmConstants.ALARM_STREAM_NAME), any(DefaultAlarmStateChangeNotification.class)); DefaultAlarmStateChangeNotification notification = m_internalAlarmService.getNotification(); ModelNodeDataStoreManager actualDsm = notification.getModelNodeDSM(); assertNotNull(actualDsm); assertEquals(m_dsm, actualDsm); AlarmNotification alarmNotification = notification.getAlarmNotification(); assertEquals(AlarmCondition.ALARM_OFF, alarmNotification.getAlarmCondition()); destroyAlarms(); }
@Test public void testClearAlarmsOnNodeAndSubtreeForEmptyAlarmList() { PersistenceManagerUtil persistenceManagerUtil = mock(PersistenceManagerUtil.class); EntityDataStoreManager entityDataStoreManager = mock(EntityDataStoreManager.class); AlarmServiceImpl alarmService = new AlarmServiceImpl(persistenceManagerUtil, m_alarmQueue); Map<String, String> matchValue = new HashMap<String, String>(); List<Alarm> alarms = new ArrayList<Alarm>(); when(persistenceManagerUtil.getEntityDataStoreManager()).thenReturn(entityDataStoreManager); when(entityDataStoreManager.findLike(Alarm.class, matchValue)).thenReturn(alarms); alarmService.clearAlarmsOnNodeAndSubtree(MODEL_NODE_ID, MOUNT_KEY); verify(m_notificationService, times(0)).sendNotification(eq(AlarmConstants.ALARM_STREAM_NAME), any(DefaultAlarmStateChangeNotification.class)); }