Search in sources :

Example 6 with DlmsConnection

use of org.openmuc.jdlms.DlmsConnection in project open-smart-grid-platform by OSGP.

the class DlmsHelperTest method assertGetWithListException.

private void assertGetWithListException(final Class<? extends Exception> jdlmsExceptionClazz, final Class<? extends Exception> exceptionClazz) throws IOException {
    final DlmsConnection dlmsConnection = mock(DlmsConnection.class);
    final DlmsConnectionManager connectionManager = mock(DlmsConnectionManager.class);
    final DlmsDevice dlmsDevice = mock(DlmsDevice.class);
    when(dlmsDevice.getDeviceIdentification()).thenReturn("666");
    when(connectionManager.getConnection()).thenReturn(dlmsConnection);
    final AttributeAddress[] attrAddresses = new AttributeAddress[1];
    attrAddresses[0] = mock(AttributeAddress.class);
    when(dlmsDevice.isWithListSupported()).thenReturn(true);
    when(dlmsConnection.get(Arrays.asList(attrAddresses))).thenThrow(jdlmsExceptionClazz);
    final Exception exception = assertThrows(exceptionClazz, () -> {
        this.dlmsHelper.getWithList(connectionManager, dlmsDevice, attrAddresses);
    });
    assertThat(exception.getMessage()).contains(dlmsDevice.getDeviceIdentification());
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsConnection(org.openmuc.jdlms.DlmsConnection) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Aggregations

DlmsConnection (org.openmuc.jdlms.DlmsConnection)6 Test (org.junit.jupiter.api.Test)4 IOException (java.io.IOException)3 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)3 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)3 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 DeviceKeyProcessAlreadyRunningException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 RecoverKeyException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.RecoverKeyException)1 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 ThrottlingPermitDeniedException (org.opensmartgridplatform.throttling.ThrottlingPermitDeniedException)1 Permit (org.opensmartgridplatform.throttling.api.Permit)1