SetRandomisationSettingsCommandExecutor extends AbstractCommandExecutor<SetRandomisationSettingsRequestDataDto, AccessResultCode> { @Override public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final SetRandomisationSettingsRequestDataDto setRandomisationSettingsRequestDataDto) throws ProtocolAdapterException { LOGGER.info("Executing SetRandomisationSettingsCommandExecutor. Data = {}", setRandomisationSettingsRequestDataDto); boolean directAttach = setRandomisationSettingsRequestDataDto.getDirectAttach() == 1; int randomisationStartWindow = setRandomisationSettingsRequestDataDto.getRandomisationStartWindow(); int multiplicationFactor = setRandomisationSettingsRequestDataDto.getMultiplicationFactor(); int numberOfRetries = setRandomisationSettingsRequestDataDto.getNumberOfRetries(); if (directAttach) { LOGGER.info("Enabling directAttach on device {}.", device.getDeviceIdentification()); writeDirectAttach(conn, device, true); } else { LOGGER.info("Disabling directAttach and setting Randomisation Settings for device {}.", device.getDeviceIdentification()); writeDirectAttach(conn, device, false); writeRandomisationSettings(conn, device, randomisationStartWindow, multiplicationFactor, numberOfRetries); } return AccessResultCode.SUCCESS; } @Autowired  SetRandomisationSettingsCommandExecutor(final DlmsObjectConfigService dlmsObjectConfigService,
            final ProtocolServiceLookup protocolServiceLookup); @Override SetRandomisationSettingsRequestDataDto fromBundleRequestInput(final ActionRequestDto bundleInput); @Override ActionResponseDto asBundleResponse(final AccessResultCode executionResult); @Override AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device,
            final SetRandomisationSettingsRequestDataDto setRandomisationSettingsRequestDataDto);  }
@Test public void testExecuteSuccess() throws ProtocolAdapterException { final AccessResultCode resultCode = this.executor.execute(this.dlmsConnectionManager, this.device, this.dataDto); assertThat(resultCode).isEqualTo(AccessResultCode.SUCCESS); }
@Test public void testExecuteFailConfiguration() throws ProtocolAdapterException { when(this.setConfigurationObjectService.setConfigurationObject(any(DlmsConnectionManager.class), any(ConfigurationObjectDto.class), any(ConfigurationObjectDto.class))) .thenReturn(AccessResultCode.OTHER_REASON); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.executor.execute(this.dlmsConnectionManager, this.device, this.dataDto); }); }
@Test public void testExecuteFailSetRandomisationSettings() throws ProtocolAdapterException, IOException { when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.OTHER_REASON); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.executor.execute(this.dlmsConnectionManager, this.device, this.dataDto); }); }
@Test public void testUnknownAttribute() throws ProtocolAdapterException { when(this.dlmsObjectConfigService.findAttributeAddress(this.device, DlmsObjectType.RANDOMISATION_SETTINGS, null)).thenReturn(Optional.empty()); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.executor.execute(this.dlmsConnectionManager, this.device, this.dataDto); }); }