use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto in project open-smart-grid-platform by OSGP.
the class SpecialDaysRequestMappingTest method testSpecialDaysRequestMappingNonEmptyListNoCosemDate.
// To check mapping of SpecialDaysRequest, when its SpecialDaysRequestData
// has a filled List (1 value), where CosemDate is not specified.
@Test
public void testSpecialDaysRequestMappingNonEmptyListNoCosemDate() {
final String deviceIdentification = "nr1";
final int dayId = 1;
final SpecialDay specialDay = new SpecialDay(new CosemDate(), dayId);
final SpecialDaysRequestData specialDaysRequestData = new SpecialDaysRequestDataBuilder().addSpecialDay(specialDay).build();
final SpecialDaysRequest specialDaysRequestValueObject = new SpecialDaysRequest(deviceIdentification, specialDaysRequestData);
final SpecialDaysRequestDto specialDaysRequestDto = this.configurationMapper.map(specialDaysRequestValueObject, SpecialDaysRequestDto.class);
assertThat(specialDaysRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
final SpecialDaysRequestDataDto requestDataDto = specialDaysRequestDto.getSpecialDaysRequestData();
assertThat(requestDataDto).isNotNull();
assertThat(requestDataDto.getSpecialDays()).isNotNull();
assertThat(requestDataDto.getSpecialDays().size()).isEqualTo(dayId);
final SpecialDayDto specialDayDto = requestDataDto.getSpecialDays().get(0);
assertThat(specialDayDto.getDayId()).isEqualTo(dayId);
final CosemDate specialDayDate = specialDay.getSpecialDayDate();
final CosemDateDto specialDayDateDto = specialDayDto.getSpecialDayDate();
assertThat(specialDayDateDto.getYear()).isEqualTo(specialDayDate.getYear());
assertThat(specialDayDateDto.getMonth()).isEqualTo(specialDayDate.getMonth());
assertThat(specialDayDateDto.getDayOfMonth()).isEqualTo(specialDayDate.getDayOfMonth());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto in project open-smart-grid-platform by OSGP.
the class SpecialDaysRequestMappingTest method testSpecialDaysRequestMappingNonEmptyList.
// To check mapping of SpecialDaysRequest, when its SpecialDaysRequestData
// has a filled List (1 value).
@Test
public void testSpecialDaysRequestMappingNonEmptyList() {
final String deviceIdentification = "nr1";
final int year = 2016;
final int month = 3;
final int dayOfMonth = 11;
final int dayId = 1;
final SpecialDay specialDay = new SpecialDay(new CosemDate(year, month, dayOfMonth), dayId);
final SpecialDaysRequestData specialDaysRequestData = new SpecialDaysRequestDataBuilder().addSpecialDay(specialDay).build();
final SpecialDaysRequest specialDaysRequestValueObject = new SpecialDaysRequest(deviceIdentification, specialDaysRequestData);
final SpecialDaysRequestDto specialDaysRequestDto = this.configurationMapper.map(specialDaysRequestValueObject, SpecialDaysRequestDto.class);
assertThat(specialDaysRequestDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
final SpecialDaysRequestDataDto requestDataDto = specialDaysRequestDto.getSpecialDaysRequestData();
assertThat(requestDataDto).isNotNull();
assertThat(requestDataDto.getSpecialDays()).isNotNull();
assertThat(requestDataDto.getSpecialDays().size()).isEqualTo(dayId);
final SpecialDayDto specialDayDto = requestDataDto.getSpecialDays().get(0);
assertThat(specialDayDto.getDayId()).isEqualTo(dayId);
final CosemDateDto specialDayDateDto = specialDayDto.getSpecialDayDate();
assertThat(specialDayDateDto.getYear()).isEqualTo(year);
assertThat(specialDayDateDto.getMonth()).isEqualTo(month);
assertThat(specialDayDateDto.getDayOfMonth()).isEqualTo(dayOfMonth);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutorTest method areDatesEqual.
// Compares date with cosemDateTime. Note: cosemDateTime uses hundredths and
// not milliseconds
private boolean areDatesEqual(final Date date, final CosemDateTimeDto cosemDateTime) {
final DateTime dateTime = new DateTime(date);
final CosemDateDto cosemDate = cosemDateTime.getDate();
final CosemTimeDto cosemTime = cosemDateTime.getTime();
return (dateTime.getYear() == cosemDate.getYear() && dateTime.getMonthOfYear() == cosemDate.getMonth() && dateTime.getDayOfMonth() == cosemDate.getDayOfMonth() && dateTime.getHourOfDay() == cosemTime.getHour() && dateTime.getMinuteOfHour() == cosemTime.getMinute() && dateTime.getSecondOfMinute() == cosemTime.getSecond() && dateTime.getMillisOfSecond() == cosemTime.getHundredths() * 10);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarWithMultipleSeasons.
@Test
void testSetActivityCalendarWithMultipleSeasons() throws ProtocolAdapterException, IOException, FunctionalException {
// SETUP
when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
when(this.activationExecutor.execute(this.conn, this.DLMS_DEVICE, null, this.messageMetadata)).thenReturn(MethodResultCode.SUCCESS);
final List<Short> dayIds = Collections.singletonList((short) 1);
final List<CosemTimeDto> actionStartTimes = Collections.singletonList(new CosemTimeDto(0, 0, 0, 0));
final List<String> weekNames = Collections.singletonList("1");
final List<String> seasonNames = Arrays.asList("1", "2");
final List<CosemDateDto> seasonStarts = Arrays.asList(new CosemDateDto(0xFFFF, 1, 1), new CosemDateDto(0xFFFF, 6, 15));
final ActivityCalendarDto activityCalendar = this.createActivityCalendar(seasonNames, seasonStarts, weekNames, dayIds, actionStartTimes);
// CALL
final AccessResultCode resultCode = this.executor.execute(this.conn, this.DLMS_DEVICE, activityCalendar, this.messageMetadata);
// VERIFY
assertThat(resultCode).isEqualTo(AccessResultCode.SUCCESS);
verify(this.dlmsConnection, times(4)).set(this.setParameterArgumentCaptor.capture());
this.activityCalendarValidator.verify(() -> ActivityCalendarValidator.validate(activityCalendar), times(1));
final List<SetParameter> setParameters = this.setParameterArgumentCaptor.getAllValues();
this.verifySetParameters(setParameters, dayIds, actionStartTimes, weekNames, seasonNames, seasonStarts);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarWithSingleSeason.
@Test
void testSetActivityCalendarWithSingleSeason() throws ProtocolAdapterException, IOException, FunctionalException {
// SETUP
when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
when(this.activationExecutor.execute(this.conn, this.DLMS_DEVICE, null, this.messageMetadata)).thenReturn(MethodResultCode.SUCCESS);
final List<Short> dayIds = Collections.singletonList((short) 1);
final List<CosemTimeDto> actionStartTimes = Collections.singletonList(new CosemTimeDto(0, 0, 0, 0));
final List<String> weekNames = Collections.singletonList("1");
final List<String> seasonNames = Collections.singletonList("1");
final List<CosemDateDto> seasonStarts = Collections.singletonList(new CosemDateDto(0xFFFF, 1, 1));
final ActivityCalendarDto activityCalendar = this.createActivityCalendar(seasonNames, seasonStarts, weekNames, dayIds, actionStartTimes);
// CALL
final AccessResultCode resultCode = this.executor.execute(this.conn, this.DLMS_DEVICE, activityCalendar, this.messageMetadata);
// VERIFY
assertThat(resultCode).isEqualTo(AccessResultCode.SUCCESS);
verify(this.dlmsConnection, times(4)).set(this.setParameterArgumentCaptor.capture());
this.activityCalendarValidator.verify(() -> ActivityCalendarValidator.validate(activityCalendar), times(1));
final List<SetParameter> setParameters = this.setParameterArgumentCaptor.getAllValues();
this.verifySetParameters(setParameters, dayIds, actionStartTimes, weekNames, seasonNames, seasonStarts);
}
Aggregations