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;
}
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;
}
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());
}
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);
}
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);
}
Aggregations