use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutor method alarmNotifications.
private AlarmNotificationsDto alarmNotifications(final long alarmFilterLongValue, final DlmsObjectType alarmRegisterDlmsObjectType) {
final BitSet bitSet = BitSet.valueOf(new long[] { alarmFilterLongValue });
final Set<AlarmNotificationDto> notifications = new TreeSet<>();
for (final AlarmTypeDto alarmType : this.alarmHelperService.alarmTypesForRegister(alarmRegisterDlmsObjectType)) {
final boolean enabled = bitSet.get(this.alarmHelperService.getAlarmRegisterBitIndex(alarmType));
notifications.add(new AlarmNotificationDto(alarmType, enabled));
}
return new AlarmNotificationsDto(notifications);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class AlarmNotificationsMappingTest method testWithSet.
// Tests if mapping with a Set with an entry succeeds.
@Test
public void testWithSet() {
// create test data
final AlarmNotification alarmNotification = new AlarmNotification(AlarmType.CLOCK_INVALID, true);
final Set<AlarmNotification> alarmNotificationSet = new TreeSet<>();
alarmNotificationSet.add(alarmNotification);
final AlarmNotifications alarmNotifications = new AlarmNotifications(alarmNotificationSet);
// actual mapping
final AlarmNotificationsDto alarmNotificationsDto = this.configurationMapper.map(alarmNotifications, AlarmNotificationsDto.class);
// check if mapping was successful
assertThat(alarmNotificationsDto).isNotNull();
assertThat(alarmNotificationsDto.getAlarmNotificationsSet()).isNotNull();
assertThat(alarmNotificationsDto.getAlarmNotificationsSet().size()).isEqualTo(alarmNotificationSet.size());
assertThat(alarmNotificationsDto.getAlarmNotificationsSet().isEmpty()).isFalse();
// To see if there is an AlarmNotifictionDto with the same variables as
// the AlarmNotification in the Set.
final AlarmNotificationDto alarmNotificationDto = new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true);
assertThat(alarmNotificationsDto.getAlarmNotificationsSet().contains(alarmNotificationDto)).isTrue();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method testSetSettingEnabled.
@Test
void testSetSettingEnabled() throws OsgpException {
// Now we enable something: CLOCK_INVALID to enabled.
final AccessResultCode res = this.execute(new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true));
assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
assertThat(this.setParametersReceived.size()).isEqualTo(1);
// Expecting 11 (0b1011).
assertThat((long) this.setParametersReceived.get(0).getData().getValue()).isEqualTo(11);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method execute.
private AccessResultCode execute(final AlarmNotificationDto... alarmNotificationDtos) throws OsgpException {
final Set<AlarmNotificationDto> alarmNotificationDtoSet = new HashSet<>(Arrays.asList(alarmNotificationDtos));
final AlarmNotificationsDto alarmNotificationsDto = new AlarmNotificationsDto(alarmNotificationDtoSet);
return this.executor.execute(this.connMgr, this.device, alarmNotificationsDto, this.messageMetadata);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutorTest method testSetSettingThatIsAlreadySet.
@Test
void testSetSettingThatIsAlreadySet() throws OsgpException {
// Setting notifications that are not different from what is on the
// meter already,
// should always be successful.
final AccessResultCode res = this.execute(new AlarmNotificationDto(AlarmTypeDto.REPLACE_BATTERY, true));
assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
// Since nothing changed, not a single message should have been sent to
// the meter.
assertThat(this.setParametersReceived.size()).isZero();
}
Aggregations