Search in sources :

Example 66 with DlmsDevice

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

the class BundleServiceTest method shouldNotHandleActionsContainingResult.

@Test
public void shouldNotHandleActionsContainingResult() {
    final ActionResponseDto previousActionResponse = new ActionResponseDto();
    final BundleMessagesRequestDto bundleMessagesRequest = new BundleMessagesRequestDto(Arrays.asList(this.createAction(this.builder.makePeriodicMeterReadsRequestDataDto(), previousActionResponse)));
    final BundleMessagesRequestDto result = this.bundleService.callExecutors(null, new DlmsDevice(), bundleMessagesRequest, this.messageMetadata);
    verify(this.bundleCommandExecutorMap, never()).getCommandExecutor(PeriodicMeterReadsRequestDataDto.class);
    assertThat(result.getAllResponses().size()).isOne();
    assertThat(result.getAllResponses().get(0)).isEqualTo(previousActionResponse);
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 67 with DlmsDevice

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

the class DomainHelperServiceTest method setsIpAddressFromSessionProviderIfIpAddressIsNotStatic.

@Test
void setsIpAddressFromSessionProviderIfIpAddressIsNotStatic() throws Exception {
    final String communicationProvider = "comm-prov";
    final String iccId = "icc-id";
    final String ipAddress = IP_ADDRESS;
    this.whenSessionProviderReturnsIpAddressAfterWakeUp(communicationProvider, iccId, ipAddress);
    final DlmsDevice dlmsDevice = new DlmsDeviceBuilder().withIpAddressStatic(false).withCommunicationProvider(communicationProvider).setIccId(iccId).build();
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withIpAddress(null).build();
    this.domainHelperService.setIpAddressFromMessageMetadataOrSessionProvider(dlmsDevice, messageMetadata);
    assertThat(dlmsDevice.getIpAddress()).isEqualTo(ipAddress);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) 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 68 with DlmsDevice

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

the class SystemEventServiceTest method verifyMaxValueNotReachedEvent.

@Test
void verifyMaxValueNotReachedEvent() {
    final DlmsDevice device = new DlmsDeviceBuilder().withInvocationCounter(this.invocationCounterEventThreshold - 1).build();
    final MessageMetadata messageMetadata = new Builder().withOrganisationIdentification("org-id").build();
    this.service.verifySystemEventThresholdReachedEvent(device, messageMetadata);
    verifyNoInteractions(this.correlationIdProviderService);
    verify(this.osgpRequestMessageSender, never()).send(any(RequestMessage.class), eq(MessageType.SYSTEM_EVENT.name()), any(MessageMetadata.class));
}
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) Test(org.junit.jupiter.api.Test)

Example 69 with DlmsDevice

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

the class SystemEventServiceTest method verifyInvocationCounterIsNull.

@Test
void verifyInvocationCounterIsNull() {
    final DlmsDevice device = new DlmsDeviceBuilder().withInvocationCounter(null).build();
    final MessageMetadata messageMetadata = new Builder().withOrganisationIdentification("org-id").build();
    this.service.verifySystemEventThresholdReachedEvent(device, messageMetadata);
    verifyNoInteractions(this.correlationIdProviderService);
    verify(this.osgpRequestMessageSender, never()).send(any(RequestMessage.class), eq(MessageType.SYSTEM_EVENT.name()), any(MessageMetadata.class));
}
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) Test(org.junit.jupiter.api.Test)

Example 70 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice 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)

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