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