Search in sources :

Example 1 with DeviceType

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceType in project open-smart-grid-platform by OSGP.

the class ConnectionSteps method whenIConnectToIEC60870Device.

@When("I connect to IEC60870 device {string}")
public void whenIConnectToIEC60870Device(final String deviceIdentification) throws Exception {
    LOGGER.debug("When I connect to IEC60870 device {}", deviceIdentification);
    final Iec60870Device device = this.iec60870DeviceSteps.getDevice(deviceIdentification).orElseThrow(() -> new Exception("Device not found"));
    final DeviceType deviceType = device.getDeviceType();
    final String connectionDeviceIdentification = device.getConnectionDeviceIdentification();
    this.connectionParameters = this.initConnectionParameters(connectionDeviceIdentification);
    this.connectionEventListener = new ClientConnectionEventListener.Builder().withDeviceIdentification(connectionDeviceIdentification).withClientAsduHandlerRegistry(this.clientAsduHandlerRegistry).withClientConnectionCache(this.connectionCacheSpy).withLoggingService(this.loggingService).withLogItemFactory(this.logItemFactory).withResponseMetadata(this.initResponseMetadata(deviceIdentification, deviceType)).withResponseMetadataFactory(this.responseMetadataFactory).build();
    when(this.clientMock.connect(any(ConnectionParameters.class), any(ConnectionEventListener.class))).thenReturn(new DeviceConnection(this.connection, this.connectionParameters));
}
Also used : DeviceType(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceType) ConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Iec60870Device(org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device) ConnectionFailureException(org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException) ClientConnectionAlreadyInCacheException(org.opensmartgridplatform.adapter.protocol.iec60870.domain.exceptions.ClientConnectionAlreadyInCacheException) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) ConnectionEventListener(org.openmuc.j60870.ConnectionEventListener) When(io.cucumber.java.en.When)

Example 2 with DeviceType

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceType in project open-smart-grid-platform by OSGP.

the class ConnectionSteps method initResponseMetadata.

private ResponseMetadata initResponseMetadata(final String deviceIdentification, final DeviceType deviceType) throws Exception {
    final DomainInfo domainInfo = DomainInfoFactory.forDeviceType(deviceType);
    // Make sure the connection event listener works as expected
    final ResponseMetadata responseMetadata = new ResponseMetadata.Builder().withDeviceIdentification(deviceIdentification).withDeviceType(deviceType).withOrganisationIdentification(DEFAULT_ORGANISATION_IDENTIFICATION).withDomainInfo(domainInfo).withMessageType(DEFAULT_MESSAGE_TYPE).build();
    return responseMetadata;
}
Also used : DomainInfo(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)

Example 3 with DeviceType

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceType in project open-smart-grid-platform by OSGP.

the class ConnectionSteps method givenIec60870DeviceIsConnected.

@Given("an existing connection with IEC60870 device {string} of type {deviceType}")
public void givenIec60870DeviceIsConnected(final String deviceIdentification, final DeviceType deviceType) throws Exception {
    LOGGER.debug("Given an existing connection with IEC60870 device {} of type {}", deviceIdentification, deviceType);
    // Make sure the connection event listener works as expected
    this.connectionParameters = this.initConnectionParameters(deviceIdentification);
    final ResponseMetadata responseMetadata = this.initResponseMetadata(deviceIdentification, deviceType);
    this.connectionEventListener = new ClientConnectionEventListener.Builder().withDeviceIdentification(deviceIdentification).withClientAsduHandlerRegistry(this.clientAsduHandlerRegistry).withClientConnectionCache(this.connectionCacheSpy).withLoggingService(this.loggingService).withLogItemFactory(this.logItemFactory).withResponseMetadata(responseMetadata).withResponseMetadataFactory(this.responseMetadataFactory).build();
    // Make sure a connection could be retrieved from the cache
    // Only needed for scenarios sending requests to a device
    // final Connection connection = mock(Connection.class);
    this.connectionCacheSpy.addConnection(deviceIdentification, new DeviceConnection(this.connection, this.connectionParameters));
}
Also used : DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) Given(io.cucumber.java.en.Given)

Aggregations

ClientConnectionEventListener (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener)2 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)2 ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)2 Given (io.cucumber.java.en.Given)1 When (io.cucumber.java.en.When)1 ConnectionEventListener (org.openmuc.j60870.ConnectionEventListener)1 Iec60870Device (org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)1 ClientConnectionAlreadyInCacheException (org.opensmartgridplatform.adapter.protocol.iec60870.domain.exceptions.ClientConnectionAlreadyInCacheException)1 ConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters)1 DeviceType (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceType)1 DomainInfo (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo)1 ConnectionFailureException (org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException)1