Search in sources :

Example 1 with AlarmTypeDto

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);
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) TreeSet(java.util.TreeSet) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) BitSet(java.util.BitSet) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)

Example 2 with AlarmTypeDto

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());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Test(org.junit.jupiter.api.Test)

Example 3 with AlarmTypeDto

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());
}
Also used : PushNotificationAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm) AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Test(org.junit.jupiter.api.Test)

Example 4 with AlarmTypeDto

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);
}
Also used : AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) ArrayList(java.util.ArrayList) DlmsPushNotification(org.opensmartgridplatform.dlms.DlmsPushNotification) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 5 with AlarmTypeDto

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();
}
Also used : AlarmTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto) TreeSet(java.util.TreeSet) AlarmRegister(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmRegister) AlarmRegisterResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmRegisterResponseDto) Test(org.junit.jupiter.api.Test)

Aggregations

AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)11 Test (org.junit.jupiter.api.Test)7 TreeSet (java.util.TreeSet)4 PushNotificationAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushNotificationAlarm)3 AlarmNotificationDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto)3 AlarmRegisterResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmRegisterResponseDto)3 PushNotificationAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto)3 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 AccessResultCode (org.openmuc.jdlms.AccessResultCode)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 DlmsPushNotification (org.opensmartgridplatform.dlms.DlmsPushNotification)2 AlarmRegister (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmRegister)2 AlarmNotificationsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto)2 IOException (java.io.IOException)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1