Search in sources :

Example 6 with Protocol

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);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) Test(org.junit.jupiter.api.Test)

Example 7 with Protocol

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");
}
Also used : SetConfigurationObjectService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.configuration.service.SetConfigurationObjectService) GetConfigurationObjectService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.configuration.service.GetConfigurationObjectService) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)

Example 8 with Protocol

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);
}
Also used : DATA_NOT_VALID(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.DATA_NOT_VALID) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) PeriodTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodTypeDto) DlmsConnectionManagerStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionManagerStub) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) CRITICAL_ERROR(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.CRITICAL_ERROR) DlmsObjectConfigService(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigService) ChannelDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) Calendar(java.util.Calendar) ObisCode(org.openmuc.jdlms.ObisCode) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) DlmsConnectionStub(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.stub.DlmsConnectionStub) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto) AttributeAddressAssert(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.AttributeAddressAssert) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) RECOVERED_VALUE(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.RECOVERED_VALUE) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) GregorianCalendar(java.util.GregorianCalendar) POWER_DOWN(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.POWER_DOWN) TimeZone(java.util.TimeZone) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DateTime(org.joda.time.DateTime) DAYLIGHT_SAVING(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.DAYLIGHT_SAVING) DataObject(org.openmuc.jdlms.datatypes.DataObject) DlmsObjectConfigConfiguration(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectConfigConfiguration) AmrProfileStatusCodeHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.AmrProfileStatusCodeHelper) CLOCK_INVALID(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.CLOCK_INVALID) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CosemDateTime(org.openmuc.jdlms.datatypes.CosemDateTime) List(java.util.List) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) CLOCK_ADJUSTED(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.CLOCK_ADJUSTED) NOT_USED(org.opensmartgridplatform.dto.valueobjects.smartmetering.AmrProfileStatusCodeFlagDto.NOT_USED) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Collections(java.util.Collections) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) PeriodicMeterReadsGasResponseItemDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsGasResponseItemDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) PeriodicMeterReadGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadGasResponseDto) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)

Example 9 with Protocol

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

Example 10 with Protocol

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));
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) Test(org.junit.jupiter.api.Test)

Aggregations

Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)11 Test (org.junit.jupiter.api.Test)6 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)5 AttributeAddress (org.openmuc.jdlms.AttributeAddress)4 ObisCode (org.openmuc.jdlms.ObisCode)4 DataObject (org.openmuc.jdlms.datatypes.DataObject)4 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 List (java.util.List)3 DateTime (org.joda.time.DateTime)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)3 DlmsHelper (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper)3 ConfigurationObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto)3 Calendar (java.util.Calendar)2 Collections (java.util.Collections)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 TimeZone (java.util.TimeZone)2