Search in sources :

Example 6 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class LightMeasurementDeviceAsduFactory method createLightMeasurementEvent.

public ASdu createLightMeasurementEvent() {
    final long timestamp = System.currentTimeMillis();
    final InformationObject[] informationObjects = new InformationObject[1];
    final int index = new Random().nextInt(this.ioa.length);
    this.switchValue(index);
    final String eventValue = this.iev[index] ? "DARK" : "LIGHT";
    LOGGER.info("Creating Light Measurement event for IOA {} with value {} ({})", this.ioa[index], this.iev[index], eventValue);
    informationObjects[0] = new InformationObject(this.ioa[index], this.createInformationElementWithTimetag(this.iev[index], timestamp));
    return new Iec60870AsduBuilder().withAsduType(ASduType.M_SP_TB_1).withSequenceOfElements(false).withCauseOfTransmission(CauseOfTransmission.SPONTANEOUS).withInformationObjects(informationObjects).build();
}
Also used : Random(java.util.Random) InformationObject(org.openmuc.j60870.ie.InformationObject) Iec60870AsduBuilder(org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder)

Example 7 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class Iec60870AsduFactoryTest method testCreateInterrogationCommand.

@Test
void testCreateInterrogationCommand() {
    // Arrange
    final ASdu expected = this.getAsdu(CauseOfTransmission.ACTIVATION_CON);
    // Act
    final ASdu actual = this.iec60870AsduFactory.createInterrogationCommandAsdu();
    // Assert
    assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
}
Also used : ASdu(org.openmuc.j60870.ASdu) Test(org.junit.jupiter.api.Test)

Example 8 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class Iec60870AsduFactoryTest method testCreateActivationTerminationResponse.

@Test
void testCreateActivationTerminationResponse() {
    // Arrange
    final ASdu expected = this.getAsdu(CauseOfTransmission.ACTIVATION_TERMINATION);
    // Act
    final ASdu actual = this.iec60870AsduFactory.createActivationTerminationResponseAsdu();
    // Assert
    assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
}
Also used : ASdu(org.openmuc.j60870.ASdu) Test(org.junit.jupiter.api.Test)

Example 9 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class Iec60870ConnectionEventListenerTest method interrogationCommandShouldBeHandledByInterrogationCommandHandler.

@Test
void interrogationCommandShouldBeHandledByInterrogationCommandHandler() throws Exception {
    // Arrange
    final ASdu asdu = this.iec60870AsduFactory.createInterrogationCommandAsdu();
    when(this.iec60870AsduHandlerRegistry.getHandler(ASduType.C_IC_NA_1)).thenReturn(this.interrogationCommandHandler);
    // Act
    this.iec60870ConnectionEventListener.newASdu(asdu);
    // Assert
    verify(this.interrogationCommandHandler).handleAsdu(any(Connection.class), any(ASdu.class));
}
Also used : Connection(org.openmuc.j60870.Connection) ASdu(org.openmuc.j60870.ASdu) Test(org.junit.jupiter.api.Test)

Example 10 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class Iec60870ConnectionEventListenerTest method singleCommandShouldBeHandledBySingleCommandHandler.

@Test
void singleCommandShouldBeHandledBySingleCommandHandler() throws Exception {
    // Arrange
    final ASdu asdu = this.iec60870AsduFactory.createSingleCommandAsdu();
    when(this.iec60870AsduHandlerRegistry.getHandler(ASduType.C_SC_NA_1)).thenReturn(this.singleCommandHandler);
    // Act
    this.iec60870ConnectionEventListener.newASdu(asdu);
    // Assert
    Mockito.verify(this.singleCommandHandler, Mockito.times(1)).handleAsdu(this.connection, asdu);
}
Also used : ASdu(org.openmuc.j60870.ASdu) 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