Search in sources :

Example 16 with DlmsDeviceBuilder

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

the class SystemEventServiceTest method verifyMaxValueReachedEvent.

@Test
void verifyMaxValueReachedEvent() {
    final DlmsDevice device = new DlmsDeviceBuilder().withDeviceIdentification("device-1").withInvocationCounter(this.invocationCounterEventThreshold).build();
    final MessageMetadata messageMetadata = new Builder().withIpAddress("127.0-.0.1").withOrganisationIdentification("org-id").withDomain("domain").withDomainVersion("1.0").build();
    when(this.correlationIdProviderService.getCorrelationId(messageMetadata.getOrganisationIdentification(), device.getDeviceIdentification())).thenReturn("corr-id");
    this.service.verifySystemEventThresholdReachedEvent(device, messageMetadata);
    final ArgumentCaptor<MessageMetadata> messageMetadataCaptor = ArgumentCaptor.forClass(MessageMetadata.class);
    final ArgumentCaptor<RequestMessage> requestMessageCaptor = ArgumentCaptor.forClass(RequestMessage.class);
    verify(this.osgpRequestMessageSender).send(requestMessageCaptor.capture(), eq(MessageType.SYSTEM_EVENT.name()), messageMetadataCaptor.capture());
    final RequestMessage requestMessage = requestMessageCaptor.getValue();
    assertThat(requestMessage.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
    assertThat(requestMessage.getCorrelationUid()).isEqualTo("corr-id");
    assertThat(requestMessage.getOrganisationIdentification()).isEqualTo(messageMetadata.getOrganisationIdentification());
    assertThat(requestMessage.getIpAddress()).isEqualTo(messageMetadata.getIpAddress());
    assertThat(requestMessage.getRequest()).isInstanceOf(SystemEventDto.class);
    final SystemEventDto systemEventDto = (SystemEventDto) requestMessage.getRequest();
    assertThat(systemEventDto.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
    assertThat(systemEventDto.getSystemEventType()).isEqualTo(SystemEventTypeDto.INVOCATION_COUNTER_THRESHOLD_REACHED);
    assertThat(systemEventDto.getTimestamp()).isNotNull();
    final MessageMetadata metadata = messageMetadataCaptor.getValue();
    assertThat(metadata.getDeviceIdentification()).isEqualTo(device.getDeviceIdentification());
    assertThat(metadata.getCorrelationUid()).isEqualTo("corr-id");
    assertThat(metadata.getOrganisationIdentification()).isEqualTo(messageMetadata.getOrganisationIdentification());
    assertThat(metadata.getIpAddress()).isEqualTo(messageMetadata.getIpAddress());
    assertThat(metadata.getMessagePriority()).isEqualTo(MessagePriorityEnum.HIGH.getPriority());
    assertThat(metadata.getMessageType()).isEqualTo(MessageType.SYSTEM_EVENT.name());
    assertThat(metadata.getDomain()).isEqualTo(messageMetadata.getDomain());
    assertThat(metadata.getDomainVersion()).isEqualTo(messageMetadata.getDomainVersion());
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) SystemEventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto) Test(org.junit.jupiter.api.Test)

Example 17 with DlmsDeviceBuilder

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

the class DlmsConnectionHelperTest method initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForIskraDevice.

@Test
void initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForIskraDevice() 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 E0033006878667817 with Ip address:62.133.86.119 Port:4059 " + "UseHdlc:false UseSn:false Message:UNKNOWN: Received an association response (AARE) with an" + " error message. Result name REJECTED_PERMANENT. Assumed fault: user.");
    doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
    assertThrows(ConnectionException.class, () -> 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)

Example 18 with DlmsDeviceBuilder

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

the class DlmsConnectionHelperTest method createsConnectionForDeviceThatNeedsInvocationCounterWithInvocationCounterInitialized.

@Test
void createsConnectionForDeviceThatNeedsInvocationCounterWithInvocationCounterInitialized() throws Exception {
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withInvocationCounter(123L).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);
    verifyNoMoreInteractions(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 19 with DlmsDeviceBuilder

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

the class DlmsConnectionHelperTest method initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForLAndGDevice.

@Test
void initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForLAndGDevice() 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.");
    doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
    assertThrows(ConnectionException.class, () -> 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)

Example 20 with DlmsDeviceBuilder

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

the class DlmsConnectionHelperTest method doesNotPingDeviceWithoutIpAddressBeforeCreatingConnectionIfPingingIsEnabled.

@Test
void doesNotPingDeviceWithoutIpAddressBeforeCreatingConnectionIfPingingIsEnabled() throws Exception {
    when(this.devicePingConfig.pingingEnabled()).thenReturn(true);
    final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).build();
    device.setIpAddress(null);
    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)

Aggregations

DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)28 Test (org.junit.jupiter.api.Test)25 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)24 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)18 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)17 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)6 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Builder (org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder)3 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Consumer (java.util.function.Consumer)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 SystemEventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto)1