InstallationService { public void addMeter(final DeviceMessageMetadata deviceMessageMetadata, final AddSmartMeterRequest addSmartMeterRequest) throws FunctionalException { final String organisationId = deviceMessageMetadata.getOrganisationIdentification(); final String deviceId = deviceMessageMetadata.getDeviceIdentification(); LOGGER.debug("addMeter for organisationIdentification: {} for deviceIdentification: {}", organisationId, deviceId); final SmartMeteringDevice smartMeteringDevice = addSmartMeterRequest.getDevice(); final SmartMeter smartMeter = this.smartMeterService.getSmartMeter(deviceId, smartMeteringDevice); this.smartMeterService.storeMeter(organisationId, addSmartMeterRequest, smartMeter); this.osgpCoreRequestMessageSender.send(this.getRequestMessage(deviceMessageMetadata, smartMeteringDevice), deviceMessageMetadata.getMessageType(), deviceMessageMetadata.getMessagePriority(), deviceMessageMetadata.getScheduleTime()); } InstallationService(); void addMeter(final DeviceMessageMetadata deviceMessageMetadata,
            final AddSmartMeterRequest addSmartMeterRequest); void removeMeter(final DeviceMessageMetadata deviceMessageMetadata); @Transactional(value = "transactionManager") void handleAddMeterResponse(final DeviceMessageMetadata deviceMessageMetadata,
            final ResponseMessageResultType deviceResult, final OsgpException exception); void coupleMbusDevice(final DeviceMessageMetadata deviceMessageMetadata,
            final CoupleMbusDeviceRequestData requestData); @Transactional(value = "transactionManager") void deCoupleMbusDevice(final DeviceMessageMetadata deviceMessageMetadata,
            final DeCoupleMbusDeviceRequestData requestData); @Transactional(value = "transactionManager") void coupleMbusDeviceByChannel(final DeviceMessageMetadata deviceMessageMetadata,
            final CoupleMbusDeviceByChannelRequestData requestData); @Transactional(value = "transactionManager") void handleCoupleMbusDeviceResponse(final DeviceMessageMetadata deviceMessageMetadata,
            final ResponseMessageResultType result, final OsgpException exception,
            final MbusChannelElementsResponseDto dataObject); @Transactional(value = "transactionManager") void handleDeCoupleMbusDeviceResponse(final DeviceMessageMetadata deviceMessageMetadata,
            final ResponseMessageResultType result, final OsgpException exception,
            final DeCoupleMbusDeviceResponseDto deCoupleMbusDeviceResponseDto); @Transactional(value = "transactionManager") void handleCoupleMbusDeviceByChannelResponse(final DeviceMessageMetadata deviceMessageMetadata,
            final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException,
            final CoupleMbusDeviceByChannelResponseDto dataObject); @Transactional(value = "transactionManager") void handleResponse(final String methodName, final DeviceMessageMetadata deviceMessageMetadata,
            final ResponseMessageResultType deviceResult, final OsgpException exception);  }
@Test public void addMeterProtocolInfoSaved() throws FunctionalException { when(this.smartMeteringDeviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(null); when(this.smartMeteringDevice.getProtocolName()).thenReturn(PROTOCOL_NAME); when(this.smartMeteringDevice.getProtocolVersion()).thenReturn(PROTOCOL_VERSION); when(this.protocolInfoRepository .findByProtocolAndProtocolVersion(this.smartMeteringDevice.getProtocolInfoLookupName(), PROTOCOL_VERSION)).thenReturn(this.protocolInfo); this.instance.addMeter(this.deviceMessageMetadata, this.addSmartMeterRequest); verify(this.smartMeter).updateProtocol(this.protocolInfo); verify(this.smartMeteringDeviceRepository).save(this.smartMeter); }
@Test public void addMeterProtocolInfoNotFound() { when(this.smartMeteringDeviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(null); when(this.smartMeteringDevice.getProtocolName()).thenReturn(PROTOCOL_NAME); when(this.smartMeteringDevice.getProtocolVersion()).thenReturn(PROTOCOL_VERSION); when(this.protocolInfoRepository.findByProtocolAndProtocolVersion(PROTOCOL_NAME, PROTOCOL_VERSION)) .thenReturn(null); try { this.instance.addMeter(this.deviceMessageMetadata, this.addSmartMeterRequest); } catch (final FunctionalException e) { assertThat(e.getExceptionType()).isEqualTo(FunctionalExceptionType.UNKNOWN_PROTOCOL_NAME_OR_VERSION); assertThat(e.getComponentType()).isEqualTo(ComponentType.DOMAIN_SMART_METERING); } }
@Test public void addMeterDeviceExists() { when(this.smartMeteringDeviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)) .thenReturn(this.smartMeter); try { this.instance.addMeter(this.deviceMessageMetadata, this.addSmartMeterRequest); } catch (final FunctionalException e) { assertThat(e.getExceptionType()).isEqualTo(FunctionalExceptionType.EXISTING_DEVICE); assertThat(e.getComponentType()).isEqualTo(ComponentType.DOMAIN_SMART_METERING); } }