Search in sources :

Example 1 with ActivityCalendarDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto in project open-smart-grid-platform by OSGP.

the class ActivityCalendarMappingTest method testWithCosemDateTimeAndEmptyList.

// Test mapping with a CosemDateTime object AND an empty list
@Test
public void testWithCosemDateTimeAndEmptyList() {
    // build test data
    final ActivityCalendar activityCalendar = new ActivityCalendarBuilder().withCosemDateTime(this.cosemDateTime).build();
    // actual mapping
    final ActivityCalendarDto activityCalendarDto = this.configurationMapper.map(activityCalendar, ActivityCalendarDto.class);
    // check if mapping succeeded
    assertThat(activityCalendarDto).isNotNull();
    assertThat(activityCalendarDto.getActivatePassiveCalendarTime()).isNotNull();
    assertThat(activityCalendarDto.getSeasonProfileList()).isNotNull();
    assertThat(activityCalendarDto.getCalendarName()).isEqualTo(activityCalendar.getCalendarName());
    this.checkEmptyListMapping(activityCalendar.getSeasonProfileList(), activityCalendarDto.getSeasonProfileList());
    this.checkCosemDateTimeMapping(activityCalendar.getActivatePassiveCalendarTime(), activityCalendarDto.getActivatePassiveCalendarTime());
}
Also used : ActivityCalendar(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActivityCalendar) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) Test(org.junit.jupiter.api.Test)

Example 2 with ActivityCalendarDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto 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 3 with ActivityCalendarDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto 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)

Example 4 with ActivityCalendarDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto in project open-smart-grid-platform by OSGP.

the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarEmpty.

@Test
void testSetActivityCalendarEmpty() 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 ActivityCalendarDto activityCalendar = new ActivityCalendarDto(CALENDAR_NAME, ACTIVATE_PASSIVE_CALENDAR_TIME, Collections.emptyList());
    // 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, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
}
Also used : AccessResultCode(org.openmuc.jdlms.AccessResultCode) SetParameter(org.openmuc.jdlms.SetParameter) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) Test(org.junit.jupiter.api.Test)

Example 5 with ActivityCalendarDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto 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);
}
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

ActivityCalendarDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto)12 Test (org.junit.jupiter.api.Test)9 SetParameter (org.openmuc.jdlms.SetParameter)5 AccessResultCode (org.openmuc.jdlms.AccessResultCode)4 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)4 AssertionsForClassTypes.catchThrowable (org.assertj.core.api.AssertionsForClassTypes.catchThrowable)3 CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)3 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 ActivityCalendar (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActivityCalendar)2 ArrayList (java.util.ArrayList)1 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1 DayProfileActionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileActionDto)1 DayProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto)1 SeasonProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto)1 WeekProfileDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto)1 Builder (org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto.Builder)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1