use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class DecoupleMBusDeviceCommandExecutorTest method testHappyFlow.
@Test
public void testHappyFlow() throws ProtocolAdapterException {
final short channel = (short) 1;
final ChannelElementValuesDto channelElementValuesDto = mock(ChannelElementValuesDto.class);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
when(this.deviceChannelsHelper.getObisCode(this.device, channel)).thenReturn(new ObisCode("0.1.24.1.0.255"));
when(this.decoupleMbusDto.getChannel()).thenReturn(channel);
when(this.deviceChannelsHelper.deinstallSlave(eq(this.conn), eq(this.device), any(Short.class), any(CosemObjectAccessor.class))).thenReturn(MethodResultCode.SUCCESS);
when(this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, channel)).thenReturn(channelElementValuesDto);
final DecoupleMbusDeviceResponseDto responseDto = this.commandExecutor.execute(this.conn, this.device, this.decoupleMbusDto, messageMetadata);
assertThat(responseDto).isNotNull();
assertThat(responseDto.getChannelElementValues()).isEqualTo(channelElementValuesDto);
verify(this.deviceChannelsHelper, times(1)).getChannelElementValues(eq(this.conn), eq(this.device), any(Short.class));
verify(this.deviceChannelsHelper, times(1)).deinstallSlave(eq(this.conn), eq(this.device), any(Short.class), any(CosemObjectAccessor.class));
verify(this.deviceChannelsHelper, times(1)).resetMBusClientAttributeValues(eq(this.conn), eq(this.device), any(Short.class), any(String.class));
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class FirmwareServiceTest method updateFirmwareUsingFirmwareFileShouldStoreFirmwareFileAndCallExecutor.
@Test
public void updateFirmwareUsingFirmwareFileShouldStoreFirmwareFileAndCallExecutor() throws OsgpException {
// Arrange
final byte[] firmwareFile = firmwareIdentification.getBytes();
final byte[] firmwareImageIdentifier = Hex.decode("496d6167654964656e746966696572");
final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareIdentification, deviceIdentification, firmwareFile, firmwareImageIdentifier);
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
when(this.firmwareFileCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true);
when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile);
when(this.firmwareImageIdentifierCachingRepository.isAvailable(firmwareIdentification)).thenReturn(true);
when(this.firmwareImageIdentifierCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareImageIdentifier);
// Act
this.firmwareService.updateFirmware(this.dlmsConnectionManagerMock, this.dlmsDeviceMock, firmwareFileDto, messageMetadata);
// Assert
verify(this.firmwareFileCachingRepository, times(1)).store(firmwareIdentification, firmwareFile);
verify(this.firmwareImageIdentifierCachingRepository, times(1)).store(firmwareIdentification, firmwareImageIdentifier);
verify(this.updateFirmwareCommandExecutor, times(1)).execute(same(this.dlmsConnectionManagerMock), same(this.dlmsDeviceMock), any(UpdateFirmwareRequestDto.class), same(messageMetadata));
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectCommandExecutorTest method execute.
@Test
public void execute() throws ProtocolAdapterException {
// SETUP
final DlmsDevice device = new DlmsDevice();
final Protocol protocol = Protocol.DSMR_4_2_2;
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
device.setProtocol(protocol);
when(this.protocolServiceLookup.lookupGetService(protocol)).thenReturn(this.getService);
when(this.getService.getConfigurationObject(this.conn)).thenReturn(this.configurationObjectDto);
// CALL
final ConfigurationObjectDto result = this.instance.execute(this.conn, device, null, messageMetadata);
// VERIFY
assertThat(result).isSameAs(this.configurationObjectDto);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class OsgpResponseMessageListener method onMessage.
@Override
public void onMessage(final Message message) {
try {
LOGGER.info("[{}] - Received message of type: {}", message.getJMSCorrelationID(), message.getJMSType());
final MessageMetadata metadata = MessageMetadata.fromMessage(message);
final ObjectMessage objectMessage = (ObjectMessage) message;
final MessageProcessor messageProcessor = this.messageProcessorMap.getMessageProcessor(objectMessage);
if (messageProcessor != null) {
messageProcessor.processMessage(objectMessage);
} else {
LOGGER.error("[{}] - Unknown messagetype {}", metadata.getCorrelationUid(), metadata.getMessageType());
}
} catch (final JMSException ex) {
LOGGER.error("Exception: {} ", ex.getMessage(), ex);
}
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Processing {} response message", this.messageType.name());
}
// Get metadata from message and update message type to update
// firmware
final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
final Serializable messageObject = message.getObject();
final ThrowingConsumer<DlmsConnectionManager> taskForConnectionManager = conn -> this.processMessageTasks(messageObject, messageMetadata, conn);
try {
this.createAndHandleConnectionForDevice(this.domainHelperService.findDlmsDevice(messageMetadata), messageMetadata, taskForConnectionManager);
} catch (final OsgpException e) {
LOGGER.error("Something went wrong with the DlmsConnection", e);
}
}
Aggregations