use of org.openmuc.j60870.ASduType in project open-smart-grid-platform by OSGP.
the class ClientAsduHandlerRegistry method getHandler.
public ClientAsduHandler getHandler(final ASdu asdu) throws Iec60870AsduHandlerNotFoundException {
final ASduType asduType = asdu.getTypeIdentification();
final ClientAsduHandler handler = this.handlers.get(asduType);
if (handler == null) {
LOGGER.error("Unable to process ASDU {}, no ASDU handler found for ASDU type {}", asdu, asduType);
throw new Iec60870AsduHandlerNotFoundException(asduType);
}
return handler;
}
use of org.openmuc.j60870.ASduType in project open-smart-grid-platform by OSGP.
the class Iec60870AsduHandlerRegistryTest method registryShouldThrowExceptionWhenHandlerIsNotFound.
@Test
public void registryShouldThrowExceptionWhenHandlerIsNotFound() {
// arrange
// Type Id PRIVATE_255 is used here, as it is likely to not have a
// handler implemented...
final ASduType asduType = ASduType.PRIVATE_255;
final Class<?> expected = Iec60870AsduHandlerNotFoundException.class;
// act
final Throwable actual = catchThrowable(() -> this.iec60870AsduHandlerRegistry.getHandler(asduType));
// assert
assertThat(actual).isInstanceOf(expected);
}
use of org.openmuc.j60870.ASduType in project open-smart-grid-platform by OSGP.
the class Iec60870AsduHandlerRegistryTest method registryShouldReturnSingleCommandHandlerForSingleCommandAsduType.
@Test
public void registryShouldReturnSingleCommandHandlerForSingleCommandAsduType() throws Exception {
// arrange
final ASduType asduType = ASduType.C_SC_NA_1;
final Iec60870SingleCommandAsduHandler expected = this.iec60870SingleCommandAsduHandler;
// act
final Iec60870AsduHandler actual = this.iec60870AsduHandlerRegistry.getHandler(asduType);
// assert
assertThat(actual).isEqualTo(expected);
}
use of org.openmuc.j60870.ASduType in project open-smart-grid-platform by OSGP.
the class Iec60870AsduHandlerRegistryTest method getHandlerShouldThrowExceptionWhenNotPresent.
@Test
public void getHandlerShouldThrowExceptionWhenNotPresent() {
// Arrange
final ASduType typeId = ASduType.M_ME_TF_1;
final Class<?> expected = Iec60870AsduHandlerNotFoundException.class;
// Act
final Throwable actual = catchThrowable(() -> this.iec60870AsduHandlerRegistry.getHandler(typeId));
// Assert
assertThat(actual).isInstanceOf(expected);
}
use of org.openmuc.j60870.ASduType in project open-smart-grid-platform by OSGP.
the class Iec60870AsduHandlerRegistryTest method getHandlerShouldReturnHandlerWhenPresent.
@Test
public void getHandlerShouldReturnHandlerWhenPresent() throws Iec60870AsduHandlerNotFoundException {
// Arrange
final ASduType typeId = ASduType.M_ME_TF_1;
final Iec60870AsduHandler expected = mock(Iec60870AsduHandler.class);
this.iec60870AsduHandlerRegistry.registerHandler(typeId, expected);
// Act
final Iec60870AsduHandler actual = this.iec60870AsduHandlerRegistry.getHandler(typeId);
// Assert
assertThat(actual).isEqualTo(expected);
}
Aggregations