Search in sources :

Example 1 with CosemDateDto

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());
}
Also used : SpecialDaysRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest) SpecialDaysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto) SpecialDaysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData) SpecialDay(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto) Test(org.junit.jupiter.api.Test)

Example 2 with CosemDateDto

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);
}
Also used : SpecialDaysRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest) SpecialDaysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto) SpecialDaysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData) SpecialDay(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay) CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) CosemDate(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate) SpecialDayDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto) SpecialDaysRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto) Test(org.junit.jupiter.api.Test)

Example 3 with CosemDateDto

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);
}
Also used : CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) DateTime(org.joda.time.DateTime) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)

Example 4 with CosemDateDto

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);
}
Also used : CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) AccessResultCode(org.openmuc.jdlms.AccessResultCode) SetParameter(org.openmuc.jdlms.SetParameter) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto) Test(org.junit.jupiter.api.Test)

Example 5 with CosemDateDto

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);
}
Also used : CosemDateDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto) AccessResultCode(org.openmuc.jdlms.AccessResultCode) SetParameter(org.openmuc.jdlms.SetParameter) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) CosemTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto) Test(org.junit.jupiter.api.Test)

Aggregations

CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)12 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)10 Test (org.junit.jupiter.api.Test)5 CosemDate (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemDate)5 ClockStatusDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ClockStatusDto)4 AccessResultCode (org.openmuc.jdlms.AccessResultCode)3 SetParameter (org.openmuc.jdlms.SetParameter)3 ClockStatus (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ClockStatus)3 CosemTime (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemTime)3 ActivityCalendarDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto)3 SpecialDay (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDay)2 SpecialDaysRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest)2 SpecialDaysRequestData (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData)2 SpecialDayDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDayDto)2 SpecialDaysRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto)2 SpecialDaysRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto)2 ByteBuffer (java.nio.ByteBuffer)1 DateTime (org.joda.time.DateTime)1 ClockStatus (org.openmuc.jdlms.datatypes.CosemDateTime.ClockStatus)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1