Search in sources :

Example 16 with InvocationCountingDlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.

the class DlmsConnectionFactoryTest method setsIpAddressWhenConnectingToTheDevice.

@Test
void setsIpAddressWhenConnectingToTheDevice() throws Exception {
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withIpAddress(null).withIpAddressStatic(false).build();
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    when(this.hls5Connector.connect(this.messageMetadata, device, listener)).thenReturn(this.connection);
    this.factory.createAndHandleConnection(this.messageMetadata, device, listener, this.task);
    verify(this.domainHelperService).setIpAddressFromMessageMetadataOrSessionProvider(device, this.messageMetadata);
}
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 17 with InvocationCountingDlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.

the class DlmsConnectionFactoryTest method createAndHandleConnectionThrowsForHls4Device.

@Test
void createAndHandleConnectionThrowsForHls4Device() {
    final DlmsDevice device = new DlmsDeviceBuilder().withHls4Active(true).build();
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> this.factory.createAndHandleConnection(this.messageMetadata, device, listener, 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) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Test(org.junit.jupiter.api.Test)

Example 18 with InvocationCountingDlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.

the class DlmsConnectionFactoryTest method createsConnectionManagerForLls1Device.

@Test
void createsConnectionManagerForLls1Device() throws Exception {
    final DlmsDevice device = new DlmsDeviceBuilder().withLls1Active(true).build();
    final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
    when(this.lls1Connector.connect(this.messageMetadata, device, listener)).thenReturn(this.connection);
    final DlmsConnectionManager expected = this.newConnectionManager(device, listener, this.lls1Connector);
    this.factory.createAndHandleConnection(this.messageMetadata, device, listener, this.task);
    this.assertConnectionManagerForDevice(expected);
}
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 19 with InvocationCountingDlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.

the class SecureDlmsConnector method createConnection.

/**
 * Create a connection with the device.
 *
 * @param messageMetadata the metadata of the request message
 * @param device The device to connect with.
 * @param dlmsMessageListener Listener to set on the connection.
 * @return The connection.
 * @throws IOException When there are problems in connecting to or communicating with the device.
 * @throws OsgpException When there are problems reading the security and authorization keys.
 */
DlmsConnection createConnection(final MessageMetadata messageMetadata, final DlmsDevice device, final DlmsMessageListener dlmsMessageListener, final SecurityKeyProvider keyProvider) throws IOException, OsgpException {
    // Setup connection to device
    final TcpConnectionBuilder tcpConnectionBuilder = new TcpConnectionBuilder(InetAddress.getByName(device.getIpAddress())).setResponseTimeout(this.responseTimeout).setLogicalDeviceId(this.logicalDeviceAddress);
    tcpConnectionBuilder.setClientId(this.clientId).setReferencingMethod(device.isUseSn() ? ReferencingMethod.SHORT : ReferencingMethod.LOGICAL);
    if (device.isUseHdlc()) {
        tcpConnectionBuilder.useHdlc();
    }
    this.setSecurity(messageMetadata, device, keyProvider, tcpConnectionBuilder);
    this.setOptionalValues(device, tcpConnectionBuilder);
    if (device.isInDebugMode() || dlmsMessageListener instanceof InvocationCountingDlmsMessageListener) {
        tcpConnectionBuilder.setRawMessageListener(dlmsMessageListener);
    }
    return tcpConnectionBuilder.build();
}
Also used : TcpConnectionBuilder(org.openmuc.jdlms.TcpConnectionBuilder) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)

Aggregations

InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)19 Test (org.junit.jupiter.api.Test)17 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)17 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)17 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)17 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 IOException (java.io.IOException)1 DlmsConnection (org.openmuc.jdlms.DlmsConnection)1 TcpConnectionBuilder (org.openmuc.jdlms.TcpConnectionBuilder)1 DeviceKeyProcessAlreadyRunningException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException)1 RecoverKeyException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.RecoverKeyException)1 ThrottlingPermitDeniedException (org.opensmartgridplatform.throttling.ThrottlingPermitDeniedException)1 Permit (org.opensmartgridplatform.throttling.api.Permit)1