Search in sources :

Example 41 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutorTest method nullResultAlarmRegister1.

@Test
void nullResultAlarmRegister1() throws ProtocolAdapterException, IOException {
    when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(null);
    final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
    this.setupAlarmRegister1(dlmsDevice);
    final Throwable actual = catchThrowable(() -> this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata));
    assertThat(actual).isInstanceOf(ProtocolAdapterException.class);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ThrowableAssert.catchThrowable(org.assertj.core.api.ThrowableAssert.catchThrowable) Test(org.junit.jupiter.api.Test)

Example 42 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutorTest method failureRegister1AndResultAlarmRegister2.

@Test
void failureRegister1AndResultAlarmRegister2() throws ProtocolAdapterException, IOException {
    when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(AccessResultCode.OTHER_REASON).thenReturn(AccessResultCode.SUCCESS);
    final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
    this.setupAlarmRegister1(dlmsDevice);
    final AccessResultCode accessResultCode = this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
    assertThat(accessResultCode).isEqualTo(AccessResultCode.OTHER_REASON);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test)

Example 43 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class SetAlarmNotificationsCommandExecutorTest method setUp.

@BeforeEach
public void setUp() {
    this.setParametersReceived = new ArrayList<>();
    this.device = new DlmsDevice("SuperAwesomeHeroicRockstarDevice");
    this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    final DlmsObjectConfigConfiguration dlmsObjectConfigConfiguration = new DlmsObjectConfigConfiguration();
    final DlmsObjectConfigService dlmsObjectConfigService = new DlmsObjectConfigService(new DlmsHelper(), dlmsObjectConfigConfiguration.getDlmsObjectConfigs()) {

        @Override
        public Optional<AttributeAddress> findAttributeAddress(final DlmsDevice device, final DlmsObjectType type, final Integer channel) {
            switch(type) {
                case ALARM_FILTER_1:
                    return Optional.of(new AttributeAddress(40, "0.0.97.98.10.255", 2));
                case ALARM_FILTER_2:
                    return Optional.of(new AttributeAddress(40, "0.0.97.98.11.255", 2));
            }
            return Optional.empty();
        }
    };
    this.executor = new SetAlarmNotificationsCommandExecutor(dlmsObjectConfigService);
    final DlmsConnectionStub conn = new DlmsConnectionStub() {

        @Override
        public AccessResultCode set(final SetParameter setParameter) {
            SetAlarmNotificationsCommandExecutorTest.this.setParametersReceived.add(setParameter);
            return AccessResultCode.SUCCESS;
        }
    };
    // Set the return value to 10 (0b1010):
    // REPLACE_BATTERY enabled, AUXILIARY_EVENT enabled.
    conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.10.255", 2), DataObject.newInteger32Data(10));
    conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.11.255", 2), DataObject.newInteger32Data(0));
    this.connMgr = new DlmsConnectionManagerStub(conn);
}
Also used : DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DlmsObjectConfigConfiguration(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) DlmsConnectionManagerStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SetParameter(org.openmuc.jdlms.SetParameter) DlmsObjectType(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 44 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class SessionProviderSimulator method getIpAddress.

/**
 * This implementation depends on the iccId having the same value as the device identification (in
 * order to be able to look up some data with the device for calling the simulator starting web
 * service, like the port number and logicalId of a simulated device).
 *
 * @throws SessionProviderException when no dlmsDevice can be found with a deviceId equal to the
 *     given iccId, or the simulator was not successfully started.
 */
@Override
public String getIpAddress(final String iccId) throws SessionProviderException {
    DlmsDevice dlmsDevice;
    try {
        dlmsDevice = this.domainHelperService.findDlmsDevice(iccId);
        this.simulatorTriggerClient.sendTrigger(dlmsDevice);
    } catch (final FunctionalException e) {
        throw new SessionProviderException("Unable to find dlmsDevice. ", e);
    } catch (final SimulatorTriggerClientException e) {
        throw new SessionProviderException("Unable to successfully start a simulator. ", e);
    }
    return this.ipAddress;
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SessionProviderException(org.opensmartgridplatform.adapter.protocol.jasper.sessionproviders.exceptions.SessionProviderException)

Example 45 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class OsgpResponseMessageProcessor method processMessageTask.

// SilentException cannot be caught since
@SuppressWarnings("squid:S1193")
private // it does not extend Exception.
void processMessageTask(final Serializable messageObject, final MessageMetadata messageMetadata, final DlmsConnectionManager conn) throws OsgpException {
    try {
        final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
        LOGGER.info("{} called for device: {} for organisation: {}", messageMetadata.getMessageType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification());
        if (this.usesDeviceConnection()) {
            this.handleMessage(conn, this.domainHelperService.findDlmsDevice(messageMetadata), messageObject);
        } else {
            this.handleMessage(device, messageObject);
        }
    } catch (final Exception exception) {
        // Return original request + exception
        if (!(exception instanceof SilentException)) {
            LOGGER.error("Unexpected exception during {}", this.messageType.name(), exception);
        }
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, exception, this.responseMessageSender, messageObject);
    } finally {
        final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
        this.doConnectionPostProcessing(device, conn, messageMetadata);
    }
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException)

Aggregations

DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)103 Test (org.junit.jupiter.api.Test)58 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)24 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)17 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)17 AttributeAddress (org.openmuc.jdlms.AttributeAddress)15 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)13 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)10 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)10 Then (io.cucumber.java.en.Then)9 DataObject (org.openmuc.jdlms.datatypes.DataObject)7 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Instant (java.time.Instant)5 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)5 IOException (java.io.IOException)4 Date (java.util.Date)4 List (java.util.List)4 ThrowableAssert.catchThrowable (org.assertj.core.api.ThrowableAssert.catchThrowable)4 SetParameter (org.openmuc.jdlms.SetParameter)4