Search in sources :

Example 1 with ResponseMetadata

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());
}
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 2 with ResponseMetadata

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);
}
Also used : MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto) ASdu(org.openmuc.j60870.ASdu) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) Test(org.junit.jupiter.api.Test)

Example 3 with 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);
}
Also used : ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)

Example 4 with ResponseMetadata

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;
}
Also used : ClientConnectionAlreadyInCacheException(org.opensmartgridplatform.adapter.protocol.iec60870.domain.exceptions.ClientConnectionAlreadyInCacheException) ConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters) Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)

Example 5 with ResponseMetadata

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;
}
Also used : DomainInfo(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)

Aggregations

ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)10 MeasurementReportDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)5 Test (org.junit.jupiter.api.Test)4 Iec60870Device (org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)3 ASdu (org.openmuc.j60870.ASdu)2 Given (io.cucumber.java.en.Given)1 IOException (java.io.IOException)1 ClientConnectionAlreadyInCacheException (org.opensmartgridplatform.adapter.protocol.iec60870.domain.exceptions.ClientConnectionAlreadyInCacheException)1 ClientConnectionEventListener (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener)1 DeviceResponseService (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.DeviceResponseService)1 ConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)1 DomainInfo (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo)1 LogItem (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem)1 Iec60870AsduHandlerNotFoundException (org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)1