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());
}
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());
}
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));
}
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);
}
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));
}
Aggregations