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));
}
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();
}
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);
}
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);
}
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);
}
Aggregations