Search in sources :

Example 21 with ASdu

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);
}
Also used : DefaultControlledStationAsduFactory(org.opensmartgridplatform.simulator.protocol.iec60870.domain.defaultcontrolledstation.DefaultControlledStationAsduFactory) ASdu(org.openmuc.j60870.ASdu) InformationObject(org.openmuc.j60870.ie.InformationObject) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with ASdu

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);
}
Also used : ASdu(org.openmuc.j60870.ASdu) Test(org.junit.jupiter.api.Test)

Example 23 with ASdu

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

Example 24 with ASdu

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

Example 25 with ASdu

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

Aggregations

ASdu (org.openmuc.j60870.ASdu)20 Test (org.junit.jupiter.api.Test)14 InformationObject (org.openmuc.j60870.ie.InformationObject)9 LogItem (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem)3 MeasurementReportDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 When (io.cucumber.java.en.When)2 ASduType (org.openmuc.j60870.ASduType)2 IeQualifierOfInterrogation (org.openmuc.j60870.ie.IeQualifierOfInterrogation)2 ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)2 Iec60870AsduHandlerNotFoundException (org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)2 Iec60870AsduBuilder (org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ZonedDateTime (java.time.ZonedDateTime)1 Random (java.util.Random)1 InOrder (org.mockito.InOrder)1 CauseOfTransmission (org.openmuc.j60870.CauseOfTransmission)1 Connection (org.openmuc.j60870.Connection)1 ConnectionEventListener (org.openmuc.j60870.ConnectionEventListener)1