use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto 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.CosemTimeDto 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.CosemTimeDto 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);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarWithMultipleSeasonsWeeksDaysAndActions.
@Test
void testSetActivityCalendarWithMultipleSeasonsWeeksDaysAndActions() 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 = Arrays.asList((short) 1, (short) 2, (short) 3);
final List<CosemTimeDto> actionStartTimes = Arrays.asList(new CosemTimeDto(0, 0, 0, 0), new CosemTimeDto(10, 15, 0, 0));
final List<String> weekNames = Arrays.asList("1", "2");
final List<String> seasonNames = Arrays.asList("1", "2", "3");
final List<CosemDateDto> seasonStarts = Arrays.asList(new CosemDateDto(0xFFFF, 1, 1), new CosemDateDto(0xFFFF, 6, 15), new CosemDateDto(0xFFFF, 12, 25));
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.CosemTimeDto in project open-smart-grid-platform by OSGP.
the class ActivityCalendarMappingTest method checkListMapping.
// method to test mapping of Filled Lists
private void checkListMapping(final List<SeasonProfile> seasonProfileList, final List<SeasonProfileDto> seasonProfileDtoList) {
assertThat(seasonProfileList).isNotNull();
assertThat(seasonProfileDtoList).isNotNull();
assertThat(seasonProfileList.isEmpty()).isFalse();
assertThat(seasonProfileDtoList.isEmpty()).isFalse();
final SeasonProfile seasonProfile = seasonProfileList.get(0);
final SeasonProfileDto seasonProfileDto = seasonProfileDtoList.get(0);
assertThat(seasonProfileDto.getSeasonProfileName()).isEqualTo(seasonProfile.getSeasonProfileName());
this.checkCosemDateTimeMapping(seasonProfile.getSeasonStart(), seasonProfileDto.getSeasonStart());
final WeekProfile weekProfile = seasonProfile.getWeekProfile();
final WeekProfileDto weekProfileDto = seasonProfileDto.getWeekProfile();
assertThat(weekProfileDto.getWeekProfileName()).isEqualTo(weekProfile.getWeekProfileName());
final DayProfile dayProfile = weekProfile.getMonday();
final DayProfileDto dayProfileDto = weekProfileDto.getMonday();
assertThat(dayProfileDto.getDayId()).isEqualTo(dayProfile.getDayId());
assertThat(dayProfile.getDayProfileActionList().size()).isEqualTo(dayProfile.getDayProfileActionList().size());
final DayProfileAction dayProfileAction = dayProfile.getDayProfileActionList().get(0);
final DayProfileActionDto dayProfileActionDto = dayProfileDto.getDayProfileActionList().get(0);
assertThat(dayProfileActionDto.getScriptSelector()).isEqualTo(dayProfileAction.getScriptSelector());
final CosemTime cosemTime = dayProfileAction.getStartTime();
final CosemTimeDto cosemTimeDto = dayProfileActionDto.getStartTime();
assertThat(cosemTimeDto.getHour()).isEqualTo(cosemTime.getHour());
assertThat(cosemTimeDto.getMinute()).isEqualTo(cosemTime.getMinute());
assertThat(cosemTimeDto.getSecond()).isEqualTo(cosemTime.getSecond());
assertThat(cosemTimeDto.getHundredths()).isEqualTo(cosemTime.getHundredths());
}
Aggregations