use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata 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.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class MeasurementAsduHandlerTest method shouldSendMeasurementReportWhenHandlingAsdu.
@Test
void shouldSendMeasurementReportWhenHandlingAsdu() throws Exception {
// Arrange
final ASdu asdu = AsduFactory.ofType(ASduType.M_ME_TF_1);
final MeasurementReportDto measurementReportDto = this.mapper.map(asdu, MeasurementReportDto.class);
final ResponseMetadata responseMetadata = new ResponseMetadata.Builder().withCorrelationUid(CORRELATION_UID).withDeviceIdentification(DEVICE_IDENTIFICATION).withDeviceType(DEVICE_TYPE).withOrganisationIdentification(ORGANISATION_IDENTIFICATION).build();
when(this.converter.convert(asdu)).thenReturn(measurementReportDto);
when(this.deviceResponseServiceRegistry.forDeviceType(DEVICE_TYPE)).thenReturn(this.deviceResponseService);
// Act
this.asduHandler.handleAsdu(asdu, responseMetadata);
// Assert
verify(this.deviceResponseService).process(measurementReportDto, responseMetadata);
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class LightSensorDeviceResponseService method sendEvent.
private void sendEvent(final EventNotificationDto eventNotification, final Iec60870Device device, final ResponseMetadata responseMetadata) {
final ResponseMetadata rm = new ResponseMetadata.Builder().withCorrelationUid(responseMetadata.getCorrelationUid()).withDeviceIdentification(device.getDeviceIdentification()).withDomainInfo(responseMetadata.getDomainInfo()).withMessageType(MessageType.EVENT_NOTIFICATION.name()).withOrganisationIdentification(responseMetadata.getOrganisationIdentification()).build();
this.lightMeasurementService.sendEventNotification(eventNotification, rm);
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class ClientConnectionService method createConnection.
private ClientConnection createConnection(final RequestMetadata requestMetadata) throws ConnectionFailureException {
final String deviceIdentification = requestMetadata.getDeviceIdentification();
final Iec60870Device device = this.getIec60870Device(deviceIdentification);
final Iec60870Device connectionDevice = this.getConnectionDevice(device);
final String connectionDeviceIdentification = device.getConnectionDeviceIdentification();
final ConnectionParameters connectionParameters = this.createConnectionParameters(connectionDevice, requestMetadata.getIpAddress());
final ResponseMetadata responseMetadata = ResponseMetadata.from(requestMetadata, connectionDeviceIdentification, connectionDevice.getDeviceType());
final ClientConnectionEventListener eventListener = new ClientConnectionEventListener.Builder().withDeviceIdentification(connectionDeviceIdentification).withClientAsduHandlerRegistry(this.clientAsduHandlerRegistry).withClientConnectionCache(this.connectionCache).withLoggingService(this.loggingService).withLogItemFactory(this.logItemFactory).withResponseMetadata(responseMetadata).withResponseMetadataFactory(this.responseMetadataFactory).build();
final ClientConnection newDeviceConnection = this.iec60870Client.connect(connectionParameters, eventListener);
try {
this.connectionCache.addConnection(connectionDeviceIdentification, newDeviceConnection);
} catch (final ClientConnectionAlreadyInCacheException e) {
LOGGER.warn("Client connection for device {} already exists. Closing new connection and returning existing connection", connectionDeviceIdentification);
LOGGER.debug("Exception: ", e);
newDeviceConnection.getConnection().close();
return e.getClientConnection();
}
return newDeviceConnection;
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class ConnectionSteps method initResponseMetadata.
private ResponseMetadata initResponseMetadata(final String deviceIdentification, final DeviceType deviceType) throws Exception {
final DomainInfo domainInfo = DomainInfoFactory.forDeviceType(deviceType);
// Make sure the connection event listener works as expected
final ResponseMetadata responseMetadata = new ResponseMetadata.Builder().withDeviceIdentification(deviceIdentification).withDeviceType(deviceType).withOrganisationIdentification(DEFAULT_ORGANISATION_IDENTIFICATION).withDomainInfo(domainInfo).withMessageType(DEFAULT_MESSAGE_TYPE).build();
return responseMetadata;
}
Aggregations