Search in sources :

Example 1 with Iec60870Device

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

the class Iec60870DistributionAutomationDeviceCreator method apply.

@Override
public Iec60870Device apply(final Map<String, String> settings) {
    final Iec60870Device device = new Iec60870Device(this.deviceIdentification(settings), this.deviceType());
    device.setPort(this.port(settings));
    device.setCommonAddress(this.commonAddress(settings));
    return device;
}
Also used : Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)

Example 2 with Iec60870Device

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

the class Iec60870LightSensorDeviceCreator method apply.

@Override
public Iec60870Device apply(final Map<String, String> settings) {
    final Iec60870Device device = new Iec60870Device(this.deviceIdentification(settings), this.deviceType());
    device.setGatewayDeviceIdentification(this.gatewayDeviceIdentification(settings));
    device.setInformationObjectAddress(this.informationObjectAddress(settings));
    // Field common address is not needed for light measurement device, but
    // is currently not nullable...
    device.setCommonAddress(-1);
    return device;
}
Also used : Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)

Example 3 with Iec60870Device

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

the class LightMeasurementGatewayDeviceResponseServiceTest method processShouldDelegateProcessingReportsForEachDeviceBehindTheGateway.

@Test
void processShouldDelegateProcessingReportsForEachDeviceBehindTheGateway() {
    // Arrange
    final Iec60870Device gatewayDevice = Iec60870DeviceFactory.getGatewayDevice();
    final Iec60870Device lightMeasurementDevice1 = Iec60870DeviceFactory.getLightMeasurementDevice1();
    final Iec60870Device lightMeasurementDevice2 = Iec60870DeviceFactory.getLightMeasurementDevice2();
    when(this.iec60870DeviceRepository.findByGatewayDeviceIdentification(gatewayDevice.getDeviceIdentification())).thenReturn(Arrays.asList(lightMeasurementDevice1, lightMeasurementDevice2));
    final MeasurementReportDto measurementReportDto = MeasurementReportFactory.getMeasurementReportDto();
    final ResponseMetadata responseMetadata = new ResponseMetadata.Builder().withCorrelationUid(CORRELATION_UID).withDeviceIdentification(Iec60870DeviceFactory.GATEWAY_DEVICE_IDENTIFICATION).withOrganisationIdentification(ORGANISATION_IDENTIFICATION).build();
    // Act
    this.lightMeasurementGatewayDeviceResponseService.process(measurementReportDto, responseMetadata);
    // Assert
    verify(this.lightMeasurementDeviceResponseService, times(1)).sendLightSensorStatusResponse(same(measurementReportDto), same(lightMeasurementDevice1), same(responseMetadata), anyString());
    verify(this.lightMeasurementDeviceResponseService, times(1)).sendLightSensorStatusResponse(same(measurementReportDto), same(lightMeasurementDevice2), same(responseMetadata), anyString());
}
Also used : MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto) Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) Test(org.junit.jupiter.api.Test)

Example 4 with Iec60870Device

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

the class ClientConnectionServiceTest method testGetConnectionShouldReturnExistingConnectionToGatewayDeviceWhenInCache.

@Test
void testGetConnectionShouldReturnExistingConnectionToGatewayDeviceWhenInCache() throws Exception {
    // Arrange
    final String deviceIdentification = "LM_DVC_1";
    final String gatewayDeviceIdentification = "LM_GATEWAY_1";
    final Iec60870Device device = Iec60870DeviceFactory.createLightMeasurementDevice(deviceIdentification, gatewayDeviceIdentification);
    when(this.iec60870DeviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(Optional.of(device));
    final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(deviceIdentification);
    final ClientConnection expectedConnection = ClientConnectionFactory.forDevice(gatewayDeviceIdentification);
    this.connectionCache.addConnection(gatewayDeviceIdentification, expectedConnection);
    // Act
    final ClientConnection actualConnection = this.clientConnectionService.getConnection(requestMetadata);
    // Assert
    assertThat(actualConnection).isEqualTo(expectedConnection);
}
Also used : Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device) RequestMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata) Test(org.junit.jupiter.api.Test)

Example 5 with Iec60870Device

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

the class ClientConnectionServiceTest method testGetConnectionShouldReturnNewConnectionToGatewayDeviceWhenNotInCache.

@Test
void testGetConnectionShouldReturnNewConnectionToGatewayDeviceWhenNotInCache() throws Exception {
    // Arrange
    final String deviceIdentification = "LM_DVC_1";
    final String gatewayDeviceIdentification = "LM_GATEWAY_1";
    final Iec60870Device device = Iec60870DeviceFactory.createLightMeasurementDevice(deviceIdentification, gatewayDeviceIdentification);
    final Iec60870Device gateway = Iec60870DeviceFactory.createLightMeasurementGatewayDevice(gatewayDeviceIdentification);
    when(this.iec60870DeviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(Optional.of(device));
    when(this.iec60870DeviceRepository.findByDeviceIdentification(gatewayDeviceIdentification)).thenReturn(Optional.of(gateway));
    final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(deviceIdentification);
    final ClientConnection expectedConnection = ClientConnectionFactory.forDevice(gatewayDeviceIdentification);
    when(this.iec60870Client.connect(eq(expectedConnection.getConnectionParameters()), any(ConnectionEventListener.class))).thenReturn(expectedConnection);
    // Act
    final ClientConnection actualConnection = this.clientConnectionService.getConnection(requestMetadata);
    // Assert
    assertThat(actualConnection).isEqualTo(expectedConnection);
}
Also used : Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device) RequestMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata) ConnectionEventListener(org.openmuc.j60870.ConnectionEventListener) Test(org.junit.jupiter.api.Test)

Aggregations

Iec60870Device (org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)21 Test (org.junit.jupiter.api.Test)6 RequestMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)4 ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)4 ConnectionEventListener (org.openmuc.j60870.ConnectionEventListener)3 ClientConnectionAlreadyInCacheException (org.opensmartgridplatform.adapter.protocol.iec60870.domain.exceptions.ClientConnectionAlreadyInCacheException)2 ConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters)2 DomainInfo (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo)2 MeasurementReportDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)2 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)2 Given (io.cucumber.java.en.Given)1 When (io.cucumber.java.en.When)1 ClientConnectionEventListener (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)1 DeviceType (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceType)1 LightSensorStatusDto (org.opensmartgridplatform.dto.valueobjects.LightSensorStatusDto)1 ConnectionFailureException (org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException)1