Search in sources :

Example 26 with MessageMetadata

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));
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) CosemObjectAccessor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.CosemObjectAccessor) DecoupleMbusDeviceResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto) ObisCode(org.openmuc.jdlms.ObisCode) Test(org.junit.jupiter.api.Test)

Example 27 with MessageMetadata

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));
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Test(org.junit.jupiter.api.Test)

Example 28 with 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);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) Test(org.junit.jupiter.api.Test)

Example 29 with MessageMetadata

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);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) MessageProcessor(org.opensmartgridplatform.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException)

Example 30 with MessageMetadata

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);
    }
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) Logger(org.slf4j.Logger) OsgpResponseMessageProcessor(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.responses.from.core.OsgpResponseMessageProcessor) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) LoggerFactory(org.slf4j.LoggerFactory) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) JMSException(javax.jms.JMSException) Serializable(java.io.Serializable) Component(org.springframework.stereotype.Component) FirmwareService(org.opensmartgridplatform.adapter.protocol.dlms.application.services.FirmwareService) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ThrowingConsumer(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)

Aggregations

MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)147 JMSException (javax.jms.JMSException)65 Device (org.opensmartgridplatform.domain.core.entities.Device)29 Test (org.junit.jupiter.api.Test)25 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)23 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)22 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)20 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)20 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)20 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)19 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)18 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)14 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)14 ObjectMessage (javax.jms.ObjectMessage)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)13 Serializable (java.io.Serializable)12 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)12 UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)10