use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto 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.AlarmTypeDto in project open-smart-grid-platform by OSGP.
the class PushNotificationAlarmMappingTest method testWithNullVariables.
// Test if mapping a PushNotificationAlarm object succeeds with null
// variables
@Test
public void testWithNullVariables() {
// build test data
final String deviceId = null;
final EnumSet<AlarmTypeDto> alarms = null;
final PushNotificationAlarmDto pushNotificationAlarmDto = new PushNotificationAlarmDto(deviceId, alarms, this.alarmBytes);
// actual mapping
final PushNotificationAlarm pushNotificationAlarm = this.mapperFactory.getMapperFacade().map(pushNotificationAlarmDto, PushNotificationAlarm.class);
// test mapping
assertThat(pushNotificationAlarm).isNotNull();
assertThat(pushNotificationAlarm.getDeviceIdentification()).isNull();
// the constructor creates an empty EnumSet when passed a null value.
assertThat(pushNotificationAlarmDto.getAlarms()).isEmpty();
assertThat(pushNotificationAlarm.getAlarms()).isEmpty();
assertThat(this.alarmBytes).withFailMessage("The alarm bytes should be the same after the mapping").isEqualTo(pushNotificationAlarm.getAlarmBytes());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.
the class PushNotificationAlarmMappingTest method testWithEmptyEnumSet.
// Test if mapping a PushNotificationAlarm object succeeds when the EnumSet
// is empty
@Test
public void testWithEmptyEnumSet() {
// build test data
final String deviceId = "device1";
final EnumSet<AlarmTypeDto> alarms = EnumSet.noneOf(AlarmTypeDto.class);
final PushNotificationAlarmDto pushNotificationAlarmDto = new PushNotificationAlarmDto(deviceId, alarms, this.alarmBytes);
// actual mapping
final PushNotificationAlarm pushNotificationAlarm = this.mapperFactory.getMapperFacade().map(pushNotificationAlarmDto, PushNotificationAlarm.class);
// test mapping
assertThat(pushNotificationAlarm).isNotNull();
assertThat(pushNotificationAlarm.getDeviceIdentification()).isEqualTo(deviceId);
assertThat(pushNotificationAlarm.getAlarms()).isEmpty();
assertThat(this.alarmBytes).isEqualTo(pushNotificationAlarm.getAlarmBytes());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.
the class DlmsPushNotificationDecoderTest method decodeSmr5AlarmsWithAlarmRegister.
@Test
public void decodeSmr5AlarmsWithAlarmRegister() throws UnrecognizedMessageDataException {
// SETUP
this.decoder = new DlmsPushNotificationDecoder();
final ByteBuf buffer = mock(ByteBuf.class);
// Create alarm register with 4 alarms: replace battery, 2 mbus alarms
// and phase outage detected (new in SMR5.1)
final byte[] alarmRegister = new byte[] { 0x10, 0x18, 0x00, 0x02 };
this.setupSmr5BufferWithAlarm(buffer, IDENTIFIER, ALARM_OBISCODE_BYTES, alarmRegister);
// CALL
final List<Object> out = new ArrayList<>();
this.decoder.decode(this.ctx, buffer, out);
final Object pushNotificationObject = out.get(0);
// VERIFY
assertThat(pushNotificationObject instanceof DlmsPushNotification).isTrue();
final DlmsPushNotification dlmsPushNotification = (DlmsPushNotification) pushNotificationObject;
assertThat(dlmsPushNotification.getEquipmentIdentifier()).isEqualTo(IDENTIFIER);
assertThat(dlmsPushNotification.getTriggerType()).isEqualTo(PUSH_ALARM_TRIGGER);
final Set<AlarmTypeDto> alarms = dlmsPushNotification.getAlarms();
assertThat(alarms.size()).isEqualTo(4);
assertThat(alarms.contains(REPLACE_BATTERY)).isTrue();
assertThat(alarms.contains(COMMUNICATION_ERROR_M_BUS_CHANNEL_4)).isTrue();
assertThat(alarms.contains(FRAUD_ATTEMPT_M_BUS_CHANNEL_1)).isTrue();
assertThat(alarms.contains(PHASE_OUTAGE_DETECTED_L1)).isTrue();
this.verifySmr5BufferCallsWithAlarm(buffer, alarmRegister);
// Verify the addressing bytes, the 0x0F for data-notification and the
// invoke-id bytes were skipped
verify(buffer, times(1)).skipBytes(SMR5_NUMBER_OF_BYTES_FOR_ADDRESSING + 1 + SMR5_NUMBER_OF_BYTES_FOR_INVOKE_ID);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto in project open-smart-grid-platform by OSGP.
the class AlarmRegisterMappingTest method testWithEmptySet.
// Test if mapping with an empty set succeeds
@Test
public void testWithEmptySet() {
// build test data
final Set<AlarmTypeDto> alarmTypes = new TreeSet<>();
final AlarmRegisterResponseDto alarmRegisterDto = new AlarmRegisterResponseDto(alarmTypes);
// actual mapping
final AlarmRegister alarmRegister = this.monitoringMapper.map(alarmRegisterDto, AlarmRegister.class);
// test mapping
assertThat(alarmRegister).isNotNull();
assertThat(alarmRegister.getAlarmTypes()).isEmpty();
}
Aggregations