Search in sources :

Example 86 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceDsmr4Test method getConfigurationObjectElementsNull.

@Test
public void getConfigurationObjectElementsNull() throws ProtocolAdapterException {
    // SETUP
    final DataObject structure = mock(DataObject.class);
    when(structure.isComplex()).thenReturn(true);
    when(this.getResult.getResultData()).thenReturn(structure);
    final List<DataObject> elements = null;
    when(structure.getValue()).thenReturn(elements);
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        // CALL
        this.instance.getConfigurationObject(this.getResult);
    });
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 87 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceDsmr4Test method getConfigurationObjectElementsSizeNotTwo.

@Test
public void getConfigurationObjectElementsSizeNotTwo() throws ProtocolAdapterException {
    // SETUP
    final DataObject structure = mock(DataObject.class);
    when(structure.isComplex()).thenReturn(true);
    when(this.getResult.getResultData()).thenReturn(structure);
    final List<DataObject> elements = new ArrayList<>();
    // elements is empty so size is not two
    when(structure.getValue()).thenReturn(elements);
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        // CALL
        this.instance.getConfigurationObject(this.getResult);
    });
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 88 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceDsmr4Test method getConfigurationObjectGprsModeNotNumber.

@Test
public void getConfigurationObjectGprsModeNotNumber() throws ProtocolAdapterException {
    // SETUP
    final DataObject structure = mock(DataObject.class);
    when(structure.isComplex()).thenReturn(true);
    when(this.getResult.getResultData()).thenReturn(structure);
    final List<DataObject> elements = new ArrayList<>();
    final DataObject gprsMode = mock(DataObject.class);
    // gprs mode is not a number
    when(gprsMode.isNumber()).thenReturn(false);
    elements.add(gprsMode);
    elements.add(null);
    when(structure.getValue()).thenReturn(elements);
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        // CALL
        this.instance.getConfigurationObject(this.getResult);
    });
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 89 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetGsmDiagnosticCommandExecutorIntegrationTest method testExecute.

