use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticResponseDto in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutorTest method testHappy.
@Test
public void testHappy() throws Exception {
// SETUP
when(this.dlmsObjectConfigService.getDlmsObjectForCommunicationMethod(this.device, DlmsObjectType.GSM_DIAGNOSTIC)).thenReturn(new DlmsObject(DlmsObjectType.GSM_DIAGNOSTIC, this.classId, this.obisCode));
// SETUP - mock return data objects
final GetResult result2 = mock(GetResult.class);
final GetResult result3 = mock(GetResult.class);
final GetResult result4 = mock(GetResult.class);
final GetResult result5 = mock(GetResult.class);
final GetResult result6 = mock(GetResult.class);
final GetResult result7 = mock(GetResult.class);
when(result2.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(result3.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(result4.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(result5.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(result6.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(result7.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
final DataObject operator = mock(DataObject.class);
when(result2.getResultData()).thenReturn(operator);
when(operator.getValue()).thenReturn(new byte[] { 65, 66 });
final DataObject modemRegistrationStatus = mock(DataObject.class);
when(result3.getResultData()).thenReturn(modemRegistrationStatus);
when(modemRegistrationStatus.getValue()).thenReturn(2);
final DataObject csStatus = mock(DataObject.class);
when(result4.getResultData()).thenReturn(csStatus);
when(csStatus.getValue()).thenReturn(3);
final DataObject psStatus = mock(DataObject.class);
when(result5.getResultData()).thenReturn(psStatus);
when(psStatus.getValue()).thenReturn(4);
final DataObject cellInfo = mock(DataObject.class);
when(result6.getResultData()).thenReturn(cellInfo);
final DataObject cellId = mock(DataObject.class);
final DataObject locationId = mock(DataObject.class);
final DataObject signalQuality = mock(DataObject.class);
final DataObject bitErrorRate = mock(DataObject.class);
final DataObject mcc = mock(DataObject.class);
final DataObject mnc = mock(DataObject.class);
final DataObject channelNumber = mock(DataObject.class);
when(cellInfo.getValue()).thenReturn(Arrays.asList(cellId, locationId, signalQuality, bitErrorRate, mcc, mnc, channelNumber));
when(cellId.getValue()).thenReturn(128L);
when(locationId.getValue()).thenReturn(1);
when(signalQuality.getValue()).thenReturn((short) 2);
when(bitErrorRate.getValue()).thenReturn((short) 3);
when(mcc.getValue()).thenReturn(4);
when(mnc.getValue()).thenReturn(5);
when(channelNumber.getValue()).thenReturn(6L);
final DataObject adjacentCells = mock(DataObject.class);
when(result7.getResultData()).thenReturn(adjacentCells);
final DataObject adjacentCell = mock(DataObject.class);
when(adjacentCells.getValue()).thenReturn(Collections.singletonList(adjacentCell));
final DataObject adjacentCellId = mock(DataObject.class);
final DataObject adjacentCellSignalQuality = mock(DataObject.class);
when(adjacentCell.getValue()).thenReturn(Arrays.asList(adjacentCellId, adjacentCellSignalQuality));
when(adjacentCellId.getValue()).thenReturn(256L);
when(adjacentCellSignalQuality.getValue()).thenReturn((short) 7);
when(this.dlmsHelper.getAndCheck(eq(this.connectionManager), eq(this.device), eq("Get GsmDiagnostic"), any())).thenReturn(Arrays.asList(result2, result3, result4, result5, result6, result7));
// CALL
final GetGsmDiagnosticResponseDto result = this.executor.execute(this.connectionManager, this.device, this.request, this.messageMetadata);
// VERIFY calls to mocks
verify(this.dlmsMessageListener).setDescription(String.format("Get GsmDiagnostic, retrieve attributes: %s, %s, %s, %s, %s, %s", this.createAttributeAddress(2), this.createAttributeAddress(3), this.createAttributeAddress(4), this.createAttributeAddress(5), this.createAttributeAddress(6), this.createAttributeAddress(7)));
verify(this.dlmsObjectConfigService).getDlmsObjectForCommunicationMethod(this.device, DlmsObjectType.GSM_DIAGNOSTIC);
// VERIFY contents of the return value
assertThat(result.getOperator()).isEqualTo("AB");
assertThat(result.getModemRegistrationStatus()).isEqualTo(ModemRegistrationStatusDto.fromIndexValue(2));
assertThat(result.getCircuitSwitchedStatus()).isEqualTo(CircuitSwitchedStatusDto.fromIndexValue(3));
assertThat(result.getPacketSwitchedStatus()).isEqualTo(PacketSwitchedStatusDto.fromIndexValue(4));
assertThat(result.getCellInfo().getCellId()).isEqualTo(128L);
assertThat(result.getCellInfo().getLocationId()).isEqualTo(1);
assertThat(result.getCellInfo().getSignalQuality()).isEqualTo(SignalQualityDto.fromIndexValue(2));
assertThat(result.getCellInfo().getBitErrorRate()).isEqualTo(BitErrorRateDto.fromIndexValue(3));
assertThat(result.getCellInfo().getMobileCountryCode()).isEqualTo(4);
assertThat(result.getCellInfo().getMobileNetworkCode()).isEqualTo(5);
assertThat(result.getCellInfo().getChannelNumber()).isEqualTo(6);
assertThat(result.getAdjacentCells().size()).isEqualTo(1);
assertThat(result.getAdjacentCells().get(0).getCellId()).isEqualTo(256L);
assertThat(result.getAdjacentCells().get(0).getSignalQuality()).isEqualTo(SignalQualityDto.fromIndexValue(7));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticResponseDto in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method execute.
@Override
public GetGsmDiagnosticResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final GetGsmDiagnosticRequestDto getGsmDiagnosticQuery, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final DlmsObject dlmsObject = this.dlmsObjectConfigService.getDlmsObjectForCommunicationMethod(device, DlmsObjectType.GSM_DIAGNOSTIC);
final AttributeAddress[] addresses = this.createAttributeAddresses(dlmsObject);
final String addressesDescriptions = JdlmsObjectToStringUtil.describeAttributes(addresses);
conn.getDlmsMessageListener().setDescription("Get GsmDiagnostic, retrieve attributes: " + addressesDescriptions);
LOGGER.info("Get GsmDiagnostic, retrieve attributes: {}", addressesDescriptions);
final List<GetResult> getResultList = this.dlmsHelper.getAndCheck(conn, device, "Get GsmDiagnostic", addresses);
LOGGER.info("GetResultList: {}", describeGetResults(getResultList));
if (!getResultList.stream().allMatch(result -> result.getResultCode() == AccessResultCode.SUCCESS)) {
throw new ProtocolAdapterException("Get gsm diagnostic failed for " + device.getDeviceId());
}
return this.createGetGsmDiagnosticResponse(getResultList);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticResponseDto in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutor method createGetGsmDiagnosticResponse.
private GetGsmDiagnosticResponseDto createGetGsmDiagnosticResponse(final List<GetResult> getResultList) throws ProtocolAdapterException {
final String operator = this.getOperator(getResultList);
final ModemRegistrationStatusDto registrationStatus = this.getRegistrationStatus(getResultList);
final CircuitSwitchedStatusDto circuitSwitchedStatus = this.getCircuitSwitchedStatus(getResultList);
final PacketSwitchedStatusDto packetSwitchedStatusDto = this.getPacketSwitchedStatus(getResultList);
final CellInfoDto cellInfo = this.getCellInfo(getResultList);
final List<AdjacentCellInfoDto> adjacentCells = this.getAdjacentCells(getResultList);
final Date captureTimeDto = this.getCaptureTime(getResultList);
return new GetGsmDiagnosticResponseDto(operator, registrationStatus, circuitSwitchedStatus, packetSwitchedStatusDto, cellInfo, adjacentCells, captureTimeDto);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetGsmDiagnosticResponseDto 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());
}
Aggregations