Search in sources :

Example 6 with ActivityCalendarDto

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

the class ActivityCalendarMappingTest method testCompleteMapping.

// Test the mapping of a complete ActivityCalendar object
@Test
public void testCompleteMapping() {
    // build test data
    final ActivityCalendar activityCalendar = new ActivityCalendarBuilder().withCosemDateTime(this.cosemDateTime).withFilledList().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.checkListMapping(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 7 with ActivityCalendarDto

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

the class ConfigurationService method setActivityCalendar.

public void setActivityCalendar(final MessageMetadata messageMetadata, final ActivityCalendar activityCalendar) throws FunctionalException {
    log.info("set Activity Calendar for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
    final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
    final ActivityCalendarDto requestDto = this.configurationMapper.map(activityCalendar, ActivityCalendarDto.class);
    this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
}
Also used : SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto)

Example 8 with ActivityCalendarDto

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

the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarWithOneOfTheSetRequestsFailing.

@Test
void testSetActivityCalendarWithOneOfTheSetRequestsFailing() throws IOException {
    // SETUP
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(// Calendar name
    AccessResultCode.SUCCESS).thenReturn(// Season profiles
    AccessResultCode.OTHER_REASON).thenReturn(// Week profiles
    AccessResultCode.SUCCESS).thenReturn(// Day profiles
    AccessResultCode.SUCCESS);
    final ActivityCalendarDto activityCalendar = this.createDefaultActivityCalendar();
    // CALL
    final Throwable thrown = catchThrowable(() -> this.executor.execute(this.conn, this.DLMS_DEVICE, activityCalendar, this.messageMetadata));
    // VERIFY
    assertThat(thrown).isInstanceOf(ProtocolAdapterException.class).hasMessageContaining("SEASONS: Result(OTHER_REASON)");
    this.activityCalendarValidator.verify(() -> ActivityCalendarValidator.validate(activityCalendar), times(1));
}
Also used : AssertionsForClassTypes.catchThrowable(org.assertj.core.api.AssertionsForClassTypes.catchThrowable) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) Test(org.junit.jupiter.api.Test)

Example 9 with ActivityCalendarDto

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

the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarWithValidationFailure.

@Test
void testSetActivityCalendarWithValidationFailure() throws IOException {
    // SETUP
    this.activityCalendarValidator.when(() -> ActivityCalendarValidator.validate(any())).thenThrow(new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_DLMS));
    final ActivityCalendarDto activityCalendar = this.createDefaultActivityCalendar();
    // CALL
    final Throwable thrown = catchThrowable(() -> this.executor.execute(this.conn, this.DLMS_DEVICE, activityCalendar, this.messageMetadata));
    // VERIFY
    assertThat(thrown).isInstanceOf(FunctionalException.class);
}
Also used : AssertionsForClassTypes.catchThrowable(org.assertj.core.api.AssertionsForClassTypes.catchThrowable) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) Test(org.junit.jupiter.api.Test)

Example 10 with ActivityCalendarDto

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

the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarWithActivationFailure.

@Test
void testSetActivityCalendarWithActivationFailure() throws ProtocolAdapterException, IOException {
    // SETUP
    final String errorMessage = "Activation failure";
    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)).thenThrow(new ProtocolAdapterException(errorMessage));
    final ActivityCalendarDto activityCalendar = this.createDefaultActivityCalendar();
    // CALL
    final Throwable thrown = catchThrowable(() -> this.executor.execute(this.conn, this.DLMS_DEVICE, activityCalendar, this.messageMetadata));
    // VERIFY
    assertThat(thrown).isInstanceOf(ProtocolAdapterException.class).hasMessageContaining(errorMessage);
    this.activityCalendarValidator.verify(() -> ActivityCalendarValidator.validate(activityCalendar), times(1));
}
Also used : AssertionsForClassTypes.catchThrowable(org.assertj.core.api.AssertionsForClassTypes.catchThrowable) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SetParameter(org.openmuc.jdlms.SetParameter) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) 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