private void testExecute(final Protocol protocol, final CommunicationMethod method, final boolean expectObjectNotFound) throws Exception {
    // SETUP
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    // Reset stub
    this.connectionStub.clearRequestedAttributeAddresses();
    // Create device with requested protocol version and communication method
    final DlmsDevice device = this.createDlmsDevice(protocol, method);
    // Create request object
    final GetGsmDiagnosticRequestDto request = new GetGsmDiagnosticRequestDto();
    // Get expected addresses
    final AttributeAddress expectedAddressOperator = this.createAttributeAddress(method, 2);
    final AttributeAddress expectedAddressRegistrationStatus = this.createAttributeAddress(method, 3);
    final AttributeAddress expectedAddressCsStatus = this.createAttributeAddress(method, 4);
    final AttributeAddress expectedAddressPsStatus = this.createAttributeAddress(method, 5);
    final AttributeAddress expectedAddressCellInfo = this.createAttributeAddress(method, 6);
    final AttributeAddress expectedAddressAdjacentCells = this.createAttributeAddress(method, 7);
    final AttributeAddress expectedAddressCaptureTime = this.createAttributeAddress(method, 8);
    // Reading of capture_time is disabled for now, therefore only 6 addresses expected
    final int expectedTotalNumberOfAttributeAddresses = 6;
    // Set responses in stub
    this.setResponseForOperator(expectedAddressOperator);
    this.setResponseForRegistrationStatus(expectedAddressRegistrationStatus);
    this.setResponseForCsStatus(expectedAddressCsStatus);
    this.setResponseForPsStatus(expectedAddressPsStatus);
    this.setResponseForCellInfo(expectedAddressCellInfo);
    this.setResponseForAdjacentCells(expectedAddressAdjacentCells);
    this.setResponseForCaptureTime(expectedAddressCaptureTime);
    // CALL
    GetGsmDiagnosticResponseDto response = null;
    try {
        response = this.executor.execute(this.connectionManagerStub, device, request, messageMetadata);
    } catch (final ProtocolAdapterException e) {
        if (expectObjectNotFound) {
            assertThat(e.getMessage()).isEqualTo("Did not find GSM_DIAGNOSTIC object with communication method " + method.getMethodName() + " for device 6789012");
            return;
        } else {
            fail("Unexpected ProtocolAdapterException: " + e.getMessage());
        }
    }
    // VERIFY
    // Get resulting requests from connection stub
    final List<AttributeAddress> requestedAttributeAddresses = this.connectionStub.getRequestedAttributeAddresses();
    assertThat(requestedAttributeAddresses.size()).isEqualTo(expectedTotalNumberOfAttributeAddresses);
    // Check response
    assertThat(response).isNotNull();
    assertThat(response).isNotNull();
    assertThat(response.getOperator()).isEqualTo("Operator");
    assertThat(response.getModemRegistrationStatus()).isEqualTo(ModemRegistrationStatusDto.REGISTERED_ROAMING);
    assertThat(response.getCircuitSwitchedStatus()).isEqualTo(CircuitSwitchedStatusDto.INACTIVE);
    assertThat(response.getPacketSwitchedStatus()).isEqualTo(PacketSwitchedStatusDto.CDMA);
    final CellInfoDto cellInfo = response.getCellInfo();
    assertThat(cellInfo.getCellId()).isEqualTo(93L);
    assertThat(cellInfo.getLocationId()).isEqualTo(2232);
    assertThat(cellInfo.getSignalQuality()).isEqualTo(SignalQualityDto.MINUS_87_DBM);
    assertThat(cellInfo.getBitErrorRate()).isEqualTo(BitErrorRateDto.RXQUAL_6);
    assertThat(cellInfo.getMobileCountryCode()).isEqualTo(204);
    assertThat(cellInfo.getMobileNetworkCode()).isEqualTo(66);
    assertThat(cellInfo.getChannelNumber()).isEqualTo(107);
    final List<AdjacentCellInfoDto> adjacentCells = response.getAdjacentCells();
    assertThat(adjacentCells.size()).isEqualTo(3);
    assertThat(adjacentCells.get(0).getCellId()).isEqualTo(85L);
    assertThat(adjacentCells.get(0).getSignalQuality()).isEqualTo(SignalQualityDto.MINUS_65_DBM);
// Reading of capture_time is disabled, so don't check the capture time
// assertThat(response.getCaptureTime())
// .isEqualTo(new DateTime(2021, 4, 1, 9, 28, DateTimeZone.UTC).toDate());
}
Also used : GetGsmDiagnosticRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticRequestDto) GetGsmDiagnosticResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticResponseDto) AdjacentCellInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AdjacentCellInfoDto) CellInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CellInfoDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) AdjacentCellInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AdjacentCellInfoDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 90 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class CosemObjectAccessor method writeAttribute.

public void writeAttribute(final AttributeClass attributeClass, final DataObject data) throws ProtocolAdapterException {
    final AttributeAddress attributeAddress = this.createAttributeAddress(attributeClass);
    final SetParameter setParameter = new SetParameter(attributeAddress, data);
    final AccessResultCode accessResultCode;
    try {
        accessResultCode = this.connector.getConnection().set(setParameter);
    } catch (final IOException e) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_WRITING_ATTRIBUTE, attributeClass, this.classId, this.obisCode), e);
    }
    if (accessResultCode != AccessResultCode.SUCCESS) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_ACCESS_RESULT_NOT_SUCCESS, accessResultCode.name(), attributeClass, this.classId, this.obisCode));
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) AccessResultCode(org.openmuc.jdlms.AccessResultCode) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SetParameter(org.openmuc.jdlms.SetParameter)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)95 DataObject (org.openmuc.jdlms.datatypes.DataObject)32 Test (org.junit.jupiter.api.Test)22 AccessResultCode (org.openmuc.jdlms.AccessResultCode)15 GetResult (org.openmuc.jdlms.GetResult)15 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)9 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)9 BitString (org.openmuc.jdlms.datatypes.BitString)7 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)7 ObisCode (org.openmuc.jdlms.ObisCode)6 SetParameter (org.openmuc.jdlms.SetParameter)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 DateTime (org.joda.time.DateTime)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)4 Date (java.util.Date)3 List (java.util.List)3