Search in sources :

Example 1 with LogItem

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

the class LogItemRequestMessageSenderTest method shouldSendLogItem.

@Test
public void shouldSendLogItem() {
    // Arrange
    final LogItem logItem = new LogItem("TEST-DEVICE-1", "TEST-ORG-1", true, "TEST-MESSAGE");
    // Act
    this.messageSender.send(logItem);
    // Assert
    verify(this.logItemRequestsJmsTemplate).send(any(MessageCreator.class));
}
Also used : LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) MessageCreator(org.springframework.jms.core.MessageCreator) Test(org.junit.jupiter.api.Test)

Example 2 with LogItem

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

the class ClientConnectionEventListener method newASdu.

@Override
public void newASdu(final ASdu asdu) {
    LOGGER.info("Received incoming ASDU from device {}:\n{}", this.deviceIdentification, asdu);
    try {
        final ResponseMetadata newResponseMetadata = this.responseMetadataFactory.createWithNewCorrelationUid(this.responseMetadata);
        final LogItem logItem = this.logItemFactory.create(asdu, this.deviceIdentification, newResponseMetadata.getOrganisationIdentification(), true);
        this.loggingService.log(logItem);
        final ClientAsduHandler asduHandler = this.asduHandlerRegistry.getHandler(asdu);
        asduHandler.handleAsdu(asdu, newResponseMetadata);
    } catch (final Iec60870AsduHandlerNotFoundException e) {
        LOGGER.error("Unknown request received, no handler available for ASDU: {}", asdu, e);
    } catch (final Exception e) {
        LOGGER.error("Exception occurred while handling an incoming ASDU from device {}.", this.deviceIdentification, e);
    }
}
Also used : LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException) IOException(java.io.IOException) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)

Example 3 with LogItem

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

the class GeneralInterrogationService method sendGeneralInterrogation.

public void sendGeneralInterrogation(final ClientConnection deviceConnection, final RequestMetadata requestMetadata) throws IOException {
    final String connectedDevice = deviceConnection.getConnectionParameters().getDeviceIdentification();
    final int commonAddress = deviceConnection.getConnectionParameters().getCommonAddress();
    deviceConnection.getConnection().interrogation(commonAddress, CauseOfTransmission.ACTIVATION, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID));
    // interrogation command creates this asdu internally, however we
    // need it here as well for logging...
    final ASdu asdu = new ASdu(ASduType.C_IC_NA_1, false, CauseOfTransmission.ACTIVATION, false, false, ORIGINATOR_ADDRESS, commonAddress, new InformationObject(0, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID)));
    final LogItem logItem = new LogItem(connectedDevice, requestMetadata.getOrganisationIdentification(), false, asdu.toString());
    this.loggingService.log(logItem);
}
Also used : LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) IeQualifierOfInterrogation(org.openmuc.j60870.ie.IeQualifierOfInterrogation) ASdu(org.openmuc.j60870.ASdu) InformationObject(org.openmuc.j60870.ie.InformationObject)

Example 4 with LogItem

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

the class ClientConnectionEventListenerTest method shouldSendLogItemWhenNewAsduIsReceived.

@Test
void shouldSendLogItemWhenNewAsduIsReceived() throws Exception {
    // Arrange
    final ASdu asdu = AsduFactory.ofType(ASduType.C_IC_NA_1);
    final LogItem logItem = new LogItem(DEFAULT_DEVICE_IDENTIFICATION, DEFAULT_ORGANISATION_IDENTIFICATION, true, asdu.toString());
    when(this.asduHandlerRegistry.getHandler(asdu)).thenReturn(this.asduHandler);
    when(this.responseMetadataFactory.createWithNewCorrelationUid(this.responseMetadata)).thenReturn(this.responseMetadata);
    when(this.logItemFactory.create(asdu, DEFAULT_DEVICE_IDENTIFICATION, DEFAULT_ORGANISATION_IDENTIFICATION, true)).thenReturn(logItem);
    // Act
    this.clientConnectionEventListener.newASdu(asdu);
    // Assert
    verify(this.loggingService).log(logItem);
}
Also used : LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) ASdu(org.openmuc.j60870.ASdu) Test(org.junit.jupiter.api.Test)

Example 5 with LogItem

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

the class GeneralInterrogationServiceTest method testSendGeneralInterrogationShouldLogSameAsduAsUsedInInterrogation.

/**
 * Test method for {@link
 * org.opensmartgridplatform.adapter.protocol.iec60870.infra.messaging.processors.ConnectRequestMessageProcessor#process(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection,
 * org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)}.
 *
 * @throws Exception
 */
@Test
void testSendGeneralInterrogationShouldLogSameAsduAsUsedInInterrogation() throws Exception {
    // Arrange
    final ConnectionParameters connectionParameters = ConnectionParameters.newBuilder().deviceIdentification(DEVICE_IDENTIFICATION).build();
    final DeviceConnection deviceConnection = new DeviceConnection(this.connection, connectionParameters);
    final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(DEVICE_IDENTIFICATION);
    doCallRealMethod().when(this.connection).interrogation(anyInt(), any(CauseOfTransmission.class), any(IeQualifierOfInterrogation.class));
    // Act
    this.generalInterrogationService.sendGeneralInterrogation(deviceConnection, requestMetadata);
    // Assert
    final ArgumentCaptor<ASdu> asduCaptor = ArgumentCaptor.forClass(ASdu.class);
    final ArgumentCaptor<LogItem> logItemCaptor = ArgumentCaptor.forClass(LogItem.class);
    verify(this.connection).send(asduCaptor.capture());
    verify(this.loggingService).log(logItemCaptor.capture());
    assertThat(logItemCaptor.getValue().getMessage()).isEqualTo(asduCaptor.getValue().toString());
}
Also used : CauseOfTransmission(org.openmuc.j60870.CauseOfTransmission) LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) ConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) IeQualifierOfInterrogation(org.openmuc.j60870.ie.IeQualifierOfInterrogation) ASdu(org.openmuc.j60870.ASdu) RequestMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

LogItem (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem)5 Test (org.junit.jupiter.api.Test)3 ASdu (org.openmuc.j60870.ASdu)3 IeQualifierOfInterrogation (org.openmuc.j60870.ie.IeQualifierOfInterrogation)2 IOException (java.io.IOException)1 CauseOfTransmission (org.openmuc.j60870.CauseOfTransmission)1 InformationObject (org.openmuc.j60870.ie.InformationObject)1 ConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)1 RequestMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)1 ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)1 Iec60870AsduHandlerNotFoundException (org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)1 MessageCreator (org.springframework.jms.core.MessageCreator)1