Search in sources :

Example 6 with SsldPendingFirmwareUpdate

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);
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 7 with SsldPendingFirmwareUpdate

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);
}
Also used : ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Example 8 with SsldPendingFirmwareUpdate

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);
}
Also used : ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Example 9 with SsldPendingFirmwareUpdate

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);
    }
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 10 with SsldPendingFirmwareUpdate

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);
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) ArrayList(java.util.ArrayList) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) Test(org.junit.jupiter.api.Test)

Aggregations

SsldPendingFirmwareUpdate (org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate)11 Test (org.junit.jupiter.api.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 FirmwareModuleType (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType)4 Date (java.util.Date)3 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)2 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)2 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)2 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)2 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)2 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)2 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)2 ComponentType (org.opensmartgridplatform.shared.exceptionhandling.ComponentType)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Given (io.cucumber.java.en.Given)1 ArrayList (java.util.ArrayList)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1