use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectCommandExecutorTest 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.configurationObjectDto);
// CALL
final ConfigurationObjectDto result = this.instance.execute(this.conn, device, null, messageMetadata);
// VERIFY
assertThat(result).isSameAs(this.configurationObjectDto);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class SetRandomisationSettingsCommandExecutor method writeDirectAttach.
private void writeDirectAttach(final DlmsConnectionManager conn, final DlmsDevice device, final boolean directAttach) throws ProtocolAdapterException {
final Protocol protocol = Protocol.forDevice(device);
final GetConfigurationObjectService getConfigurationObjectService = this.protocolServiceLookup.lookupGetService(protocol);
final ConfigurationObjectDto configurationOnDevice = getConfigurationObjectService.getConfigurationObject(conn);
final SetConfigurationObjectService setService = this.protocolServiceLookup.lookupSetService(protocol);
final ConfigurationObjectDto configurationToSet = this.createNewConfiguration(directAttach, configurationOnDevice);
final AccessResultCode result = setService.setConfigurationObject(conn, configurationToSet, configurationOnDevice);
this.checkResult(result, "directAttach");
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutorIntegrationTest method testExecute.
private void testExecute(final Protocol protocol, final PeriodTypeDto type, final boolean useNullData) throws Exception {
// SETUP
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
// Reset stub
this.connectionStub.clearRequestedAttributeAddresses();
// Create device with requested protocol version
final DlmsDevice device = this.createDlmsDevice(protocol);
// Create request object
final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(type, this.TIME_FROM, this.TIME_TO, ChannelDto.fromNumber(1));
// Get expected values
final AttributeAddress expectedAddressProfile = this.createAttributeAddress(protocol, type, this.TIME_FROM, this.TIME_TO);
final List<AttributeAddress> expectedScalerUnitAddresses = this.getScalerUnitAttributeAddresses(protocol);
// Set response in stub
this.setResponseForProfile(expectedAddressProfile, protocol, type, useNullData);
this.setResponsesForScalerUnit(expectedScalerUnitAddresses);
// CALL
final PeriodicMeterReadGasResponseDto response = this.executor.execute(this.connectionManagerStub, device, request, messageMetadata);
// VERIFY
// Get resulting requests from connection stub
final List<AttributeAddress> requestedAttributeAddresses = this.connectionStub.getRequestedAttributeAddresses();
assertThat(requestedAttributeAddresses.size()).isEqualTo(2);
// There should be 1 request to the buffer (id = 2) of a profile
// (class-id = 7)
final AttributeAddress actualAttributeAddressProfile = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_PROFILE).collect(Collectors.toList()).get(0);
AttributeAddressAssert.is(actualAttributeAddressProfile, expectedAddressProfile);
// Check the amount of requests to the scaler_unit of the meter value in
// the extended register
final List<AttributeAddress> attributeAddressesScalerUnit = requestedAttributeAddresses.stream().filter(a -> a.getClassId() == this.CLASS_ID_EXTENDED_REGISTER && a.getId() == this.ATTR_ID_SCALER_UNIT).collect(Collectors.toList());
assertThat(attributeAddressesScalerUnit.size()).isEqualTo(1);
// Check response
assertThat(response.getPeriodType()).isEqualTo(type);
final List<PeriodicMeterReadsGasResponseItemDto> periodicMeterReads = response.getPeriodicMeterReadsGas();
final int AMOUNT_OF_PERIODS = 2;
assertThat(periodicMeterReads.size()).isEqualTo(AMOUNT_OF_PERIODS);
this.checkClockValues(periodicMeterReads, type, useNullData);
this.checkValues(periodicMeterReads);
this.checkAmrStatus(periodicMeterReads, protocol, type);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol 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);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol in project open-smart-grid-platform by OSGP.
the class ProtocolServiceLookupTest method lookupGetServiceNotFound.
@Test
public void lookupGetServiceNotFound() {
// SETUP
final Protocol protocol = Protocol.OTHER_PROTOCOL;
// CALL
assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> this.instance.lookupSetService(protocol));
}
Aggregations