use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotification 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.domain.core.valueobjects.smartmetering.AlarmNotification in project open-smart-grid-platform by OSGP.
the class AlarmNotificationsMappingTest method testWithEmptySet.
// The Set may be empty. Tests if mapping with an empty Set succeeds.
@Test
public void testWithEmptySet() {
// create test data
final Set<AlarmNotification> alarmNotificationSet = new TreeSet<>();
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()).isEmpty();
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotification in project open-smart-grid-platform by OSGP.
the class AlarmNotificationsConverter method convertTo.
@Override
public org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotifications convertTo(final AlarmNotifications source, final Type<org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotifications> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotifications result = new org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotifications();
final List<org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotification> alarmNotifications = result.getAlarmNotification();
final Set<AlarmNotification> sourceNotifications = source.getAlarmNotificationsSet();
for (final AlarmNotification sourceNotification : sourceNotifications) {
final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotification alarmNotification = new org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotification();
alarmNotification.setAlarmType(org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.AlarmType.valueOf(sourceNotification.getAlarmType().name()));
alarmNotification.setEnabled(sourceNotification.isEnabled());
alarmNotifications.add(alarmNotification);
}
return result;
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotification in project open-smart-grid-platform by OSGP.
the class AlarmNotificationsConverter method convertFrom.
@Override
public AlarmNotifications convertFrom(final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotifications source, final Type<AlarmNotifications> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
final Set<AlarmNotification> alarmNotifications = new TreeSet<AlarmNotification>();
final List<org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotification> sourceNotifications = source.getAlarmNotification();
for (final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.AlarmNotification sourceNotification : sourceNotifications) {
final AlarmType alarmType = AlarmType.valueOf(sourceNotification.getAlarmType().name());
final boolean enabled = sourceNotification.isEnabled();
alarmNotifications.add(new AlarmNotification(alarmType, enabled));
}
return new AlarmNotifications(alarmNotifications);
}
Aggregations