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