PushNotificationAlarmMessageProcessor extends AbstractProtocolRequestMessageProcessor { @Override public void processMessage(final ObjectMessage message) throws JMSException { final MessageMetadata metadata = MessageMetadata.fromMessage(message); LOGGER.info("Received message of messageType: {} organisationIdentification: {} deviceIdentification: {}", messageType, metadata.getOrganisationIdentification(), metadata.getDeviceIdentification()); final RequestMessage requestMessage = (RequestMessage) message.getObject(); final Object dataObject = requestMessage.getRequest(); try { final Device device = getDevice(metadata.getDeviceIdentification()); final PushNotificationAlarmDto pushNotificationAlarm = (PushNotificationAlarmDto) dataObject; this.storeAlarmAsEvent(pushNotificationAlarm); final String ownerIdentification = this.getOrganisationIdentificationOfOwner(device); LOGGER.info("Matching owner {} with device {} handling {} from {}", ownerIdentification, metadata.getDeviceIdentification(), messageType, requestMessage.getIpAddress()); final RequestMessage requestWithUpdatedOrganization = new RequestMessage(requestMessage.getCorrelationUid(), ownerIdentification, requestMessage.getDeviceIdentification(), requestMessage.getIpAddress(), pushNotificationAlarm); Optional<DomainInfo> smartMeteringDomain = getDomainInfo(); if (smartMeteringDomain.isPresent()) { this.domainRequestService.send(requestWithUpdatedOrganization, DeviceFunction.PUSH_NOTIFICATION_ALARM.name(), smartMeteringDomain.get()); device.updateConnectionDetailsToSuccess(); deviceRepository.save(device); } else { LOGGER.error( "No DomainInfo found for SMART_METERING 1.0, unable to send message of message type: {} to " + "domain adapter. RequestMessage for {} dropped.", messageType, pushNotificationAlarm); } } catch (OsgpException e) { String errorMessage = String.format("%s occurred, reason: %s", e.getClass().getName(), e.getMessage()); LOGGER.error(errorMessage, e); throw new JMSException(errorMessage); } } protected  PushNotificationAlarmMessageProcessor(); @Override void processMessage(final ObjectMessage message);  }
@Test public void testProcessMessageSuccess() throws JMSException { assertThat(this.device.getLastSuccessfulConnectionTimestamp()).isNull(); this.pushNotificationAlarmMessageProcessor.processMessage(this.message); assertThat(this.device.getLastSuccessfulConnectionTimestamp()).isNotNull(); verify(this.deviceRepository).save(this.device); }
@Test public void testUnknownDevice() { when(this.deviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(null); assertThatExceptionOfType(JMSException.class).isThrownBy(() -> { this.pushNotificationAlarmMessageProcessor.processMessage(this.message); }); }
@Test public void testUnknownDeviceAuthorization() { when(this.deviceAuthorizationRepository.findByDeviceAndFunctionGroup(this.device, DeviceFunctionGroup.OWNER)) .thenReturn(null); assertThatExceptionOfType(JMSException.class).isThrownBy(() -> { this.pushNotificationAlarmMessageProcessor.processMessage(this.message); }); }