Search in sources :

Example 1 with GetResultImpl

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl in project open-smart-grid-platform by OSGP.

the class DeviceChannelsHelperTest method testGetChannelElementValuesInvalidManufacturerId.

@Test
void testGetChannelElementValuesInvalidManufacturerId() throws Exception {
    final GetResult manufacturerIdentificationInvalid = new GetResultImpl(DataObject.newUInteger16Data(123));
    final List<GetResult> resultList = new ArrayList<>(Arrays.asList(this.primaryAddress, this.identificationNumberInBcd, manufacturerIdentificationInvalid, this.version, this.deviceType));
    when(this.device.isWithListSupported()).thenReturn(true);
    when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.get(anyList())).thenReturn(resultList);
    assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
        this.deviceChannelsHelper.getChannelElementValues(this.conn, this.device, (short) 1);
    });
}
Also used : GetResult(org.openmuc.jdlms.GetResult) GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with GetResultImpl

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl in project open-smart-grid-platform by OSGP.

the class SetPushSetupAlarmCommandExecutorTest method testSetPushObjectList.

@Test
void testSetPushObjectList() 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.Builder pushSetupAlarmBuilder = new PushSetupAlarmDto.Builder();
    pushSetupAlarmBuilder.withPushObjectList(PUSH_OBJECT_LIST);
    final PushSetupAlarmDto pushSetupAlarmDto = pushSetupAlarmBuilder.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(1)).set(this.setParameterArgumentCaptor.capture());
    final List<SetParameter> setParameters = this.setParameterArgumentCaptor.getAllValues();
    this.verifyPushObjectListParameter(setParameters.get(0));
}
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)

Example 3 with GetResultImpl

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl in project open-smart-grid-platform by OSGP.

the class JdlmsObjectToStringUtilTest method testDescribeGetResults.

@Test
public void testDescribeGetResults() {
    final GetResult getResult1 = new GetResultImpl(DataObject.newInteger32Data(100), AccessResultCode.SUCCESS);
    final GetResult getResult2 = new GetResultImpl(DataObject.newVisibleStringData("Test".getBytes()), AccessResultCode.OBJECT_UNDEFINED);
    final String description = JdlmsObjectToStringUtil.describeGetResults(Arrays.asList(getResult1, getResult2));
    assertThat(description).isEqualTo("{SUCCESS, DOUBLE_LONG Value: 100 - OBJECT_UNDEFINED, VISIBLE_STRING Value: Test}");
}
Also used : GetResult(org.openmuc.jdlms.GetResult) GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) Test(org.junit.jupiter.api.Test)

Example 4 with GetResultImpl

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl in project open-smart-grid-platform by OSGP.

the class JdlmsObjectToStringUtilTest method testDescribeGetResultWithSuccess.

@Test
public void testDescribeGetResultWithSuccess() {
    final GetResult getResult = new GetResultImpl(DataObject.newInteger32Data(100), AccessResultCode.SUCCESS);
    final String description = JdlmsObjectToStringUtil.describeGetResult(getResult);
    assertThat(description).isEqualTo("SUCCESS, DOUBLE_LONG Value: 100");
}
Also used : GetResult(org.openmuc.jdlms.GetResult) GetResultImpl(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl) Test(org.junit.jupiter.api.Test)

Example 5 with GetResultImpl

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl 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));
    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)

Aggregations

GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)14 GetResult (org.openmuc.jdlms.GetResult)11 Test (org.junit.jupiter.api.Test)8 DataObject (org.openmuc.jdlms.datatypes.DataObject)6 ArrayList (java.util.ArrayList)5 AttributeAddress (org.openmuc.jdlms.AttributeAddress)3 PushSetupAlarmDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto)3 AccessResultCode (org.openmuc.jdlms.AccessResultCode)2 SetParameter (org.openmuc.jdlms.SetParameter)2 AssertionsForClassTypes.catchThrowable (org.assertj.core.api.AssertionsForClassTypes.catchThrowable)1 PowerQualityObjectMetadata (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.GetActualPowerQualityCommandExecutor.PowerQualityObjectMetadata)1 ChannelElementValuesDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto)1