Search in sources :

Example 51 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class SetDeviceLifecycleStatusByChannelCommandExecutor method execute.

@Override
public SetDeviceLifecycleStatusByChannelResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice gatewayDevice, final SetDeviceLifecycleStatusByChannelRequestDataDto request, final MessageMetadata messageMetadata) throws OsgpException {
    final GetMBusDeviceOnChannelRequestDataDto mbusDeviceOnChannelRequest = new GetMBusDeviceOnChannelRequestDataDto(gatewayDevice.getDeviceIdentification(), request.getChannel());
    final ChannelElementValuesDto channelElementValues = this.getMBusDeviceOnChannelCommandExecutor.execute(conn, gatewayDevice, mbusDeviceOnChannelRequest, messageMetadata);
    if (!channelElementValues.hasChannel() || !channelElementValues.hasDeviceTypeIdentification() || !channelElementValues.hasManufacturerIdentification()) {
        throw new FunctionalException(FunctionalExceptionType.NO_DEVICE_FOUND_ON_CHANNEL, ComponentType.PROTOCOL_DLMS);
    }
    final DlmsDevice mbusDevice = this.dlmsDeviceRepository.findByMbusIdentificationNumberAndMbusManufacturerIdentification(channelElementValues.getIdentificationNumber(), channelElementValues.getManufacturerIdentification());
    if (mbusDevice == null) {
        throw new FunctionalException(FunctionalExceptionType.NO_MATCHING_MBUS_DEVICE_FOUND, ComponentType.PROTOCOL_DLMS);
    }
    return new SetDeviceLifecycleStatusByChannelResponseDto(gatewayDevice.getDeviceIdentification(), request.getChannel(), mbusDevice.getDeviceIdentification(), request.getDeviceLifecycleStatus());
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) SetDeviceLifecycleStatusByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) GetMBusDeviceOnChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)

Example 52 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageListenerIT method testProcessRequestMessages.

@Test
void testProcessRequestMessages() throws JMSException, OsgpException {
    // SETUP
    final DlmsDevice dlmsDevice = new DlmsDevice();
    dlmsDevice.setDeviceIdentification("1");
    dlmsDevice.setIpAddress("127.0.0.1");
    dlmsDevice.setHls5Active(true);
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(dlmsDevice);
    doNothing().when(this.protocolDlmsOutboundOsgpCoreResponsesMessageSender).send(any(ResponseMessage.class));
    // EXECUTE
    LOGGER.info("Starting Test");
    for (int i = 0; i < 200; i++) {
        LOGGER.info("Send message number {} ", i);
        final ObjectMessage message = new ObjectMessageBuilder().withDeviceIdentification("osgp").withMessageType(MessageType.GET_PROFILE_GENERIC_DATA.toString()).withObject(new GetPowerQualityProfileRequestDataDto("PUBLIC", new Date(), new Date(), null)).build();
        this.listener.onMessage(message);
    }
    verify(this.protocolDlmsOutboundOsgpCoreResponsesMessageSender, times(200)).send(any(ResponseMessage.class));
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) GetPowerQualityProfileRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileRequestDataDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) Date(java.util.Date) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 53 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class DlmsConnectionHelperTest method doesNotPingDeviceBeforeCreatingConnectionIfPingingIsDisabled.

@Test
void doesNotPingDeviceBeforeCreatingConnectionIfPingingIsDisabled() throws Exception {
    final String deviceIpAddress = "192.168.92.56";
    when(this.devicePingConfig.pingingEnabled()).thenReturn(false);
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).build();
    device.setIpAddress(deviceIpAddress);
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, this.task);
    verifyNoInteractions(this.pinger);
    verifyNoMoreInteractions(this.devicePingConfig);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 54 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class DlmsConnectionHelperTest method noInteractionsWithInvocationCounterManagerForDeviceThatDoesNotNeedInvocationCounter.

@Test
void noInteractionsWithInvocationCounterManagerForDeviceThatDoesNotNeedInvocationCounter() throws Exception {
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(false).build();
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    doNothing().when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
    this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, this.task);
    verifyNoInteractions(this.invocationCounterManager);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 55 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class DlmsConnectionHelperTest method invocationCounterUpdateSuccesfull.

@Test
void invocationCounterUpdateSuccesfull() throws Exception {
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("SMR").withInvocationCounter(123L).build();
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    final ConnectionException exception = new ConnectionException("Error creating connection for device E0051004228715518 with Ip address:62.133.88.34 Port:null " + "UseHdlc:false UseSn:false Message:Socket was closed by remote host.");
    // First try throw exception, second time no exception
    doThrow(exception).doNothing().when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
    this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, null, this.task);
    verify(this.invocationCounterManager).initializeInvocationCounter(this.messageMetadata, device);
    verify(this.connectionFactory, times(2)).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) Test(org.junit.jupiter.api.Test)

Aggregations

DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)103 Test (org.junit.jupiter.api.Test)58 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)24 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)17 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)17 AttributeAddress (org.openmuc.jdlms.AttributeAddress)15 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)13 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)10 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)10 Then (io.cucumber.java.en.Then)9 DataObject (org.openmuc.jdlms.datatypes.DataObject)7 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Instant (java.time.Instant)5 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)5 IOException (java.io.IOException)4 Date (java.util.Date)4 List (java.util.List)4 ThrowableAssert.catchThrowable (org.assertj.core.api.ThrowableAssert.catchThrowable)4 SetParameter (org.openmuc.jdlms.SetParameter)4