Search in sources :

Example 1 with ASduType

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;
}
Also used : ASduType(org.openmuc.j60870.ASduType) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)

Example 2 with ASduType

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);
}
Also used : ASduType(org.openmuc.j60870.ASduType) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ASduType

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);
}
Also used : ASduType(org.openmuc.j60870.ASduType) Iec60870AsduHandler(org.opensmartgridplatform.iec60870.Iec60870AsduHandler) Iec60870SingleCommandAsduHandler(org.opensmartgridplatform.simulator.protocol.iec60870.server.handlers.Iec60870SingleCommandAsduHandler) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ASduType

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);
}
Also used : ASduType(org.openmuc.j60870.ASduType) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException) Test(org.junit.jupiter.api.Test)

Example 5 with ASduType

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

Aggregations

ASduType (org.openmuc.j60870.ASduType)7 Test (org.junit.jupiter.api.Test)5 Iec60870AsduHandlerNotFoundException (org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 Iec60870AsduHandler (org.opensmartgridplatform.iec60870.Iec60870AsduHandler)2 When (io.cucumber.java.en.When)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ASdu (org.openmuc.j60870.ASdu)1 Iec60870InterrogationCommandAsduHandler (org.opensmartgridplatform.simulator.protocol.iec60870.server.handlers.Iec60870InterrogationCommandAsduHandler)1 Iec60870SingleCommandAsduHandler (org.opensmartgridplatform.simulator.protocol.iec60870.server.handlers.Iec60870SingleCommandAsduHandler)1