Search in sources :

Example 1 with DlmsDeviceBuilder

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder 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 2 with DlmsDeviceBuilder

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

Example 3 with DlmsDeviceBuilder

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

the class DomainHelperServiceTest method setsIpAddressFromMessageMetadataIfIpAddressIsStatic.

@Test
void setsIpAddressFromMessageMetadataIfIpAddressIsStatic() throws Exception {
    final String ipAddress = IP_ADDRESS;
    final DlmsDevice dlmsDevice = new DlmsDeviceBuilder().withIpAddress(null).withIpAddressStatic(true).build();
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withIpAddress(ipAddress).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 4 with DlmsDeviceBuilder

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

the class InvocationCounterManagerTest method initializesInvocationCounterForDevice.

@Test
void initializesInvocationCounterForDevice() throws Exception {
    final long invocationCounterValueOnDevice = 123;
    final DlmsConnectionManager connectionManager = mock(DlmsConnectionManager.class);
    final DataObject dataObject = DataObject.newUInteger32Data(invocationCounterValueOnDevice);
    when(this.dlmsHelper.getAttributeValue(eq(connectionManager), refEq(ATTRIBUTE_ADDRESS_INVOCATION_COUNTER_VALUE))).thenReturn(dataObject);
    when(this.deviceRepository.save(this.device)).thenReturn(new DlmsDeviceBuilder().withDeviceIdentification(this.device.getDeviceIdentification()).withInvocationCounter(this.device.getInvocationCounter()).withVersion(this.device.getVersion() + 1).build());
    this.manager.initializeWithInvocationCounterStoredOnDeviceTask(this.device, connectionManager);
    verify(this.deviceRepository).save(this.device);
    verify(this.deviceRepository).save(this.device);
    assertThat(this.device.getVersion()).isGreaterThan(this.initialDeviceVersion);
    assertThat(this.device.getInvocationCounter()).isEqualTo(invocationCounterValueOnDevice);
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with DlmsDeviceBuilder

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

the class UpdateFirmwareRequestMessageProcessorTest method setup.

@BeforeEach
void setup() throws OsgpException {
    this.device = new DlmsDeviceBuilder().withHls5Active(true).build();
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.device);
    when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.messageListenerMock);
    when(this.throttlingClientConfig.clientEnabled()).thenReturn(false);
    doNothing().when(this.connectionHelper).createAndHandleConnectionForDevice(any(MessageMetadata.class), same(this.device), nullable(DlmsMessageListener.class), any(Consumer.class));
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Consumer(java.util.function.Consumer) DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

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