use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.
the class DefaultControlledStationAsduFactoryTest method testCreateSingleCommand.
@Test
void testCreateSingleCommand() {
// Arrange
final DefaultControlledStationAsduFactory defaultControlledAsduFactory = new DefaultControlledStationAsduFactory();
final ASdu expected = new ASdu(ASduType.C_SC_NA_1, false, CauseOfTransmission.SPONTANEOUS, false, false, 0, 1, new InformationObject[] { new InformationObject(0, this.informationElementFactory.createInformationElements(Iec60870InformationObjectType.QUALIFIER_OF_INTERROGATION, 20)) });
// Act
final ASdu actual = defaultControlledAsduFactory.createSingleCommandAsdu();
// Assert
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
}
use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.
the class ClientConnectionEventListenerTest method shouldHandleAsduWhenNewAsduIsReceived.
@Test
void shouldHandleAsduWhenNewAsduIsReceived() throws Exception {
// Arrange
final ASdu asdu = AsduFactory.ofType(ASduType.C_IC_NA_1);
when(this.asduHandlerRegistry.getHandler(asdu)).thenReturn(this.asduHandler);
when(this.responseMetadataFactory.createWithNewCorrelationUid(this.responseMetadata)).thenReturn(this.responseMetadata);
// Act
this.clientConnectionEventListener.newASdu(asdu);
// Assert
verify(this.asduHandler).handleAsdu(asdu, this.responseMetadata);
}
use of org.openmuc.j60870.ASdu 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.openmuc.j60870.ASdu 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());
}
use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.
the class SinglePointWithQualityAsduHandlerTest method testHandleAsduShouldSendMeasurementReport.
/**
* Test method for {@link
* org.opensmartgridplatform.adapter.protocol.iec60870.domain.lightmeasurement.asduhandlers.SinglePointWithQualityAsduHandler#handleAsdu(org.openmuc.j60870.ASdu,
* org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)}.
*
* @throws Exception
*/
@Test
void testHandleAsduShouldSendMeasurementReport() throws Exception {
// Arrange
when(this.deviceResponseServiceMap.forDeviceType(DeviceType.LIGHT_MEASUREMENT_RTU)).thenReturn(this.deviceResponseService);
final ASdu asdu = this.createAsdu();
final ResponseMetadata responseMetadata = this.createResponseMetadata();
final MeasurementReportDto measurementReport = this.createMeasurementReportDto();
when(this.converterService.convert(asdu)).thenReturn(measurementReport);
when(this.deviceResponseServiceMap.forDeviceType(GATEWAY_DEVICE_TYPE)).thenReturn(this.deviceResponseService);
// Act
this.asduHandler.handleAsdu(asdu, responseMetadata);
// Assert
verify(this.deviceResponseService).process(any(MeasurementReportDto.class), eq(responseMetadata));
}
Aggregations