Search in sources :

Example 1 with DlmsDevice

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

the class SetDeviceCommunicationSettingsSteps method theDeviceShouldBeInTheDatabaseWithAttributes.

@Then("^the device \"([^\"]*)\" should be in the database with attributes$")
public void theDeviceShouldBeInTheDatabaseWithAttributes(final String deviceIdentification, final Map<String, String> settings) throws Throwable {
    final DlmsDevice device = this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification);
    final int expectedResult = getInteger(settings, PlatformSmartmeteringKeys.CHALLENGE_LENGTH, PlatformSmartmeteringDefaults.CHALLENGE_LENGTH);
    assertThat(device.getChallengeLength().intValue()).as("Number of challenge length should match").isEqualTo(expectedResult);
    assertThat(device.isWithListSupported()).as("With list supported should match").isEqualTo(getBoolean(settings, PlatformSmartmeteringKeys.WITH_LIST_SUPPORTED));
    assertThat(device.isSelectiveAccessSupported()).as("Selective access supported should match").isEqualTo(getBoolean(settings, PlatformSmartmeteringKeys.SELECTIVE_ACCESS_SUPPORTED));
    assertThat(device.isIpAddressIsStatic()).as("IP address is static should match").isEqualTo(getBoolean(settings, PlatformSmartmeteringKeys.IP_ADDRESS_IS_STATIC));
    assertThat(device.isUseSn()).as("Use SN should match").isEqualTo(getBoolean(settings, PlatformSmartmeteringKeys.USE_SN));
    assertThat(device.isUseHdlc()).as("Use HDLC should match").isEqualTo(getBoolean(settings, PlatformSmartmeteringKeys.USE_HDLC));
    assertThat(device.isPolyphase()).as("Polyphase should match").isEqualTo(getBoolean(settings, PlatformSmartmeteringKeys.POLYPHASE));
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Then(io.cucumber.java.en.Then)

Example 2 with DlmsDevice

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

the class DlmsDeviceSteps method aValidMbusUserKeyIsStored.

@Then("^a valid m-bus user key is stored$")
public void aValidMbusUserKeyIsStored(final Map<String, String> settings) {
    final String keyDeviceIdentification = PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION;
    final String deviceIdentification = settings.get(keyDeviceIdentification);
    assertThat(deviceIdentification).as("The M-Bus device identification must be in the step data for key " + keyDeviceIdentification).isNotNull();
    final String deviceDescription = "M-Bus device with identification " + deviceIdentification;
    final DlmsDevice dlmsDevice = this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification);
    assertThat(dlmsDevice).as(deviceDescription + " must be in the protocol database").isNotNull();
    final List<DbEncryptedSecret> securityKeys = this.findAllSecretsForDevice(deviceIdentification);
    int numberOfMbusDefaultKeys = 0;
    int numberOfMbusUserKeys = 0;
    int numberOfValidMbusUserKeys = 0;
    for (final DbEncryptedSecret securityKey : securityKeys) {
        switch(securityKey.getSecretType()) {
            case G_METER_MASTER_KEY:
                numberOfMbusDefaultKeys += 1;
                break;
            case G_METER_ENCRYPTION_KEY:
                numberOfMbusUserKeys += 1;
                if (securityKey.getSecretStatus().equals(SecretStatus.ACTIVE)) {
                    numberOfValidMbusUserKeys += 1;
                }
                break;
            default:
        }
    }
    assertThat(numberOfMbusDefaultKeys).as("Number of M-Bus Default keys stored").isEqualTo(1);
    assertThat(numberOfMbusUserKeys > 0).as("At least one M-Bus User key must be stored").isTrue();
    assertThat(numberOfValidMbusUserKeys).as("Number of valid M-Bus User keys stored").isEqualTo(1);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) Then(io.cucumber.java.en.Then)

Example 3 with DlmsDevice

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

the class DlmsDeviceSteps method theKeyprocessingLockShouldBeRemovedFromDlmsDeviceWithIdentification.

@Then("^the keyprocessing lock should be removed from off dlms device with identification \"([^\"]*)\"$")
public void theKeyprocessingLockShouldBeRemovedFromDlmsDeviceWithIdentification(final String deviceIdentification) {
    final DlmsDevice dlmsDevice = this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification);
    assertThat(dlmsDevice).as("DLMS device with identification " + deviceIdentification + " in protocol database").isNotNull();
    assertThat(dlmsDevice.getKeyProcessingStartTime()).as("DLMS device with identification " + deviceIdentification + " should not have lock on keyprocessing in protocol database").isNull();
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Then(io.cucumber.java.en.Then)

Example 4 with DlmsDevice

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

the class DlmsDeviceSteps method theStoredMbusDefaultKeysIsNotEqualToTheReceivedKey.

@Then("^the stored M-Bus Default key is not equal to the received key$")
public void theStoredMbusDefaultKeysIsNotEqualToTheReceivedKey() {
    final String keyDeviceIdentification = PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION;
    final String deviceIdentification = (String) ScenarioContext.current().get(keyDeviceIdentification);
    assertThat(deviceIdentification).as("Device identification must be in the scenario context for key " + keyDeviceIdentification).isNotNull();
    final String deviceDescription = "DLMS device with identification " + deviceIdentification;
    final DlmsDevice dlmsDevice = this.findExistingDlmsDevice(deviceIdentification);
    final DbEncryptedSecret mbusDefaultKey = this.findExistingSecurityKey(dlmsDevice, G_METER_MASTER_KEY, "M-Bus Default key");
    final String receivedMbusDefaultKey = (String) ScenarioContext.current().get(PlatformSmartmeteringKeys.MBUS_DEFAULT_KEY);
    assertThat(mbusDefaultKey.getEncodedSecret()).as("Stored M-Bus Default key for " + deviceDescription + " must be different from received key").isNotEqualTo(receivedMbusDefaultKey);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DbEncryptedSecret(org.opensmartgridplatform.secretmanagement.application.domain.DbEncryptedSecret) Then(io.cucumber.java.en.Then)

Example 5 with DlmsDevice

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

the class DlmsDeviceSteps method createDlmsDeviceInProtocolAdapterDatabase.

private void createDlmsDeviceInProtocolAdapterDatabase(final Map<String, String> inputSettings) {
    final ProtocolInfo protocolInfo = this.getProtocolInfo(inputSettings);
    final DlmsDeviceBuilder dlmsDeviceBuilder = new DlmsDeviceBuilder().setProtocolName(protocolInfo);
    final DlmsDevice dlmsDevice = dlmsDeviceBuilder.withSettings(inputSettings).build();
    this.dlmsDeviceRepository.save(dlmsDevice);
    this.createDlmsDeviceInSecretManagementDatabase(dlmsDevice, inputSettings);
}
Also used : ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) DlmsDeviceBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DlmsDeviceBuilder) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

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