GetFirmwareVersionsCommandExecutor extends AbstractCommandExecutor<Void, List<FirmwareVersionDto>> { @Override public List<FirmwareVersionDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final Void useless) throws ProtocolAdapterException { if (Protocol.forDevice(device).isSmr5()) { return this.getFirmwareVersions(conn, device, FOR_SMR_5); } return this.getFirmwareVersions(conn, device, FOR_DSMR_4_2_2); } @Autowired  GetFirmwareVersionsCommandExecutor(final DlmsHelper dlmsHelper); @Override Void fromBundleRequestInput(final ActionRequestDto bundleInput); @Override ActionResponseDto asBundleResponse(final List<FirmwareVersionDto> executionResult); @Override List<FirmwareVersionDto> execute(final DlmsConnectionManager conn, final DlmsDevice device,
            final Void useless);  }
@Test public void returns3FirmwareVersionsForDsmr422Device() throws Exception { final DlmsDevice device = new DlmsDevice(); final GetResult getResult1 = new GetResultBuilder().build(); final GetResult getResult2 = new GetResultBuilder().build(); final GetResult getResult3 = new GetResultBuilder().build(); when(this.helperService.getAndCheck(same(this.connectionHolder), same(device), eq("retrieve firmware versions"), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_COMMUNICATION_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)))).thenReturn(asList(getResult1, getResult2, getResult3)); when(this.helperService.readString(getResult1.getResultData(), FirmwareModuleType.ACTIVE_FIRMWARE.getDescription())).thenReturn("string1"); when(this.helperService.readString(getResult2.getResultData(), FirmwareModuleType.MODULE_ACTIVE.getDescription())).thenReturn("string2"); when(this.helperService.readString(getResult3.getResultData(), FirmwareModuleType.COMMUNICATION.getDescription())).thenReturn("string3"); final List<FirmwareVersionDto> result = this.executor.execute(this.connectionHolder, device, null); Assertions.assertThat(result) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new FirmwareVersionDto(FirmwareModuleType.ACTIVE_FIRMWARE, "string1"), new FirmwareVersionDto(FirmwareModuleType.MODULE_ACTIVE, "string2"), new FirmwareVersionDto(FirmwareModuleType.COMMUNICATION, "string3")); }
@Test public void returns4FirmwareVersionsForSmr51Device() throws Exception { final DlmsDevice device = new DlmsDevice(); device.setProtocol(Protocol.SMR_5_1); final GetResult getResult1 = new GetResultBuilder().build(); final GetResult getResult2 = new GetResultBuilder().build(); final GetResult getResult3 = new GetResultBuilder().build(); final GetResult getResult4 = new GetResultBuilder().build(); when(this.helperService.getAndCheck(same(this.connectionHolder), same(device), eq("retrieve firmware versions"), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_COMMUNICATION_MODULE_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)), refEq(new AttributeAddress(CLASS_ID, OBIS_CODE_MBUS_DRIVER_ACTIVE_FIRMWARE_VERSION, ATTRIBUTE_ID)))) .thenReturn(asList(getResult1, getResult2, getResult3, getResult4)); when(this.helperService.readString(getResult1.getResultData(), FirmwareModuleType.ACTIVE_FIRMWARE.getDescription())).thenReturn("string1"); when(this.helperService.readString(getResult2.getResultData(), FirmwareModuleType.MODULE_ACTIVE.getDescription())).thenReturn("string2"); when(this.helperService.readString(getResult3.getResultData(), FirmwareModuleType.COMMUNICATION.getDescription())).thenReturn("string3"); when(this.helperService.readString(getResult4.getResultData(), FirmwareModuleType.M_BUS_DRIVER_ACTIVE.getDescription())).thenReturn("string4"); final List<FirmwareVersionDto> result = this.executor.execute(this.connectionHolder, device, null); Assertions.assertThat(result) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new FirmwareVersionDto(FirmwareModuleType.ACTIVE_FIRMWARE, "string1"), new FirmwareVersionDto(FirmwareModuleType.MODULE_ACTIVE, "string2"), new FirmwareVersionDto(FirmwareModuleType.COMMUNICATION, "string3"), new FirmwareVersionDto(FirmwareModuleType.M_BUS_DRIVER_ACTIVE, "string4")); }