use of org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method checkSsldPendingFirmwareUpdateReturnsTrueAndDeletesPendingUpdateWithMatchingCorrelationUid.
@Test
void checkSsldPendingFirmwareUpdateReturnsTrueAndDeletesPendingUpdateWithMatchingCorrelationUid() {
final String correlationUid = "correlation-uid-matching-pending-update";
final CorrelationIds ids = new CorrelationIds(ORGANISATION_IDENTIFICATION, DEVICE_IDENTIFICATION, correlationUid);
final List<FirmwareVersion> firmwareVersions = Collections.singletonList(new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_2));
final SsldPendingFirmwareUpdate matchingPendingFirmwareUpdate = this.anSsldPendingFirmwareUpdate(437L, new Date(), DEVICE_IDENTIFICATION, correlationUid);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(Arrays.asList(this.anSsldPendingFirmwareUpdate(457198L, new Date(), DEVICE_IDENTIFICATION, "some-other-correlation-uid"), matchingPendingFirmwareUpdate, this.anSsldPendingFirmwareUpdate(94085089L, new Date(), DEVICE_IDENTIFICATION, "yet-another-correlation-uid")));
final boolean hasPendingFirmwareUpdate = this.firmwareManagementService.checkSsldPendingFirmwareUpdate(ids, firmwareVersions);
assertThat(hasPendingFirmwareUpdate).isTrue();
verify(this.ssldPendingFirmwareUpdateRepository).delete(matchingPendingFirmwareUpdate);
}
use of org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method handlesOneSsldPendingFirmwareUpdateRetrievingFirmwareVersion.
@Test
void handlesOneSsldPendingFirmwareUpdateRetrievingFirmwareVersion() throws Exception {
final String deviceIdentification = "Test-SSLD-1";
final Ssld ssld = new Ssld(deviceIdentification);
final String correlationUid = "correlation-uid-pending-firmware-update";
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.anSsldPendingFirmwareUpdate(1L, new Date(), deviceIdentification, correlationUid);
final Organisation organisation = new Organisation(ssldPendingFirmwareUpdate.getOrganisationIdentification(), "Organisation", "ORG", PlatformFunctionGroup.USER);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(Collections.singletonList(ssldPendingFirmwareUpdate));
when(this.deviceDomainService.searchActiveDevice(eq(deviceIdentification), any(ComponentType.class))).thenReturn(ssld);
when(this.organisationDomainService.searchOrganisation(organisation.getOrganisationIdentification())).thenReturn(organisation);
this.firmwareManagementService.handleSsldPendingFirmwareUpdate(deviceIdentification);
verify(this.ssldPendingFirmwareUpdateRepository, never()).delete(ssldPendingFirmwareUpdate);
/*
* Verify the firmware version request is made for the device with the
* SsldPendingFirmwareUpdate and that it uses the correlation UID from
* SsldPendingFirmwareUpdate, as this is important for the way the
* firmware version response will be treated later-on in a more complete
* firmware update scenario than the fragment seen here in this unit
* test.
*/
this.assertFirmwareVersionRequested(organisation.getOrganisationIdentification(), deviceIdentification, correlationUid);
}
use of org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method handlesMultipleSsldPendingFirmwareUpdatesWithoutFailure.
@Test
void handlesMultipleSsldPendingFirmwareUpdatesWithoutFailure() throws Exception {
final String deviceIdentification = "Test-SSLD-1";
final Ssld ssld = new Ssld(deviceIdentification);
final String correlationUidMostRecentPendingFirmwareUpdate = "correlation-uid-most-recent";
final long mostRecentCreationMillis = System.currentTimeMillis();
final SsldPendingFirmwareUpdate olderPendingFirmwareUpdate1 = this.anSsldPendingFirmwareUpdate(134562345L, new Date(mostRecentCreationMillis - 3_000_000_000L), deviceIdentification, "correlation-uid-1");
final SsldPendingFirmwareUpdate olderPendingFirmwareUpdate2 = this.anSsldPendingFirmwareUpdate(227587L, new Date(mostRecentCreationMillis - 604_800_000L), deviceIdentification, "correlation-uid-2");
final SsldPendingFirmwareUpdate olderPendingFirmwareUpdate3 = this.anSsldPendingFirmwareUpdate(308943152L, new Date(mostRecentCreationMillis - 123L), deviceIdentification, "correlation-uid-3");
final SsldPendingFirmwareUpdate mostRecentPendingFirmwareUpdate = this.anSsldPendingFirmwareUpdate(4459483L, new Date(mostRecentCreationMillis), deviceIdentification, correlationUidMostRecentPendingFirmwareUpdate);
final Organisation organisation = new Organisation(mostRecentPendingFirmwareUpdate.getOrganisationIdentification(), "Organisation", "ORG", PlatformFunctionGroup.USER);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(Arrays.asList(olderPendingFirmwareUpdate1, olderPendingFirmwareUpdate2, mostRecentPendingFirmwareUpdate, olderPendingFirmwareUpdate3));
when(this.deviceDomainService.searchActiveDevice(eq(deviceIdentification), any(ComponentType.class))).thenReturn(ssld);
when(this.organisationDomainService.searchOrganisation(organisation.getOrganisationIdentification())).thenReturn(organisation);
this.firmwareManagementService.handleSsldPendingFirmwareUpdate(deviceIdentification);
/*
* Verify the older pending firmware updates are deleted. This appears
* to be a reasonable way to deal with multiple records being present.
* The most recent pending update should not be deleted at this point,
* as it is important for the way the firmware version response will be
* treated later-on in a more complete firmware update scenario than the
* fragment seen here in this unit test.
*
* The check is here to confirm the code works as it was meant to be
* implemented. Not so much as a definitive specification as how it
* should work.
*/
final ArgumentCaptor<SsldPendingFirmwareUpdate> pendingUpdateCaptor = ArgumentCaptor.forClass(SsldPendingFirmwareUpdate.class);
verify(this.ssldPendingFirmwareUpdateRepository, atLeastOnce()).delete(pendingUpdateCaptor.capture());
final List<SsldPendingFirmwareUpdate> deletedPendingUpdates = pendingUpdateCaptor.getAllValues();
assertThat(deletedPendingUpdates).containsExactlyInAnyOrder(olderPendingFirmwareUpdate1, olderPendingFirmwareUpdate2, olderPendingFirmwareUpdate3);
/*
* Check that a get firmware version message is sent for the most recent
* pending firmware update.
*/
this.assertFirmwareVersionRequested(organisation.getOrganisationIdentification(), deviceIdentification, correlationUidMostRecentPendingFirmwareUpdate);
}
use of org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method handleSsldPendingFirmwareUpdate.
public void handleSsldPendingFirmwareUpdate(final String deviceIdentification) {
final List<SsldPendingFirmwareUpdate> ssldPendingFirmwareUpdates = this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification);
if (CollectionUtils.isEmpty(ssldPendingFirmwareUpdates)) {
return;
}
/*
* A pending firmware update record was stored for this device earlier.
* This means this method is probably called following a firmware
* update. Retrieve the firmware version from the device to have the
* current version that is installed available.
*
* If multiple pending update records exist, it is not really clear what
* to do. The following approach assumes the most recently created one
* is relevant, and other pending records are out-dated.
*/
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate;
if (ssldPendingFirmwareUpdates.size() == 1) {
ssldPendingFirmwareUpdate = ssldPendingFirmwareUpdates.get(0);
} else {
LOGGER.warn("Found multiple pending firmware update records for SSLD: {}", ssldPendingFirmwareUpdates);
ssldPendingFirmwareUpdate = this.getMostRecentSsldPendingFirmwareUpdate(ssldPendingFirmwareUpdates).orElseThrow(() -> new AssertionError("No most recent pending firmware update from a non-empty list"));
this.deleteOutdatedSsldPendingFirmwareUpdates(ssldPendingFirmwareUpdates, ssldPendingFirmwareUpdate);
}
final String organisationIdentification = ssldPendingFirmwareUpdate.getOrganisationIdentification();
final String correlationUid = ssldPendingFirmwareUpdate.getCorrelationUid();
LOGGER.info("Handling SSLD pending firmware update for device identification: {}, organisation identification: {} and correlation UID: {}.", deviceIdentification, organisationIdentification, correlationUid);
try {
final int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
this.getFirmwareVersion(organisationIdentification, deviceIdentification, correlationUid, DeviceFunction.GET_FIRMWARE_VERSION.name(), messagePriority, this.getFirmwareVersionDelay);
} catch (final FunctionalException e) {
LOGGER.error("Caught exception when calling get firmware version", e);
}
}
use of org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionWithNonMatchingCorrelationUid.
@Test
void testHandleGetFirmwareVersionWithNonMatchingCorrelationUid() {
final List<FirmwareVersionDto> versionsOnDevice = new ArrayList<>();
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = Mockito.mock(SsldPendingFirmwareUpdate.class);
final List<SsldPendingFirmwareUpdate> ssldPendingFirmwareUpdates = Collections.singletonList(ssldPendingFirmwareUpdate);
when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(any())).thenReturn(ssldPendingFirmwareUpdates);
when(ssldPendingFirmwareUpdate.getCorrelationUid()).thenReturn("differentUid");
this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDevice, CORRELATION_IDS, "messageType", 1, ResponseMessageResultType.OK, null);
verify(this.webServiceResponseMessageSender).send(this.responseMessageCaptor.capture());
final ResponseMessage responseMessage = this.responseMessageCaptor.getValue();
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(CORRELATION_IDS).withResult(ResponseMessageResultType.OK).withMessagePriority(1).withMessageType(MessageType.GET_FIRMWARE_VERSION.name()).build();
assertThat(responseMessage).usingRecursiveComparison().ignoringFields("dataObject").isEqualTo(expectedResponseMessage);
}
Aggregations