Search in sources :

Example 26 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class SetPushSetupAlarmCommandExecutorTest method testSetBothSendDestinationAndPushObjectList.

@Test
void testSetBothSendDestinationAndPushObjectList() throws ProtocolAdapterException, IOException {
    // SETUP
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
    when(this.dlmsConnection.get(any(AttributeAddress.class))).thenReturn(new GetResultImpl(DataObject.newNullData(), AccessResultCode.SUCCESS));
    final PushSetupAlarmDto pushSetupAlarmDto = new PushSetupAlarmDto.Builder().withSendDestinationAndMethod(SEND_DESTINATION_AND_METHOD).withPushObjectList(PUSH_OBJECT_LIST).build();
    // CALL
    final AccessResultCode resultCode = this.executor.execute(this.conn, this.DLMS_DEVICE, pushSetupAlarmDto, this.messageMetadata);
    // VERIFY
    assertThat(resultCode).isEqualTo(AccessResultCode.SUCCESS);
    verify(this.dlmsConnection, times(2)).set(this.setParameterArgumentCaptor.capture());
    final List<SetParameter> setParameters = this.setParameterArgumentCaptor.getAllValues();
    this.verifySendDestinationAndMethodParameter(setParameters.get(0), Protocol.forDevice(this.DLMS_DEVICE));
    this.verifyPushObjectListParameter(setParameters.get(1));
}
Also used : GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode) PushSetupAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto) SetParameter(org.openmuc.jdlms.SetParameter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class SetAlarmNotificationsCommandExecutorTest method testSetSettingThatIsAlreadySetInAlarmRegister2.

@Test
void testSetSettingThatIsAlreadySetInAlarmRegister2() throws OsgpException {
    final DlmsDevice device = this.createDevice(Protocol.SMR_5_2);
    // Set the return value for alarm register 2 to 3F (all alarms set):
    this.conn.addReturnValue(new AttributeAddress(1, "0.0.97.98.11.255", 2), DataObject.newInteger32Data(0x3F));
    // Setting notifications that are not different from what is on the meter already,
    // should always be successful.
    final AccessResultCode res = this.execute(device, new AlarmNotificationDto(AlarmTypeDto.VOLTAGE_SWELL_IN_PHASE_DETECTED_L3, true));
    assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
    // Since nothing changed, not a single message should have been sent to the meter.
    assertThat(this.setParametersReceived.size()).isZero();
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class SetAlarmNotificationsCommandExecutorTest method testSetSettingEnabledAndDisabled.

@Test
void testSetSettingEnabledAndDisabled() throws OsgpException {
    final DlmsDevice device = this.createDevice(Protocol.SMR_5_0_0);
    // Both enable and disable in one call:
    // CLOCK_INVALID to enabled and REPLACE_BATTERY to disabled.
    final AccessResultCode res = this.execute(device, new AlarmNotificationDto(AlarmTypeDto.CLOCK_INVALID, true), new AlarmNotificationDto(AlarmTypeDto.REPLACE_BATTERY, false));
    assertThat(res).isEqualTo(AccessResultCode.SUCCESS);
    assertThat(this.setParametersReceived.size()).isEqualTo(1);
    // Expecting 9 (0b1001).
    assertThat((long) this.setParametersReceived.get(0).getData().getValue()).isEqualTo(9);
}
Also used : AlarmNotificationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectCommandExecutorDsmr4IT method execute.

@Test
public void execute() throws IOException, ProtocolAdapterException {
    // SETUP
    // configurationToSet: 0111-----1------
    final GprsOperationModeTypeDto gprsModeToSet = GprsOperationModeTypeDto.TRIGGERED;
    final ConfigurationObjectDto configurationToSet = this.createConfigurationObjectDto(gprsModeToSet, this.createFlagDto(ConfigurationFlagTypeDto.DISCOVER_ON_OPEN_COVER, false), this.createFlagDto(ConfigurationFlagTypeDto.DISCOVER_ON_POWER_ON, true), this.createFlagDto(ConfigurationFlagTypeDto.DYNAMIC_MBUS_ADDRESS, true), this.createFlagDto(ConfigurationFlagTypeDto.PO_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_5_ON_PO_ENABLE, true));
    // flagsOnDevice: 1000101010000000
    final byte[] flagsOnDevice = this.createFlagBytes(ConfigurationFlagTypeDto.DISCOVER_ON_OPEN_COVER, ConfigurationFlagTypeDto.HLS_3_ON_P_3_ENABLE, ConfigurationFlagTypeDto.HLS_5_ON_P_3_ENABLE, ConfigurationFlagTypeDto.HLS_4_ON_PO_ENABLE);
    // result of merging configurationToSet and flagsOnDevice
    final byte firstExpectedByte = this.asByte("01111010");
    final byte secondExpectedByte = this.asByte("11000000");
    final GprsOperationModeTypeDto gprsModeOnDevice = GprsOperationModeTypeDto.ALWAYS_ON;
    final DataObject deviceData = this.createStructureData(flagsOnDevice, gprsModeOnDevice);
    when(this.getResult.getResultData()).thenReturn(deviceData);
    final DlmsDevice device = new DlmsDevice();
    device.setProtocol(Protocol.DSMR_4_2_2);
    // CALL
    final AccessResultCode result = this.instance.execute(this.conn, device, configurationToSet, this.messageMetadata);
    // VERIFY
    assertThat(result).isEqualTo(AccessResultCode.SUCCESS);
    final List<DataObject> elements = this.captureSetParameterStructureData();
    final Number gprsOperationMode = elements.get(INDEX_OF_GPRS_OPERATION_MODE).getValue();
    assertThat(gprsOperationMode).isEqualTo(gprsModeToSet.getNumber());
    final BitString configurationFlags = elements.get(INDEX_OF_CONFIGURATION_FLAGS).getValue();
    final byte[] flagsSentToDevice = configurationFlags.getBitString();
    assertThat(flagsSentToDevice[0]).isEqualTo(firstExpectedByte);
    assertThat(flagsSentToDevice[1]).isEqualTo(secondExpectedByte);
}
Also used : GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test)

Example 30 with AccessResultCode

use of org.openmuc.jdlms.AccessResultCode in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectCommandExecutorTest method execute.

@Test
public void execute() throws ProtocolAdapterException {
    // SETUP
    final DlmsDevice device = new DlmsDevice();
    final Protocol protocol = Protocol.DSMR_4_2_2;
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    device.setProtocol(protocol);
    when(this.protocolServiceLookup.lookupGetService(protocol)).thenReturn(this.getService);
    when(this.getService.getConfigurationObject(this.conn)).thenReturn(this.configurationOnDevice);
    when(this.protocolServiceLookup.lookupSetService(protocol)).thenReturn(this.setService);
    final AccessResultCode accessResultCode = AccessResultCode.SUCCESS;
    when(this.setService.setConfigurationObject(this.conn, this.configurationToSet, this.configurationOnDevice)).thenReturn(accessResultCode);
    // CALL
    final AccessResultCode result = this.instance.execute(this.conn, device, this.configurationToSet, messageMetadata);
    // VERIFY
    assertThat(result).isSameAs(accessResultCode);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) Test(org.junit.jupiter.api.Test)

Aggregations

AccessResultCode (org.openmuc.jdlms.AccessResultCode)44 Test (org.junit.jupiter.api.Test)17 SetParameter (org.openmuc.jdlms.SetParameter)16 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)15 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 AttributeAddress (org.openmuc.jdlms.AttributeAddress)11 AlarmNotificationDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationDto)8 IOException (java.io.IOException)4 ActivityCalendarDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto)4 AlarmTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmTypeDto)4 ConfigurationObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)4 PushSetupAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto)4 CsvSource (org.junit.jupiter.params.provider.CsvSource)3 BitString (org.openmuc.jdlms.datatypes.BitString)3 DataObject (org.openmuc.jdlms.datatypes.DataObject)3 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)3 CosemDateDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateDto)3 CosemTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemTimeDto)3 GprsOperationModeTypeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto)3