Search in sources :

Example 31 with DlmsDevice

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

the class DeviceConverterTest method convertsSmartMeteringDtoToDlmsDevice.

@Test
public void convertsSmartMeteringDtoToDlmsDevice() {
    final SmartMeteringDeviceDto dto = new SmartMeteringDeviceDtoBuilder().build();
    final DlmsDevice result = this.converter.convertTo(dto, null, null);
    final DlmsDevice expected = this.converted(dto);
    Assertions.assertThat(result).isEqualToIgnoringGivenFields(expected, "creationTime", "modificationTime", "version");
}
Also used : SmartMeteringDeviceDtoBuilder(org.opensmartgridplatform.dto.valueobjects.smartmetering.SmartMeteringDeviceDtoBuilder) SmartMeteringDeviceDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SmartMeteringDeviceDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 32 with DlmsDevice

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

the class GetFirmwareFileResponseMessageProcessor method processMessageTasks.

@SuppressWarnings(// SilentException cannot be caught since it does not extend Exception.
"squid:S1193")
void processMessageTasks(final Serializable messageObject, final MessageMetadata messageMetadata, final DlmsConnectionManager conn) throws OsgpException {
    try {
        final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
        LOGGER.info("{} called for device: {} for organisation: {}", messageMetadata.getMessageType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification());
        final Serializable response;
        response = this.handleMessage(conn, device, messageObject);
        // Send response
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, this.responseMessageSender, response);
    } catch (final Exception exception) {
        // Return original request + exception
        if (!(exception instanceof SilentException)) {
            LOGGER.error("Unexpected exception during {}", this.messageType.name(), exception);
        }
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, exception, this.responseMessageSender, this.createUpdateFirmwareRequestDto(messageObject));
    } finally {
        final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
        this.doConnectionPostProcessing(device, conn, messageMetadata);
    }
}
Also used : Serializable(java.io.Serializable) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException)

Example 33 with DlmsDevice

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

the class BundleServiceTest method shouldHandleActionsWithoutPreviousResult.

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

Example 34 with DlmsDevice

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

the class DomainHelperServiceTest method getDeviceIpAddressFromSessionProviderReturnsAddressFromProviderIfDeviceIsInSession.

@Test
void getDeviceIpAddressFromSessionProviderReturnsAddressFromProviderIfDeviceIsInSession() throws Exception {
    final String communicationProvider = "comm-prov";
    final String iccId = "icc-id";
    final String ipAddress = IP_ADDRESS;
    this.whenSessionProviderReturnsIpAddress(communicationProvider, iccId, ipAddress);
    final DlmsDevice dlmsDevice = new DlmsDeviceBuilder().withCommunicationProvider(communicationProvider).setIccId(iccId).build();
    final String actualIpAddress = this.domainHelperService.getDeviceIpAddressFromSessionProvider(dlmsDevice);
    assertThat(actualIpAddress).isEqualTo(ipAddress);
}
Also used : 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 35 with DlmsDevice

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

the class DomainHelperServiceTest method getDeviceIpAddressFromSessionProviderReturnsIpAddressOnlyAfterWakeUp.

@Test
void getDeviceIpAddressFromSessionProviderReturnsIpAddressOnlyAfterWakeUp() 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().withCommunicationProvider(communicationProvider).setIccId(iccId).build();
    final String actualIpAddress = this.domainHelperService.getDeviceIpAddressFromSessionProvider(dlmsDevice);
    assertThat(actualIpAddress).isEqualTo(ipAddress);
    verify(this.jasperWirelessSmsClient).sendWakeUpSMS(iccId);
}
Also used : 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

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